diff --git a/src/main/java/biz/nynja/account/accesspoints/AccessPointRepository.java b/src/main/java/biz/nynja/account/accesspoints/AccessPointRepository.java index 9f2c3c045b616f4565b5d11840818da60e56dfc7..84b4c0df136349912bfae198c675108729ae9dc9 100644 --- a/src/main/java/biz/nynja/account/accesspoints/AccessPointRepository.java +++ b/src/main/java/biz/nynja/account/accesspoints/AccessPointRepository.java @@ -22,4 +22,6 @@ public interface AccessPointRepository @Query("select * from auth.accesspoint where accountid=:accountId;") List findAllByAccountId(@Param("accountId") UUID accountId); + @Query("delete from auth.accesspoint where accountid=:accountId;") + void deleteById(@Param("accountId") UUID accountId); } diff --git a/src/main/java/biz/nynja/account/accesspoints/AccessPointService.java b/src/main/java/biz/nynja/account/accesspoints/AccessPointService.java index 2ac4a44cbe2be24a62b27c8c48e80c3bfb3ae4e8..74cc4af997df326d6fdaecb1486c239c0bde23ee 100644 --- a/src/main/java/biz/nynja/account/accesspoints/AccessPointService.java +++ b/src/main/java/biz/nynja/account/accesspoints/AccessPointService.java @@ -33,6 +33,18 @@ public class AccessPointService { return Optional.empty(); } + public boolean deleteAccessPointsForAccount(UUID accountId) { + try { + accessPointRepository.deleteById(accountId); + logger.info("AccessPoint successfully deleted from the DB."); + return true; + } catch (Exception e) { + logger.error("Error deleting accesspoints for account {}. Message: {}, cause: {}", accountId, + e.getMessage(), e.getCause()); + return false; + } + } + public AccessPoint buildAccessPoint(String deviceId, String accessToken, String accountId, long expiresIn) { AccessPoint accessPoint = new AccessPoint(); accessPoint.setDeviceId(deviceId); diff --git a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java index 6518636304f793003c2c9e150f408dca02294965..48aaa80775db4dd3b708283d1d675b3320a60d69 100644 --- a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java +++ b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java @@ -35,10 +35,12 @@ import com.datastax.driver.core.PreparedStatement; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Session; +import biz.nynja.account.accesspoints.AccessPointService; import biz.nynja.account.components.AccountServiceHelper; import biz.nynja.account.components.StatementsPool; import biz.nynja.account.configuration.AccountDataConfiguration; import biz.nynja.account.configuration.PendingAccountConfiguration; +import biz.nynja.account.grpc.AccessStatus; import biz.nynja.account.grpc.CompletePendingAccountCreationRequest; import biz.nynja.account.grpc.ContactType; import biz.nynja.account.grpc.ErrorResponse.Cause; @@ -83,6 +85,7 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio private final Session session; private final ErlangAccountBridge erlangAccountBridge; private final PermissionsValidator permissionsValidator; + private final AccessPointService accessPointService; public AccountRepositoryAdditionalImpl(PendingAccountConfiguration pendingAccountConfiguration, CassandraTemplate cassandraTemplate, StatementsPool statementsPool, AccountRepository accountRepository, @@ -93,7 +96,7 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio PendingAccountByAuthenticationProviderRepository pendingAccountByAuthenticationProviderRepository, PendingAccountRepository pendingAccountRepository, AccountServiceHelper accountServiceHelper, Session session, ErlangAccountBridge erlangAccountBridge, PermissionsValidator permissionsValidator, - AccountDataConfiguration accountDataConfiguration) { + AccountDataConfiguration accountDataConfiguration, AccessPointService accessPointService) { this.pendingAccountConfiguration = pendingAccountConfiguration; this.cassandraTemplate = cassandraTemplate; this.statementsPool = statementsPool; @@ -110,6 +113,7 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio this.erlangAccountBridge = erlangAccountBridge; this.permissionsValidator = permissionsValidator; this.accountDataConfiguration = accountDataConfiguration; + this.accessPointService= accessPointService; } @PostConstruct @@ -254,6 +258,12 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio if (wr != null) { boolean applied = wr.wasApplied(); if (applied) { + if (request.getAccessStatus().equals(AccessStatus.DISABLED) + || request.getAccessStatus().equals(AccessStatus.SUSPENDED)) { + if (!accessPointService.deleteAccessPointsForAccount(UUID.fromString(request.getAccountId()))) { + logger.error("Error deleting accesspoints from the DB for account {}.", request.getAccountId()); + } + } Account updatedAccount = accountRepository.findByAccountId(UUID.fromString(request.getAccountId())); return updatedAccount; }