SEC-641: Reomove use of SecurityConfigException during parsing.
This commit is contained in:
parent
717ab0b3cc
commit
8859034d11
|
@ -28,7 +28,7 @@ public class AbstractUserDetailsServiceBeanDefinitionParser extends AbstractSing
|
||||||
|
|
||||||
// If top level, use the default name or throw an exception if already used
|
// If top level, use the default name or throw an exception if already used
|
||||||
if (parserContext.getRegistry().containsBeanDefinition(BeanIds.USER_DETAILS_SERVICE)) {
|
if (parserContext.getRegistry().containsBeanDefinition(BeanIds.USER_DETAILS_SERVICE)) {
|
||||||
throw new SecurityConfigurationException("No id supplied in <" + element.getNodeName() + "> and another " +
|
throw new BeanDefinitionStoreException("No id supplied and another " +
|
||||||
"bean is already registered as " + BeanIds.USER_DETAILS_SERVICE);
|
"bean is already registered as " + BeanIds.USER_DETAILS_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,9 +43,10 @@ class AuthenticationProviderBeanDefinitionParser implements BeanDefinitionParser
|
||||||
Element ldapUserServiceElt = DomUtils.getChildElementByTagName(element, Elements.LDAP_USER_SERVICE);
|
Element ldapUserServiceElt = DomUtils.getChildElementByTagName(element, Elements.LDAP_USER_SERVICE);
|
||||||
|
|
||||||
if (StringUtils.hasText(ref)) {
|
if (StringUtils.hasText(ref)) {
|
||||||
if (userServiceElt != null || jdbcUserServiceElt != null) {
|
if (userServiceElt != null || jdbcUserServiceElt != null || ldapUserServiceElt != null) {
|
||||||
throw new SecurityConfigurationException("The ref attribute cannot be used in combination with child" +
|
parserContext.getReaderContext().error("The ref attribute cannot be used in combination with child" +
|
||||||
"elements '" + Elements.USER_SERVICE + "' or '" + Elements.JDBC_USER_SERVICE + "'");
|
"elements '" + Elements.USER_SERVICE + "', '" + Elements.JDBC_USER_SERVICE + "' or '" +
|
||||||
|
Elements.LDAP_USER_SERVICE + "'", element);
|
||||||
}
|
}
|
||||||
|
|
||||||
authProvider.getPropertyValues().addPropertyValue("userDetailsService", new RuntimeBeanReference(ref));
|
authProvider.getPropertyValues().addPropertyValue("userDetailsService", new RuntimeBeanReference(ref));
|
||||||
|
@ -54,7 +55,7 @@ class AuthenticationProviderBeanDefinitionParser implements BeanDefinitionParser
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the child elements to create the UserDetailsService
|
// Use the child elements to create the UserDetailsService
|
||||||
BeanDefinition userDetailsService;
|
BeanDefinition userDetailsService = null;
|
||||||
|
|
||||||
if (userServiceElt != null) {
|
if (userServiceElt != null) {
|
||||||
userDetailsService = new UserServiceBeanDefinitionParser().parse(userServiceElt, parserContext);
|
userDetailsService = new UserServiceBeanDefinitionParser().parse(userServiceElt, parserContext);
|
||||||
|
@ -63,8 +64,7 @@ class AuthenticationProviderBeanDefinitionParser implements BeanDefinitionParser
|
||||||
} else if (ldapUserServiceElt != null) {
|
} else if (ldapUserServiceElt != null) {
|
||||||
userDetailsService = new LdapUserServiceBeanDefinitionParser().parse(ldapUserServiceElt, parserContext);
|
userDetailsService = new LdapUserServiceBeanDefinitionParser().parse(ldapUserServiceElt, parserContext);
|
||||||
} else {
|
} else {
|
||||||
throw new SecurityConfigurationException(Elements.AUTHENTICATION_PROVIDER
|
parserContext.getReaderContext().error("A user-service is required", element);
|
||||||
+ " requires a UserDetailsService" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
authProvider.getPropertyValues().addPropertyValue("userDetailsService", userDetailsService);
|
authProvider.getPropertyValues().addPropertyValue("userDetailsService", userDetailsService);
|
||||||
|
|
|
@ -155,8 +155,7 @@ public class HttpSecurityConfigPostProcessor implements BeanFactoryPostProcessor
|
||||||
mainEntryPoint = (AuthenticationEntryPoint) entryPointMap.get(BeanIds.FORM_LOGIN_ENTRY_POINT);
|
mainEntryPoint = (AuthenticationEntryPoint) entryPointMap.get(BeanIds.FORM_LOGIN_ENTRY_POINT);
|
||||||
|
|
||||||
if (mainEntryPoint == null) {
|
if (mainEntryPoint == null) {
|
||||||
mainEntryPoint = (AuthenticationEntryPoint)
|
mainEntryPoint = (AuthenticationEntryPoint) entryPointMap.get(BeanIds.BASIC_AUTHENTICATION_ENTRY_POINT);
|
||||||
entryPointMap.get(BeanIds.BASIC_AUTHENTICATION_ENTRY_POINT);
|
|
||||||
if (mainEntryPoint == null) {
|
if (mainEntryPoint == null) {
|
||||||
throw new SecurityConfigurationException("Failed to resolve authentication entry point");
|
throw new SecurityConfigurationException("Failed to resolve authentication entry point");
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.springframework.security.config;
|
||||||
|
|
||||||
import org.springframework.security.userdetails.jdbc.JdbcUserDetailsManager;
|
import org.springframework.security.userdetails.jdbc.JdbcUserDetailsManager;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||||
|
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
@ -24,7 +25,7 @@ public class JdbcUserServiceBeanDefinitionParser extends AbstractUserDetailsServ
|
||||||
builder.addPropertyReference("dataSource", dataSource);
|
builder.addPropertyReference("dataSource", dataSource);
|
||||||
} else {
|
} else {
|
||||||
// TODO: Have some sensible fallback if dataSource not specified, eg autowire
|
// TODO: Have some sensible fallback if dataSource not specified, eg autowire
|
||||||
throw new SecurityConfigurationException(ATT_DATA_SOURCE + " is required for "
|
throw new BeanDefinitionStoreException(ATT_DATA_SOURCE + " is required for "
|
||||||
+ Elements.JDBC_USER_SERVICE );
|
+ Elements.JDBC_USER_SERVICE );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class RememberMeBeanDefinitionParser implements BeanDefinitionParser {
|
||||||
boolean tokenRepoSet = StringUtils.hasText(tokenRepository);
|
boolean tokenRepoSet = StringUtils.hasText(tokenRepository);
|
||||||
|
|
||||||
if (dataSourceSet && tokenRepoSet) {
|
if (dataSourceSet && tokenRepoSet) {
|
||||||
throw new SecurityConfigurationException("Specify tokenRepository or dataSource but not both");
|
parserContext.getReaderContext().error("Specify tokenRepository or dataSource but not both", element);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isPersistent = dataSourceSet | tokenRepoSet;
|
boolean isPersistent = dataSourceSet | tokenRepoSet;
|
||||||
|
|
Loading…
Reference in New Issue