2016-08-29 20 views
2

私は、Spring Security OAuth 2.0ベースのアプリケーションをJDBCとLDAPで構成しています。 OAuth 2.0仕様では、クライアントシークレットが必要です。Spring Securityでclient_secretを使用しないでトークンを生成する方法OAuth2

私はそれがトークンを生成し、正常に動作し、次のURLを使用してトークンを生成する場合:

/oauth/token?grant_type=password&client_secret=test&client_id=test&username=test&password=test 

を、私はclient_secretなしでトークンを生成しようとすると、それが与える:

401:不正な

error_description:「Bad User Credentials」

が、私は次のようにclient_secretせずにトークンを生成します:

/oauth/token?grant_type=password&username=test&password=test 

securityConfig.java

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

    private static final int EMBEDDED_LDAP_SERVER_PORT = 33388; 

    @Autowired 
    private UserAuthenticationProvider userAuthenticationProvider;  

    @Autowired 
    private LdapAuthenticationProvider ldapAuthenticationProvider; 

    @Autowired 
    private AuthTokenStore oAuthTokenStore;  

    @Autowired 
    private AuthDelegatingAuthenticationEntryPoint delegatingAuthenticationEntryPoint; 

    @Override 
    @Qualifier("authenticationManagerBean") 
    @Bean 
    protected AuthenticationManager authenticationManager() throws Exception { 
     return new ProviderManager(Arrays.asList((AuthenticationProvider) ldapAuthenticationProvider,userAuthenticationProvider)); 
    } 
    @Override 
    protected void configure(HttpSecurity http) throws Exception {  
     http 
      .csrf().disable() 
      .sessionManagement() 
        .sessionCreationPolicy(SessionCreationPolicy.STATELESS) 
        .and() 
      .authorizeRequests() 
        .anyRequest().authenticated() 
        .and() 
      .exceptionHandling().authenticationEntryPoint(delegatingAuthenticationEntryPoint); 
    } 

    @Bean 
    public ResourceServerTokenServices tokenService() { 

     DefaultTokenServices tokenServices = new DefaultTokenServices(); 
     tokenServices.setTokenStore(oAuthTokenStore); 
     tokenServices.setReuseRefreshToken(true); 
     return tokenServices; 
    } 
+0

パスワードは、client_idだけを渡すことができます。クライアントの秘密は必要ありません。/ oauth/token?grant_type = password&username = test&password = test&client_id = CLIENT_ID' –

+0

どうすればこのURLを使用できますか? /oauth/token?grant_type = password&username =テスト&パスワード=テスト&クライアントID = CLIENT_ID @PrasannaKumar –

+0

セキュリティ設定のクライアントIDを言い、そのクライアントIDを渡してください... –

答えて

0

残念ながらあなたの問題を回避する簡単な方法はありません。クライアントタイプが機密であるか、クライアントが他の認証要件をクライアントに
資格証明書を発行した(または割り当てられていた場合

:これはのOAuth2仕様からの引用である

RFC 6749, section 4.3.2 (Resource Owner Password Credentials Grant - Access Token Request):春のセキュリティは非常に厳しい基準を解釈します)、
クライアントは、セクション3.2.1の
のように認証サーバーで認証する必要があります。

春のセキュリティの場合、パスワードの付与は常にこのカテゴリに分類されます。 3.2.1項には、クライアントIDとクライアントパスワードが必要です。

また春のセキュリティドキュメントはこの道を行く: 28.1.1 Authorization Server

あなたは春のセキュリティののOAuth2(推奨されません)あなたが立ち往生しているの認証ロジックを変更したい場合を除き。

私の観点からは問題ありません。クライアントIDとパスワードは何も必要とせず、アプリケーションのセキュリティを少し強化します。

+0

私はこれを取得しません。 Webクライアントを使用してAPIに話をすれば、そのクライアントコードをどこかにハードコードするか、クライアントに送信するだけですか?私はこれがどういう意味か分かりません。 ^^ – displayname

関連する問題