2010-06-26 76 views
1

我正在嘗試使用Glassfish中的JAAS來處理我的Web應用程序中針對Active Directory的身份驗證和授權。首先,我寫了一些POJO程序,可以成功連接到我的AD,並對我設置的用戶和組進行身份驗證。所以我確信我的web應用程序中使用的用戶名,密碼和組是正確的。Glassfish JAAS活動目錄

我跟隨This tutorial在Glassfish中設置Realm以處理我的webapp中的身份驗證和授權。我用我想要的數據修改了我的web.xml和sun-web.xml。

的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> 
<display-name>myapp</display-name> 
<welcome-file-list> 
    <welcome-file>index.jsp</welcome-file> 
</welcome-file-list> 
<login-config> 
    <auth-method>FORM</auth-method> 
    <realm-name>activedirectory</realm-name> 
    <form-login-config> 
    <form-login-page>/login.jsp</form-login-page> 
    <form-error-page>/error.html</form-error-page> 
    </form-login-config> 
</login-config> 
<security-role> 
    <role-name>authorized</role-name> 
</security-role> 
<security-constraint> 
    <display-name>Security</display-name> 
    <web-resource-collection> 
    <web-resource-name>Secured</web-resource-name> 
    <url-pattern>/*</url-pattern> 
    </web-resource-collection> 
    <auth-constraint> 
    <role-name>authorized</role-name> 
    </auth-constraint> 
    <user-data-constraint> 
<transport-guarantee>NONE</transport-guarantee> 
    </user-data-constraint> 
</security-constraint> 
</web-app> 

和我的sun-web.xml中

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd"> 
<sun-web-app error-url=""> 
    <context-root>/myapp</context-root> 
    <security-role-mapping> 
<role-name>authorized</role-name> 
<group-name>Test</group-name> 
    </security-role-mapping> 
    <class-loader delegate="true"/> 
    <jsp-config> 
    <property name="keepgenerated" value="true"> 
     <description>Keep a copy of the generated servlet class java code.</description> 
    </property> 
    </jsp-config> 
</sun-web-app> 

我的境界

name: activedirectory 
class name: com.sun.enterprise.security.auth.realm.ldap.LDAPRealm 
JAAS context: ldapRealm 
Directory: ldap://myADServersIPAddress:389 
Base DN: DC=myAD,DC=com 
search-filter    (&(objectClass=user)(userPrincipalName=%s)) 
search-bind-password  fakepasswordhere 
group-search-filter  (&(objectClass=group)(member=%d)) 
search-bind-dn   DN=Administrator 

該錯誤消息我在日誌中獲取的,當我登錄,它失敗是

Login failed: javax.security.auth.login.LoginException: 
javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID- 
0C090290, comment: AcceptSecurityContext error, data 525, v893] 

我做了一些關於錯誤代碼「data 525」的研究,顯然這意味着用戶名無效。我使用的ID和密碼,我知道是有效的,我知道是我的sun-web.xml中定義的「測試」的成員。我已經嘗試過使用當前設置的userPrincipal格式(username @ domain)以及sAMAccountName表單(域\用戶名),但沒有運氣。我還更改了我的領域中的搜索過濾器,以使用sAMAccountName,其中userPrincipalName是,並且這兩個組合都無法使用。有沒有人有任何線索或建議?我覺得我已經完成了這項研究,而且我非常接近,但是在這一點上非常困難。謝謝,如果有人真的花時間閱讀所有這些!

回答

1

我實際測試的內容可能是您的查找憑證,因爲您基於DN = Administrator進行搜索,對嗎?你有沒有嘗試給它的全部dn到search-bind-dn的管理員帳號?通常默認情況下,會根據您的信息DN=Administrator, CN=Users, DC=myAD, DC=com

0

我同意REW - 我的search-bind-dn必須完全符合搜索綁定標識的要求。