在spring spring中注册registerglobal(),configure(),configureglobal(),configureglobalsecurity之间的区别 [英] Difference between registerglobal(), configure(), configureglobal(),configureglobalsecurity in spring security
问题描述
我有三个代码片段,它们都在创建内存中的身份验证。那么它如何影响用不同的方法名称定义它?
registerGlobal
configure
configureGlobal
configureGlobalSecurity
ONE
I have below three code snippets all doing the same thing creating in-memory authentication. So how it impacts defining it in different method names?
registerGlobal
configure
configureGlobal
configureGlobalSecurity
ONE
public void registerGlobal(AuthenticationManagerBuilder auth) throws
Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER").and()
.withUser("admin").password("password").roles("USER",
"ADMIN");
}
}
TWO
TWO
@Override
protected void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles
("USER");
}
三
Three
public void configureGlobal(AuthenticationManagerBuilder auth)
throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles
("USER");
}
FOURTH
FOURTH
<pre lang="java">
@Autowired
public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("user").roles("USER");
}
我的尝试:
搜索spring.io和其他博客,但只找到用法而不是解释
What I have tried:
Searched spring.io and other blogs but only found usages not explanations
推荐答案
我将我的示例项目中的方法重命名为以下并让我惊讶它工作和验证用户。
I renamed the method in my sample project to below and to my surprise it working and authenticating the users.
@Autowired
public void anyMethodName(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("user").roles("USER");
}
您可以任意命名并且有效
configureGlobal方法的名称并不重要。但是,仅在使用@EnableWebSecurity,@ EnableWebMvcSecurity,@ EnableGlobalMethodSecurity或@EnableGlobalAuthentication注释的类中配置AuthenticationManagerBuilder非常重要。否则会产生不可预测的结果。
这篇关于在spring spring中注册registerglobal(),configure(),configureglobal(),configureglobalsecurity之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!