SEC-641: Reomove use of SecurityConfigException during parsing.

This commit is contained in:
Luke Taylor 2008-02-05 11:46:27 +00:00
parent 717ab0b3cc
commit 8859034d11
5 changed files with 11 additions and 11 deletions

View File

@ -28,7 +28,7 @@ public class AbstractUserDetailsServiceBeanDefinitionParser extends AbstractSing
// If top level, use the default name or throw an exception if already used
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);
}

View File

@ -43,9 +43,10 @@ class AuthenticationProviderBeanDefinitionParser implements BeanDefinitionParser
Element ldapUserServiceElt = DomUtils.getChildElementByTagName(element, Elements.LDAP_USER_SERVICE);
if (StringUtils.hasText(ref)) {
if (userServiceElt != null || jdbcUserServiceElt != null) {
throw new SecurityConfigurationException("The ref attribute cannot be used in combination with child" +
"elements '" + Elements.USER_SERVICE + "' or '" + Elements.JDBC_USER_SERVICE + "'");
if (userServiceElt != null || jdbcUserServiceElt != null || ldapUserServiceElt != null) {
parserContext.getReaderContext().error("The ref attribute cannot be used in combination with child" +
"elements '" + Elements.USER_SERVICE + "', '" + Elements.JDBC_USER_SERVICE + "' or '" +
Elements.LDAP_USER_SERVICE + "'", element);
}
authProvider.getPropertyValues().addPropertyValue("userDetailsService", new RuntimeBeanReference(ref));
@ -54,7 +55,7 @@ class AuthenticationProviderBeanDefinitionParser implements BeanDefinitionParser
}
// Use the child elements to create the UserDetailsService
BeanDefinition userDetailsService;
BeanDefinition userDetailsService = null;
if (userServiceElt != null) {
userDetailsService = new UserServiceBeanDefinitionParser().parse(userServiceElt, parserContext);
@ -63,8 +64,7 @@ class AuthenticationProviderBeanDefinitionParser implements BeanDefinitionParser
} else if (ldapUserServiceElt != null) {
userDetailsService = new LdapUserServiceBeanDefinitionParser().parse(ldapUserServiceElt, parserContext);
} else {
throw new SecurityConfigurationException(Elements.AUTHENTICATION_PROVIDER
+ " requires a UserDetailsService" );
parserContext.getReaderContext().error("A user-service is required", element);
}
authProvider.getPropertyValues().addPropertyValue("userDetailsService", userDetailsService);

View File

@ -155,8 +155,7 @@ public class HttpSecurityConfigPostProcessor implements BeanFactoryPostProcessor
mainEntryPoint = (AuthenticationEntryPoint) entryPointMap.get(BeanIds.FORM_LOGIN_ENTRY_POINT);
if (mainEntryPoint == null) {
mainEntryPoint = (AuthenticationEntryPoint)
entryPointMap.get(BeanIds.BASIC_AUTHENTICATION_ENTRY_POINT);
mainEntryPoint = (AuthenticationEntryPoint) entryPointMap.get(BeanIds.BASIC_AUTHENTICATION_ENTRY_POINT);
if (mainEntryPoint == null) {
throw new SecurityConfigurationException("Failed to resolve authentication entry point");
}

View File

@ -2,6 +2,7 @@ package org.springframework.security.config;
import org.springframework.security.userdetails.jdbc.JdbcUserDetailsManager;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.w3c.dom.Element;
@ -24,7 +25,7 @@ public class JdbcUserServiceBeanDefinitionParser extends AbstractUserDetailsServ
builder.addPropertyReference("dataSource", dataSource);
} else {
// 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 );
}
}

View File

@ -50,7 +50,7 @@ public class RememberMeBeanDefinitionParser implements BeanDefinitionParser {
boolean tokenRepoSet = StringUtils.hasText(tokenRepository);
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;