use of io.gravitee.am.factor.api.RecoveryFactor in project gravitee-access-management by gravitee-io.
the class MFAChallengeEndpoint method generateRecoveryCode.
private Completable generateRecoveryCode(io.gravitee.am.model.User endUser, Client client) {
final Factor recoveryFactor = getRecoveryFactor(client);
final FactorProvider recoveryFactorProvider = factorManager.get(recoveryFactor.getId());
final Map<String, Object> factorData = Map.of(FactorContext.KEY_RECOVERY_FACTOR, recoveryFactor, KEY_USER, endUser);
final FactorContext recoveryFactorCtx = new FactorContext(applicationContext, factorData);
return ((RecoveryFactor) recoveryFactorProvider).generateRecoveryCode(recoveryFactorCtx);
}
use of io.gravitee.am.factor.api.RecoveryFactor in project gravitee-access-management by gravitee-io.
the class RecoveryCodeFactorProvider method generateRecoveryCode.
@Override
public Completable generateRecoveryCode(FactorContext context) {
final Factor recoveryFactor = context.getData(FactorContext.KEY_RECOVERY_FACTOR, Factor.class);
final EnrolledFactor enrolledFactor = new EnrolledFactor();
enrolledFactor.setFactorId(recoveryFactor.getId());
enrolledFactor.setStatus(FactorStatus.PENDING_ACTIVATION);
enrolledFactor.setCreatedAt(new Date());
enrolledFactor.setUpdatedAt(enrolledFactor.getCreatedAt());
return addRecoveryCodeFactor(context, enrolledFactor);
}
use of io.gravitee.am.factor.api.RecoveryFactor in project gravitee-access-management by gravitee-io.
the class AccountFactorsEndpointHandler method enrollRecoveryCode.
/**
* Enroll user to recovery code factor and generate recovery code
* in the process
* @param routingContext the routingContext holding the current user
*/
public void enrollRecoveryCode(RoutingContext routingContext) {
final Client client = routingContext.get(ConstantKeys.CLIENT_CONTEXT_KEY);
final Factor recoveryCodeFactor = getClientRecoveryCodeFactor(client);
if (recoveryCodeFactor == null) {
routingContext.fail(new InvalidRequestException(client.getClientName() + " does not support recovery code. Please ask your administrator for further information."));
return;
}
final RecoveryFactor recoveryCodeFactorProvider = (RecoveryFactor) factorManager.get(recoveryCodeFactor.getId());
generateRecoveryCode(routingContext, recoveryCodeFactor, recoveryCodeFactorProvider).subscribe(() -> {
final User user = routingContext.get(ConstantKeys.USER_CONTEXT_KEY);
// Need updated user data after recovery code generation, hence the accountService call
accountService.get(user.getId()).subscribe(usr -> AccountResponseHandler.handleDefaultResponse(routingContext, getUserRecoveryCodes(usr)));
}, routingContext::fail);
}
Aggregations