use of io.getlime.core.rest.model.base.response.ObjectResponse in project powerauth-restful-integration by lime-company.
the class ActivationController method getActivationStatus.
/**
* Get activation status.
* @param request PowerAuth RESTful request with {@link ActivationStatusRequest} payload.
* @return PowerAuth RESTful response with {@link ActivationStatusResponse} payload.
*/
@RequestMapping(value = "status", method = RequestMethod.POST)
@ResponseBody
public ObjectResponse<ActivationStatusResponse> getActivationStatus(@RequestBody ObjectRequest<ActivationStatusRequest> request) throws PowerAuthActivationException {
try {
String activationId = request.getRequestObject().getActivationId();
GetActivationStatusResponse soapResponse = powerAuthClient.getActivationStatus(activationId);
ActivationStatusResponse response = new ActivationStatusResponse();
response.setActivationId(soapResponse.getActivationId());
response.setEncryptedStatusBlob(soapResponse.getEncryptedStatusBlob());
if (applicationConfiguration != null) {
response.setCustomObject(applicationConfiguration.statusServiceCustomObject());
}
return new ObjectResponse<>(response);
} catch (Exception ex) {
throw new PowerAuthActivationException();
}
}
use of io.getlime.core.rest.model.base.response.ObjectResponse in project powerauth-restful-integration by lime-company.
the class TokenController method removeToken.
@RequestMapping(value = "remove", method = RequestMethod.POST)
@PowerAuth(resourceId = "/pa/token/remove", signatureType = { PowerAuthSignatureTypes.POSSESSION, PowerAuthSignatureTypes.POSSESSION_KNOWLEDGE, PowerAuthSignatureTypes.POSSESSION_BIOMETRY, PowerAuthSignatureTypes.POSSESSION_KNOWLEDGE_BIOMETRY })
@ResponseBody
public ObjectResponse<TokenRemoveResponse> removeToken(@RequestBody ObjectRequest<TokenRemoveRequest> request, PowerAuthApiAuthentication authentication) throws PowerAuthAuthenticationException {
try {
if (authentication != null && authentication.getActivationId() != null) {
// Fetch activation ID
final String activationId = authentication.getActivationId();
// Fetch token ID from the request
final TokenRemoveRequest requestObject = request.getRequestObject();
final String tokenId = requestObject.getTokenId();
// Remove a token, ignore response, since the endpoint should quietly return
powerAuthClient.removeToken(tokenId, activationId);
// Prepare a response
final TokenRemoveResponse responseObject = new TokenRemoveResponse();
responseObject.setTokenId(requestObject.getTokenId());
return new ObjectResponse<>(responseObject);
} else {
throw new PowerAuthAuthenticationException();
}
} catch (PowerAuthAuthenticationException ex) {
throw ex;
} catch (Exception ex) {
throw new PowerAuthAuthenticationException(ex.getMessage());
}
}
use of io.getlime.core.rest.model.base.response.ObjectResponse in project powerauth-restful-integration by lime-company.
the class PowerAuthNonPersonalizedEncryptor method encrypt.
/**
* Encrypt data.
*
* @param originalData Bytes to be encrypted.
* @return Encrypted object.
* @throws GenericCryptoException In case of a cryptography error.
* @throws CryptoProviderException In case of a cryptographic provider error.
* @throws InvalidKeyException In case the key provided for encryption is invalid.
*/
public ObjectResponse<NonPersonalizedEncryptedPayloadModel> encrypt(byte[] originalData) throws GenericCryptoException, CryptoProviderException, InvalidKeyException {
if (originalData == null) {
return null;
}
final NonPersonalizedEncryptedMessage message = encryptor.encrypt(originalData);
if (message == null) {
// this will happen only in case of an unlikely randomness error, or if keys are corrupted
return null;
}
final NonPersonalizedEncryptedPayloadModel responseObject = new NonPersonalizedEncryptedPayloadModel();
responseObject.setApplicationKey(BaseEncoding.base64().encode(message.getApplicationKey()));
responseObject.setEphemeralPublicKey(BaseEncoding.base64().encode(message.getEphemeralPublicKey()));
responseObject.setSessionIndex(BaseEncoding.base64().encode(message.getSessionIndex()));
responseObject.setAdHocIndex(BaseEncoding.base64().encode(message.getAdHocIndex()));
responseObject.setMacIndex(BaseEncoding.base64().encode(message.getMacIndex()));
responseObject.setNonce(BaseEncoding.base64().encode(message.getNonce()));
responseObject.setMac(BaseEncoding.base64().encode(message.getMac()));
responseObject.setEncryptedData(BaseEncoding.base64().encode(message.getEncryptedData()));
return new ObjectResponse<>(responseObject);
}
use of io.getlime.core.rest.model.base.response.ObjectResponse 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.core.rest.model.base.response.ObjectResponse 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