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));
}
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));
}
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());
}
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;
}
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;
}
Aggregations