【发布时间】:2019-07-18 15:10:27
【问题描述】:
假设登录网址是“/login”。 有两个受保护的资源:
- “/保护”
- “/”是一个 302 重定向到“/protected”
当未经身份验证的用户尝试访问“/protected”时,他会被重定向到“/login”。在后台创建了一个会话,其中存储了 SPRING_SECURITY_SAVED_REQUEST,以便在成功登录后将用户重定向到“/protected”网址。
这是 Spring Security 的默认行为。
我的问题: 即使用户调用“/”,也会创建会话。因此,所有在没有有效登录信息的情况下调用域的机器人和渗透测试都会在底层 redis 层中创建会话。
当没有存储重定向请求或至少将它们限制为有效后端端点的定义列表时,如何防止创建这些会话?
我的安全配置:
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();
}
【问题讨论】:
标签: spring spring-boot session spring-security