我正在开发一个非常简单的 Java 应用程序,它需要使用用户名和密码进行保护。我必须使用 Active Directory 进行身份验证。我只能允许经过身份验证的用户访问它。我不需要任何类型的组/角色检查来确定用户可以看到或看不到的内容。我正在使用 JETTY 来运行应用程序。
我已经尝试使用 Jetty 实现 LDAP 登录模块已经有一段时间了。但是每次我提交登录表单时,我都会收到带有“!role”消息的 403 错误。
HTTP ERROR 403
Problem accessing /JAAS/. Reason:
!role
提交登录表单时的 Jetty 标准输出:
2013-07-18 19:28:47.035:INFO:oejpjs.LdapLoginModule:Searching for users with filter: '(&(objectClass={0})({1}={2}))' from base dn: DC=mydomain,DC=test,DC=local
2013-07-18 19:28:47.041:INFO:oejpjs.LdapLoginModule:Found user?: true
2013-07-18 19:28:47.042:INFO:oejpjs.LdapLoginModule:Attempting authentication: CN=User Name,OU=ADMIN_HOME,DC=mydomain,DC=test,DC=local
提交登录表单时的 Jetty 日志文件(我输入的用户名出现在日志中,因此部分身份验证似乎有效):
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 和 security-roke 的 web.xml 的摘录:
<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";
};
jetty 领域配置(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>
最后是jetty启动命令:
java -Xdebug -Djava.naming.referral=follow -Djava.security.auth.login.config=etc/ldaploginmodule.conf -jar start.jar etc/my-jaas.xml
我检查了 Windows 安全事件日志,我确实看到了我在登录表单中提供的用户的成功登录审核条目。
问题是,我不需要任何角色。我只想执行身份验证并允许所有经过身份验证的用户访问该应用程序。
知道如何只进行身份验证并避免角色吗?我正在考虑覆盖 LdapLoginModule 类并强制我将在 web.xml 中声明的“虚拟”角色。但我不确定这是否是正确的做法。
最佳答案
您的身份验证成功。
由于您希望允许所有经过身份验证的用户访问所有内容,因此您仍然需要像现在一样保护 URL 模式/*。您可以使用 RegExpAuthorizationFilter(参见 https://wiki.apache.org/solr/SolrSecurity)。现在,他们不在常规分发中包含此类。我在这里 ( https://issues.apache.org/jira/secure/attachment/12572819/SOLR-4470_branch_4x_r1454444.patch ) 找到了代码,它很容易编译。
当您配置过滤器时,指定一个具有任何角色的任意(不存在,如/abcde)URL 模式。它的工作方式是查看请求的 URL 是否与此模式匹配。因为没有,所以它向前移动。但是没有更多的规则,并且允许访问。
因此它需要对所有 URL 进行身份验证,但在身份验证成功后所有有效的 URL 都将可以访问。
我的设置是在 Jetty 上运行的 solr 上下文中。但是,我认为我的所有配置都与标准内容相关联,例如 web.xml。
关于java - Jetty - JAAS 和 Active Directory - 仅身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17730950/