Glassfish JAAS活动目录

时间:2010-06-26 02:32:00

标签: web-applications active-directory java-ee glassfish jaas

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

我正在关注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中定义的“Test”的成员。我已经尝试了userPrincipal格式(用户名@域)与当前设置以及sAMAccountName表单(域\用户名)没有运气。我还改变了我的领域中的搜索过滤器以使用sAMAccountName,其中userPrincipalName是,并且使用两个组合也不起作用。有没有人有任何线索或建议?我觉得我已经完成了这项研究,而且我非常接近,但在这一点上非常困难。如果有人真的花时间阅读所有这些内容,感谢您!

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

我同意REW - 我的search-bind-dn必须完全有资格让搜索绑定ID生效。

相关问题