Spring引导安全性:请求的url创建不需要的redis会话
假设登录url为“/login”。 有两种受保护的资源:Spring引导安全性:请求的url创建不需要的redis会话,spring,spring-boot,session,spring-security,Spring,Spring Boot,Session,Spring Security,假设登录url为“/login”。 有两种受保护的资源: “/受保护” “/”是指向“/protected”的302重定向 当未经身份验证的用户尝试访问“/protected”时,他将被重定向到“/login”。在后台创建了一个会话,其中存储了SPRING\u SECURITY\u SAVED\u请求,以便在成功登录后将用户重定向到“/protected”url 这是spring security的默认行为 我的问题: 即使用户调用“/”也会创建会话。因此,所有在没有有效登录信息的情况下调用
- “/受保护”
- “/”是指向“/protected”的302重定向
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/password/forgot/**").permitAll()
.antMatchers("/password/reset/**").permitAll()
.antMatchers("/css/**").permitAll()
.antMatchers("/js/**").permitAll()
.antMatchers("/img/**").permitAll()
.antMatchers( "/favicon.ico").permitAll()
.antMatchers("/login").permitAll()
.anyRequest().fullyAuthenticated();
http
.formLogin()
.loginPage("/login")
.permitAll()
.successHandler(authSuccessHandler)
.and()
.logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessUrl("/login")
.deleteCookies("SESSION")
.clearAuthentication(true)
.invalidateHttpSession(true)
.permitAll();
http.sessionManagement()
.maximumSessions(1)
.and()
.sessionCreationPolicy(SessionCreationPolicy.NEVER);
http.headers().frameOptions().disable();
http.csrf().disable();
}
您可以通过设置NullRequestCache来避免SPRING\u SECURITY\u保存\u请求,但我想这对您的用例不起作用 或者至少将它们限制在定义的有效后端端点列表中 这可以通过提供requestCache并设置RequestMatcher-
final HttpSessionRequestCache requestCache = new HttpSessionRequestCache();
requestCache.setRequestMatcher(new AntPathRequestMatcher("/**"));
http
.authorizeRequests()
.antMatchers("/", "/home").permitAll()
.anyRequest().authenticated()
.and()
.requestCache().requestCache(requestCache)
.and()...