Search in sources :

Example 1 with CreateTokenResponse

use of io.getlime.powerauth.soap.CreateTokenResponse in project powerauth-restful-integration by lime-company.

the class TokenController method createToken.

@RequestMapping(value = "create", method = RequestMethod.POST)
@PowerAuth(resourceId = "/pa/token/create", signatureType = { PowerAuthSignatureTypes.POSSESSION, PowerAuthSignatureTypes.POSSESSION_KNOWLEDGE, PowerAuthSignatureTypes.POSSESSION_BIOMETRY, PowerAuthSignatureTypes.POSSESSION_KNOWLEDGE_BIOMETRY })
@ResponseBody
public ObjectResponse<TokenCreateResponse> createToken(@RequestBody ObjectRequest<TokenCreateRequest> request, PowerAuthApiAuthentication authentication) throws PowerAuthAuthenticationException {
    try {
        if (authentication != null && authentication.getActivationId() != null) {
            // Fetch activation ID and signature type
            final String activationId = authentication.getActivationId();
            final PowerAuthSignatureTypes signatureFactors = authentication.getSignatureFactors();
            // Fetch data from the request
            final TokenCreateRequest requestObject = request.getRequestObject();
            final String ephemeralPublicKey = requestObject.getEphemeralPublicKey();
            // Prepare a signature type converter
            SignatureTypeConverter converter = new SignatureTypeConverter();
            // Create a token
            final CreateTokenResponse token = powerAuthClient.createToken(activationId, ephemeralPublicKey, converter.convertFrom(signatureFactors));
            // Prepare a response
            final TokenCreateResponse responseObject = new TokenCreateResponse();
            responseObject.setMac(token.getMac());
            responseObject.setEncryptedData(token.getEncryptedData());
            return new ObjectResponse<>(responseObject);
        } else {
            throw new PowerAuthAuthenticationException();
        }
    } catch (PowerAuthAuthenticationException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new PowerAuthAuthenticationException(ex.getMessage());
    }
}
Also used : TokenCreateRequest(io.getlime.security.powerauth.rest.api.model.request.TokenCreateRequest) PowerAuthAuthenticationException(io.getlime.security.powerauth.rest.api.base.exception.PowerAuthAuthenticationException) CreateTokenResponse(io.getlime.powerauth.soap.CreateTokenResponse) PowerAuthSignatureTypes(io.getlime.security.powerauth.crypto.lib.enums.PowerAuthSignatureTypes) ObjectResponse(io.getlime.core.rest.model.base.response.ObjectResponse) TokenCreateResponse(io.getlime.security.powerauth.rest.api.model.response.TokenCreateResponse) PowerAuthAuthenticationException(io.getlime.security.powerauth.rest.api.base.exception.PowerAuthAuthenticationException) SignatureTypeConverter(io.getlime.security.powerauth.rest.api.spring.converter.SignatureTypeConverter) PowerAuth(io.getlime.security.powerauth.rest.api.spring.annotation.PowerAuth) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ObjectResponse (io.getlime.core.rest.model.base.response.ObjectResponse)1 CreateTokenResponse (io.getlime.powerauth.soap.CreateTokenResponse)1 PowerAuthSignatureTypes (io.getlime.security.powerauth.crypto.lib.enums.PowerAuthSignatureTypes)1 PowerAuthAuthenticationException (io.getlime.security.powerauth.rest.api.base.exception.PowerAuthAuthenticationException)1 TokenCreateRequest (io.getlime.security.powerauth.rest.api.model.request.TokenCreateRequest)1 TokenCreateResponse (io.getlime.security.powerauth.rest.api.model.response.TokenCreateResponse)1 PowerAuth (io.getlime.security.powerauth.rest.api.spring.annotation.PowerAuth)1 SignatureTypeConverter (io.getlime.security.powerauth.rest.api.spring.converter.SignatureTypeConverter)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1