【发布时间】:2019-05-19 01:51:10
【问题描述】:
我的登录页面是http://localhost:8080/nradmin/welcome 我的主页(成功登录后)是http://localhost:8080/nradmin/home
我想退出,不再能够访问任何其他页面,例如主页,而只能访问欢迎(登录)页面。如果我在注销后在浏览器上输入http://localhost:8080/nradmin/home,我将继续访问主页而无需登录。
我已经实现了从抽象类 WebSecurityConfigurerAdapter 覆盖的以下方法:
@Override
protected void configure(HttpSecurity http) throws Exception { http
.authorizeRequests()
.antMatchers("/welcome").permitAll()
.antMatchers("/home", "/account/**", "/price/**").hasRole("ADMIN")
.antMatchers("/home", "/account/**", "/price/**").access("hasRole('ROLE_ADMIN')")
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginPage("/welcome")
.defaultSuccessUrl("/home")
.and()
.logout()
.invalidateHttpSession(true)
.clearAuthentication(true)
.logoutSuccessUrl("/welcome")
.logoutUrl("/welcome")
.deleteCookies()
.permitAll()
.and()
.exceptionHandling()
.accessDeniedPage("/welcome")
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED);
}
@Override
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication() .withUser("username").password(passwordEncoder().encode("12345")).roles(LoginDataConstants.ROLE_ADMIN)
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
有人知道怎么做吗?
【问题讨论】:
标签: spring-boot spring-security logout