Search in sources :

Example 1 with OneTimeTokenAccount

use of org.apereo.cas.otp.repository.credentials.OneTimeTokenAccount in project cas by apereo.

the class OneTimeTokenAccountCheckRegistrationAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
    final RequestContext context = RequestContextHolder.getRequestContext();
    final String uid = WebUtils.getAuthentication(context).getPrincipal().getId();
    final String secretKey = repository.getSecret(uid);
    if (StringUtils.isBlank(secretKey)) {
        final OneTimeTokenAccount keyAccount = this.repository.create(uid);
        final String keyUri = "otpauth://totp/" + this.label + ':' + uid + "?secret=" + keyAccount.getSecretKey() + "&issuer=" + this.issuer;
        requestContext.getFlowScope().put("key", keyAccount);
        requestContext.getFlowScope().put("keyUri", keyUri);
        LOGGER.debug("Registration key URI is [{}]", keyUri);
        return new EventFactorySupport().event(this, "register");
    }
    return success();
}
Also used : OneTimeTokenAccount(org.apereo.cas.otp.repository.credentials.OneTimeTokenAccount) RequestContext(org.springframework.webflow.execution.RequestContext) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Example 2 with OneTimeTokenAccount

use of org.apereo.cas.otp.repository.credentials.OneTimeTokenAccount in project cas by apereo.

the class OneTimeTokenAccountSaveRegistrationAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
    final OneTimeTokenAccount account = requestContext.getFlowScope().get("key", OneTimeTokenAccount.class);
    final String uid = WebUtils.getAuthentication(requestContext).getPrincipal().getId();
    repository.save(uid, account.getSecretKey(), account.getValidationCode(), account.getScratchCodes());
    return success();
}
Also used : OneTimeTokenAccount(org.apereo.cas.otp.repository.credentials.OneTimeTokenAccount)

Aggregations

OneTimeTokenAccount (org.apereo.cas.otp.repository.credentials.OneTimeTokenAccount)2 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)1 RequestContext (org.springframework.webflow.execution.RequestContext)1