我有三个代码片段都在做同样的事情:创建内存中的身份验证.那么它如何影响在不同的方法名称中定义它?
第一:
public void registerGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER").and()
.withUser("admin").password("password").roles("USER","ADMIN");
}
}
Run Code Online (Sandbox Code Playgroud)
第二个:
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
Run Code Online (Sandbox Code Playgroud)
第三个:
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
Run Code Online (Sandbox Code Playgroud)
第四:
@Autowired
public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("user").roles("USER");
}
Run Code Online (Sandbox Code Playgroud)
更新1: 我还想补充一点:
configure()方法存在于WebSecurityConfigurerAdapter类中,而其他类不存在.
更新2:
我将示例项目中的方法重命名为以下内容,令我惊讶的是它正在对用户进行工作和身份验证.
你把它命名为什么,它的工作原理
@Autowired
public void anyMethodName(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("user").roles("USER");
}
Run Code Online (Sandbox Code Playgroud)