進行中のスプリングブートプロジェクトに認証および承認サービスを実装しようとしています。JPAベースの認証プロバイダーを実装しましたが、正常に動作しています。LDAP認証プロバイダーを同じプロジェクトに追加し、ユーザー認証タイプに応じて認証方法を切り替えるにはどうすればよいですか?
以下は私のコードです
@Configuration
public class ProjectConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UsernamePasswordAuthProvider authProvider;
@Autowired
private LdapAuth ldapAuth;
@Autowired
private LdapAuthenticationpopulator ldapAuthenticationpopulator;
private String ldapUrls = "ldap://localhost:3890";
private String ldapSecurityPrincipal = "cn=admin,dc=mycompany,dc=com";
private String ldapPrincipalPassword = "admin";
private String userDnPattern = "uid={0}";
@Autowired
private UsernamePasswordAuthFilter usernamePasswordAuthFilter;
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Order(1)
protected void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.ldapAuthentication()
.contextSource()
.url(ldapUrls)
.managerDn(ldapSecurityPrincipal)
.managerPassword(ldapPrincipalPassword)
.and()
.userDnPatterns(userDnPattern)
.ldapAuthoritiesPopulator(ldapAuthenticationpopulator);
}
@Override
@Order(2)
protected void configure(AuthenticationManagerBuilder auth) {
auth.authenticationProvider(authProvider);
}
@Override
protected void configure(HttpSecurity http) {
http.addFilterAt(usernamePasswordAuthFilter,
BasicAuthenticationFilter.class);
}
@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
}
私のLDAP資格情報は正しいですが、その方法に到達していません。アプリケーションのDB ex(LDAP、JPA、SSO)から認証方法を取得し、対応する認証プロバイダーメソッドを実行するにはどうすればよいですか?
MultipleAuthenticationProvidersの複数のドキュメントを調べましたが、あまり明確ではありませんでした。これについて考えられる解決策があるかどうかをお知らせください。前もって感謝します
私はこれに対する一つの解決策を見つけました。LDAP対応またはJPA認証対応のプロパティをDBに配置し、特定の認証メソッドを呼び出しているブール値に応じて、実行時にそれらをロードしました。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加