Search in sources :

Example 1 with PowerAuthActivationException

use of io.getlime.security.powerauth.rest.api.base.exception.PowerAuthActivationException 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.
 * @throws RemoteException In case SOAP communication fails
 */
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Path("status")
public ObjectResponse<ActivationStatusResponse> getActivationStatus(ObjectRequest<ActivationStatusRequest> request) throws RemoteException, PowerAuthActivationException {
    if (request.getRequestObject() == null) {
        throw new PowerAuthActivationException();
    }
    try {
        String activationId = request.getRequestObject().getActivationId();
        PowerAuthPortServiceStub.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 e) {
        throw new PowerAuthActivationException();
    }
}
Also used : PowerAuthActivationException(io.getlime.security.powerauth.rest.api.base.exception.PowerAuthActivationException) PowerAuthPortServiceStub(io.getlime.powerauth.soap.PowerAuthPortServiceStub) ObjectResponse(io.getlime.core.rest.model.base.response.ObjectResponse) PowerAuthAuthenticationException(io.getlime.security.powerauth.rest.api.base.exception.PowerAuthAuthenticationException) RemoteException(java.rmi.RemoteException) PowerAuthActivationException(io.getlime.security.powerauth.rest.api.base.exception.PowerAuthActivationException) ActivationStatusResponse(io.getlime.security.powerauth.rest.api.model.response.ActivationStatusResponse)

Example 2 with 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.
 */
@RequestMapping(value = "create", method = RequestMethod.POST)
@ResponseBody
public ObjectResponse<ActivationCreateResponse> createActivation(@RequestBody ObjectRequest<ActivationCreateRequest> request) throws 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();
        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 ex) {
        throw new PowerAuthActivationException();
    }
}
Also used : PrepareActivationResponse(io.getlime.powerauth.soap.PrepareActivationResponse) PowerAuthActivationException(io.getlime.security.powerauth.rest.api.base.exception.PowerAuthActivationException) ActivationCreateResponse(io.getlime.security.powerauth.rest.api.model.response.ActivationCreateResponse) ObjectResponse(io.getlime.core.rest.model.base.response.ObjectResponse) PowerAuthAuthenticationException(io.getlime.security.powerauth.rest.api.base.exception.PowerAuthAuthenticationException) PowerAuthActivationException(io.getlime.security.powerauth.rest.api.base.exception.PowerAuthActivationException)

Example 3 with PowerAuthActivationException

use of io.getlime.security.powerauth.rest.api.base.exception.PowerAuthActivationException 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();
    }
}
Also used : PowerAuthActivationException(io.getlime.security.powerauth.rest.api.base.exception.PowerAuthActivationException) GetActivationStatusResponse(io.getlime.powerauth.soap.GetActivationStatusResponse) ObjectResponse(io.getlime.core.rest.model.base.response.ObjectResponse) PowerAuthAuthenticationException(io.getlime.security.powerauth.rest.api.base.exception.PowerAuthAuthenticationException) PowerAuthActivationException(io.getlime.security.powerauth.rest.api.base.exception.PowerAuthActivationException) ActivationStatusResponse(io.getlime.security.powerauth.rest.api.model.response.ActivationStatusResponse) GetActivationStatusResponse(io.getlime.powerauth.soap.GetActivationStatusResponse)

Example 4 with PowerAuthActivationException

use of io.getlime.security.powerauth.rest.api.base.exception.PowerAuthActivationException in project powerauth-restful-integration by lime-company.

the class CustomActivationController method createNewActivation.

