use of org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult in project cas by apereo.
the class CasKryoTranscoderTests method verifyEncodeDecodeTGTImpl.
@Test
public void verifyEncodeDecodeTGTImpl() {
val userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
val bldr = new DefaultAuthenticationBuilder(PrincipalFactoryUtils.newPrincipalFactory().createPrincipal("user", new HashMap<>(this.principalAttributes)));
bldr.setAttributes(new HashMap<>(this.principalAttributes));
bldr.setAuthenticationDate(ZonedDateTime.now(ZoneId.systemDefault()));
bldr.addCredential(new BasicCredentialMetaData(userPassCredential));
bldr.addFailure("error", new AccountNotFoundException());
bldr.addSuccess("authn", new DefaultAuthenticationHandlerExecutionResult(new AcceptUsersAuthenticationHandler(StringUtils.EMPTY), new BasicCredentialMetaData(userPassCredential)));
val authentication = bldr.build();
val expectedTGT = new TicketGrantingTicketImpl(TGT_ID, RegisteredServiceTestUtils.getService(), null, authentication, NeverExpiresExpirationPolicy.INSTANCE);
val serviceTicket = (ProxyGrantingTicketIssuerTicket) expectedTGT.grantServiceTicket(ST_ID, RegisteredServiceTestUtils.getService(), NeverExpiresExpirationPolicy.INSTANCE, false, true);
var encoded = transcoder.encode(expectedTGT);
var decoded = transcoder.decode(encoded);
assertEquals(expectedTGT, decoded);
encoded = transcoder.encode(serviceTicket);
decoded = transcoder.decode(encoded);
assertEquals(serviceTicket, decoded);
decoded = transcoder.decode(encoded);
assertEquals(serviceTicket, decoded);
val pgt = serviceTicket.grantProxyGrantingTicket(PGT_ID, authentication, new HardTimeoutExpirationPolicy(100));
encoded = transcoder.encode(pgt);
decoded = transcoder.decode(encoded);
assertEquals(pgt, decoded);
val pt = pgt.grantProxyTicket(PT_ID, RegisteredServiceTestUtils.getService(), new HardTimeoutExpirationPolicy(100), true);
encoded = transcoder.encode(pt);
decoded = transcoder.decode(encoded);
assertEquals(pt, decoded);
}
use of org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult 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.DefaultAuthenticationHandlerExecutionResult in project cas by apereo.
the class TestOneTimePasswordAuthenticationHandler method authenticate.
@Override
public AuthenticationHandlerExecutionResult authenticate(final Credential credential) throws GeneralSecurityException {
val otp = (OneTimePasswordCredential) credential;
val valueOnRecord = credentialMap.get(otp.getId());
if (otp.getPassword().equals(valueOnRecord)) {
return new DefaultAuthenticationHandlerExecutionResult(this, new BasicCredentialMetaData(otp), getPrincipalFactory().createPrincipal(otp.getId()));
}
throw new FailedLoginException();
}
Aggregations