我正在研究一个非常简单的Java应用程序,需要使用用户名和密码进行保护。我必须使用Active Directory进行身份验证。我只能允许经过身份验证的用户访问它。我不需要任何种类的组/角色检查来确定用户可以看到或不看。我正在使用JETTY来运行应用程序。Jetty - JAAS和活动目录 - 只有身份验证?
我一直在尝试相当一段时间来实现与Jetty的LDAP登录模块。但每次提交登录表单时,我都会收到“!role”消息的403错误。
HTTP ERROR 403
Problem accessing /JAAS/. Reason:
!role
码头时,我提交登录表单标准输出:
码头日志文件时,我提交登录表单(我在日志中输入出现的用户名,所以认证的一部分,似乎工作):在web.xml的
0:0:0:0:0:0:0:1 - - [18/Jul/2013:17:28:38 +0000] "GET /JAAS/ HTTP/1.1" 302 0
0:0:0:0:0:0:0:1 - - [18/Jul/2013:17:28:38 +0000] "GET /JAAS/login.html HTTP/1.1" 304 0
0:0:0:0:0:0:0:1 - - [18/Jul/2013:17:28:47 +0000] "POST /JAAS/j_security_check HTTP/1.1" 302 0
0:0:0:0:0:0:0:1 - username [18/Jul/2013:17:28:47 +0000] "GET /JAAS/ HTTP/1.1" 403 1362
提取物那里的安全约束和安全洛克声明:
<security-constraint>
<web-resource-collection>
<web-resource-name>Entire Application</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<role-name>*</role-name>
</security-role>
<security-role>
<role-name>Domain Users</role-name>
</security-role>
<security-role>
<role-name>MyLocalGroup</role-name>
</security-role>
LDAP登录模块配置文件(ldaploginmodule.conf):
myloginmodule {
org.eclipse.jetty.plus.jaas.spi.LdapLoginModule required
debug="true"
debugNative="true"
contextFactory="com.sun.jndi.ldap.LdapCtxFactory"
hostname="ldapserver"
port="389"
bindDn="CN=Administrator,CN=Users,DC=mydomain,DC=test,DC=local"
bindPassword="secret"
directGroupExtraction="true"
userGroupAttribute="cn"
allRolesMode="authOnly"
userFilter="(objectClass=organizationalPerson)"
authenticationMethod="simple"
forceBindingLogin="true"
userBaseDn="DC=mydomain,DC=test,DC=local"
userRdnAttribute="cn"
userIdAttribute="sAMAccountName"
userPasswordAttribute="unicodePwd"
userObjectClass="user"
roleSearch="(member={0})"
roleName="cn"
roleSubtree="true"
roleBaseDn="CN=Users,DC=mydomain,DC=test,DC=local";
};
码头领域配置(MY-jaas.xml):
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- JAAS TEST -->
<Call name="addBean">
<Arg>
<New class="org.eclipse.jetty.plus.jaas.JAASLoginService">
<Set name="Name">Test JAAS Realm</Set>
<Set name="LoginModuleName">myloginmodule</Set>
<Set name="roleClassNames">
<Array type="java.lang.String">
<Item>org.eclipse.jetty.plus.jaas.JAASRole</Item>
</Array>
</Set>
</New>
</Arg>
</Call>
</Configure>
最后,码头启动命令:
java -Xdebug -Djava.naming.referral=follow -Djava.security.auth.login.config=etc/ldaploginmodule.conf -jar start.jar etc/my-jaas.xml
我检查了Windows安全事件日志,并且确实看到登录成功的审核条目r我在登录表单中提供的用户。
事情是,我不需要任何角色。我只想执行身份验证并允许所有经过身份验证的用户访问应用程序。
任何想法如何我只能进行身份验证,并避免角色?我正在考虑重写LdapLoginModule类并强制一个我将在web.xml中声明的“虚拟”角色。但我不确定这是否是正确的做法。