2014-07-23 4 views
1

저는 스프링 시큐리티 Oauth를 사용하여 안정적인 서비스를 확보하기 위해 노력해 왔습니다. SSL을 사용하여/oauth/token 엔드 포인트를 보호하려고 시도하고 POST 호출만을 허용하려고했습니다. 나는의 DispatcherServlet 컨텍스트해야 현재 응용 프로그램 맥락에서 인증 서버 (즉 AuthorizationEndpoint과 TokenEndpoint)을 가능하게하는스프링 부트 OAuthTokenEndpoint를 재정의하는 방법

편의 주석 상태 @EnableAuthorizationServer을 사용하고

. 의 많은 기능은 AuthorizationServerConfigurer 유형의 @Beans를 사용하여 (예 : AuthorizationServerConfigurerAdapter를 확장하여) 사용자 정의 할 수 있습니다. 사용자는 스프링 보안 기능 (@EnableWebSecurity 등)을 사용하여 인증 끝점 (/ oauth/authorize)을 에 안전하게 보관할 책임이 있지만 HTTP 기본 인증을 사용하여 토큰 끝점 (/ oauth/token)이 자동으로 보호됩니다 클라이언트의 크리 덴셜 하나 이상의 AuthorizationServerConfigurer를 통해 ClientDetailsService를 제공하여 클라이언트를 으로 등록해야합니다.

중대하다

,하지만 난 토큰 엔드 포인트 부분을 무시하거나 POST 전용 나는 내 자원 서버를 확보

@Configuration 
@EnableAuthorizationServer 
protected static class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter { 

    @Bean 
    public TokenStore tokenStore() { 
     return new InMemoryTokenStore() 
    } 

    @Autowired 
    AuthenticationManager authenticationManager 

    @Override 
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) { 
     endpoints 
       .tokenStore(tokenStore()) 
       .authenticationManager(authenticationManager); 

    } 

    @Override 
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception { 
     clients 
       .inMemory() 
       .withClient('testApp') 
       .scopes("read", "write") 
       .authorities('ROLE_CLIENT') 
       .authorizedGrantTypes("password","refresh_token") 
       .secret('secret') 
       .accessTokenValiditySeconds(7200) 

    } 
} 

절편-URL의 XML 구문처럼 호출을 적용 할 수없는 것

@Configuration 
@EnableResourceServer 
protected static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter { 

    @Autowired 
    private RestAuthenticationEntryPoint authenticationEntryPoint; 


    @Override 
    public void configure(HttpSecurity http) throws Exception { 
     http 
       .exceptionHandling() 
        .authenticationEntryPoint(authenticationEntryPoint) 
       .and() 
        .requiresChannel().anyRequest().requiresSecure() 
       .and() 
        .csrf() 
        .requireCsrfProtectionMatcher(new AntPathRequestMatcher("/oauth/authorize")) 
        .disable() 
       .headers() 
        .frameOptions().disable() 
        .sessionManagement() 
        .sessionCreationPolicy(SessionCreationPolicy.STATELESS) 
       .and() 
        .authorizeRequests() 
        .antMatchers("/api/**").authenticated() 
    } 
} 

requiresChannel을 사용하는 Authorization Servers TokenEndpoint 보안에 대한 빌더 구문이 있습니까?

답변

0

나는 내가 봄 부팅을 사용하고 있기 때문에 난 그냥 SecurityProperties를 autowire가 org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerSecurityConfiguration

를 사용하여 내 자신의 설정을 만들어 결국이 라인을 추가 의 Oauth에 SSL에 대한

if (this.security.isRequireSsl()) { 
      http.requiresChannel().anyRequest().requiresSecure(); 
     } 

을 엔드 포인트 그리고 POST 요구 사항에 대한

HTTP.authorizeRequests() .antMatchers (HttpMethod.POST, tokenEndpointPath) 내 설정을 사용하므로

는 그 뒤 @EnableAuthorizationServer을 제거() .fullyAuthenticated() .antMatchers (HttpMethod.GET, tokenEndpointPath) .denyAll .

+0

POST 만 기본값입니다 (2.0.7 이후). 보안 채널 문제에 대한 또 다른 문제가 발생했습니다. https://github.com/spring-projects/spring-security-oauth/issues/480 –