【发布时间】:2018-01-08 07:15:50
【问题描述】:
Spring Boot Web MVC 允许一个用户在任何地方一次登录,如果他/她想登录,就会强制登录。
我在网上搜索了很多,我发现我可以做类似的事情:
http.sessionManagement()
.invalidSessionUrl("/invalidSession")
.maximumSessions(1)
.maxSessionsPreventsLogin(true)
.sessionRegistry(sessionRegistry())
但这不起作用,我可以从其他浏览器登录而不会出现任何错误。
我从上周开始尝试解决这个问题,但没有找到任何可行的解决方案。
更新
http.antMatchers("/", "/register/**", "/email/**","/captcha.png/**")
.permitAll()
.antMatchers("/login/**")
.permitAll()// Basically I'm allowing parameters for login so
// .antMatchers("/services/ownerTaxInformation/**")
.permitAll()
.antMatchers("/forgot/password/**", "/user/verify/**")
.permitAll()
.antMatchers("/user/resetPassword*")
.hasAuthority("CHANGE_PASSWORD_PRIVILEGE")
.anyRequest()
.authenticated()
.and()
.addFilterBefore(jCaptchaAuthenticationFilter(),UsernamePasswordAuthenticationFilter.class)
.formLogin()
.loginPage("/login")
.permitAll().and()
.csrf()
.disable()
.sessionManagement()
.invalidSessionUrl("/invalidSession")
.maximumSessions(1)
.maxSessionsPreventsLogin(true)
.sessionRegistry(sessionRegistry()).and()
.sessionFixation()
.none()
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/")
.invalidateHttpSession(false)
.deleteCookies("JSESSIONID")
.permitAll();
【问题讨论】:
-
添加 .sessionRegistry(sessionRegistry) 而不是 .sessionRegistry(sessionRegistry())
标签: spring spring-mvc spring-boot spring-security