use of org.apereo.cas.authentication.OneTimePasswordCredential in project cas by apereo.
the class MultifactorAuthenticationTests method verifyAllowsAccessToNormalSecurityServiceWithOTP.
@Test
public void verifyAllowsAccessToNormalSecurityServiceWithOTP() throws Exception {
final AuthenticationResult ctx = processAuthenticationAttempt(NORMAL_SERVICE, new OneTimePasswordCredential(ALICE, PASSWORD_31415));
final TicketGrantingTicket tgt = cas.createTicketGrantingTicket(ctx);
assertNotNull(tgt);
final ServiceTicket st = cas.grantServiceTicket(tgt.getId(), NORMAL_SERVICE, ctx);
assertNotNull(st);
}
use of org.apereo.cas.authentication.OneTimePasswordCredential in project cas by apereo.
the class TestOneTimePasswordAuthenticationHandler method authenticate.
@Override
public HandlerResult authenticate(final Credential credential) throws GeneralSecurityException, PreventedException {
final OneTimePasswordCredential otp = (OneTimePasswordCredential) credential;
final String valueOnRecord = credentialMap.get(otp.getId());
if (otp.getPassword().equals(valueOnRecord)) {
return new DefaultHandlerResult(this, new BasicCredentialMetaData(otp), new DefaultPrincipalFactory().createPrincipal(otp.getId()));
}
throw new FailedLoginException();
}
use of org.apereo.cas.authentication.OneTimePasswordCredential in project cas by apereo.
the class MultifactorAuthenticationTests method verifyAllowsAccessToHighSecurityServiceWithPasswordAndOTP.
@Test
public void verifyAllowsAccessToHighSecurityServiceWithPasswordAndOTP() throws Exception {
final AuthenticationResult ctx = processAuthenticationAttempt(HIGH_SERVICE, newUserPassCredentials(ALICE, ALICE), new OneTimePasswordCredential(ALICE, PASSWORD_31415));
final TicketGrantingTicket tgt = cas.createTicketGrantingTicket(ctx);
assertNotNull(tgt);
final ServiceTicket st = cas.grantServiceTicket(tgt.getId(), HIGH_SERVICE, ctx);
assertNotNull(st);
}
use of org.apereo.cas.authentication.OneTimePasswordCredential in project cas by apereo.
the class MultifactorAuthenticationTests method verifyDeniesAccessToHighSecurityServiceWithOTP.
@Test
public void verifyDeniesAccessToHighSecurityServiceWithOTP() throws Exception {
final AuthenticationResult ctx = processAuthenticationAttempt(HIGH_SERVICE, new OneTimePasswordCredential(ALICE, PASSWORD_31415));
final TicketGrantingTicket tgt = cas.createTicketGrantingTicket(ctx);
assertNotNull(tgt);
this.thrown.expect(UnsatisfiedAuthenticationPolicyException.class);
final ServiceTicket st = cas.grantServiceTicket(tgt.getId(), HIGH_SERVICE, ctx);
assertNotNull(st);
}
use of org.apereo.cas.authentication.OneTimePasswordCredential in project cas by apereo.
the class MultifactorAuthenticationTests method verifyAllowsAccessToHighSecurityServiceWithPasswordAndOTPViaRenew.
@Test
public void verifyAllowsAccessToHighSecurityServiceWithPasswordAndOTPViaRenew() throws Exception {
// Note the original credential used to start SSO session does not satisfy security policy
final AuthenticationResult ctx2 = processAuthenticationAttempt(HIGH_SERVICE, newUserPassCredentials(ALICE, ALICE), new OneTimePasswordCredential(ALICE, PASSWORD_31415));
final TicketGrantingTicket tgt = cas.createTicketGrantingTicket(ctx2);
assertNotNull(tgt);
final ServiceTicket st = cas.grantServiceTicket(tgt.getId(), HIGH_SERVICE, ctx2);
assertNotNull(st);
// Confirm the authentication in the assertion is the one that satisfies security policy
final Assertion assertion = cas.validateServiceTicket(st.getId(), HIGH_SERVICE);
assertEquals(2, assertion.getPrimaryAuthentication().getSuccesses().size());
assertTrue(assertion.getPrimaryAuthentication().getSuccesses().containsKey(AcceptUsersAuthenticationHandler.class.getSimpleName()));
assertTrue(assertion.getPrimaryAuthentication().getSuccesses().containsKey(TestOneTimePasswordAuthenticationHandler.class.getSimpleName()));
assertTrue(assertion.getPrimaryAuthentication().getAttributes().containsKey(AuthenticationHandler.SUCCESSFUL_AUTHENTICATION_HANDLERS));
}
Aggregations