1
このコード私は認証できるデータベースからユーザを追加するのに使用しますが、このコードは一度実行されると問題はどのようにして登録できますか? 私はこの解決策を持っていますHow to adding new user to Spring Security in runtimeしかし私はそれを私の実際のコードに追加して助けてください。 これはあなたが単に別のauthenticationProvider
を設定することができます私のコードSpringでユーザを動的に追加するJava
@Configuration
@EnableWebSecurity
protected static class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
DataSource dataSource;
@Autowired
UserRepository userRepository;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
for (UsersEntity user : userRepository.findAll())
if (user.getUsername() != null && user.getPassword() != null)
auth.
inMemoryAuthentication()
.passwordEncoder(UsersEntity.ENCODE_PASS)
.withUser(user.getUsername()).password(user.getPassword())
.roles("USER");
}
@Bean
@Override
public AuthenticationManager authenticationManagerBean()
throws Exception {
return super.authenticationManagerBean();
}
}
私は単純化のために最初の解決策を使用しました:)ありがとうございました –
これは、「UserRepository」という1つの場所で全体の「ユーザーの検索」ロジックを維持するという利点があるためです。 JDBCソリューションはそれを複製する傾向があり、何かが変更された場合、維持するのが難しくなります。 –
こんにちはjdbcソリューションは、新しいロールを動的に更新しますか? –