use of io.getlime.powerauth.soap.CreateActivationResponse 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();
}
}
Aggregations