SEC-656: Provide ability to dependency inject additional exception to event mappings, rather than require subclassing.

This commit is contained in:
Ben Alex 2008-02-15 11:56:53 +00:00
parent afca3d8adc
commit bdc791649d
1 changed files with 14 additions and 9 deletions

View File

@ -119,6 +119,7 @@ public class ProviderManager extends AbstractAuthenticationManager implements In
private List providers;
protected MessageSourceAccessor messages = SpringSecurityMessageSource.getAccessor();
private Properties exceptionMappings = new Properties();
private Properties additionalExceptionMappings = new Properties();
static {
DEFAULT_EXCEPTION_MAPPINGS.put(AccountExpiredException.class.getName(),
@ -152,7 +153,7 @@ public class ProviderManager extends AbstractAuthenticationManager implements In
public void afterPropertiesSet() throws Exception {
checkIfValidList(this.providers);
Assert.notNull(this.messages, "A message source must be set");
doAddExtraDefaultExceptionMappings(exceptionMappings);
exceptionMappings.putAll(additionalExceptionMappings);
}
private void checkIfValidList(List listToCheck) {
@ -161,14 +162,6 @@ public class ProviderManager extends AbstractAuthenticationManager implements In
}
}
/**
* Provided so subclasses can add extra exception mappings during startup if no exception mappings are
* injected by the IoC container.
*
* @param exceptionMappings the properties object, which already has entries in it
*/
protected void doAddExtraDefaultExceptionMappings(Properties exceptionMappings) {}
/**
* Attempts to authenticate the passed {@link Authentication} object.
* <p>
@ -345,4 +338,16 @@ public class ProviderManager extends AbstractAuthenticationManager implements In
applicationEventPublisher.publishEvent(event);
}
}
/**
* Sets additional exception to event mappings. These are automatically merged with the default
* exception to event mappings that <code>ProviderManager</code> defines.
*
* @param additionalExceptionMappings where keys are the fully-qualified string name of the
* exception class and the values are the fully-qualified string name of the event class to fire
*/
public void setAdditionalExceptionMappings(
Properties additionalExceptionMappings) {
this.additionalExceptionMappings = additionalExceptionMappings;
}
}