Changed LDAP namespace parsing to make sure LDAP provider is registered with ProviderManager.

This commit is contained in:
Luke Taylor 2007-12-03 23:58:38 +00:00
parent 89d04b54bd
commit 97030e8942
3 changed files with 15 additions and 34 deletions

View File

@ -1,11 +1,9 @@
package org.springframework.security.config;
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.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.security.providers.ProviderManager;
import org.springframework.security.providers.dao.DaoAuthenticationProvider;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
@ -16,11 +14,6 @@ import org.w3c.dom.Element;
*/
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) {
ConfigUtils.registerProviderManagerIfNecessary(parserContext);
@ -37,7 +30,7 @@ class AuthenticationProviderBeanDefinitionParser implements BeanDefinitionParser
throw new IllegalArgumentException("Only support user-service provider at the moment.");
}
getRegisteredProviders(parserContext).add(authProvider);
ConfigUtils.getRegisteredProviders(parserContext).add(authProvider);
return null;
}

View File

@ -105,7 +105,7 @@ public abstract class ConfigUtils {
"use a specific Id in yur configuration");
}
return (UserDetailsService) services.values().toArray()[0];
return (UserDetailsService) services.values().toArray()[0];
}
private static AuthenticationManager getAuthenticationManager(ConfigurableListableBeanFactory bf) {
@ -124,4 +124,8 @@ public abstract class ConfigUtils {
return accessMgr;
}
static ManagedList getRegisteredProviders(ParserContext parserContext) {
BeanDefinition authManager = registerProviderManagerIfNecessary(parserContext);
return (ManagedList) authManager.getPropertyValues().getPropertyValue("providers").getValue();
}
}

View File

@ -4,10 +4,10 @@ import org.springframework.security.ldap.DefaultSpringSecurityContextSource;
import org.springframework.security.providers.ldap.LdapAuthenticationProvider;
import org.springframework.security.providers.ldap.authenticator.BindAuthenticator;
import org.springframework.security.providers.ldap.populator.DefaultLdapAuthoritiesPopulator;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.util.Assert;
@ -30,7 +30,7 @@ import java.util.HashSet;
* @version $Id$
* @since 2.0
*/
public class LdapBeanDefinitionParser extends AbstractBeanDefinitionParser {
public class LdapBeanDefinitionParser implements BeanDefinitionParser {
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 */
@ -56,12 +56,12 @@ public class LdapBeanDefinitionParser extends AbstractBeanDefinitionParser {
// Defaults
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_GROUP_CONTEXT = "ou=groups";
protected AbstractBeanDefinition parseInternal(Element elt, ParserContext parserContext) {
public BeanDefinition parse(Element elt, ParserContext parserContext) {
String url = elt.getAttribute(URL_ATTRIBUTE);
RootBeanDefinition contextSource;
@ -84,12 +84,7 @@ public class LdapBeanDefinitionParser extends AbstractBeanDefinitionParser {
contextSource.getPropertyValues().addPropertyValue("password", managerPassword);
}
// 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 id = elt.getAttribute(AbstractBeanDefinitionParser.ID_ATTRIBUTE);
String contextSourceId = "contextSource";
if (StringUtils.hasText(id)) {
@ -113,7 +108,9 @@ public class LdapBeanDefinitionParser extends AbstractBeanDefinitionParser {
ldapProvider.getConstructorArgumentValues().addGenericArgumentValue(bindAuthenticator);
ldapProvider.getConstructorArgumentValues().addGenericArgumentValue(authoritiesPopulator);
return ldapProvider;
ConfigUtils.getRegisteredProviders(parserContext).add(ldapProvider);
return null;
}
@ -190,17 +187,4 @@ public class LdapBeanDefinitionParser extends AbstractBeanDefinitionParser {
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;
}
}