use of org.apereo.cas.authentication.credential.OneTimePasswordCredential in project cas by apereo.
the class MultifactorAuthenticationTests method verifyAllowsAccessToHighSecurityServiceWithPasswordAndOTPViaRenew.
@Test
public void verifyAllowsAccessToHighSecurityServiceWithPasswordAndOTPViaRenew() {
val ctx2 = processAuthenticationAttempt(HIGH_SERVICE, newUserPassCredentials(ALICE, ALICE), new OneTimePasswordCredential(ALICE, PASSWORD_31415));
val tgt = cas.createTicketGrantingTicket(ctx2);
assertNotNull(tgt);
val st = cas.grantServiceTicket(tgt.getId(), HIGH_SERVICE, ctx2);
assertNotNull(st);
/*
* Confirm the authentication in the assertion
* is the one that satisfies security policy
*/
val assertion = cas.validateServiceTicket(st.getId(), HIGH_SERVICE);
val authn = assertion.getPrimaryAuthentication();
assertEquals(2, authn.getSuccesses().size());
assertTrue(authn.getSuccesses().containsKey(AcceptUsersAuthenticationHandler.class.getSimpleName()));
assertTrue(authn.getSuccesses().containsKey(TestOneTimePasswordAuthenticationHandler.class.getSimpleName()));
assertTrue(authn.getAttributes().containsKey(AuthenticationHandler.SUCCESSFUL_AUTHENTICATION_HANDLERS));
}
use of org.apereo.cas.authentication.credential.OneTimePasswordCredential in project cas by apereo.
the class MultifactorAuthenticationTests method verifyAllowsAccessToHighSecurityServiceWithPasswordAndOTP.
@Test
public void verifyAllowsAccessToHighSecurityServiceWithPasswordAndOTP() {
val ctx = processAuthenticationAttempt(HIGH_SERVICE, newUserPassCredentials(ALICE, ALICE), new OneTimePasswordCredential(ALICE, PASSWORD_31415));
val tgt = cas.createTicketGrantingTicket(ctx);
assertNotNull(tgt);
val st = cas.grantServiceTicket(tgt.getId(), HIGH_SERVICE, ctx);
assertNotNull(st);
}
use of org.apereo.cas.authentication.credential.OneTimePasswordCredential in project cas by apereo.
the class PasswordlessTokenAuthenticationHandler method doAuthentication.
@Override
protected AuthenticationHandlerExecutionResult doAuthentication(final Credential credential) throws GeneralSecurityException {
val c = (OneTimePasswordCredential) credential;
val token = passwordlessTokenRepository.findToken(c.getId());
if (token.isPresent() && token.get().equalsIgnoreCase(c.getPassword())) {
val principal = principalFactory.createPrincipal(c.getId());
return createHandlerResult(credential, principal, new ArrayList<>(0));
}
throw new FailedLoginException("Passwordless authentication has failed");
}
use of org.apereo.cas.authentication.credential.OneTimePasswordCredential 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