Search in sources :

Example 6 with ObjectResponse

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

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());
    }
}
Also used : TokenRemoveRequest(io.getlime.security.powerauth.rest.api.model.request.TokenRemoveRequest) PowerAuthAuthenticationException(io.getlime.security.powerauth.rest.api.base.exception.PowerAuthAuthenticationException) ObjectResponse(io.getlime.core.rest.model.base.response.ObjectResponse) PowerAuthAuthenticationException(io.getlime.security.powerauth.rest.api.base.exception.PowerAuthAuthenticationException) TokenRemoveResponse(io.getlime.security.powerauth.rest.api.model.response.TokenRemoveResponse) PowerAuth(io.getlime.security.powerauth.rest.api.spring.annotation.PowerAuth) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 8 with ObjectResponse

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);
}
Also used : NonPersonalizedEncryptedPayloadModel(io.getlime.security.powerauth.rest.api.model.entity.NonPersonalizedEncryptedPayloadModel) ObjectResponse(io.getlime.core.rest.model.base.response.ObjectResponse) NonPersonalizedEncryptedMessage(io.getlime.security.powerauth.crypto.lib.encryptor.model.NonPersonalizedEncryptedMessage)

Example 9 with ObjectResponse

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);
}
Also used : PowerAuthInvalidRequestException(io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthInvalidRequestException) PowerAuthSignatureInvalidException(io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthSignatureInvalidException) ActivationRemoveResponse(io.getlime.security.powerauth.rest.api.model.response.v3.ActivationRemoveResponse) PowerAuthApiAuthentication(io.getlime.security.powerauth.rest.api.spring.authentication.PowerAuthApiAuthentication) ObjectResponse(io.getlime.core.rest.model.base.response.ObjectResponse)

Example 10 with ObjectResponse

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);
}
Also used : PowerAuthInvalidRequestException(io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthInvalidRequestException) PowerAuthSignatureInvalidException(io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthSignatureInvalidException) ActivationRemoveResponse(io.getlime.security.powerauth.rest.api.model.response.v3.ActivationRemoveResponse) PowerAuthApiAuthentication(io.getlime.security.powerauth.rest.api.spring.authentication.PowerAuthApiAuthentication) ObjectResponse(io.getlime.core.rest.model.base.response.ObjectResponse)

Aggregations

ObjectResponse (io.getlime.core.rest.model.base.response.ObjectResponse)17 PowerAuthAuthenticationException (io.getlime.security.powerauth.rest.api.base.exception.PowerAuthAuthenticationException)12 PowerAuthActivationException (io.getlime.security.powerauth.rest.api.base.exception.PowerAuthActivationException)6 PowerAuthPortServiceStub (io.getlime.powerauth.soap.PowerAuthPortServiceStub)5 RemoteException (java.rmi.RemoteException)5 PowerAuthApiAuthentication (io.getlime.security.powerauth.rest.api.base.authentication.PowerAuthApiAuthentication)4 PowerAuthSignatureHttpHeader (io.getlime.security.powerauth.http.PowerAuthSignatureHttpHeader)3 InvalidPowerAuthHttpHeaderException (io.getlime.security.powerauth.http.validator.InvalidPowerAuthHttpHeaderException)3 PowerAuthInvalidRequestException (io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthInvalidRequestException)3 PowerAuthSignatureInvalidException (io.getlime.security.powerauth.rest.api.spring.exception.authentication.PowerAuthSignatureInvalidException)3 NonPersonalizedEncryptedMessage (io.getlime.security.powerauth.crypto.lib.encryptor.model.NonPersonalizedEncryptedMessage)2 PowerAuthSignatureTypes (io.getlime.security.powerauth.crypto.lib.enums.PowerAuthSignatureTypes)2 PowerAuthSecureVaultException (io.getlime.security.powerauth.rest.api.base.exception.PowerAuthSecureVaultException)2 SignatureTypeConverter (io.getlime.security.powerauth.rest.api.jaxrs.converter.SignatureTypeConverter)2 NonPersonalizedEncryptedPayloadModel (io.getlime.security.powerauth.rest.api.model.entity.NonPersonalizedEncryptedPayloadModel)2 TokenCreateRequest (io.getlime.security.powerauth.rest.api.model.request.TokenCreateRequest)2 TokenRemoveRequest (io.getlime.security.powerauth.rest.api.model.request.TokenRemoveRequest)2 VaultUnlockRequest (io.getlime.security.powerauth.rest.api.model.request.VaultUnlockRequest)2 ActivationCreateResponse (io.getlime.security.powerauth.rest.api.model.response.ActivationCreateResponse)2 ActivationRemoveResponse (io.getlime.security.powerauth.rest.api.model.response.ActivationRemoveResponse)2