環境
認証されたユーザーが、組織によって公開された API で使用するOAuth2 ベアラー トークンを作成できるようにするアプリケーションを開発しています。アイデアは、GitHub のPersonal API tokensと同様に、ユーザーがそのようなトークンを自己生成/取り消しできるようにすることです。その後、ユーザーは発行されたトークンを使用して、保護されたリソースへのプログラムによるアクセスを取得できます。この構成では、OAuth の「クライアント」、「認可サーバー」、「リソース サーバー」が組織に属します。今のところ、これらのサービスはすべて同じプロセスにあります。
この目的のために、私はResource Owner Password Credentials Grantタイプをサポートしようとしています。実装環境は以下で構成されます。
- スプリングブーツ
- Spring セキュリティ OAuth2
実装の制約の 1 つは、保存されているパスワードにアクセスできないことです。この処理は、実際の認証を行う内部 Web サービスに委任されます。
問題
保存されたパスワードにアクセスできないという制約があるため、構成されたデフォルトは使用できません。これは、プロバイダーの によって返されるオブジェクトDaoAuthenticationProvider
によって提供されるパスワードにアクセスする必要があるためです。UserDetails
UserDetailsService
AuthenticationProvider
これをカスタム実装に置き換える必要があると思います。ただし、そうしようとするすべての試みが効果を発揮するわけではないようです。
parent
以下は のリファレンスに正しく登録されているように見えますAuthenticationManager
が、実行時に委任されません (DaoAuthenticationProvider
優先されるため):
@Configuration
public class SecurityConfig extends GlobalAuthenticationConfigurerAdapter {
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(new AuthenticationProvider() {
@Override
public boolean supports(Class<?> authentication) {
// For testing this is easier, but should check for UsernamePasswordAuthentication.class
return true;
}
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
// Perform custom logic...
return authentication;
}
});
}
}
私が何をしようとしても(以下の参考文献を参照してください)、私は常に次の2つのプロバイダをメソッドで呼び出すProviderManager
ときに取得します:BasicAuthenticationFilter
Authentication authResult = authenticationManager.authenticate(authRequest)
doFilter
[ org.springframework.security.authentication.AnonymousAuthenticationProvider@366815e4, org.springframework.security.authentication.dao.DaoAuthenticationProvider@5da3e311 ]
AuthorizationServerSecurityConfigurer
これは'sclientCredentialsTokenEndpointFilter
メソッドの結果である可能性があると思います。ただし、このクラスはマークされfinal
ているため、カスタマイズできません。
提案や指針をいただければ幸いです。
資力
私が試した/研究したこと:
- http://projects.spring.io/spring-security-oauth/docs/oauth2.html#toc_7
- http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-change-the-authenticationmanager-and-add-user-accounts
- Spring Security 3.2: @Autowire は、Spring MVC アプリケーションの Java 構成とカスタム AuthenticationProvider では機能しませんか?
- カスタム フィルターで Java 構成を使用して AuthenticationManager を挿入する方法
- Spring Security と Java Config を使用したカスタム認証プロバイダー
- https://gist.github.com/SlyDen/9408539 -https://github.com/royclarkson/spring-rest-service-oauth/blob/master/src/main/java/hello/WebSecurityConfiguration.java
- https://github.com/spring-projects/spring-boot/blob/master/spring-boot-samples/spring-boot-sample-web-secure/src/main/java/sample/ui/secure/SampleWebSecureApplication.ジャワ
- https://github.com/spring-projects/spring-security-oauth/blob/master/samples/oauth2/sparklr/src/main/java/org/springframework/security/oauth/examples/sparklr/config/OAuth2ServerConfig.ジャワ
- https://github.com/spring-projects/spring-security-oauth/blob/6d9de66787cb60249f0de00ffe9075366a803924/tests/annotation/vanilla/src/main/java/demo/Application.java
- https://github.com/spring-projects/spring-security-javaconfig/blob/master/samples/oauth2-sparklr/src/main/java/org/springframework/security/oauth/examples/sparklr/config/SecurityConfiguration.ジャワ