SEC-656: Provide ability to dependency inject additional exception to event mappings, rather than require subclassing.
This commit is contained in:
parent
afca3d8adc
commit
bdc791649d
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue