Changed LDAP namespace parsing to make sure LDAP provider is registered with ProviderManager.
This commit is contained in:
parent
89d04b54bd
commit
97030e8942
|
@ -1,11 +1,9 @@
|
||||||
package org.springframework.security.config;
|
package org.springframework.security.config;
|
||||||
|
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.beans.factory.support.ManagedList;
|
|
||||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||||
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||||
import org.springframework.beans.factory.xml.ParserContext;
|
import org.springframework.beans.factory.xml.ParserContext;
|
||||||
import org.springframework.security.providers.ProviderManager;
|
|
||||||
import org.springframework.security.providers.dao.DaoAuthenticationProvider;
|
import org.springframework.security.providers.dao.DaoAuthenticationProvider;
|
||||||
import org.springframework.util.xml.DomUtils;
|
import org.springframework.util.xml.DomUtils;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
@ -16,11 +14,6 @@ import org.w3c.dom.Element;
|
||||||
*/
|
*/
|
||||||
class AuthenticationProviderBeanDefinitionParser implements BeanDefinitionParser {
|
class AuthenticationProviderBeanDefinitionParser implements BeanDefinitionParser {
|
||||||
|
|
||||||
private ManagedList getRegisteredProviders(ParserContext parserContext) {
|
|
||||||
BeanDefinition authManager = ConfigUtils.registerProviderManagerIfNecessary(parserContext);
|
|
||||||
return (ManagedList) authManager.getPropertyValues().getPropertyValue("providers").getValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public BeanDefinition parse(Element element, ParserContext parserContext) {
|
public BeanDefinition parse(Element element, ParserContext parserContext) {
|
||||||
ConfigUtils.registerProviderManagerIfNecessary(parserContext);
|
ConfigUtils.registerProviderManagerIfNecessary(parserContext);
|
||||||
|
|
||||||
|
@ -37,7 +30,7 @@ class AuthenticationProviderBeanDefinitionParser implements BeanDefinitionParser
|
||||||
throw new IllegalArgumentException("Only support user-service provider at the moment.");
|
throw new IllegalArgumentException("Only support user-service provider at the moment.");
|
||||||
}
|
}
|
||||||
|
|
||||||
getRegisteredProviders(parserContext).add(authProvider);
|
ConfigUtils.getRegisteredProviders(parserContext).add(authProvider);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,4 +124,8 @@ public abstract class ConfigUtils {
|
||||||
return accessMgr;
|
return accessMgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ManagedList getRegisteredProviders(ParserContext parserContext) {
|
||||||
|
BeanDefinition authManager = registerProviderManagerIfNecessary(parserContext);
|
||||||
|
return (ManagedList) authManager.getPropertyValues().getPropertyValue("providers").getValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,10 @@ import org.springframework.security.ldap.DefaultSpringSecurityContextSource;
|
||||||
import org.springframework.security.providers.ldap.LdapAuthenticationProvider;
|
import org.springframework.security.providers.ldap.LdapAuthenticationProvider;
|
||||||
import org.springframework.security.providers.ldap.authenticator.BindAuthenticator;
|
import org.springframework.security.providers.ldap.authenticator.BindAuthenticator;
|
||||||
import org.springframework.security.providers.ldap.populator.DefaultLdapAuthoritiesPopulator;
|
import org.springframework.security.providers.ldap.populator.DefaultLdapAuthoritiesPopulator;
|
||||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
|
||||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||||
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
|
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
|
||||||
|
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||||
import org.springframework.beans.factory.xml.ParserContext;
|
import org.springframework.beans.factory.xml.ParserContext;
|
||||||
import org.springframework.ldap.core.DirContextAdapter;
|
import org.springframework.ldap.core.DirContextAdapter;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
@ -30,7 +30,7 @@ import java.util.HashSet;
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
public class LdapBeanDefinitionParser extends AbstractBeanDefinitionParser {
|
public class LdapBeanDefinitionParser implements BeanDefinitionParser {
|
||||||
private Log logger = LogFactory.getLog(getClass());
|
private Log logger = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
/** Defines the Url of the ldap server to use. If not specified, an embedded apache DS instance will be created */
|
/** Defines the Url of the ldap server to use. If not specified, an embedded apache DS instance will be created */
|
||||||
|
@ -56,12 +56,12 @@ public class LdapBeanDefinitionParser extends AbstractBeanDefinitionParser {
|
||||||
|
|
||||||
// Defaults
|
// Defaults
|
||||||
private static final String DEFAULT_ROOT_SUFFIX = "dc=springframework,dc=org";
|
private static final String DEFAULT_ROOT_SUFFIX = "dc=springframework,dc=org";
|
||||||
private static final String DEFAULT_PROVIDER_BEAN_ID = "_ldapAuthenticationProvider";
|
// private static final String DEFAULT_PROVIDER_BEAN_ID = "_ldapAuthenticationProvider";
|
||||||
private static final String DEFAULT_DN_PATTERN = "uid={0},ou=people";
|
private static final String DEFAULT_DN_PATTERN = "uid={0},ou=people";
|
||||||
private static final String DEFAULT_GROUP_CONTEXT = "ou=groups";
|
private static final String DEFAULT_GROUP_CONTEXT = "ou=groups";
|
||||||
|
|
||||||
|
|
||||||
protected AbstractBeanDefinition parseInternal(Element elt, ParserContext parserContext) {
|
public BeanDefinition parse(Element elt, ParserContext parserContext) {
|
||||||
String url = elt.getAttribute(URL_ATTRIBUTE);
|
String url = elt.getAttribute(URL_ATTRIBUTE);
|
||||||
|
|
||||||
RootBeanDefinition contextSource;
|
RootBeanDefinition contextSource;
|
||||||
|
@ -84,12 +84,7 @@ public class LdapBeanDefinitionParser extends AbstractBeanDefinitionParser {
|
||||||
contextSource.getPropertyValues().addPropertyValue("password", managerPassword);
|
contextSource.getPropertyValues().addPropertyValue("password", managerPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String id = elt.getAttribute(AbstractBeanDefinitionParser.ID_ATTRIBUTE);
|
||||||
// TODO: Make these default values for 2.0
|
|
||||||
// contextSource.getPropertyValues().addPropertyValue("useLdapContext", Boolean.TRUE);
|
|
||||||
// contextSource.getPropertyValues().addPropertyValue("dirObjectFactory", "org.springframework.ldap.core.support.DefaultDirObjectFactory");
|
|
||||||
|
|
||||||
String id = elt.getAttribute(ID_ATTRIBUTE);
|
|
||||||
String contextSourceId = "contextSource";
|
String contextSourceId = "contextSource";
|
||||||
|
|
||||||
if (StringUtils.hasText(id)) {
|
if (StringUtils.hasText(id)) {
|
||||||
|
@ -113,7 +108,9 @@ public class LdapBeanDefinitionParser extends AbstractBeanDefinitionParser {
|
||||||
ldapProvider.getConstructorArgumentValues().addGenericArgumentValue(bindAuthenticator);
|
ldapProvider.getConstructorArgumentValues().addGenericArgumentValue(bindAuthenticator);
|
||||||
ldapProvider.getConstructorArgumentValues().addGenericArgumentValue(authoritiesPopulator);
|
ldapProvider.getConstructorArgumentValues().addGenericArgumentValue(authoritiesPopulator);
|
||||||
|
|
||||||
return ldapProvider;
|
ConfigUtils.getRegisteredProviders(parserContext).add(ldapProvider);
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -190,17 +187,4 @@ public class LdapBeanDefinitionParser extends AbstractBeanDefinitionParser {
|
||||||
|
|
||||||
return contextSource;
|
return contextSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) throws BeanDefinitionStoreException {
|
|
||||||
String id = super.resolveId(element, definition, parserContext);
|
|
||||||
|
|
||||||
if (StringUtils.hasText(id)) {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Check for duplicate using default id here.
|
|
||||||
|
|
||||||
return DEFAULT_PROVIDER_BEAN_ID;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue