use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class PasswordExpiringWarningMessageDescriptorTests method verifySerialization.
@Test
public void verifySerialization() throws Exception {
val d = new PasswordExpiringWarningMessageDescriptor("DefaultMessage", 30);
val handler = new SimpleTestUsernamePasswordAuthenticationHandler();
handler.addMessageDescriptor(d);
val credential = new UsernamePasswordCredential("casuser", "resusac");
val result = handler.authenticate(credential);
assertNotNull(result);
assertNotNull(result.getPrincipal());
assertNotNull(result.getWarnings());
MAPPER.writeValue(JSON_FILE, result);
val read = MAPPER.readValue(JSON_FILE, AuthenticationHandlerExecutionResult.class);
assertEquals(result, read);
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class AuthenticationCredentialTypeMetaDataPopulatorTests method verifyPopulator.
@Test
public void verifyPopulator() {
val credentials = new UsernamePasswordCredential();
val builder = CoreAuthenticationTestUtils.getAuthenticationBuilder();
this.populator.populateAttributes(builder, new DefaultAuthenticationTransactionFactory().newTransaction(credentials));
val auth = builder.build();
assertEquals(credentials.getClass().getSimpleName(), auth.getAttributes().get(Credential.CREDENTIAL_TYPE_ATTRIBUTE).get(0));
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class CoreAuthenticationTestUtils method getAuthentication.
public static Authentication getAuthentication(final Principal principal, final Map<String, List<Object>> attributes, final ZonedDateTime authnDate) {
val handler = new SimpleTestUsernamePasswordAuthenticationHandler();
val meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
return new DefaultAuthenticationBuilder(principal).addCredential(meta).setAuthenticationDate(authnDate).addSuccess(handler.getName(), new DefaultAuthenticationHandlerExecutionResult(handler, meta)).setAttributes(attributes).build();
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class UsernamePasswordRestHttpRequestCredentialFactory method fromRequest.
@Override
public List<Credential> fromRequest(final HttpServletRequest request, final MultiValueMap<String, String> requestBody) {
if (requestBody == null || requestBody.isEmpty()) {
LOGGER.debug("Skipping [{}] because the requestBody is null or empty", getClass().getSimpleName());
return new ArrayList<>(0);
}
val username = requestBody.getFirst(RestHttpRequestCredentialFactory.PARAMETER_USERNAME);
val password = requestBody.getFirst(RestHttpRequestCredentialFactory.PARAMETER_PASSWORD);
if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) {
LOGGER.debug("Invalid payload; missing required fields.");
return new ArrayList<>(0);
}
val c = new UsernamePasswordCredential(username, password);
return CollectionUtils.wrap(c);
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class FileAuthenticationHandlerTests method verifyFailsUserNotInFileWithDefaultSeparator.
@Test
public void verifyFailsUserNotInFileWithDefaultSeparator() {
val c = new UsernamePasswordCredential();
c.setUsername("fds");
c.setPassword("rutgers");
assertThrows(AccountNotFoundException.class, () -> this.authenticationHandler.authenticate(c));
}
Aggregations