Search in sources :

Example 16 with PasswordPolicyContext

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

the class OktaAuthenticationStateHandlerAdapterTests method handleSuccessWithoutToken.

@Test
public void handleSuccessWithoutToken() {
    val adapter = new OktaAuthenticationStateHandlerAdapter(new DefaultPasswordPolicyHandlingStrategy<>(), new PasswordPolicyContext());
    val response = mock(AuthenticationResponse.class);
    when(response.getSessionToken()).thenReturn(null);
    adapter.handleSuccess(response);
    assertNotNull(adapter.getFailureException());
    assertNotNull(adapter.getPasswordPolicyHandlingStrategy());
    assertNotNull(adapter.getPasswordPolicyConfiguration());
    assertThrows(FailedLoginException.class, adapter::throwExceptionIfNecessary);
}
Also used : lombok.val(lombok.val) PasswordPolicyContext(org.apereo.cas.authentication.support.password.PasswordPolicyContext) Test(org.junit.jupiter.api.Test)

Example 17 with PasswordPolicyContext

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

the class OktaAuthenticationStateHandlerAdapterTests method handlePasswordReset.

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

Example 18 with PasswordPolicyContext

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

the class OptionalWarningLdapAccountStateHandlerTests method verifyWarningNoAttr.

@Test
public void verifyWarningNoAttr() {
    val h = new OptionalWarningLdapAccountStateHandler();
    h.setDisplayWarningOnMatch(true);
    val response = mock(AuthenticationResponse.class);
    val config = new PasswordPolicyContext();
    config.setPasswordWarningNumberOfDays(5);
    val list = new ArrayList<MessageDescriptor>();
    h.handleWarning(new AccountState.DefaultWarning(ZonedDateTime.now(ZoneId.systemDefault()), 1), response, config, list);
    assertTrue(list.isEmpty());
    h.setWarnAttributeName("attribute");
    h.handleWarning(new AccountState.DefaultWarning(ZonedDateTime.now(ZoneId.systemDefault()), 1), response, config, list);
    assertTrue(list.isEmpty());
}
Also used : lombok.val(lombok.val) PasswordPolicyContext(org.apereo.cas.authentication.support.password.PasswordPolicyContext) ArrayList(java.util.ArrayList) AccountState(org.ldaptive.auth.AccountState) 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