use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class BaseLdapAuthenticationHandlerTests method verifyAuthenticateSuccess.
@Test
public void verifyAuthenticateSuccess() {
assertNotEquals(ldapAuthenticationHandlers.size(), 0);
ldapAuthenticationHandlers.toList().forEach(Unchecked.consumer(h -> {
val credential = new UsernamePasswordCredential(getUsername(), getSuccessPassword());
val result = h.authenticate(credential);
assertNotNull(result.getPrincipal());
assertEquals(credential.getUsername(), result.getPrincipal().getId());
val attributes = result.getPrincipal().getAttributes();
Arrays.stream(getPrincipalAttributes()).forEach(s -> assertTrue(attributes.containsKey(s)));
}));
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class JdbcPasswordManagementService method changeInternal.
@Override
public boolean changeInternal(final Credential credential, final PasswordChangeRequest bean) {
var result = this.transactionTemplate.execute(action -> {
val c = (UsernamePasswordCredential) credential;
val password = passwordEncoder.encode(bean.getPassword());
val count = this.jdbcTemplate.update(properties.getJdbc().getSqlChangePassword(), password, c.getId());
return count > 0;
});
return BooleanUtils.toBoolean(result);
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class SurrogateInitialAuthenticationActionTests method verifyUsernamePasswordCredentialsFound.
@Test
public void verifyUsernamePasswordCredentialsFound() {
try {
val context = new MockRequestContext();
val c = new UsernamePasswordCredential();
c.setUsername("cassurrogate+casuser");
c.setPassword("Mellon");
WebUtils.putCredential(context, c);
context.setExternalContext(new ServletExternalContext(new MockServletContext(), new MockHttpServletRequest(), new MockHttpServletResponse()));
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, authenticationViaFormAction.execute(context).getId());
assertTrue(WebUtils.getCredential(context) instanceof UsernamePasswordCredential);
} catch (final Exception e) {
throw new AssertionError(e);
}
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class SurrogateInitialAuthenticationActionTests method verifyUsernamePasswordCredentialsBadPasswordAndCancelled.
@Test
public void verifyUsernamePasswordCredentialsBadPasswordAndCancelled() {
try {
val context = new MockRequestContext();
var credential = new UsernamePasswordCredential();
credential.setUsername("cassurrogate+casuser");
credential.setPassword("badpassword");
WebUtils.putCredential(context, credential);
context.setExternalContext(new ServletExternalContext(new MockServletContext(), new MockHttpServletRequest(), new MockHttpServletResponse()));
assertEquals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, authenticationViaFormAction.execute(context).getId());
assertTrue(WebUtils.getCredential(context) instanceof SurrogateUsernamePasswordCredential);
val sc = WebUtils.getCredential(context, SurrogateUsernamePasswordCredential.class);
sc.setUsername("casuser");
sc.setPassword("Mellon");
WebUtils.putCredential(context, sc);
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, authenticationViaFormAction.execute(context).getId());
assertTrue(WebUtils.getCredential(context) instanceof UsernamePasswordCredential);
} catch (final Exception e) {
throw new AssertionError(e);
}
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class AbstractUsernamePasswordAuthenticationHandler method doAuthentication.
@SneakyThrows
@Override
protected AuthenticationHandlerExecutionResult doAuthentication(final Credential credential) {
val originalUserPass = (UsernamePasswordCredential) credential;
val userPass = (UsernamePasswordCredential) credential.getClass().getDeclaredConstructor().newInstance();
BeanUtils.copyProperties(userPass, originalUserPass);
transformUsername(userPass);
transformPassword(userPass);
LOGGER.debug("Attempting authentication internally for transformed credential [{}]", userPass);
return authenticateUsernamePasswordInternal(userPass, originalUserPass.getPassword());
}
Aggregations