I tried to register several filters in my Spring Security configuration, however I always get the same exception:
04-Nov-2015 14: 35: 23.792 ATTENTION [RMI TCP connection (3) -127.0.0.1] org.springframework.web.context.support.AnnotationConfigWebApplicationContext.refresh An exception occurred while initializing the context - canceled an attempt to update org.springframework.beans .factory.BeanCreationException: error creating a bean named 'Org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration': Injection of autoconnected dependencies failed; nested exception java.lang.IllegalStateException: @Order on WebSecurityConfigurers must be unique. Order 100 has already been used, so it cannot be used on com.payment21.webapp.MultiHttpSecurityConfig $ ApiW ebSecurityConfigurationAdapter $$ EnhancerBySpringCGLIB $$ 35c79fe4 @ 1d381684 too.
Since my own attempts did not work, I tried the exact same code as shown in the Spring Security reference :
@EnableWebSecurity
public class MultiHttpSecurityConfig {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER").and()
.withUser("admin").password("password").roles("USER", "ADMIN");
}
@Configuration
@Order(1)
public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/api/**")
.authorizeRequests()
.anyRequest().hasRole("ADMIN")
.and()
.httpBasic();
}
}
@Configuration
public static class FormLoginWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin();
}
}
}
To isolate the error, I tried replacing web.xml with a Java-based approach, but it didn't work either. I have no idea what’s wrong, doc wrong? Could something be confused with the setting in my application? The system starts correctly if I do not register a second WebSecurityConfigAdapter.
These are my dependencies:
compile 'org.springframework:spring-webmvc:4.2.2.RELEASE'
compile 'org.springframework:spring-messaging:4.2.2.RELEASE'
compile 'org.springframework:spring-websocket:4.2.2.RELEASE'
compile 'org.springframework:spring-aop:4.2.2.RELEASE'
compile'javax.servlet:javax.servlet-api:3.0.1'
compile 'org.springframework.security:spring-security-web:4.0.3.RELEASE'
compile 'org.springframework.security:spring-security-config:4.0.3.RELEASE'
source
share