You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2019/07/23 18:15:30 UTC
[airavata] 01/01: AIRAVATA-3125 workaround for missing users in
sharing registry
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata.git
commit 623bd05696de09ab2b5c113e90902b8c4ed49a1c
Author: Marcus Christie <ma...@iu.edu>
AuthorDate: Tue Jul 23 13:11:41 2019 -0400
AIRAVATA-3125 workaround for missing users in sharing registry
---
.../handlers/GroupManagerServiceHandler.java | 30 +++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java
index 52de998..ecd8f98 100644
--- a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java
+++ b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java
@@ -6,15 +6,17 @@ import org.apache.airavata.common.utils.ServerSettings;
import org.apache.airavata.model.error.AuthorizationException;
import org.apache.airavata.model.group.GroupModel;
import org.apache.airavata.model.security.AuthzToken;
+import org.apache.airavata.model.user.UserProfile;
import org.apache.airavata.service.profile.groupmanager.cpi.GroupManagerService;
import org.apache.airavata.service.profile.groupmanager.cpi.group_manager_cpiConstants;
import org.apache.airavata.service.profile.groupmanager.cpi.exception.GroupManagerServiceException;
-import org.apache.airavata.service.profile.groupmanager.cpi.group_manager_cpiConstants;
+import org.apache.airavata.service.profile.user.core.repositories.UserProfileRepository;
import org.apache.airavata.service.security.interceptor.SecurityCheck;
import org.apache.airavata.sharing.registry.client.SharingRegistryServiceClientFactory;
import org.apache.airavata.sharing.registry.models.GroupCardinality;
import org.apache.airavata.sharing.registry.models.GroupType;
import org.apache.airavata.sharing.registry.models.SharingRegistryException;
+import org.apache.airavata.sharing.registry.models.User;
import org.apache.airavata.sharing.registry.models.UserGroup;
import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService;
import org.apache.thrift.TException;
@@ -30,6 +32,8 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface {
private static final Logger logger = LoggerFactory.getLogger(GroupManagerServiceHandler.class);
+ private UserProfileRepository userProfileRepository = new UserProfileRepository();
+
public GroupManagerServiceHandler() {
}
@@ -57,7 +61,7 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface {
sharingUserGroup.setOwnerId(getUserId(authzToken));
String groupId = sharingClient.createGroup(sharingUserGroup);
- sharingClient.addUsersToGroup(gatewayId, groupModel.getMembers(), groupId);
+ internalAddUsersToGroup(sharingClient, gatewayId, groupModel.getMembers(), groupId);
addGroupAdmins(authzToken,groupId,groupModel.getAdmins());
return groupId;
}
@@ -198,7 +202,7 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface {
|| sharingClient.hasAdminAccess(domainId, groupId, userId))) {
throw new GroupManagerServiceException("User does not have access to add users to the group");
}
- return sharingClient.addUsersToGroup(domainId, userIds, groupId);
+ return internalAddUsersToGroup(sharingClient, domainId, userIds, groupId);
} catch (Exception e) {
String msg = "Error adding users to group. Group ID: " + groupId ;
@@ -384,4 +388,24 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface {
}
}
+ private boolean internalAddUsersToGroup(SharingRegistryService.Client sharingClient, String domainId, List<String> userIds, String groupId) throws SharingRegistryException, TException {
+
+ // FIXME: workaround for UserProfiles that failed to sync to the sharing
+ // registry: create any missing users in the sharing registry
+ for (String userId : userIds) {
+ if (!sharingClient.isUserExists(domainId, userId)) {
+ User user = new User();
+ user.setDomainId(domainId);
+ user.setUserId(userId);
+ UserProfile userProfile = userProfileRepository.get(userId);
+ user.setUserName(userProfile.getUserId());
+ user.setCreatedTime(userProfile.getCreationTime());
+ user.setEmail(userProfile.getEmailsSize() > 0 ? userProfile.getEmails().get(0) : null);
+ user.setFirstName(userProfile.getFirstName());
+ user.setLastName(userProfile.getLastName());
+ sharingClient.createUser(user);
+ }
+ }
+ return sharingClient.addUsersToGroup(domainId, userIds, groupId);
+ }
}