1

我正在尝试在 Glassfish 中使用 JAAS 来处理我的 Web 应用程序中针对 Active Directory 的身份验证和授权。首先,我编写了一些 POJO 程序,它们可以成功连接到我的 AD 并针对我设置的用户和组进行身份验证。因此,我确信我在 Web 应用程序中使用的用户名、密码和组是正确的。

我正在按照本教程在 Glassfish 中设置一个领域来处理我的 web 应用程序中的身份验证和授权。我已经用我想要的数据修改了我的 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 格式(用户名@域)以及 sAMAccountName 表单(域\用户名),但没有成功。我还更改了我的领域中的搜索过滤器以使用 userPrincipalName 所在的 sAMAccountName 并且使用这两种组合也不起作用。有没有人有任何线索或建议?我觉得我已经完成了研究,我非常接近,但在这一点上非常卡住。如果有人真的花时间阅读所有这些,谢谢!

4

2 回答 2

1

我实际上要测试的可能是您的查找凭据,因为您是基于 DN=Administrator 进行搜索的,对吧?您是否尝试将完整的 dn 提供给 search-bind-dn 的管理员帐户?通常默认情况下,这将DN=Administrator, CN=Users, DC=myAD, DC=com基于您上面的信息。

于 2010-06-29T03:06:41.960 回答
0

我同意 REW - 我的 search-bind-dn 必须完全符合 search-bind id 的工作条件。

于 2010-08-02T13:05:49.550 回答