|
|
|
@ -13,7 +13,13 @@ |
|
|
|
* limitations under the License. |
|
|
|
* limitations under the License. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package org.acegisecurity.config; |
|
|
|
package org.acegisecurity.config; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.acegisecurity.ldap.DefaultInitialDirContextFactory; |
|
|
|
import org.acegisecurity.providers.ProviderManager; |
|
|
|
import org.acegisecurity.providers.ProviderManager; |
|
|
|
|
|
|
|
import org.acegisecurity.providers.ldap.LdapAuthenticationProvider; |
|
|
|
|
|
|
|
import org.acegisecurity.providers.ldap.authenticator.BindAuthenticator; |
|
|
|
|
|
|
|
import org.acegisecurity.providers.ldap.populator.DefaultLdapAuthoritiesPopulator; |
|
|
|
|
|
|
|
import org.acegisecurity.util.BeanDefinitionParserUtils; |
|
|
|
import org.springframework.beans.factory.config.RuntimeBeanReference; |
|
|
|
import org.springframework.beans.factory.config.RuntimeBeanReference; |
|
|
|
import org.springframework.beans.factory.support.AbstractBeanDefinition; |
|
|
|
import org.springframework.beans.factory.support.AbstractBeanDefinition; |
|
|
|
import org.springframework.beans.factory.support.ManagedList; |
|
|
|
import org.springframework.beans.factory.support.ManagedList; |
|
|
|
@ -23,14 +29,15 @@ import org.springframework.beans.factory.xml.BeanDefinitionParser; |
|
|
|
import org.springframework.beans.factory.xml.ParserContext; |
|
|
|
import org.springframework.beans.factory.xml.ParserContext; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
import org.springframework.util.xml.DomUtils; |
|
|
|
import org.w3c.dom.Element; |
|
|
|
import org.w3c.dom.Element; |
|
|
|
import org.w3c.dom.Node; |
|
|
|
import org.w3c.dom.Node; |
|
|
|
import org.w3c.dom.NodeList; |
|
|
|
import org.w3c.dom.NodeList; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* * {@link BeanDefinitionParser} for the <code>authentication-mechanism</code> tag, |
|
|
|
* * {@link BeanDefinitionParser} for the <code>authentication-mechanism</code> |
|
|
|
* resolves to {@link org.acegisecurity.providers.ProviderManager} </br> |
|
|
|
* tag, resolves to {@link org.acegisecurity.providers.ProviderManager} </br> |
|
|
|
|
|
|
|
* |
|
|
|
* @author vpuri |
|
|
|
* @author vpuri |
|
|
|
* @see {@link org.springframework.beans.factory.BeanFactory} |
|
|
|
* @see {@link org.springframework.beans.factory.BeanFactory} |
|
|
|
* @see {@link org.acegisecurity.providers.ProviderManager} |
|
|
|
* @see {@link org.acegisecurity.providers.ProviderManager} |
|
|
|
@ -42,6 +49,8 @@ public class AuthenticationMechanismBeanDefinitionParser extends AbstractBeanDef |
|
|
|
// ================================================================================================
|
|
|
|
// ================================================================================================
|
|
|
|
|
|
|
|
|
|
|
|
private static final String AUTHENTICATION_JDBC = "authentication-jdbc"; |
|
|
|
private static final String AUTHENTICATION_JDBC = "authentication-jdbc"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String AUTHENTICATION_LDAP="authentication-ldap"; |
|
|
|
|
|
|
|
|
|
|
|
private static final String REF = "ref"; |
|
|
|
private static final String REF = "ref"; |
|
|
|
|
|
|
|
|
|
|
|
@ -59,7 +68,7 @@ public class AuthenticationMechanismBeanDefinitionParser extends AbstractBeanDef |
|
|
|
|
|
|
|
|
|
|
|
if (node.getNodeType() == Node.ELEMENT_NODE) { |
|
|
|
if (node.getNodeType() == Node.ELEMENT_NODE) { |
|
|
|
Element childElement = (Element) node; |
|
|
|
Element childElement = (Element) node; |
|
|
|
//this.providerExists = true;
|
|
|
|
// this.providerExists = true;
|
|
|
|
|
|
|
|
|
|
|
|
if (AUTHENTICATION_JDBC.equals(node.getLocalName())) { |
|
|
|
if (AUTHENTICATION_JDBC.equals(node.getLocalName())) { |
|
|
|
String attribute = childElement.getAttribute(REF); |
|
|
|
String attribute = childElement.getAttribute(REF); |
|
|
|
@ -67,15 +76,16 @@ public class AuthenticationMechanismBeanDefinitionParser extends AbstractBeanDef |
|
|
|
// create a beandefinition
|
|
|
|
// create a beandefinition
|
|
|
|
providers.add(new RuntimeBeanReference(attribute)); |
|
|
|
providers.add(new RuntimeBeanReference(attribute)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else if (AUTHENTICATION_LDAP.equals(node.getLocalName())){ |
|
|
|
|
|
|
|
providers.add(createLdapAuthencticationProviderBeanDefinition(childElement, parserContext)); |
|
|
|
} |
|
|
|
} |
|
|
|
// TODO:Add other providers here
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
authMechanismBeanDef.getPropertyValues().addPropertyValue("providers", providers); |
|
|
|
authMechanismBeanDef.getPropertyValues().addPropertyValue("providers", providers); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return authMechanismBeanDef; |
|
|
|
return authMechanismBeanDef; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a default bean definition. |
|
|
|
* Creates a default bean definition. |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
@ -83,12 +93,51 @@ public class AuthenticationMechanismBeanDefinitionParser extends AbstractBeanDef |
|
|
|
protected static RootBeanDefinition createAndRegisterBeanDefinitionWithDefaults(ParserContext parserContext) { |
|
|
|
protected static RootBeanDefinition createAndRegisterBeanDefinitionWithDefaults(ParserContext parserContext) { |
|
|
|
RootBeanDefinition beanDefinition = new RootBeanDefinition(ProviderManager.class); |
|
|
|
RootBeanDefinition beanDefinition = new RootBeanDefinition(ProviderManager.class); |
|
|
|
ManagedList providers = new ManagedList(); |
|
|
|
ManagedList providers = new ManagedList(); |
|
|
|
// create authentication-repository (DaoAuthenticationProvider) and add that to list
|
|
|
|
// create authentication-repository (DaoAuthenticationProvider) and add
|
|
|
|
|
|
|
|
// that to list
|
|
|
|
RootBeanDefinition authRepo = AuthenticationRepositoryBeanDefinitionParser.createBeanDefinitionWithDefaults(); |
|
|
|
RootBeanDefinition authRepo = AuthenticationRepositoryBeanDefinitionParser.createBeanDefinitionWithDefaults(); |
|
|
|
providers.add(authRepo); |
|
|
|
providers.add(authRepo); |
|
|
|
beanDefinition.getPropertyValues().addPropertyValue("providers", providers); |
|
|
|
beanDefinition.getPropertyValues().addPropertyValue("providers", providers); |
|
|
|
parserContext.getReaderContext().registerWithGeneratedName(beanDefinition); |
|
|
|
parserContext.getReaderContext().registerWithGeneratedName(beanDefinition); |
|
|
|
return beanDefinition; |
|
|
|
return beanDefinition; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected static RootBeanDefinition createLdapAuthencticationProviderBeanDefinition(Element element, |
|
|
|
|
|
|
|
ParserContext parserContext) { |
|
|
|
|
|
|
|
// element ldap
|
|
|
|
|
|
|
|
RootBeanDefinition ldapAuthProvider = new RootBeanDefinition(LdapAuthenticationProvider.class); |
|
|
|
|
|
|
|
RootBeanDefinition initialDirContextFactory = createInitialDirContextFactoryBeanDefinition(element); |
|
|
|
|
|
|
|
RootBeanDefinition ldapAuthoritiesPopulator = new RootBeanDefinition(DefaultLdapAuthoritiesPopulator.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RootBeanDefinition bindAuthenticator = new RootBeanDefinition(BindAuthenticator.class); |
|
|
|
|
|
|
|
Element property = DomUtils.getChildElementByTagName(element, "property"); |
|
|
|
|
|
|
|
Assert.notNull(property); |
|
|
|
|
|
|
|
parserContext.getDelegate().parsePropertyElement(property, bindAuthenticator); |
|
|
|
|
|
|
|
bindAuthenticator.getConstructorArgumentValues().addIndexedArgumentValue(0, initialDirContextFactory); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// LdapAuthenticator
|
|
|
|
|
|
|
|
ldapAuthProvider.getConstructorArgumentValues().addIndexedArgumentValue(0, bindAuthenticator); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ldapAuthoritiesPopulator.getConstructorArgumentValues().addIndexedArgumentValue(0, initialDirContextFactory); |
|
|
|
|
|
|
|
BeanDefinitionParserUtils.setConstructorArgumentIfAvailable(1, element, "groupSearchBase", false, |
|
|
|
|
|
|
|
ldapAuthoritiesPopulator); |
|
|
|
|
|
|
|
BeanDefinitionParserUtils.setPropertyIfAvailable(element, "groupRoleAttribute", "groupRoleAttribute", ldapAuthoritiesPopulator); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//LdapAuthoritiesPopulator
|
|
|
|
|
|
|
|
ldapAuthProvider.getConstructorArgumentValues().addIndexedArgumentValue(1, ldapAuthoritiesPopulator); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ldapAuthProvider; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static RootBeanDefinition createInitialDirContextFactoryBeanDefinition(Element element) { |
|
|
|
|
|
|
|
RootBeanDefinition initialDirContextFactory = new RootBeanDefinition(DefaultInitialDirContextFactory.class); |
|
|
|
|
|
|
|
BeanDefinitionParserUtils.setConstructorArgumentIfAvailable(0, element, "ldapUrl", false, |
|
|
|
|
|
|
|
initialDirContextFactory); |
|
|
|
|
|
|
|
BeanDefinitionParserUtils.setPropertyIfAvailable(element, "managerDn", "managerDn", initialDirContextFactory); |
|
|
|
|
|
|
|
BeanDefinitionParserUtils.setPropertyIfAvailable(element, "managerPassword", "managerPassword", |
|
|
|
|
|
|
|
initialDirContextFactory); |
|
|
|
|
|
|
|
return initialDirContextFactory; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|