Search in sources :

Example 1 with RecoveryFactor

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);
}
Also used : EnrolledFactor(io.gravitee.am.model.factor.EnrolledFactor) RecoveryFactor(io.gravitee.am.factor.api.RecoveryFactor) RecoveryFactor(io.gravitee.am.factor.api.RecoveryFactor) FactorContext(io.gravitee.am.factor.api.FactorContext) FactorProvider(io.gravitee.am.factor.api.FactorProvider)

Example 2 with RecoveryFactor

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);
}
Also used : EnrolledFactor(io.gravitee.am.model.factor.EnrolledFactor) Factor(io.gravitee.am.model.Factor) EnrolledFactor(io.gravitee.am.model.factor.EnrolledFactor) RecoveryFactor(io.gravitee.am.factor.api.RecoveryFactor) Date(java.util.Date)

Example 3 with RecoveryFactor

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);
}
Also used : DefaultUser(io.gravitee.am.identityprovider.api.DefaultUser) User(io.gravitee.am.model.User) Factor(io.gravitee.am.model.Factor) EnrolledFactor(io.gravitee.am.model.factor.EnrolledFactor) UpdateEnrolledFactor(io.gravitee.am.gateway.handler.account.model.UpdateEnrolledFactor) RecoveryFactor(io.gravitee.am.factor.api.RecoveryFactor) RecoveryFactor(io.gravitee.am.factor.api.RecoveryFactor) InvalidRequestException(io.gravitee.am.common.exception.oauth2.InvalidRequestException) Client(io.gravitee.am.model.oidc.Client)

Aggregations

RecoveryFactor (io.gravitee.am.factor.api.RecoveryFactor)3 EnrolledFactor (io.gravitee.am.model.factor.EnrolledFactor)3 Factor (io.gravitee.am.model.Factor)2 InvalidRequestException (io.gravitee.am.common.exception.oauth2.InvalidRequestException)1 FactorContext (io.gravitee.am.factor.api.FactorContext)1 FactorProvider (io.gravitee.am.factor.api.FactorProvider)1 UpdateEnrolledFactor (io.gravitee.am.gateway.handler.account.model.UpdateEnrolledFactor)1 DefaultUser (io.gravitee.am.identityprovider.api.DefaultUser)1 User (io.gravitee.am.model.User)1 Client (io.gravitee.am.model.oidc.Client)1 Date (java.util.Date)1