简体   繁体   English

Spring Security禁用rememberMe不起作用

[英]Spring Security disable rememberMe doesn't work

I have Spring Boot application. 我有Spring Boot应用程序。 It is necessary to send Authorization header on every request otherwise deny access to resource. 必须在每个请求上发送Authorization标头,否则将拒绝对资源的访问。

But if I made request with this header once I can send requests without it and receive content of resource. 但是,如果我一次使用此标头发出请求,则可以不使用它发送请求并接收资源内容。 Why? 为什么? Where am I wrong in code? 我在哪里写错代码?

Spring Security configuration: Spring Security配置:

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .rememberMe().disable()
            .csrf().disable()
            .authorizeRequests().anyRequest().fullyAuthenticated().and()
            .httpBasic().and()
            .formLogin().disable()
            .logout().disable();
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .inMemoryAuthentication()
            .withUser("1").password("1").roles("USER");
    }
}

Controller: 控制器:

    @RestController
    public class FooController {

        @RequestMapping("/foo")
        public Bar bar() {
            Bar bar = new Bar();
            return bar;
        }
    }
    http
        .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)

Disable create session. 禁用创建会话。 Session Management 会话管理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM