java – security-role-ref无法正常工作
作者:互联网
这些是我的web.xml的内容
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0" metadata-complete="true">
<servlet>
<security-role-ref>
<role-name>MY_GROUP_NAME</role-name>
<role-link>REGISTERED_USER</role-link>
</security-role-ref>
</servlet>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<resource-ref>
<description>My datasource</description>
<res-ref-name>jdbc/XXXXXXXX</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<security-constraint>
<display-name>Example Security Constraint</display-name>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
<!-- Define the context-relative URL(s) to be protected -->
<url-pattern>/protected/`*`</url-pattern>
<!-- If you list http methods, only those methods are protected -->
<http-method>DELETE</http-method>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>PUT</http-method>
</web-resource-collection>
<auth-constraint>
<!-- Anyone with one of the listed roles may access this area -->
<role-name>tomcat</role-name>
<role-name>role1</role-name>
<role-name>REGISTERED_USER</role-name>
</auth-constraint>
</security-constraint>
<!-- Default login configuration uses form-based authentication -->
<login-config>
<auth-method>FORM</auth-method>
<realm-name>Example Form-Based Authentication Area</realm-name>
<form-login-config>
<form-login-page>/protected/login.jsp</form-login-page>
<form-error-page>/protected/error.jsp</form-error-page>
</form-login-config>
</login-config>
<!-- Security roles referenced by this web application -->
<security-role>
<role-name>role1</role-name>
</security-role>
<security-role>
<role-name>tomcat</role-name>
</security-role>
<security-role>
<role-name>REGISTERED_USER</role-name>
</security-role>
</web-app>
当我使用ldap中的组MY_GROUP_NAME中的有效用户执行登录时,request.getRemoteUser()和request.getUserPrincipal()工作正常.针对MY_GROUP_NAME测试用户
String role = request.getParameter("role");
request.isUserInRole(role);
工作良好.
问题是在针对role_USER角色测试用户时不起作用.有没有人看到我在这里失踪的东西?
一些额外的信息
我使用Apache Tomcat v7.0.22
LDAP是OpenDJ 2.4.5
Windows 7操作系统
解决方法:
我没有使用OpenDJ,但根据https://wikis.forgerock.org/confluence/display/OPENDJ/Configure+Apache+Tomcat+with+OpenDJ+as+an+Identity+Store
tomcat角色和LDAP规则之间没有“映射”,因为映射是一对一的,名称应该是相同的.
您要使用的LDAP组应定义为Tomcat角色,您应该在Web描述符的security-role部分使用它们的名称(web.xml).
标签:java,jsp,servlets,tomcat,web-xml 来源: https://codeday.me/bug/20190709/1415006.html