|
@@ -7,6 +7,7 @@ import org.acegisecurity.providers.dao.DaoAuthenticationProvider;
|
|
|
import org.acegisecurity.providers.dao.salt.ReflectionSaltSource;
|
|
import org.acegisecurity.providers.dao.salt.ReflectionSaltSource;
|
|
|
import org.acegisecurity.providers.dao.salt.SystemWideSaltSource;
|
|
import org.acegisecurity.providers.dao.salt.SystemWideSaltSource;
|
|
|
import org.acegisecurity.providers.encoding.Md5PasswordEncoder;
|
|
import org.acegisecurity.providers.encoding.Md5PasswordEncoder;
|
|
|
|
|
+import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
|
|
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.RootBeanDefinition;
|
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
|
@@ -23,9 +24,10 @@ import org.w3c.dom.NodeList;
|
|
|
* @author vpuri
|
|
* @author vpuri
|
|
|
*
|
|
*
|
|
|
*/
|
|
*/
|
|
|
-public class AuthenticationRepositoryBeanDefinitionParser extends AbstractBeanDefinitionParser {
|
|
|
|
|
|
|
+public class AuthenticationRepositoryBeanDefinitionParser extends AbstractBeanDefinitionParser {
|
|
|
|
|
|
|
|
- // ~ Instance fields ================================================================================================
|
|
|
|
|
|
|
+ // ~ Instance fields
|
|
|
|
|
+ // ================================================================================================
|
|
|
|
|
|
|
|
private static final String REPOSITORY_BEAN_REF = "repositoryBeanRef";
|
|
private static final String REPOSITORY_BEAN_REF = "repositoryBeanRef";
|
|
|
|
|
|
|
@@ -38,26 +40,30 @@ public class AuthenticationRepositoryBeanDefinitionParser extends AbstractBeanDe
|
|
|
private static final String SYSTEM_WIDE_SALT_SOURCE = "system-wide";
|
|
private static final String SYSTEM_WIDE_SALT_SOURCE = "system-wide";
|
|
|
|
|
|
|
|
private static final String REFLECTION_SALT_SOURCE = "reflection";
|
|
private static final String REFLECTION_SALT_SOURCE = "reflection";
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
private static final String PASSWORD_ENCODER_ELEMENT = "password-encoder";
|
|
private static final String PASSWORD_ENCODER_ELEMENT = "password-encoder";
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
private static final String PASSWORD_ENCODER_REF = "encoderBeanRef";
|
|
private static final String PASSWORD_ENCODER_REF = "encoderBeanRef";
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
private static final String PASSWORD_ENCODER = "encoder";
|
|
private static final String PASSWORD_ENCODER = "encoder";
|
|
|
-
|
|
|
|
|
- public static final String AUTOWIRE_AUTODETECT_VALUE = "autodetect";
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- // ~ Method ================================================================================================
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // ~ Method
|
|
|
|
|
+ // ================================================================================================
|
|
|
/**
|
|
/**
|
|
|
* TODO: Document Me !!!
|
|
* TODO: Document Me !!!
|
|
|
*/
|
|
*/
|
|
|
public AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
|
|
public AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
|
|
|
Assert.notNull(parserContext, "ParserContext must not be null");
|
|
Assert.notNull(parserContext, "ParserContext must not be null");
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
RootBeanDefinition repositoryBeanDef = new RootBeanDefinition(DaoAuthenticationProvider.class);
|
|
RootBeanDefinition repositoryBeanDef = new RootBeanDefinition(DaoAuthenticationProvider.class);
|
|
|
|
|
|
|
|
|
|
+ // check if saltSource is defined
|
|
|
|
|
+ Element saltSourceEle = DomUtils.getChildElementByTagName(element, SALT_SOURCE_ELEMENT);
|
|
|
|
|
+ setSaltSourceProperty(repositoryBeanDef, saltSourceEle);
|
|
|
|
|
+
|
|
|
|
|
+ Element passwordEncoderEle = DomUtils.getChildElementByTagName(element, PASSWORD_ENCODER_ELEMENT);
|
|
|
|
|
+ setPasswordEncoderProperty(repositoryBeanDef, passwordEncoderEle);
|
|
|
|
|
+
|
|
|
// if repositoryBeanRef is specified use its referred bean
|
|
// if repositoryBeanRef is specified use its referred bean
|
|
|
String userDetailsRef = element.getAttribute(REPOSITORY_BEAN_REF);
|
|
String userDetailsRef = element.getAttribute(REPOSITORY_BEAN_REF);
|
|
|
if (StringUtils.hasLength(userDetailsRef)) {
|
|
if (StringUtils.hasLength(userDetailsRef)) {
|
|
@@ -65,41 +71,39 @@ public class AuthenticationRepositoryBeanDefinitionParser extends AbstractBeanDe
|
|
|
new RuntimeBeanReference(userDetailsRef));
|
|
new RuntimeBeanReference(userDetailsRef));
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
- // autodetect userDetailsService from App Context ? or we could even create this UserDetailsService BD with autodetection of dataSource hahaha Magic !!!
|
|
|
|
|
- //repositoryBeanDef.getPropertyValues().addPropertyValue(USER_DETAILS_SERVICE, new RuntimeBeanReference(USER_DETAILS_SERVICE));
|
|
|
|
|
- repositoryBeanDef.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_AUTODETECT);
|
|
|
|
|
|
|
+ // autodetect userDetailsService from App Context
|
|
|
|
|
+ RootBeanDefinition depConfigurer = new RootBeanDefinition(
|
|
|
|
|
+ AuthenticationRepositoryDependenciesConfigurer.class);
|
|
|
|
|
+ BeanDefinitionHolder holder = new BeanDefinitionHolder(depConfigurer, parserContext.getReaderContext().generateBeanName(depConfigurer));
|
|
|
|
|
+ registerBeanDefinition(holder, parserContext.getRegistry());
|
|
|
}
|
|
}
|
|
|
- // check if saltSource is defined
|
|
|
|
|
- Element saltSourceEle = DomUtils.getChildElementByTagName(element, SALT_SOURCE_ELEMENT);
|
|
|
|
|
- setSaltSourceProperty(repositoryBeanDef, saltSourceEle);
|
|
|
|
|
-
|
|
|
|
|
- Element passwordEncoderEle = DomUtils.getChildElementByTagName(element, PASSWORD_ENCODER_ELEMENT);
|
|
|
|
|
- setPasswordEncoderProperty(repositoryBeanDef, passwordEncoderEle);
|
|
|
|
|
-
|
|
|
|
|
return repositoryBeanDef;
|
|
return repositoryBeanDef;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
*
|
|
*
|
|
|
* @param repositoryBeanDef
|
|
* @param repositoryBeanDef
|
|
|
* @param element
|
|
* @param element
|
|
|
*/
|
|
*/
|
|
|
private void setSaltSourceProperty(RootBeanDefinition repositoryBeanDef, Element element) {
|
|
private void setSaltSourceProperty(RootBeanDefinition repositoryBeanDef, Element element) {
|
|
|
- if(element != null) {
|
|
|
|
|
- setBeanReferenceOrInnerBeanDefinitions(repositoryBeanDef, element, "saltSource",element.getAttribute(SALT_SOURCE_REF) );
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (element != null) {
|
|
|
|
|
+ setBeanReferenceOrInnerBeanDefinitions(repositoryBeanDef, element, "saltSource", element
|
|
|
|
|
+ .getAttribute(SALT_SOURCE_REF));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
*
|
|
*
|
|
|
* @param repositoryBeanDef
|
|
* @param repositoryBeanDef
|
|
|
* @param element
|
|
* @param element
|
|
|
*/
|
|
*/
|
|
|
private void setPasswordEncoderProperty(RootBeanDefinition repositoryBeanDef, Element element) {
|
|
private void setPasswordEncoderProperty(RootBeanDefinition repositoryBeanDef, Element element) {
|
|
|
- if(element != null) {
|
|
|
|
|
- setBeanReferenceOrInnerBeanDefinitions(repositoryBeanDef, element, "passwordEncoder",element.getAttribute(PASSWORD_ENCODER_REF) );
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (element != null) {
|
|
|
|
|
+ setBeanReferenceOrInnerBeanDefinitions(repositoryBeanDef, element, "passwordEncoder", element
|
|
|
|
|
+ .getAttribute(PASSWORD_ENCODER_REF));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
*
|
|
*
|
|
|
* @param repositoryBeanDef
|
|
* @param repositoryBeanDef
|
|
@@ -107,21 +111,22 @@ public class AuthenticationRepositoryBeanDefinitionParser extends AbstractBeanDe
|
|
|
* @param property
|
|
* @param property
|
|
|
* @param reference
|
|
* @param reference
|
|
|
*/
|
|
*/
|
|
|
- private void setBeanReferenceOrInnerBeanDefinitions(RootBeanDefinition repositoryBeanDef, Element element ,String property, String reference) {
|
|
|
|
|
- // check for encoderBeanRef attribute
|
|
|
|
|
- if (StringUtils.hasLength(reference)) {
|
|
|
|
|
- repositoryBeanDef.getPropertyValues().addPropertyValue(property, new RuntimeBeanReference(reference));
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- doSetInnerBeanDefinitions(repositoryBeanDef, element,property);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ private void setBeanReferenceOrInnerBeanDefinitions(RootBeanDefinition repositoryBeanDef, Element element,
|
|
|
|
|
+ String property, String reference) {
|
|
|
|
|
+ // check for encoderBeanRef attribute
|
|
|
|
|
+ if (StringUtils.hasLength(reference)) {
|
|
|
|
|
+ repositoryBeanDef.getPropertyValues().addPropertyValue(property, new RuntimeBeanReference(reference));
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ doSetInnerBeanDefinitions(repositoryBeanDef, element, property);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
*
|
|
*
|
|
|
* @param repositoryBeanDef
|
|
* @param repositoryBeanDef
|
|
|
* @param element
|
|
* @param element
|
|
|
- * @param property
|
|
|
|
|
|
|
+ * @param property
|
|
|
*/
|
|
*/
|
|
|
private void doSetInnerBeanDefinitions(RootBeanDefinition repositoryBeanDef, Element element, String property) {
|
|
private void doSetInnerBeanDefinitions(RootBeanDefinition repositoryBeanDef, Element element, String property) {
|
|
|
NodeList children = element.getChildNodes();
|
|
NodeList children = element.getChildNodes();
|
|
@@ -142,12 +147,13 @@ public class AuthenticationRepositoryBeanDefinitionParser extends AbstractBeanDe
|
|
|
}
|
|
}
|
|
|
if (PASSWORD_ENCODER.equals(node.getLocalName())) {
|
|
if (PASSWORD_ENCODER.equals(node.getLocalName())) {
|
|
|
RootBeanDefinition passwordEncoderInnerBeanDefinition = createPasswordEncoder(childElement);
|
|
RootBeanDefinition passwordEncoderInnerBeanDefinition = createPasswordEncoder(childElement);
|
|
|
- repositoryBeanDef.getPropertyValues().addPropertyValue(property, passwordEncoderInnerBeanDefinition);
|
|
|
|
|
|
|
+ repositoryBeanDef.getPropertyValues()
|
|
|
|
|
+ .addPropertyValue(property, passwordEncoderInnerBeanDefinition);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
*
|
|
*
|
|
|
* @param childElement
|
|
* @param childElement
|
|
@@ -157,12 +163,12 @@ public class AuthenticationRepositoryBeanDefinitionParser extends AbstractBeanDe
|
|
|
String attributeValue = childElement.getAttribute("method");
|
|
String attributeValue = childElement.getAttribute("method");
|
|
|
RootBeanDefinition definition = null;
|
|
RootBeanDefinition definition = null;
|
|
|
// TODO: add other encoders support
|
|
// TODO: add other encoders support
|
|
|
- if(attributeValue.equals("md5")){
|
|
|
|
|
- definition = new RootBeanDefinition(Md5PasswordEncoder.class);
|
|
|
|
|
|
|
+ if (attributeValue.equals("md5")) {
|
|
|
|
|
+ definition = new RootBeanDefinition(Md5PasswordEncoder.class);
|
|
|
}
|
|
}
|
|
|
return definition;
|
|
return definition;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
*
|
|
*
|
|
|
* @param saltSourceTypeElement
|
|
* @param saltSourceTypeElement
|
|
@@ -170,22 +176,21 @@ public class AuthenticationRepositoryBeanDefinitionParser extends AbstractBeanDe
|
|
|
*/
|
|
*/
|
|
|
private RootBeanDefinition createReflectionSaltSource(Element saltSourceTypeElement) {
|
|
private RootBeanDefinition createReflectionSaltSource(Element saltSourceTypeElement) {
|
|
|
RootBeanDefinition definition = new RootBeanDefinition(ReflectionSaltSource.class);
|
|
RootBeanDefinition definition = new RootBeanDefinition(ReflectionSaltSource.class);
|
|
|
- definition.getPropertyValues().addPropertyValue("userPropertyToUse", saltSourceTypeElement.getAttribute("userPropertyToUse"));
|
|
|
|
|
|
|
+ definition.getPropertyValues().addPropertyValue("userPropertyToUse",
|
|
|
|
|
+ saltSourceTypeElement.getAttribute("userPropertyToUse"));
|
|
|
return definition;
|
|
return definition;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
*
|
|
*
|
|
|
* @param saltSourceTypeElement
|
|
* @param saltSourceTypeElement
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- private RootBeanDefinition createSystemWideSaltSource( Element saltSourceTypeElement) {
|
|
|
|
|
|
|
+ private RootBeanDefinition createSystemWideSaltSource(Element saltSourceTypeElement) {
|
|
|
RootBeanDefinition definition = new RootBeanDefinition(SystemWideSaltSource.class);
|
|
RootBeanDefinition definition = new RootBeanDefinition(SystemWideSaltSource.class);
|
|
|
- definition.getPropertyValues().addPropertyValue("systemWideSalt", saltSourceTypeElement.getAttribute("systemWideSalt"));
|
|
|
|
|
|
|
+ definition.getPropertyValues().addPropertyValue("systemWideSalt",
|
|
|
|
|
+ saltSourceTypeElement.getAttribute("systemWideSalt"));
|
|
|
return definition;
|
|
return definition;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|