【问题标题】:Changing authenticated user's granted role and authentication token in spring-security在 spring-security 中更改经过身份验证的用户的授予角色和身份验证令牌
【发布时间】:2011-07-12 19:55:01
【问题描述】:

我正在尝试更改会话中的身份验证令牌。

场景是;

匿名用户到达主页,AnonymousAuthenticationToken 保存到会话,ROLE_ANONYMOUS 授予权限。但是当他/她想要创建项目时,应用程序强制他/她登录。在他登录后他/她的 openId 帐户我正在创建一个 OpenIDAuthenticationTokenROLE_USER 授予权限并用它替换存储的令牌。他/她可以通过ROLE_USER访问任何允许的地方。

当他想注销时,我正在从上下文中删除令牌,这没关系。

但是;

当他/她再次登录时,我可以观察到令牌在上下文中被替换,他/她无法访问 ROLE_USER 允许的部分。

登录前登录;

Current authentication is org.springframework.security.authentication.AnonymousAuthenticationToken@6fabe8e0: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@fffe9938: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: B1F6870C9FF93DCB50A6FD71302A9090; Granted Authorities: ROLE_ANONYMOUS

登录后登录;

 After refreshing authentication: [org.springframework.security.openid.OpenIDAuthenticationToken@c9e3a81c: Principal: Hugo Weaving; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@fffe9938: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: B1F6870C9FF93DCB50A6FD71302A9090; Granted Authorities: ROLE_USER, attributes : null]

我暂时没有分配 open id 属性,但我认为这不是问题。

这是我的 web.xml

<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>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
        /WEB-INF/security-context.xml
    </param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

这是我的 security.xml

<http auto-config="true">
        <intercept-url pattern="/first.jsp" access="ROLE_USER" />
        <intercept-url pattern="/second.jsp" access="ROLE_USER" />
        <openid-login login-page="/index.html"></openid-login>
    </http>

**基本上,我是在强迫想要访问 first.jspsecond.jsp 的客户使用他们的开放 ID 帐户登录。

【问题讨论】:

  • 我终于解决了。这个问题不在身份验证令牌中,而是在我的工作流程中。改了一行代码就搞定了。
  • 你评论了哪一行?

标签: authentication spring-security


【解决方案1】:

终于解决了。这个问题不在身份验证令牌中,而是在我的工作流程中。改了一行代码就搞定了。

【讨论】:

    猜你喜欢
    • 2014-03-26
    • 2016-11-30
    • 2020-10-20
    • 1970-01-01
    • 2017-07-10
    • 2016-08-15
    • 2013-06-12
    • 2019-03-12
    • 1970-01-01
    相关资源
    最近更新 更多