Search in sources :

Example 6 with PowerAuthApiAuthentication

use of io.getlime.security.powerauth.rest.api.spring.authentication.PowerAuthApiAuthentication 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 7 with PowerAuthApiAuthentication

use of io.getlime.security.powerauth.rest.api.spring.authentication.PowerAuthApiAuthentication 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

PowerAuthApiAuthentication (io.getlime.security.powerauth.rest.api.spring.authentication.PowerAuthApiAuthentication)7 PowerAuthSignatureTypes (io.getlime.security.powerauth.crypto.lib.enums.PowerAuthSignatureTypes)4 PowerAuthSignatureInvalidException (io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthSignatureInvalidException)4 PowerAuthInvalidRequestException (io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthInvalidRequestException)3 ObjectResponse (io.getlime.core.rest.model.base.response.ObjectResponse)2 PowerAuthSignatureHttpHeader (io.getlime.security.powerauth.http.PowerAuthSignatureHttpHeader)2 InvalidPowerAuthHttpHeaderException (io.getlime.security.powerauth.http.validator.InvalidPowerAuthHttpHeaderException)2 ActivationRemoveResponse (io.getlime.security.powerauth.rest.api.model.response.v3.ActivationRemoveResponse)2 PowerAuthAuthenticationException (io.getlime.security.powerauth.rest.api.spring.exception.PowerAuthAuthenticationException)2 PowerAuthHeaderMissingException (io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthHeaderMissingException)2 PowerAuthSignatureTypeInvalidException (io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthSignatureTypeInvalidException)2 Nonnull (javax.annotation.Nonnull)2 CommitUpgradeResponse (com.wultra.security.powerauth.client.v3.CommitUpgradeResponse)1 StartUpgradeResponse (com.wultra.security.powerauth.client.v3.StartUpgradeResponse)1 Response (io.getlime.core.rest.model.base.response.Response)1 PowerAuthTokenHttpHeader (io.getlime.security.powerauth.http.PowerAuthTokenHttpHeader)1 EciesEncryptedResponse (io.getlime.security.powerauth.rest.api.model.response.v3.EciesEncryptedResponse)1 PowerAuth (io.getlime.security.powerauth.rest.api.spring.annotation.PowerAuth)1 PowerAuthEncryption (io.getlime.security.powerauth.rest.api.spring.annotation.PowerAuthEncryption)1 PowerAuthToken (io.getlime.security.powerauth.rest.api.spring.annotation.PowerAuthToken)1