이것은 스프링 부트 및 스프링 보안을 사용하는 제 코드입니다. 문제는 내가 로그 아웃 (Thyemleaf 사용)을 사용하여 로그 아웃이 작동하지 않는 경우입니다. Thyemleaf를 사용스프링 부트 및 스프링 보안에서 로그 아웃이 작동하지 않습니다.
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Autowired
private DataSource dataSource;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.jdbcAuthentication()
.dataSource(dataSource)
.usersByUsernameQuery("select username as principal, password as credentials,active from users where username=?")
.authoritiesByUsernameQuery("select username as principal,roles as role from users_roles where username=?")
.rolePrefix("ROLE_")
.passwordEncoder(new Md5PasswordEncoder());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin()
.loginPage("/login");
http
.authorizeRequests()
.antMatchers("/index1").permitAll();
http
.authorizeRequests()
.antMatchers("/user").hasRole("USER")
.and()
.logout();
http
.authorizeRequests()
.antMatchers("/adpage").hasRole("ADMIN");
http
.exceptionHandling().accessDeniedPage("/403");
http
.logout().permitAll();
}
}
링크 :
<li><a th:href="@{/login?logout}">logout</a></li>
모든 로그 아웃을 제외하고 작동 GET 요청을 사용하여 사용자가 로그 아웃 수있는이 방식을 변경하여 비 POST 로그 아웃을 지원할 수있다, 내 말은 세션이 만료되지 않을 때 로그 아웃 링크를 클릭하십시오. 예를 들어 저는 사용자이고 가입 (로그인)이므로 로그 아웃합니다. 사용자 페이지에 대한 액세스 권한을 여전히 얻습니다. –
http://stackoverflow.com/questions/40885178/logout- 봄철 안전하지 않습니다. HTTP'POST'를 사용해야하고 URL은'/ logout'입니다. – dur