Search in sources :

Example 6 with OneTimePasswordCredential

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));
}
Also used : lombok.val(lombok.val) OneTimePasswordCredential(org.apereo.cas.authentication.credential.OneTimePasswordCredential) Test(org.junit.jupiter.api.Test)

Example 7 with OneTimePasswordCredential

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);
}
Also used : lombok.val(lombok.val) OneTimePasswordCredential(org.apereo.cas.authentication.credential.OneTimePasswordCredential) Test(org.junit.jupiter.api.Test)

Example 8 with OneTimePasswordCredential

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");
}
Also used : lombok.val(lombok.val) FailedLoginException(javax.security.auth.login.FailedLoginException) OneTimePasswordCredential(org.apereo.cas.authentication.credential.OneTimePasswordCredential)

Example 9 with OneTimePasswordCredential

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();
}
Also used : lombok.val(lombok.val) FailedLoginException(javax.security.auth.login.FailedLoginException) OneTimePasswordCredential(org.apereo.cas.authentication.credential.OneTimePasswordCredential) DefaultAuthenticationHandlerExecutionResult(org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult) BasicCredentialMetaData(org.apereo.cas.authentication.metadata.BasicCredentialMetaData)

Aggregations

lombok.val (lombok.val)9 OneTimePasswordCredential (org.apereo.cas.authentication.credential.OneTimePasswordCredential)9 Test (org.junit.jupiter.api.Test)6 FailedLoginException (javax.security.auth.login.FailedLoginException)2 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)1 DefaultAuthenticationHandlerExecutionResult (org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult)1 UsernamePasswordCredential (org.apereo.cas.authentication.credential.UsernamePasswordCredential)1 BasicCredentialMetaData (org.apereo.cas.authentication.metadata.BasicCredentialMetaData)1 InMemoryPasswordlessTokenRepository (org.apereo.cas.impl.token.InMemoryPasswordlessTokenRepository)1 ServicesManager (org.apereo.cas.services.ServicesManager)1 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)1 LocalAttributeMap (org.springframework.webflow.core.collection.LocalAttributeMap)1