Spring security spring security 3.1中的多会话

Spring security spring security 3.1中的多会话,spring-security,Spring Security,我们开发了一个需要不同身份验证的web应用程序,在我的例子中是代理和成员。详情如下: 代理配置文件页位于 会员资料页位于 这两个页面都由springSecurityFilterChain过滤 但我这里有一些问题。首先,我在代理配置文件页面登录,并成功登录。但随后我打开了成员页面,我得到了HTTP状态403-访问被拒绝。我想实现的情况是代理和成员都可以登录 这是我的web.xml <?xml version="1.0" encoding="UTF-8"?><web-app xml

我们开发了一个需要不同身份验证的web应用程序,在我的例子中是代理和成员。详情如下:

代理配置文件页位于 会员资料页位于 这两个页面都由springSecurityFilterChain过滤 但我这里有一些问题。首先,我在代理配置文件页面登录,并成功登录。但随后我打开了成员页面,我得到了HTTP状态403-访问被拒绝。我想实现的情况是代理和成员都可以登录

这是我的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>spring-security-hello-world</display-name>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>

<servlet>
    <servlet-name>mvc-dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>mvc-dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/mvc-dispatcher-servlet.xml,
        /WEB-INF/spring-security.xml
    </param-value>
</context-param>

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
这是我的spring-security.xml

<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">

<!-- <http pattern="/agent/login" security="none" /> -->

<http pattern="/member/**">
    <intercept-url pattern="/**" access="ROLE_MEMBER" />
    <form-login login-page="/member_login" default-target-url="/member/profile"
        authentication-failure-url="/member_loginfailed" />
    <logout logout-success-url="/member_logout" />
</http>

<http auto-config="true">
    <intercept-url pattern="/agent/**" access="ROLE_AGENT" />
    <form-login login-page="/agent_login" default-target-url="/agent/profile"
        authentication-failure-url="/agent_loginfailed" />
    <logout logout-success-url="/agent_logout" />
</http>

<authentication-manager>
    <authentication-provider>
        <user-service>
            <user name="agent" password="123456" authorities="ROLE_AGENT" />
        </user-service>
    </authentication-provider>

    <authentication-provider>
        <user-service>
            <user name="member" password="123456" authorities="ROLE_MEMBER" />
        </user-service>
    </authentication-provider>
</authentication-manager>
注:
在我的情况下,一个用户只能有一个角色(代理或仅成员)

如果您在同一浏览器中执行此操作,那么您的代理和角色\u agent将用于访问限制为角色\u成员的页面。您可以将角色成员添加到access=ROLE\u AGENT,ROLE\u MEMBER以进行检查。

你好,freakman,谢谢您的回答。但在我的例子中,一个用户只能有一个角色,即代理或成员。你对我的案子有什么解决办法吗?谢谢。然后尝试使用access=hasAnyRole'ROLE\u MEMBER',ROLE\u AGENT'作为/MEMBER/**模式,您不会以这种方式更改用户角色,而是允许成员或代理访问特定的url。当然,如果你认为代理是一个成员超集,他真的应该有权访问成员页面。再次感谢你的回答。但在我的情况下,代理角色没有访问成员页面的权限。。你能给我另一个解决方案吗?所以你需要决定他是否能够查看该页面: