Search in sources :

Example 1 with ActivationRemoveResponse

use of io.getlime.security.powerauth.rest.api.model.response.v3.ActivationRemoveResponse in project powerauth-restful-integration by lime-company.

the class ActivationService method removeActivation.

/**
 * Remove activation.
 *
 * @param apiAuthentication PowerAuth API authentication object.
 * @return Activation remove response.
 * @throws PowerAuthActivationException     In case remove activation fails.
 */
public ActivationRemoveResponse removeActivation(PowerAuthApiAuthentication apiAuthentication) throws PowerAuthActivationException {
    try {
        // Fetch context information
        final String activationId = apiAuthentication.getActivationContext().getActivationId();
        final String userId = apiAuthentication.getUserId();
        final Long applicationId = apiAuthentication.getApplicationId();
        // Call other application specific cleanup logic
        final RemoveActivationResponse paResponse;
        if (activationProvider != null) {
            final boolean revokeCodes = activationProvider.shouldRevokeRecoveryCodeOnRemove(activationId, userId, applicationId);
            paResponse = powerAuthClient.removeActivation(activationId, null, revokeCodes);
            activationProvider.activationWasRemoved(activationId, userId, applicationId);
        } else {
            // do not revoke recovery codes
            paResponse = powerAuthClient.removeActivation(activationId, null);
        }
        // Prepare and return the response
        final ActivationRemoveResponse response = new ActivationRemoveResponse();
        response.setActivationId(paResponse.getActivationId());
        return response;
    } catch (Exception ex) {
        logger.warn("PowerAuth activation removal failed, error: {}", ex.getMessage());
        logger.debug(ex.getMessage(), ex);
        throw new PowerAuthActivationException();
    }
}
Also used : PowerAuthActivationException(io.getlime.security.powerauth.rest.api.spring.exception.PowerAuthActivationException) ActivationRemoveResponse(io.getlime.security.powerauth.rest.api.model.response.v3.ActivationRemoveResponse) PowerAuthActivationException(io.getlime.security.powerauth.rest.api.spring.exception.PowerAuthActivationException) PowerAuthInvalidRequestException(io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthInvalidRequestException) PowerAuthClientException(com.wultra.security.powerauth.client.model.error.PowerAuthClientException) PowerAuthRecoveryException(io.getlime.security.powerauth.rest.api.spring.exception.PowerAuthRecoveryException)

Example 2 with ActivationRemoveResponse

use of io.getlime.security.powerauth.rest.api.model.response.v3.ActivationRemoveResponse in project powerauth-restful-integration by lime-company.

the class ActivationController method removeActivation.

/**
 * Remove activation.
 * @param signatureHeader PowerAuth signature HTTP header.
 * @return PowerAuth RESTful response with {@link ActivationRemoveResponse} payload.
 * @throws PowerAuthActivationException In case activation access fails.
 * @throws PowerAuthAuthenticationException In case the signature validation fails.
 */
@RequestMapping(value = "remove", method = RequestMethod.POST)
public ObjectResponse<ActivationRemoveResponse> removeActivation(@RequestHeader(value = PowerAuthSignatureHttpHeader.HEADER_NAME) String signatureHeader) throws PowerAuthActivationException, PowerAuthAuthenticationException {
    // Request body needs to be set to null because the SDK uses null for the signature, although {} is sent as request body
    PowerAuthApiAuthentication apiAuthentication = authenticationProvider.validateRequestSignature("POST", null, "/pa/activation/remove", signatureHeader);
    if (apiAuthentication == null || apiAuthentication.getActivationContext().getActivationId() == null) {
        logger.debug("Signature validation failed");
        throw new PowerAuthSignatureInvalidException();
    }
    if (!"2.0".equals(apiAuthentication.getVersion()) && !"2.1".equals(apiAuthentication.getVersion())) {
        logger.warn("Endpoint does not support PowerAuth protocol version {}", apiAuthentication.getVersion());
        throw new PowerAuthInvalidRequestException();
    }
    ActivationRemoveResponse response = activationServiceV3.removeActivation(apiAuthentication);
    return new ObjectResponse<>(response);
}
Also used : PowerAuthInvalidRequestException(io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthInvalidRequestException) PowerAuthSignatureInvalidException(io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthSignatureInvalidException) ActivationRemoveResponse(io.getlime.security.powerauth.rest.api.model.response.v3.ActivationRemoveResponse) PowerAuthApiAuthentication(io.getlime.security.powerauth.rest.api.spring.authentication.PowerAuthApiAuthentication) ObjectResponse(io.getlime.core.rest.model.base.response.ObjectResponse)

Example 3 with ActivationRemoveResponse

use of io.getlime.security.powerauth.rest.api.model.response.v3.ActivationRemoveResponse in project powerauth-restful-integration by lime-company.

the class ActivationController method removeActivation.

/**
 * Remove activation.
 * @param signatureHeader PowerAuth signature HTTP header.
 * @param httpServletRequest HTTP servlet request.
 * @return PowerAuth RESTful response with {@link ActivationRemoveResponse} payload.
 * @throws PowerAuthActivationException In case activation access fails.
 * @throws PowerAuthAuthenticationException In case the signature validation fails.
 */
@RequestMapping(value = "remove", method = RequestMethod.POST)
public ObjectResponse<ActivationRemoveResponse> removeActivation(@RequestHeader(value = PowerAuthSignatureHttpHeader.HEADER_NAME) String signatureHeader, HttpServletRequest httpServletRequest) throws PowerAuthActivationException, PowerAuthAuthenticationException {
    byte[] requestBodyBytes = authenticationProvider.extractRequestBodyBytes(httpServletRequest);
    PowerAuthApiAuthentication apiAuthentication = authenticationProvider.validateRequestSignature("POST", requestBodyBytes, "/pa/activation/remove", signatureHeader);
    if (apiAuthentication == null || apiAuthentication.getActivationContext().getActivationId() == null) {
        logger.debug("Signature validation failed");
        throw new PowerAuthSignatureInvalidException();
    }
    if (!"3.0".equals(apiAuthentication.getVersion()) && !"3.1".equals(apiAuthentication.getVersion())) {
        logger.warn("Endpoint does not support PowerAuth protocol version {}", apiAuthentication.getVersion());
        throw new PowerAuthInvalidRequestException();
    }
    ActivationRemoveResponse response = activationServiceV3.removeActivation(apiAuthentication);
    return new ObjectResponse<>(response);
}
Also used : PowerAuthInvalidRequestException(io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthInvalidRequestException) PowerAuthSignatureInvalidException(io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthSignatureInvalidException) ActivationRemoveResponse(io.getlime.security.powerauth.rest.api.model.response.v3.ActivationRemoveResponse) PowerAuthApiAuthentication(io.getlime.security.powerauth.rest.api.spring.authentication.PowerAuthApiAuthentication) ObjectResponse(io.getlime.core.rest.model.base.response.ObjectResponse)

Aggregations

ActivationRemoveResponse (io.getlime.security.powerauth.rest.api.model.response.v3.ActivationRemoveResponse)3 PowerAuthInvalidRequestException (io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthInvalidRequestException)3 ObjectResponse (io.getlime.core.rest.model.base.response.ObjectResponse)2 PowerAuthApiAuthentication (io.getlime.security.powerauth.rest.api.spring.authentication.PowerAuthApiAuthentication)2 PowerAuthSignatureInvalidException (io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthSignatureInvalidException)2 PowerAuthClientException (com.wultra.security.powerauth.client.model.error.PowerAuthClientException)1 PowerAuthActivationException (io.getlime.security.powerauth.rest.api.spring.exception.PowerAuthActivationException)1 PowerAuthRecoveryException (io.getlime.security.powerauth.rest.api.spring.exception.PowerAuthRecoveryException)1