Search in sources :

Example 1 with GroovyPasswordPolicyHandlingStrategy

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

the class GroovyPasswordPolicyHandlingStrategyTests method verifyStrategySupportsDefault.

@Test
public void verifyStrategySupportsDefault() {
    val resource = new ClassPathResource("lppe-strategy.groovy");
    val s = new GroovyPasswordPolicyHandlingStrategy<AuthenticationResponse>(resource, mock(ApplicationContext.class));
    val res = mock(AuthenticationResponse.class);
    when(res.getAuthenticationResultCode()).thenReturn(AuthenticationResultCode.INVALID_CREDENTIAL);
    when(res.isSuccess()).thenReturn(false);
    val results = s.handle(res, mock(PasswordPolicyContext.class));
    assertFalse(s.supports(null));
    assertTrue(s.supports(res));
    assertFalse(results.isEmpty());
}
Also used : lombok.val(lombok.val) ApplicationContext(org.springframework.context.ApplicationContext) GroovyPasswordPolicyHandlingStrategy(org.apereo.cas.authentication.support.password.GroovyPasswordPolicyHandlingStrategy) PasswordPolicyContext(org.apereo.cas.authentication.support.password.PasswordPolicyContext) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 2 with GroovyPasswordPolicyHandlingStrategy

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

the class CoreAuthenticationUtils method newPasswordPolicyHandlingStrategy.

/**
 * New password policy handling strategy.
 *
 * @param properties         the properties
 * @param applicationContext the application context
 * @return the authentication password policy handling strategy
 */
public static AuthenticationPasswordPolicyHandlingStrategy newPasswordPolicyHandlingStrategy(final PasswordPolicyProperties properties, final ApplicationContext applicationContext) {
    if (properties.getStrategy() == PasswordPolicyProperties.PasswordPolicyHandlingOptions.REJECT_RESULT_CODE) {
        LOGGER.debug("Created password policy handling strategy based on blocked authentication result codes");
        return new RejectResultCodePasswordPolicyHandlingStrategy<>();
    }
    val location = properties.getGroovy().getLocation();
    if (properties.getStrategy() == PasswordPolicyProperties.PasswordPolicyHandlingOptions.GROOVY && location != null) {
        LOGGER.debug("Created password policy handling strategy based on Groovy script [{}]", location);
        return new GroovyPasswordPolicyHandlingStrategy<>(location, applicationContext);
    }
    LOGGER.trace("Created default password policy handling strategy");
    return new DefaultPasswordPolicyHandlingStrategy<>();
}
Also used : lombok.val(lombok.val) RejectResultCodePasswordPolicyHandlingStrategy(org.apereo.cas.authentication.support.password.RejectResultCodePasswordPolicyHandlingStrategy) GroovyPasswordPolicyHandlingStrategy(org.apereo.cas.authentication.support.password.GroovyPasswordPolicyHandlingStrategy) DefaultPasswordPolicyHandlingStrategy(org.apereo.cas.authentication.support.password.DefaultPasswordPolicyHandlingStrategy)

Example 3 with GroovyPasswordPolicyHandlingStrategy

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

the class GroovyPasswordPolicyHandlingStrategyTests method verifyStrategyHandlesErrors.

@Test
public void verifyStrategyHandlesErrors() {
    val resource = new ClassPathResource("lppe-strategy-throws-error.groovy");
    val s = new GroovyPasswordPolicyHandlingStrategy<AuthenticationResponse>(resource, mock(ApplicationContext.class));
    val res = mock(AuthenticationResponse.class);
    assertThrows(AccountExpiredException.class, () -> s.handle(res, mock(PasswordPolicyContext.class)));
}
Also used : lombok.val(lombok.val) ApplicationContext(org.springframework.context.ApplicationContext) GroovyPasswordPolicyHandlingStrategy(org.apereo.cas.authentication.support.password.GroovyPasswordPolicyHandlingStrategy) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 4 with GroovyPasswordPolicyHandlingStrategy

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

the class LdapUtils method createLdapPasswordPolicyHandlingStrategy.

/**
 * Create ldap password policy handling strategy.
 *
 * @param l                  the lDAP properties
 * @param applicationContext the application context
 * @return the authentication password policy handling strategy
 */
public static AuthenticationPasswordPolicyHandlingStrategy<AuthenticationResponse, PasswordPolicyContext> createLdapPasswordPolicyHandlingStrategy(final LdapAuthenticationProperties l, final ApplicationContext applicationContext) {
    if (l.getPasswordPolicy().getStrategy() == LdapPasswordPolicyProperties.PasswordPolicyHandlingOptions.REJECT_RESULT_CODE) {
        LOGGER.debug("Created LDAP password policy handling strategy based on blocked authentication result codes");
        return new RejectResultCodeLdapPasswordPolicyHandlingStrategy();
    }
    val location = l.getPasswordPolicy().getGroovy().getLocation();
    if (l.getPasswordPolicy().getStrategy() == LdapPasswordPolicyProperties.PasswordPolicyHandlingOptions.GROOVY && location != null) {
        LOGGER.debug("Created LDAP password policy handling strategy based on Groovy script [{}]", location);
        return new GroovyPasswordPolicyHandlingStrategy(location, applicationContext);
    }
    LOGGER.debug("Created default LDAP password policy handling strategy");
    return new DefaultPasswordPolicyHandlingStrategy();
}
Also used : lombok.val(lombok.val) GroovyPasswordPolicyHandlingStrategy(org.apereo.cas.authentication.support.password.GroovyPasswordPolicyHandlingStrategy) RejectResultCodeLdapPasswordPolicyHandlingStrategy(org.apereo.cas.authentication.support.RejectResultCodeLdapPasswordPolicyHandlingStrategy) DefaultPasswordPolicyHandlingStrategy(org.apereo.cas.authentication.support.password.DefaultPasswordPolicyHandlingStrategy)

Aggregations

lombok.val (lombok.val)4 GroovyPasswordPolicyHandlingStrategy (org.apereo.cas.authentication.support.password.GroovyPasswordPolicyHandlingStrategy)4 DefaultPasswordPolicyHandlingStrategy (org.apereo.cas.authentication.support.password.DefaultPasswordPolicyHandlingStrategy)2 Test (org.junit.jupiter.api.Test)2 ApplicationContext (org.springframework.context.ApplicationContext)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 RejectResultCodeLdapPasswordPolicyHandlingStrategy (org.apereo.cas.authentication.support.RejectResultCodeLdapPasswordPolicyHandlingStrategy)1 PasswordPolicyContext (org.apereo.cas.authentication.support.password.PasswordPolicyContext)1 RejectResultCodePasswordPolicyHandlingStrategy (org.apereo.cas.authentication.support.password.RejectResultCodePasswordPolicyHandlingStrategy)1