【问题标题】:Converting LDAP from Tomcat to GlassFish将 LDAP 从 Tomcat 转换为 GlassFish
【发布时间】:2011-02-18 03:16:48
【问题描述】:

我有一个简单的网络应用程序,它是在 Netbeans(6.8) 中开发的,并且使用 LDAP(Active Directory) 在 Tomcat(6) 中运行良好。

我需要将其转换为 EE (JSF2),因此我要从 Tomcat 迁移到 GlassFish(v3)。

我已将 web 文件更改为 xhtml 并配置了 xml 文件。但是,我无法让 GlassFish LDAP 配置进行身份验证。

我正在附加我的旧 web.xml 和 server.xml(来自 Tomcat)sn-ps 以及新 web.xml、sun-web.xml 和 GlassFish 配置的部分。

如果有人能帮助我找出我遗漏了允许用户通过身份验证的部分,我将不胜感激。 (顺便说一句,我没有使用角色,只是针对 LDAP 数据库进行身份验证就足够了。)

就像现在一样,当我尝试访问“受保护”区域中的文件时,我的应用程序会提示我输入用户,并且 GlassFish 服务器在验证失败时会引发异常。因为它在 Tomcat 下工作,所以我知道我有正确的信息,我只是不知道如何格式化它以让 GlassFish 传递它。

谢谢。

TOMCAT 文件: - 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>
    

    *

    基本的 请输入您的用户名和密码:

玻璃鱼文件: (我在安全面板上启用了安全管理器,将默认领域设置为“LDAPRealm”,并添加了“-Djava.naming.referral=follow”JVM 选项。) - 域.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)

【问题讨论】:

  • 不是关于 NB 的问题...
  • 我对你的评论感到困惑。我没有将其标记为 NB 问题,我只提到我使用 NB 作为 IDE。我从您的个人资料中看到您对 gf 有所了解。您能否就我在这里缺少的内容提供任何见解?谢谢。

标签: tomcat ldap glassfish


【解决方案1】:

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

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

-- “域用户”是 Active Directory 中的组,每个人在创建帐户时都会加入该组。 (此应用只需要验证一个人是否在 AD 中,它使用内部安全性在应用内进行访问。)

  • 在 web.xml 中,必须将此身份验证约束添加到“安全约束”:
<auth-constraint>
  <description/>
  <role-name>users</role-name>
</auth-constraint>

-- "users" 在 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 /安全角色映射 &gt

-- 显然,这个消息编辑函数不能很好地处理引号或代码中的 gt 和 lt 字符。上面的代码应该有正确的符号。 (我猜 stackoverflow 需要更好的测试......)

看来我缺少的关键组件是 domain.xml 中的“assign-groups”。

希望这可以帮助遇到此问题的其他人。

【讨论】:

    猜你喜欢
    • 2016-03-28
    • 2010-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多