Spring安全OAuth2禁用基于jessionid的会话 [英] spring security oauth2 disable jsessionid based session

查看:36
本文介绍了Spring安全OAuth2禁用基于jessionid的会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有信誉来发表评论,否则post描述的是完全相同的问题。

我已经在Spring4应用程序中成功实现了Spring安全OAuth2 2.0.5。一切正常,我可以生成令牌,并且API请求得到了正确的身份验证。但问题是,一旦API在基于浏览器的应用程序中使用访问令牌进行了身份验证,后续调用就不需要访问令牌了,因为 -Spring Security似乎依赖会话ID来识别和验证用户。 -即使在访问令牌过期后,调用似乎也会生效。

所以看起来Spring只在第一次调用时依赖于访问令牌,然后它依赖于cookie/jessionid。我尝试通过以下方式禁用该行为(向Spakr2学习)-

Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.anonymous().disable();
        //oauth2 recommends that oauth token url should be only available to authorized clients
        http.requestMatchers().antMatchers("/oauth/token").and().authorizeRequests().anyRequest().fullyAuthenticated();
        http.httpBasic().authenticationEntryPoint(oAuth2AuthenticationEntryPoint()).and()
                .addFilterBefore(clientCredentialsTokenEndpointFilter(), BasicAuthenticationFilter.class)
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().exceptionHandling()
                .accessDeniedHandler(oAuth2AccessDeniedHandler);

    }

但这无济于事。在日志中我可以看到-

这篇关于Spring安全OAuth2禁用基于jessionid的会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