2016-09-27 60 views
-1

我想創建一個簡單的JSP/Servlet登錄頁面,使用websphere ldap存儲庫進行身份驗證。 我發現的所有例子看起來都非常複雜,只有數百行代碼需要驗證。如何創建使用websphere存儲庫的登錄頁面?

這真的太複雜了嗎?

有沒有人有一個簡單的例子或文章解釋如何根據已配置爲websphere聯合存儲庫的ldap存儲庫驗證用戶/通行證?

我真的很感激任何幫助。 謝謝

+0

您是否希望保護Web應用程序或WebSphere Application Server環境本身? –

+0

Web應用程序 –

+0

您希望在哪個版本的WebSphere Application Server中實現此目的? (試圖縮小可能的與您有關的鏈接列表) –

回答

1

這在現實中很簡單。你需要以下幾部分:

1)的形式指向j_security_check登錄頁面 看到這個網頁的詳細說明Customizing web application login

非常簡單的例子是這樣的:

<form method="POST" action="j_security_check"> 
<input type="text" name="j_username"> 
<input type="text" name="j_password" autocomplete="off"> 
<\form> 

2)安全性web.xml配置

類似這樣的:

<login-config> 
<auth-method>FORM</auth-method> 
<realm-name>Example Form-Based Authentication</realm-name> 
<form-login-config> 
<form-login-page>/login.jsp</form-login-page> 
<form-error-page>/login.jsp</form-error-page> 
</form-login-config> 
</login-config> 

加上安全約束:應用服務器和用戶註冊表配置上啓用

<security-constraint> 
     <display-name>allResources</display-name> 
     <web-resource-collection> 
      <web-resource-name>allResources</web-resource-name> 
      <url-pattern>/*</url-pattern> 
     </web-resource-collection> 
     <auth-constraint> 
      <role-name>users</role-name> 
     </auth-constraint> 
    </security-constraint> 

3)應用的安全性。

就是這樣。

+0

完美工作!但是現在我有以下問題。 我的項目部署在/ TrainingProject,我有index.html和login.html ...它直接到index.html沒有登錄請求,我想強制它。這可能嗎? –

+0

@RanieriMazili這很奇怪,因爲如果你在模式'/ *'上面使用了上面的安全約束,所有的應用程序資源,包括index.html都應該被保護,如果你訪問index.html,登錄表單應該會自動出現。因此,必須丟失一些東西 - 無論是應用程序安全性未啓用還是用戶角色映射到「所有人」而不是「全部驗證」 – Gas

+0

好的,此功能目前不是必需的。我還有一個疑問。 爲了使它與單點登錄一起工作,我是否必須對當前代碼進行任何修改,或者一旦我在WAS端設置了所有內容後,它將自動處理它? –