Search in sources :

Example 6 with PasswordEncoder

use of org.springframework.security.crypto.password.PasswordEncoder in project cas by apereo.

the class DefaultPasswordEncoderTests method verifyPasswordEncoderByCustomClassName.

@Test
public void verifyPasswordEncoderByCustomClassName() {
    final PasswordEncoderProperties p = new PasswordEncoderProperties();
    p.setType(StandardPasswordEncoder.class.getName());
    p.setSecret("SECRET");
    final PasswordEncoder e = Beans.newPasswordEncoder(p);
    assertNotNull(e);
}
Also used : StandardPasswordEncoder(org.springframework.security.crypto.password.StandardPasswordEncoder) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) StandardPasswordEncoder(org.springframework.security.crypto.password.StandardPasswordEncoder) PasswordEncoderProperties(org.apereo.cas.configuration.model.core.authentication.PasswordEncoderProperties) Test(org.junit.Test)

Example 7 with PasswordEncoder

use of org.springframework.security.crypto.password.PasswordEncoder in project cas by apereo.

the class DefaultPasswordEncoderTests method verifyPasswordEncoderBySHA256.

@Test
public void verifyPasswordEncoderBySHA256() {
    final PasswordEncoderProperties p = new PasswordEncoderProperties();
    p.setType(PasswordEncoderProperties.PasswordEncoderTypes.DEFAULT.name());
    p.setEncodingAlgorithm("SHA-256");
    p.setCharacterEncoding("UTF-8");
    final PasswordEncoder e = Beans.newPasswordEncoder(p);
    assertTrue(e.matches("asd123", "54d5cb2d332dbdb4850293caae4559ce88b65163f1ea5d4e4b3ac49d772ded14"));
}
Also used : PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) StandardPasswordEncoder(org.springframework.security.crypto.password.StandardPasswordEncoder) PasswordEncoderProperties(org.apereo.cas.configuration.model.core.authentication.PasswordEncoderProperties) Test(org.junit.Test)

Example 8 with PasswordEncoder

use of org.springframework.security.crypto.password.PasswordEncoder in project cas by apereo.

the class DefaultPasswordEncoderTests method verifyPasswordEncoderBySHA1.

@Test
public void verifyPasswordEncoderBySHA1() {
    final PasswordEncoderProperties p = new PasswordEncoderProperties();
    p.setType(PasswordEncoderProperties.PasswordEncoderTypes.DEFAULT.name());
    p.setEncodingAlgorithm("SHA-1");
    p.setCharacterEncoding("UTF-8");
    final PasswordEncoder e = Beans.newPasswordEncoder(p);
    assertTrue(e.matches("asd123", "2891baceeef1652ee698294da0e71ba78a2a4064"));
}
Also used : PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) StandardPasswordEncoder(org.springframework.security.crypto.password.StandardPasswordEncoder) PasswordEncoderProperties(org.apereo.cas.configuration.model.core.authentication.PasswordEncoderProperties) Test(org.junit.Test)

Example 9 with PasswordEncoder

use of org.springframework.security.crypto.password.PasswordEncoder in project cas by apereo.

the class JdbcPasswordManagementService method change.

@Audit(action = "CHANGE_PASSWORD", actionResolverName = "CHANGE_PASSWORD_ACTION_RESOLVER", resourceResolverName = "CHANGE_PASSWORD_RESOURCE_RESOLVER")
@Override
public boolean change(final Credential credential, final PasswordChangeBean bean) {
    Assert.notNull(credential, "Credential cannot be null");
    Assert.notNull(bean, "PasswordChangeBean cannot be null");
    final UsernamePasswordCredential c = (UsernamePasswordCredential) credential;
    final PasswordEncoder encoder = Beans.newPasswordEncoder(passwordManagementProperties.getJdbc().getPasswordEncoder());
    final String password = encoder.encode(bean.getPassword());
    final int count = this.jdbcTemplate.update(passwordManagementProperties.getJdbc().getSqlChangePassword(), password, c.getId());
    return count > 0;
}
Also used : PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Audit(org.apereo.inspektr.audit.annotation.Audit)

Example 10 with PasswordEncoder

use of org.springframework.security.crypto.password.PasswordEncoder in project spring-security by spring-projects.

the class DaoAuthenticationProviderTests method testUserNotFoundEncodesPassword.

// SEC-2056
@Test
public void testUserNotFoundEncodesPassword() {
    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("missing", "koala");
    PasswordEncoder encoder = mock(PasswordEncoder.class);
    when(encoder.encode(anyString())).thenReturn("koala");
    DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
    provider.setHideUserNotFoundExceptions(false);
    provider.setPasswordEncoder(encoder);
    provider.setUserDetailsService(new MockAuthenticationDaoUserrod());
    try {
        provider.authenticate(token);
        fail("Expected Exception");
    } catch (UsernameNotFoundException success) {
    }
    // ensure encoder invoked w/ non-null strings since PasswordEncoder impls may fail
    // if encoded password is null
    verify(encoder).matches(isA(String.class), isA(String.class));
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) ShaPasswordEncoder(org.springframework.security.authentication.encoding.ShaPasswordEncoder) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

PasswordEncoder (org.springframework.security.crypto.password.PasswordEncoder)12 Test (org.junit.Test)9 PasswordEncoderProperties (org.apereo.cas.configuration.model.core.authentication.PasswordEncoderProperties)5 BCryptPasswordEncoder (org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)5 StandardPasswordEncoder (org.springframework.security.crypto.password.StandardPasswordEncoder)5 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)4 ShaPasswordEncoder (org.springframework.security.authentication.encoding.ShaPasswordEncoder)4 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)4 SecureRandom (java.security.SecureRandom)2 ArrayList (java.util.ArrayList)1 HandlerResult (org.apereo.cas.authentication.HandlerResult)1 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)1 DefaultPasswordEncoder (org.apereo.cas.util.crypto.DefaultPasswordEncoder)1 PrefixSuffixPrincipalNameTransformer (org.apereo.cas.util.transforms.PrefixSuffixPrincipalNameTransformer)1 Audit (org.apereo.inspektr.audit.annotation.Audit)1 Matchers.anyString (org.mockito.Matchers.anyString)1 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 NoOpPasswordEncoder (org.springframework.security.crypto.password.NoOpPasswordEncoder)1 Pbkdf2PasswordEncoder (org.springframework.security.crypto.password.Pbkdf2PasswordEncoder)1