Search in sources :

Example 1 with QueryEncodeJdbcAuthenticationProperties

use of org.apereo.cas.configuration.model.support.jdbc.authn.QueryEncodeJdbcAuthenticationProperties in project cas by apereo.

the class QueryAndEncodeDatabaseAuthenticationHandlerTests method verifyAuthenticationInvalidSql.

@Test
public void verifyAuthenticationInvalidSql() {
    val properties = new QueryEncodeJdbcAuthenticationProperties().setAlgorithmName(ALG_NAME).setSql(buildSql("makesNoSenseInSql")).setPasswordFieldName(PASSWORD_FIELD_NAME).setSaltFieldName("salt").setDisabledFieldName("ops");
    val q = new QueryAndEncodeDatabaseAuthenticationHandler(properties, null, PrincipalFactoryUtils.newPrincipalFactory(), dataSource);
    assertThrows(PreventedException.class, () -> q.authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword()));
}
Also used : lombok.val(lombok.val) QueryEncodeJdbcAuthenticationProperties(org.apereo.cas.configuration.model.support.jdbc.authn.QueryEncodeJdbcAuthenticationProperties) Test(org.junit.jupiter.api.Test)

Example 2 with QueryEncodeJdbcAuthenticationProperties

use of org.apereo.cas.configuration.model.support.jdbc.authn.QueryEncodeJdbcAuthenticationProperties in project cas by apereo.

the class QueryAndEncodeDatabaseAuthenticationHandlerTests method verifyAuthenticationSuccessfulWithAPasswordEncoder.

@Test
public void verifyAuthenticationSuccessfulWithAPasswordEncoder() throws Exception {
    val properties = new QueryEncodeJdbcAuthenticationProperties().setAlgorithmName(ALG_NAME).setSql(buildSql()).setPasswordFieldName(PASSWORD_FIELD_NAME).setNumberOfIterationsFieldName(NUM_ITERATIONS_FIELD_NAME).setStaticSalt(STATIC_SALT).setSaltFieldName("salt");
    val q = new QueryAndEncodeDatabaseAuthenticationHandler(properties, null, PrincipalFactoryUtils.newPrincipalFactory(), dataSource);
    q.setPasswordEncoder(new PasswordEncoder() {

        @Override
        public String encode(final CharSequence password) {
            return password.toString().concat("1");
        }

        @Override
        public boolean matches(final CharSequence rawPassword, final String encodedPassword) {
            return true;
        }
    });
    q.setPrincipalNameTransformer(new PrefixSuffixPrincipalNameTransformer("user", null));
    val r = q.authenticate(CoreAuthenticationTestUtils.getCredentialsWithDifferentUsernameAndPassword("1", "user"));
    assertNotNull(r);
    assertEquals("user1", r.getPrincipal().getId());
}
Also used : lombok.val(lombok.val) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) QueryEncodeJdbcAuthenticationProperties(org.apereo.cas.configuration.model.support.jdbc.authn.QueryEncodeJdbcAuthenticationProperties) PrefixSuffixPrincipalNameTransformer(org.apereo.cas.util.transforms.PrefixSuffixPrincipalNameTransformer) Test(org.junit.jupiter.api.Test)

Example 3 with QueryEncodeJdbcAuthenticationProperties

use of org.apereo.cas.configuration.model.support.jdbc.authn.QueryEncodeJdbcAuthenticationProperties in project cas by apereo.

the class QueryAndEncodeDatabaseAuthenticationHandlerTests method verifyAuthenticationWithDisabledField.

@Test
public void verifyAuthenticationWithDisabledField() {
    val properties = new QueryEncodeJdbcAuthenticationProperties().setAlgorithmName(ALG_NAME).setSql(buildSql()).setPasswordFieldName(PASSWORD_FIELD_NAME).setDisabledFieldName(DISABLED_FIELD_NAME).setStaticSalt(STATIC_SALT).setSaltFieldName("salt");
    val q = new QueryAndEncodeDatabaseAuthenticationHandler(properties, null, PrincipalFactoryUtils.newPrincipalFactory(), dataSource);
    assertThrows(AccountDisabledException.class, () -> q.authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword("user21")));
}
Also used : lombok.val(lombok.val) QueryEncodeJdbcAuthenticationProperties(org.apereo.cas.configuration.model.support.jdbc.authn.QueryEncodeJdbcAuthenticationProperties) Test(org.junit.jupiter.api.Test)

Example 4 with QueryEncodeJdbcAuthenticationProperties

use of org.apereo.cas.configuration.model.support.jdbc.authn.QueryEncodeJdbcAuthenticationProperties in project cas by apereo.

the class QueryAndEncodeDatabaseAuthenticationHandlerTests method verifyAuthenticationWithExpiredField.

@Test
public void verifyAuthenticationWithExpiredField() {
    val properties = new QueryEncodeJdbcAuthenticationProperties().setAlgorithmName(ALG_NAME).setSql(buildSql()).setPasswordFieldName(PASSWORD_FIELD_NAME).setExpiredFieldName(EXPIRED_FIELD_NAME).setStaticSalt(STATIC_SALT).setSaltFieldName("salt");
    val q = new QueryAndEncodeDatabaseAuthenticationHandler(properties, null, PrincipalFactoryUtils.newPrincipalFactory(), dataSource);
    assertThrows(AccountPasswordMustChangeException.class, () -> q.authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword("user20")));
}
Also used : lombok.val(lombok.val) QueryEncodeJdbcAuthenticationProperties(org.apereo.cas.configuration.model.support.jdbc.authn.QueryEncodeJdbcAuthenticationProperties) Test(org.junit.jupiter.api.Test)

Example 5 with QueryEncodeJdbcAuthenticationProperties

use of org.apereo.cas.configuration.model.support.jdbc.authn.QueryEncodeJdbcAuthenticationProperties in project cas by apereo.

the class QueryAndEncodeDatabaseAuthenticationHandlerTests method verifyAuthenticationSuccessful.

@Test
public void verifyAuthenticationSuccessful() throws Exception {
    val properties = new QueryEncodeJdbcAuthenticationProperties().setAlgorithmName(ALG_NAME).setSql(buildSql()).setPasswordFieldName(PASSWORD_FIELD_NAME).setSaltFieldName("salt").setDisabledFieldName("ops").setNumberOfIterationsFieldName(NUM_ITERATIONS_FIELD_NAME).setStaticSalt(STATIC_SALT);
    val q = new QueryAndEncodeDatabaseAuthenticationHandler(properties, null, PrincipalFactoryUtils.newPrincipalFactory(), dataSource);
    val c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword("user1");
    val r = q.authenticate(c);
    assertNotNull(r);
    assertEquals("user1", r.getPrincipal().getId());
}
Also used : lombok.val(lombok.val) QueryEncodeJdbcAuthenticationProperties(org.apereo.cas.configuration.model.support.jdbc.authn.QueryEncodeJdbcAuthenticationProperties) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)7 QueryEncodeJdbcAuthenticationProperties (org.apereo.cas.configuration.model.support.jdbc.authn.QueryEncodeJdbcAuthenticationProperties)7 Test (org.junit.jupiter.api.Test)7 PrefixSuffixPrincipalNameTransformer (org.apereo.cas.util.transforms.PrefixSuffixPrincipalNameTransformer)1 PasswordEncoder (org.springframework.security.crypto.password.PasswordEncoder)1