2016-01-26 261 views
4

我玩弄春季安全配置和发现,是最常见的方式来配置内存认证使用configureGlobal()方法:'configure'和'configureGlobal'方法有什么区别?

@Configuration 
@EnableWebMvcSecurity 
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 

    @Autowired 
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{ 
    auth 
     .inMemoryAuthentication() 
     .withUser("user").password("userPwd").roles("USER"); 
    } 
} 

但还有另一种方式,这是不太广泛使用,从WebSecurityConfigurerAdapter首要configure()方法:

@Configuration 
@EnableWebMvcSecurity 
public class SecurityConfig extends WebSecurityConfigurerAdapter { 

    @Override 
    protected void configure(AuthenticationManagerBuilder auth) throws Exception { 
    auth 
     .inMemoryAuthentication(
     .withUser("user").password("userPwd").roles("USER"); 
    } 
} 

我只是想知道,什么是它们之间的区别,什么是使用configureGlobal()方法在configure()一个点?

回答

1

正如spring security doc说:

configureGlobal方法的名称并不重要。然而,其 对于仅在类别 中配置AuthenticationManagerBuilder是重要的,其用@EnableWebSecurity,@EnableGlobalMethodSecurity, 或@EnableGlobalAuthentication注释。否则会产生难以预料的 结果。

相关问题