2017-04-11 1 views
0

java configベースの認証に移動した後にauthが認証ステップを通過できません 誰かが説明することができますか、どのようにauthenticationManagerを実装するのですか?spring auth - xmlからjavaの設定に移動

私はここにhttp://localhost:8080/oauth/token?grant_type=password&[email protected]&password=cant_hack_this&client_id=sso-auth-client&client_secret=mySecret

を介して取得するトークンをしようとしたときに、今私は

{ 
    "error": "unauthorized", 
    "error_description": "Full authentication is required to access this resource" 
} 

を取得していますがレポhttps://github.com/mikesockor/SOFqstnこれを実装する方法

@SpringBootApplication 
@EnableResourceServer 
@EnableDiscoveryClient 
//@ImportResource({"classpath*:spring-security-oauth2.xml"}) 

のですか?

<sec:http pattern="/oauth/token" create-session="stateless" authentication-manager-ref="authenticationManager" > 
    <sec:intercept-url pattern="/oauth/token" /> 
    <sec:anonymous enabled="true" /> 
    <sec:http-basic entry-point-ref="clientAuthenticationEntryPoint" /> 
    <sec:custom-filter ref="clientCredentialsTokenEndpointFilter" after="BASIC_AUTH_FILTER" /> 
    <sec:access-denied-handler ref="oauthAccessDeniedHandler" /> 
</sec:http> 

<sec:http auto-config="true" pattern="/oauth/check_token" create-session="stateless" authentication-manager-ref="authenticationManager"> 
    <sec:intercept-url pattern="/oauth/check_token" access="IS_AUTHENTICATED_FULLY" /> 
    <sec:anonymous enabled="false"/> 
    <sec:http-basic entry-point-ref="clientAuthenticationEntryPoint" /> 
</sec:http> 

<sec:http pattern="/**" create-session="stateless" entry-point-ref="oauthAuthenticationEntryPoint" 
      access-decision-manager-ref="accessDecisionManager" > 
    <sec:anonymous enabled="false" /> 
    <sec:intercept-url pattern="/**" /> 
    <sec:custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" /> 
    <sec:access-denied-handler ref="oauthAccessDeniedHandler" /> 
</sec:http> 

また、私は、あなたが持っているあなたは、以下の

まず必要になりますブートで春認証の完全な設定について

{ 
    "timestamp": 1491919124442, 
    "status": 405, 
    "error": "Method Not Allowed", 
    "exception": "org.springframework.web.HttpRequestMethodNotSupportedException", 
    "message": "Request method 'POST' not supported", 
    "path": "/oauth/token" 
} 

答えて

0

を取得

#security.basic.enabled=false 
security.ignored=/** 

にしようとした場合Spring認証を設定するための基本クラスを実装する

@Configuration 
@EnableWebSecurity 
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter { 

    @Autowired 
    private CustomUserDetailsService userDetailsService; 

    @Autowired 
    private AccountAuthenticatoinProvider accountAuthenticationProvider; 

    @Override 
    protected void configure(AuthenticationManagerBuilder auth) throws Exception { 
     auth.userDetailsService(userDetailsService); 
     auth.authenticationProvider(accountAuthenticationProvider); 
    } 

    @Override 
    @Bean 
    public AuthenticationManager authenticationManagerBean() throws Exception { 
     return super.authenticationManagerBean(); 
    } 

} 

次は

@Configuration 
public class OAuth2ServerConfiguration { 

    private static final String RESOURCE_ID = "restservice"; 

    @Configuration 
    @EnableResourceServer 
    protected static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter { 

     ..... 
     @Override 
     public void configure(ResourceServerSecurityConfigurer resources) { 
      // @formatter:off 
      resources 
        .resourceId(RESOURCE_ID).tokenStore(new JwtTokenStore(jwtAccessTokenConverter)); 
      // @formatter:on 
     } 

     @Override 
     public void configure(HttpSecurity http) throws Exception { 
      // @formatter:off 
      http 
        .csrf().disable() 
        .authorizeRequests() 
        .antMatchers("/api/**").authenticated(); 



      // @formatter:on 
     } 

.... 

    } 



    @Configuration 
    @EnableAuthorizationServer 
    protected static class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter { 

     ..... 
     @Override 
     public void configure(ClientDetailsServiceConfigurer clients) throws Exception { 
      // @formatter:off 
      clients 
        .inMemory() 
        .withClient("clientapp") 
        .authorizedGrantTypes("password","refresh_token") 
        .authorities("USER") 
        .scopes("read", "write") 
        .resourceIds(RESOURCE_ID) 
        .secret("123456"); 
      // @formatter:on 
     } 

    } 
..... 

} 

参照してください、次のgitリポジトリをResourceServerConfigurationとAuthorizationServerConfigurationが必要になりますhttps://github.com/cpapidas/Spring-Boot-OAuth2-JWT-MySQL

関連する問題