@RequestMapping(value = "create", method = RequestMethod.POST)
@ResponseBody
public ObjectResponse<NonPersonalizedEncryptedPayloadModel> createNewActivation(@RequestBody ObjectRequest<NonPersonalizedEncryptedPayloadModel> object) throws PowerAuthAuthenticationException, PowerAuthActivationException {
    try {
        // Check if there is any user provider to be autowired
        if (userProvider == null) {
            throw new PowerAuthActivationException();
        }
        // Prepare an encryptor
        final PowerAuthNonPersonalizedEncryptor encryptor = encryptorFactory.buildNonPersonalizedEncryptor(object);
        if (encryptor == null) {
            throw new PowerAuthActivationException();
        }
        // Decrypt the request object
        ActivationCreateCustomRequest request = encryptor.decrypt(object, ActivationCreateCustomRequest.class);
        if (request == null) {
            throw new PowerAuthActivationException();
        }
        // Lookup user ID using a provided identity
        final Map<String, String> identity = request.getIdentity();
        String userId = userProvider.lookupUserIdForAttributes(identity);
        // If no user was found, return error
        if (userId == null) {
            throw new PowerAuthActivationException();
        }
        // Create activation for a looked up user and application related to the given application key
        ActivationCreateRequest acr = request.getPowerauth();
        CreateActivationResponse response = powerAuthClient.createActivation(acr.getApplicationKey(), userId, acr.getActivationIdShort(), acr.getActivationName(), acr.getActivationNonce(), acr.getEphemeralPublicKey(), acr.getEncryptedDevicePublicKey(), acr.getExtras(), acr.getApplicationSignature());
        // Process custom attributes using a custom logic
        final Map<String, Object> customAttributes = request.getCustomAttributes();
        userProvider.processCustomActivationAttributes(customAttributes);
        // Prepare the created activation response data
        ActivationCreateResponse createResponse = new ActivationCreateResponse();
        createResponse.setActivationId(response.getActivationId());
        createResponse.setEphemeralPublicKey(response.getEphemeralPublicKey());
        createResponse.setActivationNonce(response.getActivationNonce());
        createResponse.setEncryptedServerPublicKey(response.getEncryptedServerPublicKey());
        createResponse.setEncryptedServerPublicKeySignature(response.getEncryptedServerPublicKeySignature());
        // Encrypt response object
        final ObjectResponse<NonPersonalizedEncryptedPayloadModel> powerAuthApiResponse = encryptor.encrypt(createResponse);
        // Check if activation should be committed instantly and if yes, perform commit
        if (userProvider.shouldAutoCommitActivation(identity, customAttributes)) {
            powerAuthClient.commitActivation(response.getActivationId());
        }
        // Return response
        return powerAuthApiResponse;
    } catch (IOException e) {
        throw new PowerAuthActivationException();
    }
}
Also used : CreateActivationResponse(io.getlime.powerauth.soap.CreateActivationResponse) ActivationCreateResponse(io.getlime.security.powerauth.rest.api.model.response.ActivationCreateResponse) PowerAuthNonPersonalizedEncryptor(io.getlime.security.powerauth.rest.api.base.encryption.PowerAuthNonPersonalizedEncryptor) IOException(java.io.IOException) PowerAuthActivationException(io.getlime.security.powerauth.rest.api.base.exception.PowerAuthActivationException) ActivationCreateCustomRequest(io.getlime.security.powerauth.rest.api.model.request.ActivationCreateCustomRequest) NonPersonalizedEncryptedPayloadModel(io.getlime.security.powerauth.rest.api.model.entity.NonPersonalizedEncryptedPayloadModel) ActivationCreateRequest(io.getlime.security.powerauth.rest.api.model.request.ActivationCreateRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with 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 PowerAuthActivationException In case activation access fails.
 * @throws PowerAuthAuthenticationException In case the signature validation fails.
 */
@RequestMapping(value = "remove", method = RequestMethod.POST)
@ResponseBody
public ObjectResponse<ActivationRemoveResponse> removeActivation(@RequestHeader(value = PowerAuthSignatureHttpHeader.HEADER_NAME) String signatureHeader) throws PowerAuthActivationException, PowerAuthAuthenticationException {
    try {
        PowerAuthApiAuthentication apiAuthentication = authenticationProvider.validateRequestSignature("POST", null, "/pa/activation/remove", signatureHeader);
        if (apiAuthentication != null && apiAuthentication.getActivationId() != null) {
            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();
    }
}
Also used : PowerAuthActivationException(io.getlime.security.powerauth.rest.api.base.exception.PowerAuthActivationException) ActivationRemoveResponse(io.getlime.security.powerauth.rest.api.model.response.ActivationRemoveResponse) PowerAuthAuthenticationException(io.getlime.security.powerauth.rest.api.base.exception.PowerAuthAuthenticationException) PowerAuthApiAuthentication(io.getlime.security.powerauth.rest.api.base.authentication.PowerAuthApiAuthentication) ObjectResponse(io.getlime.core.rest.model.base.response.ObjectResponse) RemoveActivationResponse(io.getlime.powerauth.soap.RemoveActivationResponse) PowerAuthAuthenticationException(io.getlime.security.powerauth.rest.api.base.exception.PowerAuthAuthenticationException) PowerAuthActivationException(io.getlime.security.powerauth.rest.api.base.exception.PowerAuthActivationException)

Aggregations

PowerAuthActivationException (io.getlime.security.powerauth.rest.api.base.exception.PowerAuthActivationException)9 ObjectResponse (io.getlime.core.rest.model.base.response.ObjectResponse)6 PowerAuthAuthenticationException (io.getlime.security.powerauth.rest.api.base.exception.PowerAuthAuthenticationException)6 PowerAuthPortServiceStub (io.getlime.powerauth.soap.PowerAuthPortServiceStub)4 ActivationCreateResponse (io.getlime.security.powerauth.rest.api.model.response.ActivationCreateResponse)4 RemoteException (java.rmi.RemoteException)3 PowerAuthApiAuthentication (io.getlime.security.powerauth.rest.api.base.authentication.PowerAuthApiAuthentication)2 PowerAuthNonPersonalizedEncryptor (io.getlime.security.powerauth.rest.api.base.encryption.PowerAuthNonPersonalizedEncryptor)2 NonPersonalizedEncryptedPayloadModel (io.getlime.security.powerauth.rest.api.model.entity.NonPersonalizedEncryptedPayloadModel)2 ActivationCreateCustomRequest (io.getlime.security.powerauth.rest.api.model.request.ActivationCreateCustomRequest)2 ActivationCreateRequest (io.getlime.security.powerauth.rest.api.model.request.ActivationCreateRequest)2 ActivationRemoveResponse (io.getlime.security.powerauth.rest.api.model.response.ActivationRemoveResponse)2 ActivationStatusResponse (io.getlime.security.powerauth.rest.api.model.response.ActivationStatusResponse)2 IOException (java.io.IOException)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ErrorResponse (io.getlime.core.rest.model.base.response.ErrorResponse)1 CreateActivationResponse (io.getlime.powerauth.soap.CreateActivationResponse)1 GetActivationStatusResponse (io.getlime.powerauth.soap.GetActivationStatusResponse)1 PrepareActivationResponse (io.getlime.powerauth.soap.PrepareActivationResponse)1 RemoveActivationResponse (io.getlime.powerauth.soap.RemoveActivationResponse)1