diff --git a/src/main/java/biz/nynja/account/components/StatementsPool.java b/src/main/java/biz/nynja/account/components/StatementsPool.java index 5ee4b816e0ee2aca6ba635ab3718313a9e42db00..ba8c9d66456df3ab3381b998c21acb7c3a1a562d 100644 --- a/src/main/java/biz/nynja/account/components/StatementsPool.java +++ b/src/main/java/biz/nynja/account/components/StatementsPool.java @@ -55,12 +55,6 @@ public class StatementsPool { return bound; } - public BoundStatement deleteBackupAuthenticationProviderFromProfile(UUID profileId) { - String cql = "DELETE backupauthenticationprovider FROM profile WHERE profileid = ? ; "; - BoundStatement bound = preparedStatementsCache.getPreparedStatement(cql).bind(profileId); - return bound; - } - public BoundStatement deleteCreationProviderFromAccount(UUID accountId) { String cql = "DELETE authenticationprovidertype, authenticationprovider FROM account WHERE accountid = ? ;"; BoundStatement bound = preparedStatementsCache.getPreparedStatement(cql).bind(accountId); diff --git a/src/main/java/biz/nynja/account/models/Profile.java b/src/main/java/biz/nynja/account/models/Profile.java index 03ad15828185a325d92ab563b009d1ae72812ab0..f4e284455b7cc37e764f4d43f1c7dd02af3f6434 100644 --- a/src/main/java/biz/nynja/account/models/Profile.java +++ b/src/main/java/biz/nynja/account/models/Profile.java @@ -17,7 +17,6 @@ public class Profile { @PrimaryKey private UUID profileId; private Set authenticationProviders; - private AuthenticationProvider backupAuthenticationProvider; private String passcode; private UUID defaultAccount; private Long creationTimestamp; @@ -71,21 +70,11 @@ public class Profile { this.defaultAccount = defaultAccount; } - public AuthenticationProvider getBackupAuthenticationProvider() { - return backupAuthenticationProvider; - } - - public void setBackupAuthenticationProvider(AuthenticationProvider backupAuthenticationProvider) { - this.backupAuthenticationProvider = backupAuthenticationProvider; - } - @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((authenticationProviders == null) ? 0 : authenticationProviders.hashCode()); - result = prime * result - + ((backupAuthenticationProvider == null) ? 0 : backupAuthenticationProvider.hashCode()); result = prime * result + ((creationTimestamp == null) ? 0 : creationTimestamp.hashCode()); result = prime * result + ((defaultAccount == null) ? 0 : defaultAccount.hashCode()); result = prime * result + ((lastUpdateTimestamp == null) ? 0 : lastUpdateTimestamp.hashCode()); @@ -108,11 +97,6 @@ public class Profile { return false; } else if (!authenticationProviders.equals(other.authenticationProviders)) return false; - if (backupAuthenticationProvider == null) { - if (other.backupAuthenticationProvider != null) - return false; - } else if (!backupAuthenticationProvider.equals(other.backupAuthenticationProvider)) - return false; if (creationTimestamp == null) { if (other.creationTimestamp != null) return false; @@ -146,8 +130,7 @@ public class Profile { return new StringBuilder("Profile [profileId=").append(profileId).append(", authenticationProviders=") .append(authenticationProviders).append(", creationTimestamp=").append(creationTimestamp) .append(", lastUpdateTimestamp=").append(lastUpdateTimestamp).append(", passcode=******") - .append(", defaultAccount=").append(defaultAccount).append(", backupAuthenticationProvider=") - .append(backupAuthenticationProvider).append("]").toString(); + .append(", defaultAccount=").append(defaultAccount).append("]").toString(); } public ProfileDetails toProto() { @@ -161,9 +144,6 @@ public class Profile { if (getDefaultAccount() != null) { builder.setDefaultAccountId(getDefaultAccount().toString()); } - if (getBackupAuthenticationProvider() != null) { - builder.setBackupAuthProvider(getBackupAuthenticationProvider().toProto()); - } if (getAuthenticationProviders() != null) { for (AuthenticationProvider authenticationProvider : authenticationProviders) { builder.addAuthProviders(authenticationProvider.toProto()); diff --git a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java index 7a867ece08b45ed26ff82e4acb2c1a3cef719533..20e224cbe964cddf87a5b647801a267fb5f9f6f8 100644 --- a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java +++ b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java @@ -328,12 +328,6 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio private void updateProfileData(CassandraBatchOperations batchOps, UpdateProfileRequest request, Profile existingProfile, Long lastUpdateTimestamp) { Profile updatedProfile = existingProfile; - if (!request.getBackupAuthProvider().getAuthenticationProvider().trim().isEmpty()) { - updatedProfile.setBackupAuthenticationProvider( - AuthenticationProvider.createAuthenticationProviderFromProto(request.getBackupAuthProvider())); - } else { - updatedProfile.setBackupAuthenticationProvider(null); - } updatedProfile.setPasscode(request.getPasscode()); if (!request.getDefaultAccountId().trim().isEmpty()) { updatedProfile.setDefaultAccount(UUID.fromString(request.getDefaultAccountId())); @@ -585,21 +579,14 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio ResultSet rs = null; // Remove authentication provider form list of authentication providers in profile - BoundStatement st1 = statementsPool.deleteAuthenicationProviderFromProfile(profile.getProfileId(), + BoundStatement deleteAuthProviderStatement= statementsPool.deleteAuthenicationProviderFromProfile(profile.getProfileId(), authProvider); - batch.add(st1); + batch.add(deleteAuthProviderStatement); // Remove record for profile by this authentication provider - BoundStatement st2 = statementsPool.deleteProfileByAuthenticationProvider(authProvider.getValue(), + BoundStatement deleteProfileStatement = statementsPool.deleteProfileByAuthenticationProvider(authProvider.getValue(), authProvider.getType()); - batch.add(st2); - - // The requested authentication provider is set as a backup provider. We have to delete the reference. - if (profile.getBackupAuthenticationProvider() != null - && profile.getBackupAuthenticationProvider().equals(authProvider)) { - BoundStatement st3 = statementsPool.deleteBackupAuthenticationProviderFromProfile(profile.getProfileId()); - batch.add(st3); - } + batch.add(deleteProfileStatement); // Check if there is an account, created using this authentication provider Account account = accountServiceHelper.getAccountByAuthenticationProviderHelper(authProvider.getValue(), @@ -607,8 +594,8 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio // Delete authentication provider from account if (account != null) { - BoundStatement st4 = statementsPool.deleteCreationProviderFromAccount(account.getAccountId()); - batch.add(st4); + BoundStatement deleteCreationProviderStatement = statementsPool.deleteCreationProviderFromAccount(account.getAccountId()); + batch.add(deleteCreationProviderStatement); } rs = session.execute(batch); diff --git a/src/test/java/biz/nynja/account/services/AccountServiceTests.java b/src/test/java/biz/nynja/account/services/AccountServiceTests.java index 8f86a3b9c1b9cadae3ccdfe6dc5dd7b48fb19a15..10c135ad084dd2cb105e2019da69766aaf7f8da1 100644 --- a/src/test/java/biz/nynja/account/services/AccountServiceTests.java +++ b/src/test/java/biz/nynja/account/services/AccountServiceTests.java @@ -443,34 +443,9 @@ public class AccountServiceTests extends GrpcServerTestBase { reply.getError().getCause().equals(Cause.ACCOUNT_ALREADY_CREATED)); } - @Test - public void testUpdateProfileAddBackupAuthProvider() throws ExecutionException, InterruptedException { - final UpdateProfileRequest request = UpdateProfileRequest.newBuilder().setProfileId(Util.PROFILE_ID.toString()) - .setBackupAuthProvider(AuthProviderDetails.newBuilder().setAuthenticationProvider(Util.PHONE_PROVIDER) - .setAuthenticationType(AuthenticationType.PHONE).build()) - .build(); - given(accountRepositoryAdditional.updateProfile(request)).willReturn(updatedProfile); - final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc - .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); - final ProfileResponse reply = accountServiceBlockingStub.updateProfile(request); - assertNotNull("Reply should not be null", reply); - assertTrue( - String.format("Reply should contain backup auth provider type '%s'", - request.getBackupAuthProvider().getAuthenticationType().name()), - reply.getProfileDetails().getBackupAuthProvider().getAuthenticationType().toString() - .equals(AuthenticationType.PHONE.name())); - assertTrue( - String.format("Reply should contain backup auth provider '%s'", - request.getBackupAuthProvider().getAuthenticationProvider()), - reply.getProfileDetails().getBackupAuthProvider().getAuthenticationProvider() - .equals(Util.PHONE_NUMBER)); - } - @Test public void testUpdateProfileMissingProfileId() throws ExecutionException, InterruptedException { final UpdateProfileRequest request = UpdateProfileRequest.newBuilder() - .setBackupAuthProvider(AuthProviderDetails.newBuilder().setAuthenticationProvider(Util.PHONE_NUMBER) - .setAuthenticationType(AuthenticationType.PHONE).build()) .build(); final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); diff --git a/src/test/java/biz/nynja/account/utils/Util.java b/src/test/java/biz/nynja/account/utils/Util.java index fe26e10986ae8f10c4ed6ae18b40ba9a802e5134..bf925b02f155edcf635d2f415e6085441fc0fd43 100644 --- a/src/test/java/biz/nynja/account/utils/Util.java +++ b/src/test/java/biz/nynja/account/utils/Util.java @@ -183,8 +183,6 @@ public class Util { Set authProviders = new HashSet(); authProviders.add(AuthenticationProvider.createAuthenticationProviderFromStrings(PHONE_TYPE, PHONE_NUMBER)); profile.setAuthenticationProviders(authProviders); - profile.setBackupAuthenticationProvider( - AuthenticationProvider.createAuthenticationProviderFromStrings(PHONE_TYPE, PHONE_NUMBER)); return profile; }