This is an automated email from the ASF dual-hosted git repository. yasith pushed a commit to branch service-layer in repository https://gitbox.apache.org/repos/asf/airavata.git
commit 8310c362e0ccf13b3b0a75cff75a44f0159893ae Author: yasithdev <[email protected]> AuthorDate: Mon Nov 10 18:42:00 2025 -0500 update groupmanagerserverhandler --- ...erviceHandler.java => GroupManagerService.java} | 79 ++----- .../handlers/GroupManagerServiceHandler.java | 258 ++++----------------- 2 files changed, 64 insertions(+), 273 deletions(-) diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java similarity index 88% copy from airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java copy to airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java index 9b445aa11b..3da76eabc9 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java @@ -17,7 +17,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.airavata.service.profile.handlers; +package org.apache.airavata.service; import java.util.ArrayList; import java.util.List; @@ -26,15 +26,11 @@ import java.util.stream.Collectors; import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.common.utils.Constants; 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.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; @@ -46,23 +42,11 @@ import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class GroupManagerServiceHandler implements GroupManagerService.Iface { - - private static final Logger logger = LoggerFactory.getLogger(GroupManagerServiceHandler.class); - +public class GroupManagerService { + private static final Logger logger = LoggerFactory.getLogger(GroupManagerService.class); private UserProfileRepository userProfileRepository = new UserProfileRepository(); - public GroupManagerServiceHandler() {} - - @Override - public String getAPIVersion() throws TException { - return group_manager_cpiConstants.GROUP_MANAGER_CPI_VERSION; - } - - @Override - @SecurityCheck - public String createGroup(AuthzToken authzToken, GroupModel groupModel) - throws GroupManagerServiceException, AuthorizationException, TException { + public String createGroup(AuthzToken authzToken, GroupModel groupModel) throws GroupManagerServiceException { try { // TODO Validations for authorization SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); @@ -79,7 +63,9 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { String groupId = sharingClient.createGroup(sharingUserGroup); internalAddUsersToGroup(sharingClient, gatewayId, groupModel.getMembers(), groupId); - addGroupAdmins(authzToken, groupId, groupModel.getAdmins()); + if (groupModel.getAdmins() != null && !groupModel.getAdmins().isEmpty()) { + sharingClient.addGroupAdmins(gatewayId, groupId, groupModel.getAdmins()); + } return groupId; } catch (Exception e) { String msg = "Error Creating Group"; @@ -90,10 +76,7 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { } } - @Override - @SecurityCheck - public boolean updateGroup(AuthzToken authzToken, GroupModel groupModel) - throws GroupManagerServiceException, AuthorizationException, TException { + public boolean updateGroup(AuthzToken authzToken, GroupModel groupModel) throws GroupManagerServiceException { try { SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); String userId = getUserId(authzToken); @@ -122,10 +105,7 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { } } - @Override - @SecurityCheck - public boolean deleteGroup(AuthzToken authzToken, String groupId, String ownerId) - throws GroupManagerServiceException, AuthorizationException, TException { + public boolean deleteGroup(AuthzToken authzToken, String groupId, String ownerId) throws GroupManagerServiceException { try { SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); String userId = getUserId(authzToken); @@ -145,10 +125,7 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { } } - @Override - @SecurityCheck - public GroupModel getGroup(AuthzToken authzToken, String groupId) - throws GroupManagerServiceException, AuthorizationException, TException { + public GroupModel getGroup(AuthzToken authzToken, String groupId) throws GroupManagerServiceException { try { SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); final String domainId = getDomainId(authzToken); @@ -166,10 +143,7 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { } } - @Override - @SecurityCheck - public List<GroupModel> getGroups(AuthzToken authzToken) - throws GroupManagerServiceException, AuthorizationException, TException { + public List<GroupModel> getGroups(AuthzToken authzToken) throws GroupManagerServiceException { final String domainId = getDomainId(authzToken); SharingRegistryService.Client sharingClient = null; try { @@ -188,10 +162,8 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { } } - @Override - @SecurityCheck public List<GroupModel> getAllGroupsUserBelongs(AuthzToken authzToken, String userName) - throws GroupManagerServiceException, AuthorizationException, TException { + throws GroupManagerServiceException { try { SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); List<GroupModel> groupModels = new ArrayList<GroupModel>(); @@ -208,9 +180,8 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { } } - @Override public boolean addUsersToGroup(AuthzToken authzToken, List<String> userIds, String groupId) - throws GroupManagerServiceException, AuthorizationException, TException { + throws GroupManagerServiceException { try { SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); String userId = getUserId(authzToken); @@ -230,9 +201,8 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { } } - @Override public boolean removeUsersFromGroup(AuthzToken authzToken, List<String> userIds, String groupId) - throws GroupManagerServiceException, AuthorizationException, TException { + throws GroupManagerServiceException { try { SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); String userId = getUserId(authzToken); @@ -251,10 +221,8 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { } } - @Override - @SecurityCheck public boolean transferGroupOwnership(AuthzToken authzToken, String groupId, String newOwnerId) - throws GroupManagerServiceException, AuthorizationException, TException { + throws GroupManagerServiceException { try { SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); String userId = getUserId(authzToken); @@ -273,10 +241,8 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { } } - @Override - @SecurityCheck public boolean addGroupAdmins(AuthzToken authzToken, String groupId, List<String> adminIds) - throws GroupManagerServiceException, AuthorizationException, TException { + throws GroupManagerServiceException { try { SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); String userId = getUserId(authzToken); @@ -294,10 +260,8 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { } } - @Override - @SecurityCheck public boolean removeGroupAdmins(AuthzToken authzToken, String groupId, List<String> adminIds) - throws GroupManagerServiceException, AuthorizationException, TException { + throws GroupManagerServiceException { try { SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); String userId = getUserId(authzToken); @@ -315,10 +279,8 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { } } - @Override - @SecurityCheck public boolean hasAdminAccess(AuthzToken authzToken, String groupId, String adminId) - throws GroupManagerServiceException, AuthorizationException, TException { + throws GroupManagerServiceException { try { SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); return sharingClient.hasAdminAccess(getDomainId(authzToken), groupId, adminId); @@ -331,10 +293,8 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { } } - @Override - @SecurityCheck public boolean hasOwnerAccess(AuthzToken authzToken, String groupId, String ownerId) - throws GroupManagerServiceException, AuthorizationException, TException { + throws GroupManagerServiceException { try { SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); return sharingClient.hasOwnerAccess(getDomainId(authzToken), groupId, ownerId); @@ -434,3 +394,4 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { return sharingClient.addUsersToGroup(domainId, userIds, groupId); } } + diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java index 9b445aa11b..a983205e41 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java @@ -19,29 +19,14 @@ */ package org.apache.airavata.service.profile.handlers; -import java.util.ArrayList; import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; -import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.common.utils.Constants; -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.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; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,10 +34,11 @@ import org.slf4j.LoggerFactory; public class GroupManagerServiceHandler implements GroupManagerService.Iface { private static final Logger logger = LoggerFactory.getLogger(GroupManagerServiceHandler.class); + private org.apache.airavata.service.GroupManagerService groupManagerService; - private UserProfileRepository userProfileRepository = new UserProfileRepository(); - - public GroupManagerServiceHandler() {} + public GroupManagerServiceHandler() { + groupManagerService = new org.apache.airavata.service.GroupManagerService(); + } @Override public String getAPIVersion() throws TException { @@ -64,23 +50,9 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { public String createGroup(AuthzToken authzToken, GroupModel groupModel) throws GroupManagerServiceException, AuthorizationException, TException { try { - // TODO Validations for authorization - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - - UserGroup sharingUserGroup = new UserGroup(); - sharingUserGroup.setGroupId(UUID.randomUUID().toString()); - sharingUserGroup.setName(groupModel.getName()); - sharingUserGroup.setDescription(groupModel.getDescription()); - sharingUserGroup.setGroupType(GroupType.USER_LEVEL_GROUP); - sharingUserGroup.setGroupCardinality(GroupCardinality.MULTI_USER); - String gatewayId = getDomainId(authzToken); - sharingUserGroup.setDomainId(gatewayId); - sharingUserGroup.setOwnerId(getUserId(authzToken)); - - String groupId = sharingClient.createGroup(sharingUserGroup); - internalAddUsersToGroup(sharingClient, gatewayId, groupModel.getMembers(), groupId); - addGroupAdmins(authzToken, groupId, groupModel.getAdmins()); - return groupId; + return groupManagerService.createGroup(authzToken, groupModel); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { String msg = "Error Creating Group"; logger.error(msg, e); @@ -95,24 +67,9 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { public boolean updateGroup(AuthzToken authzToken, GroupModel groupModel) throws GroupManagerServiceException, AuthorizationException, TException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - String userId = getUserId(authzToken); - String domainId = getDomainId(authzToken); - if (!(sharingClient.hasOwnerAccess(domainId, groupModel.getId(), userId) - || sharingClient.hasAdminAccess(domainId, groupModel.getId(), userId))) { - throw new GroupManagerServiceException("User does not have permission to update group"); - } - - UserGroup sharingUserGroup = new UserGroup(); - sharingUserGroup.setGroupId(groupModel.getId()); - sharingUserGroup.setName(groupModel.getName()); - sharingUserGroup.setDescription(groupModel.getDescription()); - sharingUserGroup.setGroupType(GroupType.USER_LEVEL_GROUP); - sharingUserGroup.setDomainId(getDomainId(authzToken)); - - // adding and removal of users should be handle separately - sharingClient.updateGroup(sharingUserGroup); - return true; + return groupManagerService.updateGroup(authzToken, groupModel); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { String msg = "Error Updating Group"; logger.error(msg, e); @@ -127,15 +84,9 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { public boolean deleteGroup(AuthzToken authzToken, String groupId, String ownerId) throws GroupManagerServiceException, AuthorizationException, TException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - String userId = getUserId(authzToken); - String domainId = getDomainId(authzToken); - if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId))) { - throw new GroupManagerServiceException("User does not have permission to delete group"); - } - - sharingClient.deleteGroup(getDomainId(authzToken), groupId); - return true; + return groupManagerService.deleteGroup(authzToken, groupId, ownerId); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { String msg = "Error Deleting Group. Group ID: " + groupId; logger.error(msg, e); @@ -150,13 +101,9 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { public GroupModel getGroup(AuthzToken authzToken, String groupId) throws GroupManagerServiceException, AuthorizationException, TException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - final String domainId = getDomainId(authzToken); - UserGroup userGroup = sharingClient.getGroup(domainId, groupId); - - GroupModel groupModel = convertToGroupModel(userGroup, sharingClient); - - return groupModel; + return groupManagerService.getGroup(authzToken, groupId); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { String msg = "Error Retreiving Group. Group ID: " + groupId; logger.error(msg, e); @@ -170,21 +117,16 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { @SecurityCheck public List<GroupModel> getGroups(AuthzToken authzToken) throws GroupManagerServiceException, AuthorizationException, TException { - final String domainId = getDomainId(authzToken); - SharingRegistryService.Client sharingClient = null; try { - sharingClient = getSharingRegistryServiceClient(); - List<UserGroup> userGroups = sharingClient.getGroups(domainId, 0, -1); - - return convertToGroupModels(userGroups, sharingClient); + return groupManagerService.getGroups(authzToken); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { - String msg = "Error Retrieving Groups. Domain ID: " + domainId; + String msg = "Error Retrieving Groups"; logger.error(msg, e); GroupManagerServiceException exception = new GroupManagerServiceException(); exception.setMessage(msg + " More info : " + e.getMessage()); throw exception; - } finally { - closeSharingClient(sharingClient); } } @@ -193,12 +135,9 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { public List<GroupModel> getAllGroupsUserBelongs(AuthzToken authzToken, String userName) throws GroupManagerServiceException, AuthorizationException, TException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - List<GroupModel> groupModels = new ArrayList<GroupModel>(); - final String domainId = getDomainId(authzToken); - List<UserGroup> userGroups = sharingClient.getAllMemberGroupsForUser(domainId, userName); - - return convertToGroupModels(userGroups, sharingClient); + return groupManagerService.getAllGroupsUserBelongs(authzToken, userName); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { String msg = "Error Retreiving All Groups for User. User ID: " + userName; logger.error(msg, e); @@ -212,15 +151,9 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { public boolean addUsersToGroup(AuthzToken authzToken, List<String> userIds, String groupId) throws GroupManagerServiceException, AuthorizationException, TException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - String userId = getUserId(authzToken); - String domainId = getDomainId(authzToken); - if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId) - || sharingClient.hasAdminAccess(domainId, groupId, userId))) { - throw new GroupManagerServiceException("User does not have access to add users to the group"); - } - return internalAddUsersToGroup(sharingClient, domainId, userIds, groupId); - + return groupManagerService.addUsersToGroup(authzToken, userIds, groupId); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { String msg = "Error adding users to group. Group ID: " + groupId; logger.error(msg, e); @@ -234,14 +167,9 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { public boolean removeUsersFromGroup(AuthzToken authzToken, List<String> userIds, String groupId) throws GroupManagerServiceException, AuthorizationException, TException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - String userId = getUserId(authzToken); - String domainId = getDomainId(authzToken); - if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId) - || sharingClient.hasAdminAccess(domainId, groupId, userId))) { - throw new GroupManagerServiceException("User does not have access to remove users to the group"); - } - return sharingClient.removeUsersFromGroup(domainId, userIds, groupId); + return groupManagerService.removeUsersFromGroup(authzToken, userIds, groupId); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { String msg = "Error remove users to group. Group ID: " + groupId; logger.error(msg, e); @@ -256,14 +184,9 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { public boolean transferGroupOwnership(AuthzToken authzToken, String groupId, String newOwnerId) throws GroupManagerServiceException, AuthorizationException, TException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - String userId = getUserId(authzToken); - String domainId = getDomainId(authzToken); - if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId))) { - throw new GroupManagerServiceException( - "User does not have Owner permission to transfer group ownership"); - } - return sharingClient.transferGroupOwnership(getDomainId(authzToken), groupId, newOwnerId); + return groupManagerService.transferGroupOwnership(authzToken, groupId, newOwnerId); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { String msg = "Error Transferring Group Ownership"; logger.error(msg, e); @@ -278,13 +201,9 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { public boolean addGroupAdmins(AuthzToken authzToken, String groupId, List<String> adminIds) throws GroupManagerServiceException, AuthorizationException, TException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - String userId = getUserId(authzToken); - String domainId = getDomainId(authzToken); - if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId))) { - throw new GroupManagerServiceException("User does not have Owner permission to add group admins"); - } - return sharingClient.addGroupAdmins(getDomainId(authzToken), groupId, adminIds); + return groupManagerService.addGroupAdmins(authzToken, groupId, adminIds); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { String msg = "Error Adding Admins to Group. Group ID: " + groupId; logger.error(msg, e); @@ -299,13 +218,9 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { public boolean removeGroupAdmins(AuthzToken authzToken, String groupId, List<String> adminIds) throws GroupManagerServiceException, AuthorizationException, TException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - String userId = getUserId(authzToken); - String domainId = getDomainId(authzToken); - if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId))) { - throw new GroupManagerServiceException("User does not have Owner permission to remove group admins"); - } - return sharingClient.removeGroupAdmins(getDomainId(authzToken), groupId, adminIds); + return groupManagerService.removeGroupAdmins(authzToken, groupId, adminIds); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { String msg = "Error Removing Admins from the Group. Group ID: " + groupId; logger.error(msg, e); @@ -320,8 +235,9 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { public boolean hasAdminAccess(AuthzToken authzToken, String groupId, String adminId) throws GroupManagerServiceException, AuthorizationException, TException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - return sharingClient.hasAdminAccess(getDomainId(authzToken), groupId, adminId); + return groupManagerService.hasAdminAccess(authzToken, groupId, adminId); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { String msg = "Error Checking Admin Access for the Group. Group ID: " + groupId + " Admin ID: " + adminId; logger.error(msg, e); @@ -336,8 +252,9 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { public boolean hasOwnerAccess(AuthzToken authzToken, String groupId, String ownerId) throws GroupManagerServiceException, AuthorizationException, TException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - return sharingClient.hasOwnerAccess(getDomainId(authzToken), groupId, ownerId); + return groupManagerService.hasOwnerAccess(authzToken, groupId, ownerId); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { String msg = "Error Checking Owner Access for the Group. Group ID: " + groupId + " Owner ID: " + ownerId; logger.error(msg, e); @@ -346,91 +263,4 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { throw exception; } } - - // TODO: replace these methods with ThriftClientPool (see AIRAVATA-2607) - private SharingRegistryService.Client getSharingRegistryServiceClient() - throws TException, ApplicationSettingsException { - final int serverPort = Integer.parseInt(ServerSettings.getSharingRegistryPort()); - final String serverHost = ServerSettings.getSharingRegistryHost(); - try { - return SharingRegistryServiceClientFactory.createSharingRegistryClient(serverHost, serverPort); - } catch (SharingRegistryException e) { - throw new TException("Unable to create sharing registry client...", e); - } - } - - private String getDomainId(AuthzToken authzToken) { - return authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - } - - private String getUserId(AuthzToken authzToken) { - return authzToken.getClaimsMap().get(Constants.USER_NAME) + "@" + getDomainId(authzToken); - } - - private List<GroupModel> convertToGroupModels( - List<UserGroup> userGroups, SharingRegistryService.Client sharingClient) throws TException { - - List<GroupModel> groupModels = new ArrayList<>(); - - for (UserGroup userGroup : userGroups) { - GroupModel groupModel = convertToGroupModel(userGroup, sharingClient); - - groupModels.add(groupModel); - } - return groupModels; - } - - private GroupModel convertToGroupModel(UserGroup userGroup, SharingRegistryService.Client sharingClient) - throws TException { - GroupModel groupModel = new GroupModel(); - groupModel.setId(userGroup.getGroupId()); - groupModel.setName(userGroup.getName()); - groupModel.setDescription(userGroup.getDescription()); - groupModel.setOwnerId(userGroup.getOwnerId()); - final List<String> admins = userGroup.getGroupAdmins().stream() - .map(groupAdmin -> groupAdmin.getAdminId()) - .collect(Collectors.toList()); - groupModel.setAdmins(admins); - - sharingClient.getGroupMembersOfTypeUser(userGroup.getDomainId(), userGroup.getGroupId(), 0, -1).stream() - .forEach(user -> groupModel.addToMembers(user.getUserId())); - return groupModel; - } - - private void closeSharingClient(SharingRegistryService.Client sharingClient) { - if (sharingClient != null) { - if (sharingClient.getInputProtocol().getTransport().isOpen()) { - sharingClient.getInputProtocol().getTransport().close(); - } - if (sharingClient.getOutputProtocol().getTransport().isOpen()) { - sharingClient.getOutputProtocol().getTransport().close(); - } - } - } - - 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); - } }
