use of org.apereo.cas.authentication.metadata.BasicCredentialMetaData in project cas by apereo.
the class CoreAuthenticationTestUtils method getAuthenticationBuilder.
public static AuthenticationBuilder getAuthenticationBuilder(final Principal principal) {
val meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
val handler = new SimpleTestUsernamePasswordAuthenticationHandler();
return new DefaultAuthenticationBuilder(principal).addCredential(meta).addSuccess(handler.getName(), new DefaultAuthenticationHandlerExecutionResult(handler, meta));
}
use of org.apereo.cas.authentication.metadata.BasicCredentialMetaData in project cas by apereo.
the class DefaultAuthenticationBuilderTests method verifyUpdateOperation.
@Test
public void verifyUpdateOperation() {
val meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
val handler = new SimpleTestUsernamePasswordAuthenticationHandler();
val builder = new DefaultAuthenticationBuilder(CoreAuthenticationTestUtils.getPrincipal());
builder.addSuccess("test", new DefaultAuthenticationHandlerExecutionResult(handler, meta));
builder.setCredentials(List.of(meta));
val authn = builder.build();
val builder2 = new DefaultAuthenticationBuilder(CoreAuthenticationTestUtils.getPrincipal());
builder2.setAuthenticationDate(ZonedDateTime.now(Clock.systemUTC()).plusDays(10));
builder2.addAttribute("authn2", "value2");
builder2.addWarning(new DefaultMessageDescriptor("code"));
val authn2 = builder2.build();
authn.updateAll(authn2);
assertTrue(authn.getAttributes().containsKey("authn2"));
}
use of org.apereo.cas.authentication.metadata.BasicCredentialMetaData in project cas by apereo.
the class DefaultAuthenticationBuilderTests method verifyOperation.
@Test
public void verifyOperation() {
val meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
val handler = new SimpleTestUsernamePasswordAuthenticationHandler();
val builder = new DefaultAuthenticationBuilder(CoreAuthenticationTestUtils.getPrincipal());
builder.addSuccess("test", new DefaultAuthenticationHandlerExecutionResult(handler, meta));
builder.setCredentials(List.of(meta));
val result = new DefaultAuthenticationHandlerExecutionResult(new SimpleTestUsernamePasswordAuthenticationHandler(), meta);
builder.addSuccess("Success", result);
builder.setFailures(Map.of("Failure1", new FailedLoginException()));
builder.addFailure("Success", new FailedLoginException());
assertFalse(builder.hasAttribute("invalid"));
assertNotNull(builder.build());
}
use of org.apereo.cas.authentication.metadata.BasicCredentialMetaData in project cas by apereo.
the class SimpleTestUsernamePasswordAuthenticationHandler method authenticateUsernamePasswordInternal.
@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(final UsernamePasswordCredential credential, final String originalPassword) throws GeneralSecurityException, PreventedException {
val username = credential.getUsername();
val password = credential.getPassword();
val exception = this.usernameErrorMap.get(username);
if (exception instanceof GeneralSecurityException) {
throw (GeneralSecurityException) exception;
}
if (exception instanceof PreventedException) {
throw (PreventedException) exception;
}
if (exception instanceof RuntimeException) {
throw (RuntimeException) exception;
}
if (exception != null) {
LOGGER.debug("Cannot throw checked exception [{}] since it is not declared by method signature.", exception.getClass().getName(), exception);
}
if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password) && (username.equals(password) || password.equals(StringUtils.reverse(username)))) {
LOGGER.debug("User [{}] was successfully authenticated.", username);
return new DefaultAuthenticationHandlerExecutionResult(this, new BasicCredentialMetaData(credential), this.principalFactory.createPrincipal(username), this.warnings);
}
LOGGER.debug("User [{}] failed authentication", username);
throw new FailedLoginException();
}
use of org.apereo.cas.authentication.metadata.BasicCredentialMetaData in project cas by apereo.
the class DefaultAuthenticationHandlerExecutionResultTests method verifyOperation.
@Test
public void verifyOperation() {
val otp = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
val res = new DefaultAuthenticationHandlerExecutionResult(new SimpleTestUsernamePasswordAuthenticationHandler(), new BasicCredentialMetaData(otp), CollectionUtils.wrapList(new DefaultMessageDescriptor("code1")));
assertFalse(res.getWarnings().isEmpty());
res.clearWarnings();
assertTrue(res.getWarnings().isEmpty());
}
Aggregations