Annotation Interface EnableGlobalAuthentication
@Retention(RUNTIME)
@Target(TYPE)
@Documented
@Import(AuthenticationConfiguration.class)
public @interface EnableGlobalAuthentication
The
EnableGlobalAuthentication annotation signals that the annotated class can
be used to configure a global instance of AuthenticationManagerBuilder. For
example:
@Configuration
@EnableGlobalAuthentication
public class MyGlobalAuthenticationConfiguration {
@Bean
public UserDetailsService userDetailsService() {
UserDetails user = User.withDefaultPasswordEncoder()
.username("user")
.password("password")
.roles("USER")
.build();
UserDetails admin = User.withDefaultPasswordEncoder()
.username("admin")
.password("password")
.roles("ADMIN", "USER")
.build();
return new InMemoryUserDetailsManager(user, admin);
}
}
Annotations that are annotated with EnableGlobalAuthentication also signal that
the annotated class can be used to configure a global instance of
AuthenticationManagerBuilder. For example:
@Configuration
@EnableWebSecurity
public class MyWebSecurityConfiguration {
@Bean
public UserDetailsService userDetailsService() {
UserDetails user = User.withDefaultPasswordEncoder()
.username("user")
.password("password")
.roles("USER")
.build();
UserDetails admin = User.withDefaultPasswordEncoder()
.username("admin")
.password("password")
.roles("ADMIN", "USER")
.build();
return new InMemoryUserDetailsManager(user, admin);
}
// Possibly more bean methods ...
}
The following annotations are annotated with EnableGlobalAuthentication
Configuring AuthenticationManagerBuilder in a class without the
EnableGlobalAuthentication annotation has unpredictable results.