2011-11-17 18 views
0

我有一個Web應用程序,我想與客戶端證書一起使用。我在web.xml中設置了以下內容,並且可以通過https訪問我的應用程序。Glasfish 2.1 CLIENT-CERT如何獲得本金

<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>securedapp</web-resource-name> 
     <url-pattern>/*</url-pattern> 
     <http-method>DELETE</http-method> 
     <http-method>GET</http-method> 
     <http-method>POST</http-method> 
     <http-method>PUT</http-method> 
    </web-resource-collection> 
    <user-data-constraint> 
     <transport-guarantee>CONFIDENTIAL</transport-guarantee> 
    </user-data-constraint> 
</security-constraint> 

<login-config> 
    <auth-method>CLIENT-CERT</auth-method> 
</login-config> 

握手工作正常。我只使用該證書作爲糧食安全措施。我只是想知道提供的證書的主體,因此不需要登錄。但是,當我嘗試從會話中獲得主體時,它是空的。

我也曾嘗試

X509Certificate[] certs = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate"); 

但這也爲NULL。有誰知道我如何從我的證書中獲得校長?

非常感謝 Noush

回答

0

你肯定Glasfish實際上請求客戶端證書?

我試圖做同樣的Tomcat和我發現,那Tomcat的唯一請求客戶端證書,如果你把一個auth-constraintsecurity-constraint這樣的:

<security-constraint> 
    ... 
    <auth-constraint> 
     <role-name>*</role-name> 
    </auth-constraint> 
    ... 
</security-constraint> 

沒有一個auth-constraint的Tomcat不需要登錄用戶,因此不需要請求客戶端證書。 transport-guarantee僅強制使用HTTPS。

但即便如此,我不得不將證書的用戶添加到容器的角色管理中,併爲用戶分配角色,否則用戶將無法訪問該URL並獲得HTTP 401響應。所以如果你只是想要一個客戶端證書而不將它與容器中的用戶關聯起來,那麼它將不起作用。

在Tomcat中,您可以配置一個境界接受沒有角色的用戶時,role-name*,但你仍然有用戶添加到認證領域,如果你想接受的所有證書這不利於信任並自己檢查證書主體。也許這與Glasfish是可能的。