Search in sources :

Example 1 with GoogleAuthenticatorToken

use of org.apereo.cas.gauth.token.GoogleAuthenticatorToken in project cas by apereo.

the class GoogleAuthenticatorAuthenticationHandlerTests method verifyAuthnFailsTokenUsed.

@Test
public void verifyAuthnFailsTokenUsed() {
    val credential = getGoogleAuthenticatorTokenCredential();
    handler.getValidator().store(new GoogleAuthenticatorToken(Integer.valueOf(credential.getToken()), "casuser"));
    val toSave = OneTimeTokenAccount.builder().username("casuser").name(UUID.randomUUID().toString()).secretKey(account.getKey()).validationCode(account.getVerificationCode()).scratchCodes(new ArrayList<>(account.getScratchCodes())).build();
    tokenCredentialRepository.save(toSave);
    credential.setAccountId(toSave.getId());
    assertThrows(AccountExpiredException.class, () -> handler.authenticate(credential));
}
Also used : lombok.val(lombok.val) ArrayList(java.util.ArrayList) GoogleAuthenticatorToken(org.apereo.cas.gauth.token.GoogleAuthenticatorToken) Test(org.junit.jupiter.api.Test)

Example 2 with GoogleAuthenticatorToken

use of org.apereo.cas.gauth.token.GoogleAuthenticatorToken in project cas by apereo.

the class GoogleAuthenticatorOneTimeTokenCredentialValidatorTests method verifyStore.

@Test
public void verifyStore() {
    val token = new GoogleAuthenticatorToken(632435, "casuser");
    assertDoesNotThrow(() -> validator.store(token));
}
Also used : lombok.val(lombok.val) GoogleAuthenticatorToken(org.apereo.cas.gauth.token.GoogleAuthenticatorToken) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with GoogleAuthenticatorToken

use of org.apereo.cas.gauth.token.GoogleAuthenticatorToken in project syncope by apache.

the class SyncopeWAGoogleMfaAuthTokenRepositoryTest method verifyOps.

@Test
public void verifyOps() {
    tokenRepository.removeAll();
    GoogleAuthenticatorToken token = new GoogleAuthenticatorToken(123456, "SyncopeWA");
    tokenRepository.store(token);
    assertEquals(1, tokenRepository.count(token.getUserId()));
    assertEquals(1, tokenRepository.count());
}
Also used : GoogleAuthenticatorToken(org.apereo.cas.gauth.token.GoogleAuthenticatorToken) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.wa.starter.AbstractTest)

Example 4 with GoogleAuthenticatorToken

use of org.apereo.cas.gauth.token.GoogleAuthenticatorToken in project cas by apereo.

the class GoogleAuthenticatorSaveRegistrationAction method validate.

@Override
protected boolean validate(final OneTimeTokenAccount account, final RequestContext requestContext) {
    try {
        val token = requestContext.getRequestParameters().getRequiredInteger(REQUEST_PARAMETER_TOKEN);
        if (validator.isTokenAuthorizedFor(token, account)) {
            LOGGER.debug("Successfully validated token [{}]", token);
            val gtoken = new GoogleAuthenticatorToken(token, account.getUsername());
            validator.getTokenRepository().store(gtoken);
            return true;
        }
    } catch (final Exception e) {
        LoggingUtils.error(LOGGER, e);
    }
    return false;
}
Also used : lombok.val(lombok.val) GoogleAuthenticatorToken(org.apereo.cas.gauth.token.GoogleAuthenticatorToken)

Example 5 with GoogleAuthenticatorToken

use of org.apereo.cas.gauth.token.GoogleAuthenticatorToken in project syncope by apache.

the class SyncopeWAGoogleMfaAuthTokenRepository method get.

@Override
public OneTimeToken get(final String username, final Integer otp) {
    try {
        GoogleMfaAuthToken tokenTO = service().read(username, otp);
        GoogleAuthenticatorToken token = new GoogleAuthenticatorToken(tokenTO.getOtp(), username);
        LocalDateTime dateTime = tokenTO.getIssueDate().toInstant().atZone(ZoneOffset.UTC).toLocalDateTime();
        token.setIssuedDateTime(dateTime);
        return token;
    } catch (final Exception e) {
        LOG.debug("Unable to fetch token {} for user {}", otp, username);
    }
    return null;
}
Also used : LocalDateTime(java.time.LocalDateTime) GoogleMfaAuthToken(org.apache.syncope.common.lib.wa.GoogleMfaAuthToken) GoogleAuthenticatorToken(org.apereo.cas.gauth.token.GoogleAuthenticatorToken)

Aggregations

GoogleAuthenticatorToken (org.apereo.cas.gauth.token.GoogleAuthenticatorToken)6 lombok.val (lombok.val)4 Test (org.junit.jupiter.api.Test)3 IGoogleAuthenticator (com.warrenstrange.googleauth.IGoogleAuthenticator)1 GeneralSecurityException (java.security.GeneralSecurityException)1 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 AccountExpiredException (javax.security.auth.login.AccountExpiredException)1 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)1 Getter (lombok.Getter)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Slf4j (lombok.extern.slf4j.Slf4j)1 StringUtils (org.apache.commons.lang3.StringUtils)1 GoogleMfaAuthToken (org.apache.syncope.common.lib.wa.GoogleMfaAuthToken)1 AbstractTest (org.apache.syncope.wa.starter.AbstractTest)1 Authentication (org.apereo.cas.authentication.Authentication)1 OneTimeTokenAccount (org.apereo.cas.authentication.OneTimeTokenAccount)1