2017-05-09 12 views
0

私はスプリングセキュリティを使用しており、その修正版を使用しているプロジェクトを持っています。私はデフォルトのSpring '/ oauth/token'エンドポイントに依存し、適切な情報(クライアントIDなど)を持つHTTP POSTを実行すると、access_tokenと200 OK Responseの情報が返されます。トークンを取得した後のスプリングセキュリティとポストタスク

これはSpringで実装されているため、変更する権限がありませんが、レスポンスコードに基づいてポストタスクを設定したいと考えています。誰かが適切な情報で '/ oauth/token'エンドポイントに正常に到達した場合は、何かしたいと思います。私は何を上書きするべきか、この「ポストタスク」がいつ起こるべきかについて、リスナーを設定する際に何をすべきかわかりません。

答えて

0

DaoAuthenticationProviderの後に呼び出されるカスタム認証プロバイダを追加してください。例えば

あなたWebSecurityConfigurerAdapter拡張クラスへの行の下に追加します。UserStateAuthenticationProvider

public class UserStateAuthenticationProvider{ 

    @Override 
    public Authentication authenticate(Authentication authentication) 
     throws AuthenticationException { 

     //....do anything you want like below 
     String name = authentication.getName(); 
     String password = authentication.getCredentials().toString(); 

     return null; 
    } 

    @Override 
    public boolean supports(Class<?> authentication) { 
     return authentication.equals(
      UsernamePasswordAuthenticationToken.class); 
    } 
} 
のように、独自のカスタムクラス

することができ

@Autowired 
UserStateAuthenticationProvider userStateAuthenticationProvider; 



@Autowired 
public void globalUserDetails(AuthenticationManagerBuilder auth) throws 
Exception { 
    auth.userDetailsService(userDetailsService); 
    auth.authenticationProvider(userStateAuthenticationProvider); 
} 

関連する問題