use of org.apereo.cas.authentication.MessageDescriptor in project cas by apereo.
the class GroovyLdapPasswordPolicyHandlingStrategyTests method verifyStrategySupportsDefault.
@Test
public void verifyStrategySupportsDefault() {
final ClassPathResource resource = new ClassPathResource("lppe-strategy.groovy");
final GroovyLdapPasswordPolicyHandlingStrategy s = new GroovyLdapPasswordPolicyHandlingStrategy(resource);
final AuthenticationResponse res = mock(AuthenticationResponse.class);
when(res.getAuthenticationResultCode()).thenReturn(AuthenticationResultCode.INVALID_CREDENTIAL);
assertFalse(s.supports(null));
when(res.getResult()).thenReturn(false);
assertTrue(s.supports(res));
final List<MessageDescriptor> results = s.handle(res, mock(LdapPasswordPolicyConfiguration.class));
assertFalse(results.isEmpty());
}
use of org.apereo.cas.authentication.MessageDescriptor in project cas by apereo.
the class OptionalWarningLdapLdapAccountStateHandlerTests method verifyWarningOnMatch.
@Test
public void verifyWarningOnMatch() {
final OptionalWarningLdapLdapAccountStateHandler h = new OptionalWarningLdapLdapAccountStateHandler();
h.setWarnAttributeName("attribute");
h.setWarningAttributeValue("value");
h.setDisplayWarningOnMatch(true);
final AuthenticationResponse response = mock(AuthenticationResponse.class);
final LdapEntry entry = mock(LdapEntry.class);
when(response.getLdapEntry()).thenReturn(entry);
when(entry.getAttribute(anyString())).thenReturn(new LdapAttribute("attribute", "value"));
final List<MessageDescriptor> messages = new ArrayList<>();
final LdapPasswordPolicyConfiguration config = new LdapPasswordPolicyConfiguration();
config.setPasswordWarningNumberOfDays(5);
h.handleWarning(new AccountState.DefaultWarning(ZonedDateTime.now(), 1), response, config, messages);
assertEquals(2, messages.size());
}
use of org.apereo.cas.authentication.MessageDescriptor in project cas by apereo.
the class DefaultLdapLdapAccountStateHandler method handle.
@Override
public List<MessageDescriptor> handle(final AuthenticationResponse response, final LdapPasswordPolicyConfiguration configuration) throws LoginException {
LOGGER.debug("Attempting to handle LDAP account state for [{}]", response);
if (!this.attributesToErrorMap.isEmpty() && response.getResult()) {
LOGGER.debug("Handling policy based on pre-defined attributes");
handlePolicyAttributes(response);
}
final AccountState state = response.getAccountState();
if (state == null) {
LOGGER.debug("Account state not defined. Returning empty list of messages.");
return new ArrayList<>(0);
}
final List<MessageDescriptor> messages = new ArrayList<>();
handleError(state.getError(), response, configuration, messages);
handleWarning(state.getWarning(), response, configuration, messages);
return messages;
}
Aggregations