2010-05-11 36 views
0

我有一個在Netbeans的(6.8)開發和(6)使用LDAP(活動目錄)在Tomcat中工作正常,一個簡單的web應用程序。從Tomcat轉換LDAP到GlassFish

我需要將其轉換爲EE(JSF2),所以我正在從Tomcat移動到GlassFish(v3)。

我已經改變了網頁文件,XHTML和配置的XML文件。但是,我無法獲取GlassFish LDAP配置進行身份驗證。

我附加了舊的web.xml和server.xml(來自Tomcat)片段以及新的web.xml,sun-web.xml和GlassFish配置的各個部分。

如果有人可以幫我找出我在哪裏丟失了一塊將允許用戶進行身份驗證,我將不勝感激。 (順便說一下,我不使用角色,只是對LDAP數據庫進行身份驗證已經足夠了。)

現在,我的應用程序會提示我輸入用戶,當我嘗試訪問'受保護的文件'區域,GlassFish服務器在未通過身份驗證時會引發異常。因爲它在Tomcat下工作,所以我知道我有正確的信息,我只是不知道如何格式化它以讓GlassFish傳遞它。

謝謝。

TOMCAT FILES: - Tomcat的server.xml中:

  • 的web.xml:

    <web-resource-collection> 
        <web-resource-name>Protected Area</web-resource-name> 
        <description>Authentication Required</description> 
        <url-pattern>/faces/protected/*</url-pattern> 
    </web-resource-collection> 
    
    <auth-constraint> 
        <role-name>*</role-name> 
    </auth-constraint> 
    

    *

    BASIC 請輸入您的用戶名和密碼:

GLASSFISH FILES: (我啓用了安全性面板上的安全管理器,默認領域設置'LDAPRealm',並添加了「-Djava.naming.referral = follow」JVM選項。) - domain.xml:

<auth-realm name="certificate" classname="com.sun.enterprise.security.auth.realm.certificate.CertificateRealm" /> 
<auth-realm classname="com.sun.enterprise.security.auth.realm.ldap.LDAPRealm" name="LdapRealm"> 
    <property description="()" name="search-bind-password" value="xxxxxxxx" /> 
    <property description="()" name="search-bind-dn" value="cn=xxxxxxxx,ou=Administrators,ou=Information Technology,ou=ITTS,ou=Administrative,ou=xxx,dc=xxxxxx,dc=xxx" /> 
    <property name="jaas-context" value="ldapRealm" /> 
    <property name="base-dn" value="ou=xxx,dc=xxxxxx,dc=xxx" /> 
    <property name="directory" value="ldap://xxxx.xxxxxx.xxx:389" /> 
    <property name="search-filter" value="(&amp;(objectClass=user)(sAMAccountName=%s))" /> 
</auth-realm> 

-web.xml:

<security-constraint> 
    <display-name>protected</display-name> 

    <web-resource-collection> 
     <web-resource-name>ProtectedArea</web-resource-name> 
     <description/> 
     <url-pattern>/faces/protected/*</url-pattern> 
    </web-resource-collection> 

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

    <security-role> 
    <description/> 
    <role-name>*</role-name> 
    </security-role> 

    <login-config> 
    <auth-method>FORM</auth-method> 
    <realm-name>LDAPRealm</realm-name> 
    <form-login-config> 
     <form-login-page>/faces/login.xhtml</form-login-page> 
     <form-error-page>/faces/loginError.xhtml</form-error-page> 
    </form-login-config> 
    </login-config> 
  • 太陽網。XML:

這裏是它拋出異常:

SEVERE: SEC1113: Exception in LdapRealm when trying to authenticate user. 
javax.security.auth.login.LoginException: javax.security.auth.login.LoginException: User yyyyyyy not found. 
     at com.sun.enterprise.security.auth.realm.ldap.LDAPRealm.findAndBind(LDAPRealm.java:450) 
+0

不是真的有關NB的問題... – vkraemer 2010-05-11 14:54:26

+0

我很困惑你的評論。我沒有把它標記爲NB問題,我只提到我使用NB作爲IDE。 我通過你的個人資料看到你對gf有一定的瞭解。你能提供任何有關我在這裏失蹤的信息嗎?謝謝。 – Jon 2010-05-12 11:44:12

回答

0

好了,我已經解決了這個問題。 Glassfish似乎沒有像Tomcat那樣對羣體寬容。使用*作爲組名不適合我。

  • domain.xml中,我加入這一行:
<property name="assign-groups" value="Domain Users" /> 

- 「域用戶」 是在Active Directory中的組,每個人都被投入時,他們的帳戶創建。 (此應用只需要驗證一個人是AD內,則使用內部安全應用程式內的訪問。)

  • 在web.xml,該AUTH-約束必須被添加到「安全約束上」 :
<auth-constraint> 
    <description/> 
    <role-name>users</role-name> 
</auth-constraint> 

- 「用戶」 在sun-web.xml中引用,但不能在我的應用程序。

  • sun-web.xml中,需要這種映射到 「用戶」 和 「域用戶」 鏈接:

& LT安全 - 角色 - 映射& GT

&lt role-name &gt users &lt /role-name &gt 
&lt group-name &gt Domain Users &lt /group-name &gt  

& lt/security-role-mapping & gt

- 顯然,此消息編輯功能不能很好地處理引號或代碼中的gt和lt字符。上面的代碼應該有正確的符號。 (我想stackoverflow需要更好的測試...)

看來我缺少的關鍵組件是domain.xml中的「assign-groups」。

希望這可以幫助任何有此問題的人。