use of io.getlime.security.powerauth.rest.api.base.exception.PowerAuthActivationException in project powerauth-restful-integration by lime-company.
the class PowerAuthExceptionHandler method handleActivationException.
/**
* Handle PowerAuthActivationException exceptions.
* @param ex Exception instance.
* @return Error response.
*/
@ExceptionHandler(value = PowerAuthActivationException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
public ErrorResponse handleActivationException(Exception ex) {
PowerAuthActivationException paex = (PowerAuthActivationException) ex;
Logger.getLogger(PowerAuthExceptionHandler.class.getName()).log(Level.SEVERE, paex.getMessage(), paex);
return new ErrorResponse(paex.getDefaultCode(), paex);
}
use of io.getlime.security.powerauth.rest.api.base.exception.PowerAuthActivationException in project powerauth-restful-integration by lime-company.
the class CustomActivationController method createNewActivation.
@POST
@Path("create")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public ObjectResponse<NonPersonalizedEncryptedPayloadModel> createNewActivation(ObjectRequest<NonPersonalizedEncryptedPayloadModel> object) throws PowerAuthAuthenticationException, RemoteException, PowerAuthActivationException {
try {
final PowerAuthNonPersonalizedEncryptor encryptor = encryptorFactory.buildNonPersonalizedEncryptor(object);
if (encryptor == null) {
throw new PowerAuthActivationException();
}
ActivationCreateCustomRequest request = encryptor.decrypt(object, ActivationCreateCustomRequest.class);
if (request == null) {
throw new PowerAuthActivationException();
}
final Map<String, String> identity = request.getIdentity();
String userId = userProvider.lookupUserIdForAttributes(identity);
if (userId == null) {
throw new PowerAuthActivationException();
}
ActivationCreateRequest acr = request.getPowerauth();
PowerAuthPortServiceStub.CreateActivationResponse response = powerAuthClient.createActivation(acr.getApplicationKey(), userId, acr.getActivationIdShort(), acr.getActivationName(), acr.getActivationNonce(), acr.getEphemeralPublicKey(), acr.getEncryptedDevicePublicKey(), acr.getExtras(), acr.getApplicationSignature());
final Map<String, Object> customAttributes = request.getCustomAttributes();
userProvider.processCustomActivationAttributes(customAttributes);
ActivationCreateResponse createResponse = new ActivationCreateResponse();
createResponse.setActivationId(response.getActivationId());
createResponse.setEphemeralPublicKey(response.getEphemeralPublicKey());
createResponse.setActivationNonce(response.getActivationNonce());
createResponse.setEncryptedServerPublicKey(response.getEncryptedServerPublicKey());
createResponse.setEncryptedServerPublicKeySignature(response.getEncryptedServerPublicKeySignature());
final ObjectResponse<NonPersonalizedEncryptedPayloadModel> powerAuthApiResponse = encryptor.encrypt(createResponse);
if (userProvider.shouldAutoCommitActivation(identity, customAttributes)) {
powerAuthClient.commitActivation(response.getActivationId());
}
return powerAuthApiResponse;
} catch (IOException e) {
throw new PowerAuthActivationException();
}
}
use of io.getlime.security.powerauth.rest.api.base.exception.PowerAuthActivationException in project powerauth-restful-integration by lime-company.
the class ActivationController method createActivation.
/**
* Create a new activation.
* @param request PowerAuth RESTful request with {@link ActivationCreateRequest} payload.
* @return PowerAuth RESTful response with {@link ActivationCreateResponse} payload.
* @throws RemoteException In case SOAP communication fails
*/
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Path("create")
public ObjectResponse<ActivationCreateResponse> createActivation(ObjectRequest<ActivationCreateRequest> request) throws RemoteException, PowerAuthActivationException {
if (request.getRequestObject() == null) {
throw new PowerAuthActivationException();
}
try {
String activationIDShort = request.getRequestObject().getActivationIdShort();
String activationNonce = request.getRequestObject().getActivationNonce();
String cDevicePublicKey = request.getRequestObject().getEncryptedDevicePublicKey();
String activationName = request.getRequestObject().getActivationName();
String extras = request.getRequestObject().getExtras();
String applicationKey = request.getRequestObject().getApplicationKey();
String applicationSignature = request.getRequestObject().getApplicationSignature();
String clientEphemeralKey = request.getRequestObject().getEphemeralPublicKey();
PowerAuthPortServiceStub.PrepareActivationResponse soapResponse = powerAuthClient.prepareActivation(activationIDShort, activationName, activationNonce, clientEphemeralKey, cDevicePublicKey, extras, applicationKey, applicationSignature);
ActivationCreateResponse response = new ActivationCreateResponse();
response.setActivationId(soapResponse.getActivationId());
response.setActivationNonce(soapResponse.getActivationNonce());
response.setEncryptedServerPublicKey(soapResponse.getEncryptedServerPublicKey());
response.setEncryptedServerPublicKeySignature(soapResponse.getEncryptedServerPublicKeySignature());
response.setEphemeralPublicKey(soapResponse.getEphemeralPublicKey());
return new ObjectResponse<>(response);
} catch (Exception e) {
throw new PowerAuthActivationException();
}
}
use of io.getlime.security.powerauth.rest.api.base.exception.PowerAuthActivationException in project powerauth-restful-integration by lime-company.
the class ActivationController method removeActivation.
/**
* Get activation status.
* @param signatureHeader PowerAuth signature HTTP header.
* @return PowerAuth RESTful response with {@link ActivationRemoveResponse} payload.
* @throws PowerAuthAuthenticationException In case the signature validation fails.
* @throws RemoteException In case SOAP communication fails
*/
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Path("remove")
public ObjectResponse<ActivationRemoveResponse> removeActivation(@HeaderParam(PowerAuthSignatureHttpHeader.HEADER_NAME) String signatureHeader) throws PowerAuthAuthenticationException, PowerAuthActivationException {
try {
PowerAuthApiAuthentication apiAuthentication = authenticationProvider.validateRequestSignature("POST", null, "/pa/activation/remove", signatureHeader);
if (apiAuthentication != null && apiAuthentication.getActivationId() != null) {
PowerAuthPortServiceStub.RemoveActivationResponse soapResponse = powerAuthClient.removeActivation(apiAuthentication.getActivationId());
ActivationRemoveResponse response = new ActivationRemoveResponse();
response.setActivationId(soapResponse.getActivationId());
return new ObjectResponse<>(response);
} else {
throw new PowerAuthAuthenticationException("USER_NOT_AUTHENTICATED");
}
} catch (PowerAuthAuthenticationException ex) {
throw ex;
} catch (Exception ex) {
throw new PowerAuthActivationException();
}
}
Aggregations