Search in sources :

Example 11 with PasswordPolicyContext

use of org.apereo.cas.authentication.support.password.PasswordPolicyContext in project cas by apereo.

the class DefaultLdapAccountStateHandlerTests method verifyNoAttrs.

@Test
public void verifyNoAttrs() {
    val handler = new DefaultLdapAccountStateHandler();
    val response = mock(AuthenticationResponse.class);
    handler.setAttributesToErrorMap(Map.of("attr1", AccountLockedException.class));
    val entry = new LdapEntry();
    when(response.getLdapEntry()).thenReturn(entry);
    when(response.isSuccess()).thenReturn(Boolean.TRUE);
    assertDoesNotThrow(new Executable() {

        @Override
        public void execute() throws Throwable {
            handler.handle(response, new PasswordPolicyContext());
        }
    });
}
Also used : lombok.val(lombok.val) AccountLockedException(javax.security.auth.login.AccountLockedException) PasswordPolicyContext(org.apereo.cas.authentication.support.password.PasswordPolicyContext) LdapEntry(org.ldaptive.LdapEntry) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 12 with PasswordPolicyContext

use of org.apereo.cas.authentication.support.password.PasswordPolicyContext in project cas by apereo.

the class OptionalWarningLdapAccountStateHandlerTests method verifyWarningOnMatch.

@Test
public void verifyWarningOnMatch() {
    val h = new OptionalWarningLdapAccountStateHandler();
    h.setWarnAttributeName("attribute");
    h.setWarningAttributeValue("value");
    h.setDisplayWarningOnMatch(true);
    val response = mock(AuthenticationResponse.class);
    val entry = mock(LdapEntry.class);
    when(response.getLdapEntry()).thenReturn(entry);
    when(entry.getAttribute(anyString())).thenReturn(new LdapAttribute("attribute", "value"));
    val messages = new ArrayList<MessageDescriptor>();
    val config = new PasswordPolicyContext();
    config.setPasswordWarningNumberOfDays(5);
    h.handleWarning(new AccountState.DefaultWarning(ZonedDateTime.now(ZoneId.systemDefault()), 1), response, config, messages);
    assertEquals(2, messages.size());
}
Also used : lombok.val(lombok.val) PasswordPolicyContext(org.apereo.cas.authentication.support.password.PasswordPolicyContext) LdapAttribute(org.ldaptive.LdapAttribute) ArrayList(java.util.ArrayList) AccountState(org.ldaptive.auth.AccountState) Test(org.junit.jupiter.api.Test)

Example 13 with PasswordPolicyContext

use of org.apereo.cas.authentication.support.password.PasswordPolicyContext in project cas by apereo.

the class OptionalWarningLdapAccountStateHandlerTests method verifyAlwaysWarningOnMatch.

@Test
public void verifyAlwaysWarningOnMatch() {
    val h = new OptionalWarningLdapAccountStateHandler();
    h.setWarnAttributeName("attribute");
    h.setWarningAttributeValue("value");
    h.setDisplayWarningOnMatch(true);
    val response = mock(AuthenticationResponse.class);
    val entry = mock(LdapEntry.class);
    when(response.getLdapEntry()).thenReturn(entry);
    when(entry.getAttribute(anyString())).thenReturn(new LdapAttribute("attribute", "value"));
    val messages = new ArrayList<MessageDescriptor>();
    val config = new PasswordPolicyContext();
    config.setAlwaysDisplayPasswordExpirationWarning(true);
    h.handleWarning(new AccountState.DefaultWarning(ZonedDateTime.now(ZoneId.systemDefault()), 1), response, config, messages);
    assertEquals(2, messages.size());
}
Also used : lombok.val(lombok.val) PasswordPolicyContext(org.apereo.cas.authentication.support.password.PasswordPolicyContext) LdapAttribute(org.ldaptive.LdapAttribute) ArrayList(java.util.ArrayList) AccountState(org.ldaptive.auth.AccountState) Test(org.junit.jupiter.api.Test)

Example 14 with PasswordPolicyContext

use of org.apereo.cas.authentication.support.password.PasswordPolicyContext in project cas by apereo.

the class OktaAuthenticationStateHandlerAdapterTests method verifyLockout.

@Test
public void verifyLockout() {
    val adapter = new OktaAuthenticationStateHandlerAdapter(new DefaultPasswordPolicyHandlingStrategy<>(), new PasswordPolicyContext());
    val response = mock(AuthenticationResponse.class);
    when(response.getStatusString()).thenReturn("error");
    adapter.handleLockedOut(response);
    assertThrows(AccountLockedException.class, adapter::throwExceptionIfNecessary);
}
Also used : lombok.val(lombok.val) PasswordPolicyContext(org.apereo.cas.authentication.support.password.PasswordPolicyContext) Test(org.junit.jupiter.api.Test)

Example 15 with PasswordPolicyContext

use of org.apereo.cas.authentication.support.password.PasswordPolicyContext in project cas by apereo.

the class OktaAuthenticationStateHandlerAdapterTests method verifyUnknown.

@Test
public void verifyUnknown() {
    val adapter = new OktaAuthenticationStateHandlerAdapter(new DefaultPasswordPolicyHandlingStrategy<>(), new PasswordPolicyContext());
    val response = mock(AuthenticationResponse.class);
    when(response.getStatusString()).thenReturn("error");
    adapter.handleUnknown(response);
    assertThrows(AccountNotFoundException.class, adapter::throwExceptionIfNecessary);
}
Also used : lombok.val(lombok.val) PasswordPolicyContext(org.apereo.cas.authentication.support.password.PasswordPolicyContext) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)18 PasswordPolicyContext (org.apereo.cas.authentication.support.password.PasswordPolicyContext)18 Test (org.junit.jupiter.api.Test)16 AccountState (org.ldaptive.auth.AccountState)5 ArrayList (java.util.ArrayList)4 LdapAttribute (org.ldaptive.LdapAttribute)3 AccountLockedException (javax.security.auth.login.AccountLockedException)2 Executable (org.junit.jupiter.api.function.Executable)2 LdapEntry (org.ldaptive.LdapEntry)2 HashSet (java.util.HashSet)1 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)1 UtilityClass (lombok.experimental.UtilityClass)1 JsonResourceAuthenticationHandler (org.apereo.cas.adaptors.generic.JsonResourceAuthenticationHandler)1 DefaultLdapAccountStateHandler (org.apereo.cas.authentication.support.DefaultLdapAccountStateHandler)1 OptionalWarningLdapAccountStateHandler (org.apereo.cas.authentication.support.OptionalWarningLdapAccountStateHandler)1 LdapException (org.ldaptive.LdapException)1 AuthenticationRequestHandler (org.ldaptive.auth.AuthenticationRequestHandler)1 AuthenticationResponseHandler (org.ldaptive.auth.AuthenticationResponseHandler)1 ActiveDirectoryAuthenticationResponseHandler (org.ldaptive.auth.ext.ActiveDirectoryAuthenticationResponseHandler)1 EDirectoryAuthenticationResponseHandler (org.ldaptive.auth.ext.EDirectoryAuthenticationResponseHandler)1