use of com.wultra.security.powerauth.client.v3.CommitUpgradeResponse in project powerauth-restful-integration by lime-company.
the class UpgradeService method upgradeCommit.
/**
* Commit upgrade of activation to version 3.
* @param signatureHeader PowerAuth signature HTTP header.
* @param httpServletRequest HTTP servlet request.
* @return Commit upgrade response.
* @throws PowerAuthAuthenticationException in case authentication fails.
* @throws PowerAuthUpgradeException In case upgrade commit fails.
*/
public Response upgradeCommit(String signatureHeader, HttpServletRequest httpServletRequest) throws PowerAuthAuthenticationException, PowerAuthUpgradeException {
try {
// Extract request body
final byte[] requestBodyBytes = authenticationProvider.extractRequestBodyBytes(httpServletRequest);
if (requestBodyBytes == null || requestBodyBytes.length == 0) {
// Expected request body is {}, do not accept empty body
logger.warn("Empty request body");
throw new PowerAuthInvalidRequestException();
}
// Verify signature, force signature version during upgrade to version 3
final List<PowerAuthSignatureTypes> allowedSignatureTypes = Collections.singletonList(PowerAuthSignatureTypes.POSSESSION);
final PowerAuthApiAuthentication authentication = authenticationProvider.validateRequestSignatureWithActivationDetails("POST", requestBodyBytes, "/pa/upgrade/commit", signatureHeader, allowedSignatureTypes, 3);
// In case signature verification fails, upgrade fails, too
if (!authentication.getAuthenticationContext().isValid() || authentication.getActivationContext().getActivationId() == null) {
logger.debug("Signature validation failed");
throw new PowerAuthSignatureInvalidException();
}
// Get signature HTTP headers
final String activationId = authentication.getActivationContext().getActivationId();
final PowerAuthSignatureHttpHeader httpHeader = (PowerAuthSignatureHttpHeader) authentication.getHttpHeader();
final String applicationKey = httpHeader.getApplicationKey();
// Commit upgrade on PowerAuth server
final CommitUpgradeResponse upgradeResponse = powerAuthClient.commitUpgrade(activationId, applicationKey);
if (upgradeResponse.isCommitted()) {
return new Response();
} else {
logger.debug("Upgrade commit failed");
throw new PowerAuthUpgradeException();
}
} catch (PowerAuthAuthenticationException ex) {
throw ex;
} catch (Exception ex) {
logger.warn("PowerAuth upgrade commit failed, error: {}", ex.getMessage());
logger.debug(ex.getMessage(), ex);
throw new PowerAuthUpgradeException();
}
}
Aggregations