我正尝试在Glassfish中使用JAAS来处理我的web应用程序中针对Active Directory的身份验证和授权。首先,我已经编写了一些POJO程序,可以成功地连接到我的AD,并根据我设置的用户和组进行身份验证。因此,我确信我在web应用程序中使用的用户名、密码和组都是正确的。
我正在遵循This tutorial在Glassfish中设置一个域来处理我的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]我做了一些关于错误代码“数据525”的研究,显然它意味着用户名无效。我使用的id和密码是有效的,并且是sun-web.xml中定义的"Test“的成员。我尝试了当前设置的userPrincipal格式(用户名@域名)以及sAMAccountName表单(域名\用户名),但没有成功。我还在我的领域中更改了搜索过滤器,在userPrincipalName所在的位置使用sAMAccountName,这在使用这两个组合时也不起作用。有谁有什么线索或建议吗?我觉得我已经做了研究,我已经很接近了,但在这一点上却被困住了。如果有人真的花时间读了这篇文章,谢谢!
发布于 2010-06-29 11:06:42
我实际测试的可能是您的查找凭据,因为您是基于DN=Administrator进行搜索的,对吧?您是否尝试将完整dn提供给search-bind-dn的管理员帐户?通常在默认情况下,它会根据你上面的信息进行DN=Administrator, CN=Users, DC=myAD, DC=com。
发布于 2010-08-02 21:05:50
我同意REW的观点-我的search-bind-dn必须完全限定才能使用search-bind id。
https://stackoverflow.com/questions/3122487
复制相似问题