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();
}
}
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);
}
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);
}
Aggregations