2017-01-22 3 views
1

스프링 부트와 스프링 시큐리티로 빌드 된 REST API가 있습니다. 나는 스프링 시큐리티가 디폴트 값인 /logout을 요청할 때 현재 사용자를 로깅하는 것으로되어 있다는 문서를 읽었다. 그러나, 나는 이것을 작동시킬 수 없다.)를 사용하여 AngularJS와 당신이 withHttpOnlyFalse을 (사용 선택하면스프링 부트 + 스프링 보안 - 로그 아웃 할 수 없습니다.

{ 
    "timestamp": 1485096094269, 
    "status": 404, 
    "error": "Not Found", 
    "message": "No message available", 
    "path": "/login" 
} 
+0

을 당신은 ('.logout을 제공하지 않습니다)' ; 예를 들어 https://spring.io/guides/gs/securing-web/. 어떤 요청을 하시겠습니까? – jonrsharpe

+0

실제로 추가하려고했습니다. 로그 아웃(); 내가 본 여러 가지 예에서 보았지만 아무런 효과가 없습니다. 위의 예제를 변경하여 로그 아웃을 사용하도록 설정하는 것이 좋습니다. 내가하고있는 요청은 "/ logout"에 대한 GET 요청입니다. – simbro

+1

그래, 구성이 확실히 호출되고 있습니다. ".logout.permitAll()"을 추가했습니다. POST 메서드를 사용하여 "/ logout"및 여전히 동일한 메시지를 기록하고 로그 아웃하지 않았습니다. 다른 사람들이 구성 방법으로 사용하는 것은 무엇입니까? – simbro

답변

0

: 나는 /logout에 요청을 할 때, 나는 다음과 같은 오류가 발생, 그러나

@EnableWebSecurity 
@EnableGlobalMethodSecurity(prePostEnabled = true) 
@Configuration 
class WebSecurityConfig extends WebSecurityConfigurerAdapter { 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
      .authorizeRequests() 
       .anyRequest().fullyAuthenticated() 
       .and() 
      .httpBasic() 
       .and() 
      .csrf().disable(); 
    } 
} 

:

내 보안 구성입니다
.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) 

https://stackoverflow.com/a/43204307/1767316

1

아마도이 질문에 대답하기 조금 늦었 겠지만 누구나 유용 할 수 있습니다. configure() 방법에서

는 예를 들어, logout() 호출을 누락되었습니다

http.authorizeRequests() 
     .anyRequest().fullyAuthenticated() 
     .and() 
     .httpBasic() 
     .and() 
    .logout() // This is missing and is important 
     .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) 
     .logoutSuccessUrl("/login"); 

또한 당신은 당신의 자신의 로그인 페이지 구성 할 수 있습니다

http.authorizeRequests() 
     // this allows the root and resources to be available without logging in 
     .antMatchers("/", "/resources/**").permitAll() 
     // any other type of request will need the credentials 
     .anyRequest().authenticated() 
     .and() 
    // uses the custom login form 
    .formLogin() 
     .loginPage("/login") 
     .defaultSuccessUrl("/home") // redirect to home page 
     .failureUrl("/login?error") // redirect to error page 
     .permitAll() 
     .and() 
    // logout and redirect to login page 
    .logout() 
     .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) 
     .logoutSuccessUrl("/login"); 
관련 문제