Skip to content

Commit

Permalink
Fix #322: Process cancelation by user not recorded in DB
Browse files Browse the repository at this point in the history
Remove activation (if present) during onboarding cleanup
  • Loading branch information
banterCZ committed Aug 24, 2022
1 parent 6172afb commit 64a68f6
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ public RemoteCommunicationException(String message) {
super(message);
}

public RemoteCommunicationException(String message, Throwable cause) {
super(message, cause);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* PowerAuth Enrollment Server
* Copyright (C) 2022 Wultra s.r.o.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

package com.wultra.app.onboardingserver.impl.service;

import com.wultra.app.onboardingserver.errorhandling.RemoteCommunicationException;
import com.wultra.security.powerauth.client.PowerAuthClient;
import com.wultra.security.powerauth.client.model.error.PowerAuthClientException;
import com.wultra.security.powerauth.client.v3.RemoveActivationRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
* Service for working with activations.
*
* @author Lubos Racansky, lubos.racansky@wultra.com
*/
@Service
@Slf4j
public class ActivationService {

private final PowerAuthClient powerAuthClient;

/**
* All-arg constructor.
*
* @param powerAuthClient PowerAuth service client.
*/
public ActivationService(final PowerAuthClient powerAuthClient) {
this.powerAuthClient = powerAuthClient;
}

/**
* Remove activation.
*
* @param activationId Activation ID.
* @throws RemoteCommunicationException Thrown when communication with PowerAuth server fails.
*/
public void removeActivation(final String activationId) throws RemoteCommunicationException {
final RemoveActivationRequest request = new RemoveActivationRequest();
request.setActivationId(activationId);
logger.info("Removing activation ID: {}", activationId);

try {
powerAuthClient.removeActivation(request);
} catch (PowerAuthClientException e) {
throw new RemoteCommunicationException("Communication with PowerAuth server failed: " + e.getMessage(), e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@
import com.wultra.app.onboardingserver.common.service.CommonOnboardingService;
import com.wultra.app.onboardingserver.configuration.IdentityVerificationConfig;
import com.wultra.app.onboardingserver.configuration.OnboardingConfig;
import com.wultra.app.onboardingserver.errorhandling.InvalidRequestObjectException;
import com.wultra.app.onboardingserver.errorhandling.OnboardingOtpDeliveryException;
import com.wultra.app.onboardingserver.errorhandling.OnboardingProviderException;
import com.wultra.app.onboardingserver.errorhandling.TooManyProcessesException;
import com.wultra.app.onboardingserver.errorhandling.*;
import com.wultra.app.onboardingserver.impl.util.DateUtil;
import com.wultra.app.onboardingserver.provider.*;
import io.getlime.core.rest.model.base.response.Response;
Expand Down Expand Up @@ -74,6 +71,8 @@ public class OnboardingServiceImpl extends CommonOnboardingService {
private final IdentityVerificationConfig identityVerificationConfig;
private final OtpServiceImpl otpService;

private final ActivationService activationService;

// Special instance of ObjectMapper for normalized serialization of identification data
private final ObjectMapper normalizedMapper = JsonMapper
.builder()
Expand All @@ -100,12 +99,14 @@ public OnboardingServiceImpl(
final OnboardingConfig config,
final IdentityVerificationConfig identityVerificationConfig,
final OtpServiceImpl otpService,
final ActivationService activationService,
final OnboardingProvider onboardingProvider) {

super(onboardingProcessRepository);
this.onboardingConfig = config;
this.identityVerificationConfig = identityVerificationConfig;
this.otpService = otpService;
this.activationService = activationService;
this.onboardingProvider = onboardingProvider;
}

Expand Down Expand Up @@ -230,6 +231,9 @@ public Response performCleanup(OnboardingCleanupRequest request) throws Onboardi
process.setErrorDetail(OnboardingProcessEntity.ERROR_PROCESS_CANCELED);
process.setErrorOrigin(ErrorOrigin.USER_REQUEST);
onboardingProcessRepository.save(process);

removeActivation(process.getActivationId());

return new Response();
}

Expand Down Expand Up @@ -436,6 +440,16 @@ private OnboardingProcessEntity resumeExistingProcess(final OnboardingProcessEnt
return process;
}

private void removeActivation(final String activationId) throws OnboardingProcessException {
if (activationId != null) {
try {
activationService.removeActivation(activationId);
} catch (RemoteCommunicationException e) {
throw new OnboardingProcessException("Unable to remove activation ID: " + activationId, e);
}
}
}

private String parseIdentificationData(final Map<String, Object> identification) throws InvalidRequestObjectException {
try {
return normalizedMapper.writeValueAsString(identification);
Expand Down

0 comments on commit 64a68f6

Please sign in to comment.