diff --git a/config/config.gradle b/config/config.gradle
index 986aa6e403..579972d887 100644
--- a/config/config.gradle
+++ b/config/config.gradle
@@ -35,6 +35,7 @@ dependencies {
"org.springframework:spring-orm:$springVersion",
"org.springframework:spring-tx:$springVersion",
"org.spockframework:spock-core:$spockVersion",
+ "org.spockframework:spock-spring:$spockVersion",
"org.slf4j:jcl-over-slf4j:$slf4jVersion",
"org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final",
"org.hibernate:hibernate-entitymanager:4.1.0.Final",
@@ -46,12 +47,15 @@ dependencies {
"org.apache.directory.server:apacheds-server-jndi:$apacheDsVersion",
'org.apache.directory.shared:shared-ldap:0.9.15',
'ldapsdk:ldapsdk:4.1',
- powerMockDependencies
+ powerMockDependencies,
+ "org.springframework.data:spring-data-jpa:1.2.0.RELEASE",
+ "org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.0.Final",
+ "org.hibernate:hibernate-entitymanager:3.6.10.Final",
+ "org.hsqldb:hsqldb:2.2.8"
testCompile('org.openid4java:openid4java-nodeps:0.9.6') {
exclude group: 'com.google.code.guice', module: 'guice'
}
-
testRuntime "org.hsqldb:hsqldb:$hsqlVersion",
"cglib:cglib-nodep:2.2"
}
diff --git a/config/src/main/java/org/springframework/security/config/annotation/authentication/builders/AuthenticationManagerBuilder.java b/config/src/main/java/org/springframework/security/config/annotation/authentication/builders/AuthenticationManagerBuilder.java
index 5ac8af4e86..68dbef25f6 100644
--- a/config/src/main/java/org/springframework/security/config/annotation/authentication/builders/AuthenticationManagerBuilder.java
+++ b/config/src/main/java/org/springframework/security/config/annotation/authentication/builders/AuthenticationManagerBuilder.java
@@ -27,6 +27,7 @@ import org.springframework.security.authentication.ProviderManager;
import org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder;
import org.springframework.security.config.annotation.ObjectPostProcessor;
import org.springframework.security.config.annotation.SecurityBuilder;
+import org.springframework.security.config.annotation.SecurityConfigurer;
import org.springframework.security.config.annotation.authentication.ProviderManagerBuilder;
import org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer;
import org.springframework.security.config.annotation.authentication.configurers.provisioning.InMemoryUserDetailsManagerConfigurer;
@@ -221,7 +222,7 @@ public class AuthenticationManagerBuilder extends AbstractConfiguredSecurityBuil
@Override
protected ProviderManager performBuild() throws Exception {
- if(authenticationProviders.isEmpty() && parentAuthenticationManager == null) {
+ if(!isConfigured()) {
logger.debug("No authenticationProviders and no parentAuthenticationManager defined. Returning null.");
return null;
}
@@ -236,6 +237,26 @@ public class AuthenticationManagerBuilder extends AbstractConfiguredSecurityBuil
return providerManager;
}
+ /**
+ * Determines if the {@link AuthenticationManagerBuilder} is configured to
+ * build a non null {@link AuthenticationManager}. This means that either a
+ * non-null parent is specified or at least one
+ * {@link AuthenticationProvider} has been specified.
+ *
+ *
+ * When using {@link SecurityConfigurer} instances, the
+ * {@link AuthenticationManagerBuilder} will not be configured until the
+ * {@link SecurityConfigurer#configure(SecurityBuilder)} methods. This means
+ * a {@link SecurityConfigurer} that is last could check this method and
+ * provide a default configuration in the
+ * {@link SecurityConfigurer#configure(SecurityBuilder)} method.
+ *
+ * @return
+ */
+ public boolean isConfigured() {
+ return !authenticationProviders.isEmpty() || parentAuthenticationManager != null;
+ }
+
/**
* Gets the default {@link UserDetailsService} for the
* {@link AuthenticationManagerBuilder}. The result may be null in some
diff --git a/config/src/main/java/org/springframework/security/config/annotation/authentication/configuration/AuthenticationConfiguration.java b/config/src/main/java/org/springframework/security/config/annotation/authentication/configuration/AuthenticationConfiguration.java
index 75cc62c27f..3cb1d22365 100644
--- a/config/src/main/java/org/springframework/security/config/annotation/authentication/configuration/AuthenticationConfiguration.java
+++ b/config/src/main/java/org/springframework/security/config/annotation/authentication/configuration/AuthenticationConfiguration.java
@@ -15,10 +15,25 @@
*/
package org.springframework.security.config.annotation.authentication.configuration;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.aop.framework.ProxyFactoryBean;
+import org.springframework.aop.target.LazyInitTargetSource;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.core.annotation.AnnotationAwareOrderComparator;
+import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.ObjectPostProcessor;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
+import org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter;
+import org.springframework.util.Assert;
/**
* Exports the authentication {@link Configuration}
@@ -29,9 +44,98 @@ import org.springframework.security.config.annotation.authentication.builders.Au
*/
@Configuration
public class AuthenticationConfiguration {
+ private ApplicationContext applicationContext;
+
+ private AuthenticationManager authenticationManager;
+
+ private boolean authenticationManagerInitialized;
+
+ private List globalAuthConfigures = Collections.emptyList();
+
+ private ObjectPostProcessor