From 37262ce263fe7f023bb971fa40b92ebff05b2ab4 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Fri, 13 May 2016 13:27:57 +0000 Subject: [PATCH] added has Team and has Role methods to RolesManger git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vo-management/usermanagement-core@128599 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../usermanagement/RoleManager.java | 16 ++++++++++++ .../impl/LiferayRoleManager.java | 25 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/RoleManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/RoleManager.java index 51306a4..f14b9f4 100644 --- a/src/main/java/org/gcube/vomanagement/usermanagement/RoleManager.java +++ b/src/main/java/org/gcube/vomanagement/usermanagement/RoleManager.java @@ -28,6 +28,22 @@ public interface RoleManager { * @throws UserRetrievalFault */ boolean isAdmin(long userId) throws UserRetrievalFault; + /** + * + * @param userId userId the LR UserId, not the username + * @param groupId the LR groupId + * @param roleId the LR roleId + * @return + */ + boolean hasRole(long userId, long groupId, long roleId); + /** + * + * @param userId userId the LR UserId, not the username + * @param teamId the LR teamId + * @param roleId the LR roleId + * @return + */ + boolean hasTeam(long userId, long teamId); /** * * @param userId the LR UserId diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayRoleManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayRoleManager.java index fea762e..07d019f 100644 --- a/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayRoleManager.java +++ b/src/main/java/org/gcube/vomanagement/usermanagement/impl/LiferayRoleManager.java @@ -132,6 +132,30 @@ public class LiferayRoleManager implements RoleManager { } return -1; } + + @Override + public boolean hasRole(long userId, long groupId, long roleId) { + try { + List roles = listRolesByUserAndGroup(userId, groupId); + for (GCubeRole gCubeRole : roles) { + if (gCubeRole.getRoleId() == roleId) + return true; + } + } catch (GroupRetrievalFault | UserRetrievalFault e) { + e.printStackTrace(); + } + return false; + } + + @Override + public boolean hasTeam(long userId, long teamId) { + try { + return UserLocalServiceUtil.hasTeamUser(teamId, userId); + } catch (SystemException e) { + e.printStackTrace(); + } + return false; + } /** * {@inheritDoc} */ @@ -512,4 +536,5 @@ public class LiferayRoleManager implements RoleManager { } return false; } + }