将LDAP从Tomcat转换为GlassFish

时间:2010-05-11 12:40:40

标签: tomcat ldap glassfish

我有一个简单的Web应用程序,它是在Netbeans(6.8)中开发的,并且可以使用LDAP(Active Directory)在Tomcat(6)中正常工作。

我需要将其转换为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: (我在Security面板上启用了Security Manager,将Default Realm设置为'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>
  • sun-web.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)

1 个答案:

答案 0 :(得分:0)

好吧,我已经解决了这个问题。 Glassfish似乎不像群体中的Tomcat那样宽容。使用*作为组名不适用于我。

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

- “域用户”是Active Directory中创建帐户时所有人都可以使用的组。 (此应用仅需要验证某人是否在AD内,它使用内部安全性在应用内进行访问。)

  • 在web.xml中,必须将此auth-constraint添加到'security-contraints'中:
<auth-constraint>
  <description/>
  <role-name>users</role-name>
</auth-constraint>

- 在sun-web.xml中引用了“users”,但在我的应用程序中没有引用。

  • 在sun-web.xml中,需要此映射才能将“用户”与“域用户”链接:
  

&amp; lt security-role-mapping&amp; gt

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

&amp; lt / security-role-mapping&amp; gt

- 显然,此消息编辑功能无法在引号或代码中很好地处理gt和lt字符。上面的代码应该有正确的符号。 (我想stackoverflow需要更好的测试...)

我遗漏的关键组件似乎是domain.xml中的“assign-groups”。

希望这有助于其他任何有此问题的人。