Repository: airavata Updated Branches: refs/heads/develop b45fac7a9 -> 4e7d7cc64
AIRAVATA-2408 Updating Keycloak when user profile added Project: http://git-wip-us.apache.org/repos/asf/airavata/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/4e7d7cc6 Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/4e7d7cc6 Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/4e7d7cc6 Branch: refs/heads/develop Commit: 4e7d7cc646b67c5c2a51877e5e4a61182f30efec Parents: b45fac7 Author: Marcus Christie <[email protected]> Authored: Mon Jun 12 16:02:42 2017 -0400 Committer: Marcus Christie <[email protected]> Committed: Mon Jun 12 16:04:59 2017 -0400 ---------------------------------------------------------------------- .../handlers/UserProfileServiceHandler.java | 22 ++++++++++++-------- .../repositories/UserProfileRepository.java | 14 +++++++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/4e7d7cc6/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java ---------------------------------------------------------------------- diff --git a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java index 8e2e989..7d85002 100644 --- a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java +++ b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java @@ -59,7 +59,7 @@ public class UserProfileServiceHandler implements UserProfileService.Iface { @SecurityCheck public String addUserProfile(AuthzToken authzToken, UserProfile userProfile) throws UserProfileServiceException, AuthorizationException, TException { try{ - userProfile = userProfileRepository.create(userProfile); + userProfile = userProfileRepository.updateUserProfile(userProfile, getIAMUserProfileUpdater(authzToken, userProfile)); if (null != userProfile) { logger.info("Added UserProfile with userId: " + userProfile.getUserId()); // replicate userProfile at end-places @@ -87,14 +87,7 @@ public class UserProfileServiceHandler implements UserProfileService.Iface { // After updating the user profile in the database but before committing the transaction, the // following will update the user profile in the IAM service also. If the update in the IAM service // fails then the transaction will be rolled back. - IamAdminServices.Client iamAdminServicesClient = getIamAdminServicesClient(); - Runnable iamUserProfileUpdater = () -> { - try { - iamAdminServicesClient.updateUserProfile(authzToken, userProfile); - } catch (TException e) { - throw new RuntimeException("Failed to update user profile in IAM service", e); - } - }; + Runnable iamUserProfileUpdater = getIAMUserProfileUpdater(authzToken, userProfile); if(userProfileRepository.updateUserProfile(userProfile, iamUserProfileUpdater) != null) { logger.info("Updated UserProfile with userId: " + userProfile.getUserId()); // replicate userProfile at end-places @@ -113,6 +106,17 @@ public class UserProfileServiceHandler implements UserProfileService.Iface { } } + private Runnable getIAMUserProfileUpdater(AuthzToken authzToken, UserProfile userProfile) throws UserProfileServiceException { + IamAdminServices.Client iamAdminServicesClient = getIamAdminServicesClient(); + return () -> { + try { + iamAdminServicesClient.updateUserProfile(authzToken, userProfile); + } catch (TException e) { + throw new RuntimeException("Failed to update user profile in IAM service", e); + } + }; + } + @Override @SecurityCheck public UserProfile getUserProfileById(AuthzToken authzToken, String userId, String gatewayId) throws UserProfileServiceException, AuthorizationException, TException { http://git-wip-us.apache.org/repos/asf/airavata/blob/4e7d7cc6/airavata-services/profile-service/profile-user-core/src/main/java/org/apache/airavata/service/profile/user/core/repositories/UserProfileRepository.java ---------------------------------------------------------------------- diff --git a/airavata-services/profile-service/profile-user-core/src/main/java/org/apache/airavata/service/profile/user/core/repositories/UserProfileRepository.java b/airavata-services/profile-service/profile-user-core/src/main/java/org/apache/airavata/service/profile/user/core/repositories/UserProfileRepository.java index 98796a4..953c114 100644 --- a/airavata-services/profile-service/profile-user-core/src/main/java/org/apache/airavata/service/profile/user/core/repositories/UserProfileRepository.java +++ b/airavata-services/profile-service/profile-user-core/src/main/java/org/apache/airavata/service/profile/user/core/repositories/UserProfileRepository.java @@ -71,6 +71,20 @@ public class UserProfileRepository extends AbstractRepository<UserProfile, UserP return resultList; } + @Override + public UserProfile create(UserProfile userProfile) { + throw new UnsupportedOperationException("Please use createUserProfile instead"); + } + + @Override + public UserProfile update(UserProfile userProfile) { + throw new UnsupportedOperationException("Please use updateUserProfile instead"); + } + + public UserProfile createUserProfile(UserProfile userProfile, Runnable postUpdateAction) { + return updateUserProfile(userProfile, postUpdateAction); + } + public UserProfile updateUserProfile(UserProfile userProfile, Runnable postUpdateAction) { Mapper mapper = ObjectMapperSingleton.getInstance();
