我是新来的春靴。我试图使一个REST服务与mongodb后端。在mongodb中,我创建了Customers表和second users表。在users表中,我将用户名、密码和角色的列定义为一个系列。试图从表用户验证访问REST服务的用户。在互联网上,当我们扩展WebSecurityConfigurerAdapter或扩展GlobalAuthenticationConfigurerAdapter时,我发现了两种情况。在第一种情况下,我已经在web上找到了我们自定义AuthenticationProvider的例子,但在第二种情况下,我们处理userdetailsservice。我的问题是,如何才能更深入地研究这个问题?即使在源代码中看到巨大的界面结束类,我也不能像在教程中那样做这些工作。这两种方式的主要区别是什么?谁处理或者如何处理Spring-boot安全性?
@vmaric我没有使用它,但看起来逻辑是一样的:
@Configuration
public class AuthenticationManagerConfiguration extends
GlobalAuthenticationConfigurerAdapter {
@Override
public void init(AuthenticationManagerBuilder auth) {
auth.inMemoryAuthentication() // ... etc. <-------
}
}
根据Spring Security,您必须提供安全配置:
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter
具有提供AuthenticationManager的重写方法:
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {...}
可以在内存中实现:
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication() .withUser("user").password("password").roles("USER").and() .withUser("admin").password("password").roles("USER", "ADMIN");
}
或实现依赖于您的UserDetailsService实现:
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
authenticationManagerBuilder
.userDetailsService(userDetailsService)
.passwordEncoder(passwordEncoder());
}
下面是一个如何在Spring Boot