相关疑难解决方法(0)

在Spring安全性中registerGlobal(),configure(),configureGlobal(),configureGlobalSecurity之间的区别

我有三个代码片段都在做同样的事情:创建内存中的身份验证.那么它如何影响在不同的方法名称中定义它?

  1. registerGlobal
  2. 配置
  3. configureGlobal
  4. configureGlobalSecurity

第一:

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)

java spring spring-security

29
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×1

spring ×1

spring-security ×1