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);
}
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"));
}
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"));
}
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;
}
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));
}
Aggregations