[英]Configure Security at Spring Boot
我在春季靴子中很新。 我正在尝试在后端使用mongodb进行REST服务。 在mongodb中,我创建了Customers表,并估算了users表。 在用户表中,我为用户名,密码和角色定义了一系列列。 尝试对来自表用户的访问REST服务的用户进行身份验证。 在Internet上,当我们扩展WebSecurityConfigurerAdapter或扩展GlobalAuthenticationConfigurerAdapter时,发现了两种情况。 在第一种情况下,我在bean上找到了一个在Web上创建自定义AuthenticationProvider的示例,但是在第二种情况下,我们处理了UserDetailsSerivce。 我的问题是我如何才能更深入地研究这个问题? 即使在巨大接口的源代码中观看终端类,我也无法像教程中那样对这些人员进行不同的处理。 这两种方式的主要区别是什么? 谁来处理或如何处理Spring-boot安全?(是否有处理MVC的调度程序servlet之类的东西?)
@vmaric我还没有使用过,但是看起来逻辑是一样的:
@Configuration
public class AuthenticationManagerConfiguration extends
GlobalAuthenticationConfigurerAdapter {
@Override
public void init(AuthenticationManagerBuilder auth) {
auth.inMemoryAuthentication() // ... etc. <-------
}
}
根据Spring Security,您必须提供Security Configuration:
@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上启动SpringSecurity的示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.