2011-04-01 79 views
7

我有一個託管bean與2屬性:userName & password(與其相應的getter和setter方法),以及login()方法訪問數據庫來驗證登錄憑據。HTTPS協議和JSF 2,爲保護資源和登錄

我的問題是,當用戶點擊「登錄」按鈕時,動作必須通過https協議。我如何通過JSF 2實現這一目標?另外,如果我想要保護一些Faces(在https協議下),我該如何實現這一目標?有沒有一種過濾器可以讓我做到這一點?

在此先感謝。

回答

8

您可以在應用程序的web.xml定義一個安全約束:

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

適應的url-pattern包含您的登錄頁和其他所有安全網頁。 https的使用由用戶數據約束來定義。

Java EE tutorial

如果指定的機密或 INTEGRAL作爲安全限制,它 通常意味着使用SSL需要 並適用於匹配URL模式的所有請求 web 資源集合,而不僅僅是登錄對話框的 。

如果你寫了自己的登錄()方法,使用的是GlassFish,你可以看看基於容器的身份驗證與JDBCRealm作爲替代登錄方法。