diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..f3dfa12 --- /dev/null +++ b/.classpath @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..ab558ba --- /dev/null +++ b/.project @@ -0,0 +1,29 @@ + + + usermanagement-core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..a91742b --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,7 @@ +#Sat Dec 08 16:14:14 CET 2012 +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..4a3b5d9 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,9 @@ +#Fri Jul 26 17:34:06 CEST 2013 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..49824ba --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,5 @@ +#Sat Dec 08 16:14:13 CET 2012 +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/.settings/org.maven.ide.eclipse.prefs b/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 0000000..8fdc872 --- /dev/null +++ b/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,9 @@ +#Wed Aug 25 12:47:12 CEST 2010 +activeProfiles= +eclipse.preferences.version=1 +fullBuildGoals=process-test-resources +includeModules=false +resolveWorkspaceProjects=true +resourceFilterGoals=process-resources resources\:testResources +skipCompilerPlugin=true +version=1 diff --git a/distro/INSTALL b/distro/INSTALL new file mode 100644 index 0000000..30404ce --- /dev/null +++ b/distro/INSTALL @@ -0,0 +1 @@ +TODO \ No newline at end of file diff --git a/distro/LICENSE b/distro/LICENSE new file mode 100644 index 0000000..cc51139 --- /dev/null +++ b/distro/LICENSE @@ -0,0 +1,6 @@ +gCube System - License +------------------------------------------------------------ + +The gCube/gCore software is licensed as Free Open Source software conveying to the EUPL (http://ec.europa.eu/idabc/eupl). +The software and documentation is provided by its authors/distributors "as is" and no expressed or +implied warranty is given for its use, quality or fitness for a particular case. \ No newline at end of file diff --git a/distro/MAINTAINERS b/distro/MAINTAINERS new file mode 100644 index 0000000..bf3f106 --- /dev/null +++ b/distro/MAINTAINERS @@ -0,0 +1,8 @@ +Kanchanna Ramasamy Balraj (Kanchanna.RamasamyBalraj@eng.it), ENG, +Engineering Ingegneria Informatica S.p.A. + +Giulio Galiero (Giulio.Galiero@eng.it), ENG, +Engineering Ingegneria Informatica S.p.A. + +Ciro Formisano (Ciro.Formisano@eng.it), ENG, +Engineering Ingegneria Informatica S.p.A. \ No newline at end of file diff --git a/distro/README b/distro/README new file mode 100644 index 0000000..1a10266 --- /dev/null +++ b/distro/README @@ -0,0 +1,38 @@ +The gCube System +------------------------------------------------------------ + +This work is partially funded by the European Commission in the +context of the D4Science project (www.d4science.eu), under the 1st +call of FP7 IST priority. + + +Authors +------- + +Kanchanna Ramasamy Balraj (Kanchanna.RamasamyBalraj@eng.it), ENG, +Engineering Ingegneria Informatica S.p.A. + +Giulio Galiero (Giulio.Galiero@eng.it), ENG, +Engineering Ingegneria Informatica S.p.A. + +Ciro Formisano (Ciro.Formisano@eng.it), ENG, +Engineering Ingegneria Informatica S.p.A. + + +Version and Release Date +------------------------ + +03 September 2010 + * First release + +Licensing +--------- + +This software is licensed under the terms you may find in the file named "LICENSE" in this directory. + +Documentation +------------- + +Documentation is available on - line from the Projects Documentation wiki: + +https://gcube.wiki.gcube-system.org/gcube/index.php/UserManagement_Core diff --git a/distro/changelog.xml b/distro/changelog.xml new file mode 100644 index 0000000..283429d --- /dev/null +++ b/distro/changelog.xml @@ -0,0 +1,18 @@ + + + UserManagement lib for Liferay + + + #82: UserManagement Portlet cannot assign role Production-Support + + + #120: Failed to Assign Production-Support role + + + #120: Failed to Assign Production-Support role + + \ No newline at end of file diff --git a/distro/descriptor.xml b/distro/descriptor.xml new file mode 100644 index 0000000..c468f13 --- /dev/null +++ b/distro/descriptor.xml @@ -0,0 +1,48 @@ + + servicearchive + + tar.gz + + / + + + ${distroDirectory} + / + true + + README + LICENSE + INSTALL + MAINTAINERS + changelog.xml + + 755 + true + + + target/apidocs + /${artifactId}/doc/api + true + 755 + + + + + ${distroDirectory}/profile.xml + ./ + true + + + target/${build.finalName}.jar + /${artifactId} + + + ${distroDirectory}/svnpath.txt + /${artifactId} + true + + + \ No newline at end of file diff --git a/distro/profile.xml b/distro/profile.xml new file mode 100644 index 0000000..cbf4804 --- /dev/null +++ b/distro/profile.xml @@ -0,0 +1,25 @@ + + + + Library + + ASL Social Library + ApplicationSupportLayer + ${artifactId} + 1.0.0 + + + ${artifactId} + ${version} + + ${groupId} + ${artifactId} + ${version} + + + ${build.finalName}.jar + + + + + diff --git a/distro/svnpath.txt b/distro/svnpath.txt new file mode 100644 index 0000000..edacb04 --- /dev/null +++ b/distro/svnpath.txt @@ -0,0 +1 @@ +${scm.url} \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..baf1655 --- /dev/null +++ b/pom.xml @@ -0,0 +1,158 @@ + + 4.0.0 + + maven-parent + org.gcube.tools + 1.0.0 + + + + org.gcube.dvos + usermanagement-core + 1.2.0-SNAPSHOT + jar + + User Management API + + User Management API + + + scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/vo-mamangement/usermanagement-core + scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/trunk/vo-mamangement/usermanagement-core + http://svn.d4science.research-infrastructures.eu/gcube/trunk/vo-mamangement/usermanagement-core + + + distro + 1.6 + 1.6 + + UTF-8 + UTF-8 + + + + + + org.gcube.core + gcf + [1.4.0-SNAPSHOT, 2.0.0-SNAPSHOT) + provided + + + com.liferay.portal + portal-service + 6.0.6 + + + javax.portlet + portlet-api + 2.0 + provided + + + junit + junit + 3.8.1 + test + + + + + + + src/main/java + + **/*.* + + + + + + maven-compiler-plugin + 3.0 + + 1.6 + 1.6 + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.2 + + + + test-jar + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12 + + true + + + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + + copy-profile + install + + copy-resources + + + target + + + ${distroDirectory} + true + + profile.xml + + + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.2 + + + ${distroDirectory}/descriptor.xml + + + + fully.qualified.MainClass + + + + + + servicearchive + install + + single + + + + + + + + + + + diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/GroupManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/GroupManager.java new file mode 100644 index 0000000..45bf4bc --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/GroupManager.java @@ -0,0 +1,67 @@ +package org.gcube.vomanagement.usermanagement; + +import java.util.HashMap; +import java.util.List; + +import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.UserManagementNameException; +import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException; +import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; +import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; +import org.gcube.vomanagement.usermanagement.model.GroupModel; +import org.gcube.vomanagement.usermanagement.model.RoleModel; + + +/** + * This interface defines the class that manages the groups. + * + * @author Giulio Galiero + * + */ +public interface GroupManager { + + //public GroupModel createGroup(String groupName, String userId) throws UserManagementException; + + public GroupModel createRootVO(String RootVOName, String userId, String description)throws UserManagementNameException, UserManagementSystemException, UserRetrievalFault ,GroupRetrievalFault, UserManagementPortalException; + + public GroupModel createVO(String VOName, String rootVOGroupId, String userId, String description)throws UserManagementNameException, UserManagementSystemException, UserRetrievalFault, GroupRetrievalFault, UserManagementPortalException; + + public GroupModel createVRE(String VREName, String VOGroupId, String userId, String description)throws UserManagementNameException, UserManagementSystemException, UserRetrievalFault, GroupRetrievalFault, UserManagementPortalException; + + public void deleteGroup(String groupId) throws UserManagementSystemException, GroupRetrievalFault; + + public void updateGroup(GroupModel group) throws UserManagementSystemException, GroupRetrievalFault; + + public GroupModel getGroup(String groupId) throws UserManagementSystemException, GroupRetrievalFault; + + public GroupModel getRootVO() throws UserManagementSystemException, GroupRetrievalFault; + + public String getRootVOName() throws UserManagementSystemException, GroupRetrievalFault; + + public List listGroups() throws UserManagementSystemException; + + public List listGroupsByUser(String userId) throws UserManagementSystemException; + + public List listPendingGroupsByUser(String userId) throws UserManagementSystemException; + + public List listSubGroupsByGroup(String groupId) throws UserManagementSystemException, GroupRetrievalFault; + + public HashMap> listGroupsAndRolesByUser(String userId) throws UserManagementSystemException; + + public void assignSubGrouptoParentGroup(String subGroupId, String parentGroupId) throws UserManagementSystemException, GroupRetrievalFault; + + public void dismissSubGroupFromParentGroup(String subGroupId, String parentGroupId) throws UserManagementSystemException, GroupRetrievalFault; + + public String getGroupId(String groupName) throws UserManagementSystemException, GroupRetrievalFault; + + public long getGroupParentId(String groupId) throws UserManagementSystemException, GroupRetrievalFault; + + public String getScope(String groupId) throws UserManagementSystemException, GroupRetrievalFault; + + public Boolean isRootVO(String groupId) throws UserManagementSystemException, GroupRetrievalFault; + + public Boolean isVO(String groupId) throws UserManagementSystemException, GroupRetrievalFault; + + public Boolean isVRE(String groupId) throws UserManagementSystemException, GroupRetrievalFault; + +} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/RoleManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/RoleManager.java new file mode 100644 index 0000000..0328a8c --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/RoleManager.java @@ -0,0 +1,57 @@ +package org.gcube.vomanagement.usermanagement; + + +import java.util.HashMap; +import java.util.List; + +import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.RoleRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.UserManagementFileNotFoundException; +import org.gcube.vomanagement.usermanagement.exception.UserManagementIOException; +import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException; +import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; +import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; +import org.gcube.vomanagement.usermanagement.model.RoleModel; + +/** + * This interface defines the manager class that manages the roles. + * + * @author Giulio Galiero + * + */ +public interface RoleManager { + + boolean isAdmin(String userId); + + public void assignRoleToUser(String groupId, String roleId, String userId) throws UserManagementSystemException, UserRetrievalFault, GroupRetrievalFault,RoleRetrievalFault; + + public void createRole(String groupName) throws UserManagementSystemException, GroupRetrievalFault, RoleRetrievalFault, UserManagementPortalException, UserManagementFileNotFoundException, UserManagementIOException; + + public boolean createRole(String roleName,String roleDescription, String groupName) throws UserManagementSystemException, RoleRetrievalFault, GroupRetrievalFault, UserManagementPortalException; + + public void deleteRole(String roleName, String groupName) throws UserManagementSystemException, RoleRetrievalFault ; + + public void dismissRoleFromUser(String groupId, String roleId, String userId)throws UserManagementSystemException, UserRetrievalFault, GroupRetrievalFault,RoleRetrievalFault; + + public RoleModel getRole(String roleId) throws UserManagementSystemException, RoleRetrievalFault; + + public String getRoleId(String roleName, String groupName) throws UserManagementSystemException; + + public HashMap listAllowedRoles(String groupName) throws UserManagementSystemException, GroupRetrievalFault, UserManagementFileNotFoundException, UserManagementIOException; + + @Deprecated + public List listRoles() throws UserManagementSystemException; + + public List listAllRoles() throws UserManagementSystemException; + + public List listRolesByGroup(String groupId) throws UserManagementSystemException, GroupRetrievalFault, UserManagementFileNotFoundException, UserManagementIOException; + + public List listRolesByUser(String userId) throws UserManagementSystemException; + + public List listRolesByUserAndGroup(String groupId, String userId) throws UserManagementSystemException, GroupRetrievalFault,UserRetrievalFault ; + + public void updateRole(String initialRoleName, String newRoleName, String roleDescription, String groupName) throws UserManagementSystemException, RoleRetrievalFault, NumberFormatException, UserManagementFileNotFoundException, UserManagementIOException, GroupRetrievalFault,UserManagementPortalException; + + public void updatePredefinedRoles(HashMap rolesMap, String groupType) throws UserManagementIOException, UserManagementFileNotFoundException ; + +} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/UserManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/UserManager.java new file mode 100644 index 0000000..17deb05 --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/UserManager.java @@ -0,0 +1,69 @@ +package org.gcube.vomanagement.usermanagement; + +import java.util.HashMap; +import java.util.List; + +import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.RoleRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException; +import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; +import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; +import org.gcube.vomanagement.usermanagement.model.GroupModel; +import org.gcube.vomanagement.usermanagement.model.RoleModel; +import org.gcube.vomanagement.usermanagement.model.UserModel; + + +/** + * This interface defines the class that manages the users. + * + * @author Giulio Galiero + * + */ +public interface UserManager { + + public void createUser(UserModel usermodel) throws UserManagementSystemException, UserRetrievalFault; + + public void deleteUser(String userId) throws UserManagementSystemException, UserRetrievalFault; + + public void updateUser(UserModel user) throws UserRetrievalFault, UserManagementSystemException, UserManagementPortalException; + + public UserModel getUser(String userId) throws UserManagementSystemException, UserRetrievalFault ; + + public List listUsers() throws UserManagementSystemException, UserRetrievalFault; + + public List listUsersByGroup(String groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault; + + public List listPendingUsersByGroup(String groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault; + + public String getMembershipRequestComment(String userId, String groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault; + + public HashMap> listUsersAndRolesByGroup(String groupId) throws GroupRetrievalFault, UserManagementSystemException, UserRetrievalFault ; + + public HashMap> listUsersAndGroupsByRole(String roleId) throws UserManagementSystemException, RoleRetrievalFault, UserRetrievalFault ; + + public List listUsersByGroupAndRole(String groupId, String roleId) throws UserManagementSystemException, RoleRetrievalFault, GroupRetrievalFault, UserRetrievalFault; + + public void assignUserToGroup(String groupId, String userId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault, UserManagementPortalException; + + public void dismissUserFromGroup(String groupId, String userId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault; + + public void requestMembership(String userId, String groupId, String comment) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault; + + public List listUnregisteredUsersByGroup(String groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault; + + public String getUserId(String screenName) throws UserManagementSystemException; + + public List getMembershipRequests(String groupId) throws UserManagementSystemException,GroupRetrievalFault, UserRetrievalFault; + + public UserModel getUserByScreenName(String screenName) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException; + + public HashMap getUserCustomAttributes(String userId) throws UserManagementSystemException, UserRetrievalFault; + + public void setUserCustomAttributes(String userId, HashMap hMap) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException; + + public String getUserCustomAttributeByName(String userId, String attrName)throws UserManagementSystemException, UserRetrievalFault; + + public void setUserCustomAttributeByName(String userId, String attrName, String attrValue) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException; + + public void denyMembershipRequest(String userId,String groupId)throws UserManagementSystemException, GroupRetrievalFault, UserManagementPortalException; +} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/exception/GroupRetrievalFault.java b/src/main/java/org/gcube/vomanagement/usermanagement/exception/GroupRetrievalFault.java new file mode 100644 index 0000000..ede38c2 --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/exception/GroupRetrievalFault.java @@ -0,0 +1,28 @@ +package org.gcube.vomanagement.usermanagement.exception; + +import com.liferay.portal.kernel.exception.PortalException; + + + +public class GroupRetrievalFault extends Exception{ + + + /** + * + */ + private static final long serialVersionUID = -5809619725100397844L; + + public GroupRetrievalFault(String errorMsg, String orgId ){ + System.out.println(errorMsg + orgId); + } + + public GroupRetrievalFault(String errorMsg, PortalException e){ + System.out.println(errorMsg); + e.printStackTrace(); + } + + public GroupRetrievalFault(String errorMsg, String orgId , PortalException e){ + System.out.println(errorMsg + orgId); + e.printStackTrace(); + } +} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/exception/RoleRetrievalFault.java b/src/main/java/org/gcube/vomanagement/usermanagement/exception/RoleRetrievalFault.java new file mode 100644 index 0000000..8dd3b00 --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/exception/RoleRetrievalFault.java @@ -0,0 +1,28 @@ +package org.gcube.vomanagement.usermanagement.exception; + +import com.liferay.portal.kernel.exception.PortalException; + + + +public class RoleRetrievalFault extends Exception{ + + + private static final long serialVersionUID = 2824756378739545315L; + + /** + * + */ + public RoleRetrievalFault(String errorMsg, String roleId){ + System.out.println(errorMsg + roleId); + } + + public RoleRetrievalFault(String errorMsg, PortalException e){ + System.out.println(errorMsg); + e.printStackTrace(); + } + + public RoleRetrievalFault(String errorMsg, String roleId , PortalException e){ + System.out.println(errorMsg + roleId); + e.printStackTrace(); + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/exception/UserManagementFileNotFoundException.java b/src/main/java/org/gcube/vomanagement/usermanagement/exception/UserManagementFileNotFoundException.java new file mode 100644 index 0000000..b6efd6c --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/exception/UserManagementFileNotFoundException.java @@ -0,0 +1,18 @@ +package org.gcube.vomanagement.usermanagement.exception; + +import java.io.FileNotFoundException; + + +public class UserManagementFileNotFoundException extends Exception{ + + + /** + * + */ + private static final long serialVersionUID = 3573055203913190069L; + + public UserManagementFileNotFoundException(String errorMsg, FileNotFoundException e){ + System.out.println(errorMsg); + e.printStackTrace(); + } +} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/exception/UserManagementIOException.java b/src/main/java/org/gcube/vomanagement/usermanagement/exception/UserManagementIOException.java new file mode 100644 index 0000000..5c5e6b9 --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/exception/UserManagementIOException.java @@ -0,0 +1,19 @@ +package org.gcube.vomanagement.usermanagement.exception; + +import java.io.IOException; + + +public class UserManagementIOException extends Exception{ + + + /** + * + */ + private static final long serialVersionUID = -7351699091691019047L; + + public UserManagementIOException(String errorMsg, IOException e){ + System.out.println(errorMsg); + e.printStackTrace(); + } + +} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/exception/UserManagementNameException.java b/src/main/java/org/gcube/vomanagement/usermanagement/exception/UserManagementNameException.java new file mode 100644 index 0000000..5c46527 --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/exception/UserManagementNameException.java @@ -0,0 +1,14 @@ +package org.gcube.vomanagement.usermanagement.exception; + +public class UserManagementNameException extends Exception{ + + + /** + * + */ + private static final long serialVersionUID = 9127162401036769140L; + + public UserManagementNameException(String e){ + + } +} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/exception/UserManagementPortalException.java b/src/main/java/org/gcube/vomanagement/usermanagement/exception/UserManagementPortalException.java new file mode 100644 index 0000000..916632c --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/exception/UserManagementPortalException.java @@ -0,0 +1,25 @@ +package org.gcube.vomanagement.usermanagement.exception; + +import com.liferay.portal.kernel.exception.PortalException; + + + + +public class UserManagementPortalException extends Exception{ + + /** + * + */ + private static final long serialVersionUID = -4958787007913556095L; + + + public UserManagementPortalException(String errorMsg, PortalException e){ + System.out.println(errorMsg); + e.printStackTrace(); + } + + public UserManagementPortalException(String errorMsg, String orgId , PortalException e){ + System.out.println(errorMsg + orgId); + e.printStackTrace(); + } +} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/exception/UserManagementSystemException.java b/src/main/java/org/gcube/vomanagement/usermanagement/exception/UserManagementSystemException.java new file mode 100644 index 0000000..8f527f7 --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/exception/UserManagementSystemException.java @@ -0,0 +1,21 @@ +package org.gcube.vomanagement.usermanagement.exception; + +import com.liferay.portal.kernel.exception.SystemException; + + +public class UserManagementSystemException extends Exception{ + /** + * + */ + private static final long serialVersionUID = 7775831372490099004L; + + + public UserManagementSystemException(String errorMsg, SystemException e){ + System.out.println(errorMsg); + e.printStackTrace(); + } + public UserManagementSystemException(String errorMsg,String orgId, Exception e){ + System.out.println(errorMsg + orgId); + e.printStackTrace(); + } +} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/exception/UserRetrievalFault.java b/src/main/java/org/gcube/vomanagement/usermanagement/exception/UserRetrievalFault.java new file mode 100644 index 0000000..8cd7496 --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/exception/UserRetrievalFault.java @@ -0,0 +1,25 @@ +package org.gcube.vomanagement.usermanagement.exception; + +import com.liferay.portal.kernel.exception.PortalException; + + + +public class UserRetrievalFault extends Exception{ + + private static final long serialVersionUID = 4384964298359631619L; + + /** + * + */ + + + public UserRetrievalFault(String errorMsg, PortalException e){ + System.out.println(errorMsg); + e.printStackTrace(); + } + + public UserRetrievalFault(String errorMsg, String userId , PortalException e){ + System.out.println(errorMsg + userId); + e.printStackTrace(); + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/LiferayGroupManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/LiferayGroupManager.java new file mode 100644 index 0000000..4e17084 --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/LiferayGroupManager.java @@ -0,0 +1,509 @@ +package org.gcube.vomanagement.usermanagement.impl.liferay; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.gcube.vomanagement.usermanagement.GroupManager; +import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.UserManagementNameException; +import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException; +import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; +import org.gcube.vomanagement.usermanagement.model.GroupModel; +import org.gcube.vomanagement.usermanagement.model.RoleModel; + + + +import com.liferay.portal.kernel.exception.PortalException; +import com.liferay.portal.kernel.exception.SystemException; +import com.liferay.portal.kernel.util.GetterUtil; +import com.liferay.portal.kernel.util.PropsUtil; +import com.liferay.portal.model.Company; +import com.liferay.portal.model.MembershipRequest; +import com.liferay.portal.model.Organization; +import com.liferay.portal.model.Role; + +import com.liferay.portal.service.CompanyLocalServiceUtil; +import com.liferay.portal.service.MembershipRequestLocalServiceUtil; +import com.liferay.portal.service.OrganizationLocalServiceUtil; +import com.liferay.portal.service.RoleLocalServiceUtil; +import com.liferay.portal.service.ServiceContext; + + +/** + * Liferay plugin for the GroupManager interface, this implementation interacts with Liferay through a LocalService. + * + * @author Giulio Galiero + * + */ +public class LiferayGroupManager implements GroupManager { + + private static final String DEFAULT_COMPANY_WEB_ID = "liferay.com"; + private final String REG_EX_MATCH = "^[A-Za-z0-9]+([-\\.\\_\\-ε]([A-Za-z0-9]+))*"; + + private long getLongId(String groupId) throws NumberFormatException{ + + long groupIdL = Long.parseLong(groupId); + return groupIdL; + } + /** + * return the companyId + * @param webId . + * @return the company bean + * @throws PortalException . + * @throws SystemException . + */ + public static Company getCompany() throws PortalException, SystemException { + return CompanyLocalServiceUtil.getCompanyByWebId(getDefaultCompanyWebId()); + } + /** + * + * @return the default company web-id (e.g. iMarine.eu) + */ + public static String getDefaultCompanyWebId() { + String defaultWebId = ""; + try { + defaultWebId = GetterUtil.getString(PropsUtil.get("company.default.web.id")); + } + catch (NullPointerException e) { + System.out.println("Cound not find property company.default.web.id in portal.ext file returning default web id: " + DEFAULT_COMPANY_WEB_ID); + return DEFAULT_COMPANY_WEB_ID; + } + return defaultWebId; + } + + + + protected long getCompanyId() throws UserManagementSystemException, UserManagementPortalException{ + Company company = null; + try { + company = getCompany(); + } catch (PortalException e) { + throw new UserManagementPortalException("Error retrieving companyId ", e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving companyId ", e); + } + return company.getCompanyId(); + } + + /* public GroupModel.GROUP_TYPE getGroupType(GroupModel gm){ + if(gm.getGroupName().startsWith("VO")){ + return GroupModel.GROUP_TYPE.VO; + }else if(gm.getGroupName().contains("ROOT_VO")){ + return GroupModel.GROUP_TYPE.ROOT_VO; + }else if(gm.getGroupName().contains("VRE")){ + return GroupModel.GROUP_TYPE.ROOT_VO; + } + return GroupModel.GROUP_TYPE.VO; + }*/ + + public String getScope(String groupId) throws UserManagementSystemException, GroupRetrievalFault{ + StringBuilder scope = new StringBuilder("/"); + Organization org; + + try{ + long groupIdL = this.getLongId(groupId); + org = OrganizationLocalServiceUtil.getOrganization(groupIdL); + }catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving scope for group ", groupId , e); + } catch (PortalException e) { + throw new GroupRetrievalFault("No group exists with group name ",groupId, e); + } + if (isRootVO(groupId)) + scope.append(org.getName()); + else if (isVO(groupId)){ + long rootVOId = getGroupParentId(groupId); + Organization rootVO = null; + try { + rootVO = OrganizationLocalServiceUtil.getOrganization(rootVOId); + } catch (PortalException e) { + throw new GroupRetrievalFault("No group exists with group name ",String.valueOf(rootVOId), e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving scope for group ", groupId , e); + } + scope.append(rootVO.getName()).append("/").append(org.getName()); + } + else if (isVRE(groupId)){ + long voId = getGroupParentId(groupId); + Organization vo = null; + try { + vo = OrganizationLocalServiceUtil.getOrganization(voId); + } catch (PortalException e) { + throw new GroupRetrievalFault("No group exists with group name ",String.valueOf(voId), e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving scope for group ", groupId , e); + } + long rootVOId = getGroupParentId(String.valueOf(voId)); + Organization rootVO = null; + try { + rootVO = OrganizationLocalServiceUtil.getOrganization(rootVOId); + } catch (PortalException e) { + throw new GroupRetrievalFault("No group exists with group name ",String.valueOf(rootVOId), e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving scope for group ", groupId , e); + } + scope.append(rootVO.getName()).append("/").append(vo.getName()).append("/").append(org.getName()); + } + + return scope.toString(); + + } + + public Boolean isRootVO(String groupId) throws UserManagementSystemException, GroupRetrievalFault{ + if(this.getLongId(groupId)!=0){ + if (getGroupParentId(groupId) == 0) + return true; + } + return false; + } + + public Boolean isVO(String groupId) throws UserManagementSystemException, GroupRetrievalFault{ + if(this.getLongId(groupId)!=0){ + long parentId = getGroupParentId(groupId); + if (isRootVO(String.valueOf(parentId))) + return true; + } + return false; + } + + public Boolean isVRE(String groupId) throws UserManagementSystemException, GroupRetrievalFault{ + long parentId = getGroupParentId(groupId); + if (isVO(String.valueOf(parentId))) + return true; + else + return false; + } + + /* + Already available in UserManager as listUsersByGroup! + + public List getGroupUsers(long groupId){ + List orgUsers = null; + try { + orgUsers = UserLocalServiceUtil.getOrganizationUsers(groupId); + } catch (SystemException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + List userModels = new ArrayList(); + for(User user : orgUsers){ + UserModel um = new UserModel(user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName()); + userModels.add(um); + } + return userModels; + } + */ + + public String getGroupId(String groupName) throws UserManagementSystemException, GroupRetrievalFault{ + List organizations = null; + long orgId = 0; + try { + organizations = OrganizationLocalServiceUtil.getOrganizations(0, OrganizationLocalServiceUtil.getOrganizationsCount()); + } catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving Id for group ", groupName , e); + } + for(Organization organization: organizations){ + if(organization.getName().equalsIgnoreCase(groupName)){ + orgId = organization.getOrganizationId(); + break; + } + } + if(orgId == 0){ + throw new GroupRetrievalFault("No group exists with group name ",groupName); + } + return String.valueOf(orgId); + } + + public GroupModel getGroup(String groupId) throws UserManagementSystemException, GroupRetrievalFault{ + Organization group = null; + GroupModel gm = null; + try { + group = OrganizationLocalServiceUtil.getOrganization(this.getLongId(groupId)); + if(group!=null){ + gm = new GroupModel(String.valueOf(group.getOrganizationId()),String.valueOf(group.getParentOrganizationId()),group.getName(),group.getComments(),group.getLogoId()); + }else{ + // throw new UserManagementException("No Group Found with Id " + groupId); + } + + } catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving group ", groupId , e); + } catch (PortalException e) { + throw new GroupRetrievalFault("No group exists with group name ",groupId, e); + } + return gm; + } + + public List listGroups() throws UserManagementSystemException { + List groups = null; + List orgModels = new ArrayList(); + try { + groups = OrganizationLocalServiceUtil.getOrganizations(0, OrganizationLocalServiceUtil.getOrganizationsCount()); + if(groups!=null){ + for(Organization group:groups){ + GroupModel gm = new GroupModel(String.valueOf(group.getOrganizationId()),String.valueOf(group.getParentOrganizationId()),group.getName(),group.getComments(),group.getLogoId()); + orgModels.add(gm); + } + }else{ + // throw new UserManagementException("No Groups found "); + } + + } catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving list of groups ", e); + } + return orgModels; + } + + public HashMap> listGroupsAndRolesByUser(String userId) throws UserManagementSystemException { + long userIdn = Long.parseLong(userId); + HashMap> hMap = new HashMap>(); + List groups = null; + List roles = null; + String roleName; + String completeRoleName; + LiferayRoleManager roleMan = new LiferayRoleManager(); + try { + groups = OrganizationLocalServiceUtil.getUserOrganizations(userIdn); + roles = RoleLocalServiceUtil.getUserRoles(userIdn); + } catch (Exception e) { + throw new UserManagementSystemException("Error listing groups and roles of user ", userId , e); + } + Iterator groupIter = groups.iterator(); + while(groupIter.hasNext()){ + Organization group = (Organization)groupIter.next(); + List userGroupRoles = new ArrayList(); + for(Role role : roles){ + if(role.getName().contains(group.getName())){ + completeRoleName = role.getName(); + roleName = roleMan.getRoleName(completeRoleName); + RoleModel rm = new RoleModel(roleName,String.valueOf(role.getRoleId()),role.getDescription()); + rm.setCompleteName(completeRoleName); + userGroupRoles.add(rm); + } + } + hMap.put(group.getName(), userGroupRoles); + } + return hMap; + } + + public List listGroupsByUser(String userId) throws UserManagementSystemException { + List groups = null; + List orgModels = new ArrayList(); + try { + groups = OrganizationLocalServiceUtil.getUserOrganizations(getLongId(userId)); + for(Organization group:groups){ + GroupModel gm = new GroupModel(String.valueOf(group.getOrganizationId()),String.valueOf(group.getParentOrganizationId()),group.getName(),group.getComments(),group.getLogoId()); + orgModels.add(gm); + } + }catch (Exception e) { + throw new UserManagementSystemException("Error retrieving groups of user ", userId , e); + } + return orgModels; + } + + public List listSubGroupsByGroup(String groupIdn) throws UserManagementSystemException, GroupRetrievalFault{ + long groupId = getLongId(groupIdn); + List org = new ArrayList(); + List subOrgs = null; + List subOrgModels = new ArrayList(); + try { + org.add(OrganizationLocalServiceUtil.getOrganization(groupId)); + subOrgs = OrganizationLocalServiceUtil.getSuborganizations(org); + } catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving sub groups of group ", groupIdn , e); + } catch (PortalException e) { + throw new GroupRetrievalFault("No group exists with group name ",groupIdn, e); + } + + if(subOrgs!=null){ + for(Organization suborg : subOrgs){ + GroupModel gm = new GroupModel(String.valueOf(suborg.getOrganizationId()),String.valueOf(suborg.getParentOrganizationId()),suborg.getName(),suborg.getComments(),suborg.getLogoId()); + subOrgModels.add(gm); + } + }else{ + // throw new UserManagementException("No SubGroups present for the group " + groupIdn); + } + + return subOrgModels; + } + + public void assignSubGrouptoParentGroup(String subGroupId, + String parentGroupId) throws UserManagementSystemException, GroupRetrievalFault{ + Organization subOrg = null; + try { + subOrg = OrganizationLocalServiceUtil.getOrganization(this.getLongId(subGroupId)); + } catch (SystemException e) { + throw new UserManagementSystemException("Error assigning subGroup to Parent group ", e); + } catch (PortalException e) { + throw new GroupRetrievalFault("No group exists with group Id ", subGroupId, e); + } + subOrg.setParentOrganizationId(this.getLongId(parentGroupId)); + this.updateOrganization(subOrg); + + } + + private GroupModel createGroup(String groupName, String parentGroupId , String userId, String description) throws UserManagementNameException, UserManagementSystemException, GroupRetrievalFault, UserManagementPortalException{ + /*Status Id is hard coded - ATTENTION*/ + ServiceContext serviceContext = new ServiceContext(); + Organization org = null; + GroupModel gm = null; + // Check for character, -, _, . which are valid characters for a group Name - requirement by Massi + Pattern p = Pattern.compile(REG_EX_MATCH); + Matcher m = p.matcher(groupName); + if(m.matches()){ + try { + org = OrganizationLocalServiceUtil.addOrganization(getLongId(userId), this.getLongId(parentGroupId), groupName, "regular-organization", true, 0L, 0L, 12017, description, serviceContext); + org.setCompanyId(getCompanyId()); + gm = new GroupModel(String.valueOf(org.getOrganizationId()),String.valueOf(org.getParentOrganizationId()),org.getName(),org.getComments(),org.getLogoId()); + } catch (SystemException e) { + throw new UserManagementSystemException("Error creating group ", groupName , e); + } catch (PortalException e) { + throw new GroupRetrievalFault("Check the groupName and the parent groupId ", groupName, e); + } + }else{ + throw new UserManagementNameException("Not a valid group Name. The valid characters are only A-Z a-z - _ ."); + } + return gm; + } + + public void deleteGroup(String groupName) throws UserManagementSystemException, GroupRetrievalFault{ + long organizationId = this.getLongId(groupName); + Organization organization; + try { + organization = OrganizationLocalServiceUtil.getOrganization(organizationId); + OrganizationLocalServiceUtil.deleteOrganization(organization); + }catch (SystemException e) { + throw new UserManagementSystemException("Error deleting group ", groupName , e); + } catch (PortalException e) { + throw new GroupRetrievalFault("No group exists with group name ",groupName, e); + } + + List roles; + try { + roles = RoleLocalServiceUtil.getRoles(0, RoleLocalServiceUtil.getRolesCount()); + for(Role role:roles){ + if(role.getName().contains(groupName)){ + RoleLocalServiceUtil.deleteRole(role); + } + } + } catch (SystemException e) { + throw new UserManagementSystemException("Error deleting group ", groupName , e); + } + + + } + + public void dismissSubGroupFromParentGroup(String subGroupId, + String parentGroupId) throws UserManagementSystemException, GroupRetrievalFault{ + long subOrgId = this.getLongId(subGroupId); + Organization org = null; + try { + org = OrganizationLocalServiceUtil.getOrganization(subOrgId); + } catch (SystemException e) { + throw new UserManagementSystemException("Error dismissing subGroup from Parent Group ", e); + } catch (PortalException e) { + throw new GroupRetrievalFault("No group exists with group Id ",subGroupId, e); + } + org.setParentOrganizationId(0); + this.updateOrganization(org); + } + + public GroupModel createRootVO(String rootVOName, String userId, String description) throws UserManagementNameException, UserManagementSystemException, GroupRetrievalFault, UserManagementPortalException { + return createGroup(rootVOName,"0",userId, description); + } + + public GroupModel createVO(String VOName, String rootVOGroupId , String userId, String description) throws UserManagementNameException, UserManagementSystemException, UserManagementPortalException, GroupRetrievalFault { + return createGroup(VOName,rootVOGroupId,userId,description); + } + + public GroupModel createVRE(String VREName, String VOGroupId, String userId, String description) throws UserManagementNameException, UserManagementSystemException, GroupRetrievalFault, UserManagementPortalException { + return createGroup(VREName,VOGroupId,userId,description); + } + + public GroupModel getRootVO() throws UserManagementSystemException, GroupRetrievalFault { + + List orgs = null; + GroupModel gm = null; + try { + orgs = OrganizationLocalServiceUtil.getOrganizations(0, OrganizationLocalServiceUtil.getOrganizationsCount()); + } catch (SystemException e) { + e.printStackTrace(); + } + for(Organization org : orgs){ + if(this.isRootVO(String.valueOf(org.getOrganizationId()))){ + gm = new GroupModel(String.valueOf(org.getOrganizationId()),String.valueOf(org.getParentOrganizationId()),org.getName(),org.getComments(),org.getLogoId()); + break; + } + } + return gm; + } + + public String getRootVOName() throws UserManagementSystemException, GroupRetrievalFault { + GroupModel gm = getRootVO(); + return gm.getGroupName(); + + } + + public List listPendingGroupsByUser(String userId) throws UserManagementSystemException { + List memberRequests = null; + List groupModels = new ArrayList(); + long userIdL = this.getLongId(userId); + try { + memberRequests = MembershipRequestLocalServiceUtil.getMembershipRequests(0, MembershipRequestLocalServiceUtil.getMembershipRequestsCount()); + for(MembershipRequest memberRequest: memberRequests){ + if(memberRequest.getUserId() == userIdL){ + long groupId = memberRequest.getGroupId(); + List orgs = OrganizationLocalServiceUtil.getOrganizations(0, OrganizationLocalServiceUtil.getOrganizationsCount()); + for(Organization org : orgs){ + if(org.getGroup().getGroupId()==groupId){ + GroupModel gm = new GroupModel(String.valueOf(org.getOrganizationId()),String.valueOf(org.getParentOrganizationId()),org.getName(),org.getComments(),org.getLogoId()); + groupModels.add(gm); + break; + } + } + } + } + }catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving pending groups for user ", userId , e); + } + return groupModels; + } + + public void updateGroup(GroupModel group) throws UserManagementSystemException, GroupRetrievalFault{ + Organization org = null; + try { + org = OrganizationLocalServiceUtil.getOrganization(Long.parseLong(group.getGroupId())); + }catch (SystemException e) { + throw new UserManagementSystemException("Error updating group ", group.getGroupName() , e); + } catch (PortalException e) { + throw new GroupRetrievalFault("No group exists with groupId ",group.getGroupId(), e); + } + this.updateOrganization(org); + } + + private void updateOrganization(Organization org) throws UserManagementSystemException{ + try { + OrganizationLocalServiceUtil.updateOrganization(org); + } catch (SystemException e) { + throw new UserManagementSystemException("Error updating group " , e); + } + } + + public long getGroupParentId(String groupId) throws UserManagementSystemException, GroupRetrievalFault{ + long groupIdL = this.getLongId(groupId); + Organization org = null; + long parentOrgId = 0; + try { + org = OrganizationLocalServiceUtil.getOrganization(groupIdL); + + } catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving parent Group Id for group ", groupId , e); + } catch (PortalException e) { + throw new GroupRetrievalFault("No group exists with groupId ",groupId, e); + } + parentOrgId = org.getParentOrganizationId(); + return parentOrgId; + } +} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/LiferayRoleManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/LiferayRoleManager.java new file mode 100644 index 0000000..8f3d2dd --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/LiferayRoleManager.java @@ -0,0 +1,788 @@ +package org.gcube.vomanagement.usermanagement.impl.liferay; + + + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Set; + +import org.gcube.vomanagement.usermanagement.GroupManager; +import org.gcube.vomanagement.usermanagement.RoleManager; +import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.RoleRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.UserManagementFileNotFoundException; +import org.gcube.vomanagement.usermanagement.exception.UserManagementIOException; +import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException; +import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; +import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; +import org.gcube.vomanagement.usermanagement.model.GroupModel; +import org.gcube.vomanagement.usermanagement.model.RoleModel; + +import com.liferay.portal.kernel.exception.PortalException; +import com.liferay.portal.kernel.exception.SystemException; +import com.liferay.portal.model.Organization; +import com.liferay.portal.model.Role; +import com.liferay.portal.model.UserModel; +import com.liferay.portal.service.OrganizationLocalServiceUtil; +import com.liferay.portal.service.RoleLocalServiceUtil; +import com.liferay.portal.service.UserLocalServiceUtil; + + +/** + * Liferay plugin for the RoleManager interface, this implementation interacts with Liferay through a LocalService. + * + * @author Giulio Galiero + * + */ +public class LiferayRoleManager implements RoleManager { + + private static final String ADMIN_ROLE = "Administrator"; + protected static final String PRODUCTION_SUPPORT = "Production-Support"; + public static final String VRE = "vre"; + public static final String VO = "vo"; + public static final String ROOT_VO = "root-vo"; + + /** + * @return true if the user is a portal administrator, false otherwise + */ + public boolean isAdmin(String userId) { + LiferayGroupManager gm = new LiferayGroupManager(); + try { + com.liferay.portal.model.User currUser = UserLocalServiceUtil.getUserByScreenName(gm.getCompanyId(), userId); + for (Role role : currUser.getRoles()) + if (role.getName().compareTo(ADMIN_ROLE) == 0 ) + return true; + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + long convertType(String stringId){ + return Long.parseLong(stringId); + } + + protected String getRoleName(String roleNameFull){ + List orgs; + String roleName = null; + try { + orgs = OrganizationLocalServiceUtil.getOrganizations(0, OrganizationLocalServiceUtil.getOrganizationsCount()); + for(Organization org : orgs){ + if(roleNameFull.contains(org.getName())){ + roleName = roleNameFull.substring(0, roleNameFull.indexOf(org.getName())-1); + break; + } + } + } catch (SystemException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return roleName; + } + + public HashMap listAllowedRoles (String groupName) throws UserManagementSystemException, GroupRetrievalFault, UserManagementFileNotFoundException, UserManagementIOException + { + GroupManager gm = new LiferayGroupManager(); + String groupId = gm.getGroupId(groupName); + HashMap hMap = new HashMap(); + // Code changed to remove hardcoded role names to external config file as requested by Leonordo and Manzi + /* List vreRoles = Arrays.asList("VRE-Manager", "VRE-User"); + List voRoles = Arrays.asList("VO-Admin", "VRE-Designer", "VRE-Manager", "Data-Manager"); + List rootVoRoles = Arrays.asList("Infrastructure-Manager", "Site-Manager");*/ + + if(gm.isRootVO(groupId)){ + hMap = ParseXML.getRoles(ROOT_VO); + }else if (gm.isVO(groupId)){ + hMap = ParseXML.getRoles(VO); + }else if (gm.isVRE(groupId)){ + hMap = ParseXML.getRoles(VRE); + } + return hMap; + } + + + + + + public String getRoleId(String roleName, String groupName) throws UserManagementSystemException{ + List roles = null; + String rolenameLR = null; + long roleId = 0; + try { + roles = RoleLocalServiceUtil.getRoles(0, RoleLocalServiceUtil.getRolesCount()); + } catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving roles ", e); + } + if(!roleName.equalsIgnoreCase(PRODUCTION_SUPPORT)){ + roleName = roleName + "-" + groupName; + } + + for(Role role: roles){ + rolenameLR = role.getName(); + if(rolenameLR.equalsIgnoreCase(roleName)){ + roleId = role.getRoleId(); + break; + } + } + return String.valueOf(roleId); + } + + public void assignRoleToUser(String groupIdn, String roleIdn, + String userIdn) throws UserManagementSystemException, GroupRetrievalFault, RoleRetrievalFault, UserRetrievalFault{ + long[] roleIds; + long roleId = this.convertType(roleIdn); + long userId = this.convertType(userIdn); + long groupId = this.convertType(groupIdn); + int i = 0; + String orgName = null; + Role role = null; + Organization org; + List roles; + try { + org = OrganizationLocalServiceUtil.getOrganization(groupId); + roles = RoleLocalServiceUtil.getUserRoles(userId); + }catch (PortalException e){ + throw new GroupRetrievalFault("No group exists with groupId ",groupIdn, e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error assigning role to user ", e); + } + + roleIds = new long[roles.size()+1]; + for(Role userRole : roles){ + roleIds[i++] = userRole.getRoleId(); + } + roleIds[i]= this.convertType(roleIdn); + orgName = org.getName(); + try { + role = RoleLocalServiceUtil.getRole(roleId); + } catch (PortalException e) { + throw new RoleRetrievalFault("No Role exists with roleId",roleIdn,e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error assigning role to user ", e); + } + String roleName = role.getName(); + if(!roleName.equalsIgnoreCase(PRODUCTION_SUPPORT)){ + if(roleName.contains(orgName)){ + try { + if(UserLocalServiceUtil.hasOrganizationUser(groupId, userId)){ + RoleLocalServiceUtil.setUserRoles(userId, roleIds); + } + } catch (SystemException e) { + throw new UserManagementSystemException("Error assigning role to user ", e); + } catch (PortalException e) { + throw new UserRetrievalFault("No User exists with userId ",userIdn,e); + } + } + }else{ + try { + RoleLocalServiceUtil.setUserRoles(userId, roleIds); + } catch (PortalException e) { + throw new UserRetrievalFault("Error assigning role to user with userId ",userIdn,e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error assigning role to user ", e); + } + } + + } + + private RoleModel createRoleUtil(String roleName,String roleDesc) throws UserManagementSystemException, RoleRetrievalFault, UserManagementPortalException { + Role role = null; + RoleModel rm = null; + LiferayGroupManager gm = new LiferayGroupManager(); + //List allowedRoles = getAllowedRoles(groupName); + boolean roleExists = false; + + long companyId = gm.getCompanyId(); + + //roleName = roleName + "-" + groupName; + List roles; + try { + roles = RoleLocalServiceUtil.getRoles(0, RoleLocalServiceUtil.getRolesCount()); + } catch (SystemException e) { + throw new UserManagementSystemException("Error creating role ", e); + } + for(Role existingRole : roles){ + if(existingRole.getName().equals(roleName)){ + roleExists = true; + break; + } + } + if(!roleExists){ + try { + Locale english = new Locale("en"); + HashMap roleNames = new HashMap(); + roleNames.put(english, roleName); + role = RoleLocalServiceUtil.addRole(0L, companyId, roleName, roleNames, roleDesc, 1); + } catch (PortalException e) { + throw new RoleRetrievalFault("Cannot create new role, check the roleName already exists",roleName,e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error creating role ", e); + } + if(!roleName.equalsIgnoreCase(PRODUCTION_SUPPORT)){ + roleName = roleName.substring(0, roleName.lastIndexOf("-")); + } + + rm = new RoleModel(roleName,String.valueOf(role.getRoleId()),role.getDescription()); + }else{ + throw new RoleRetrievalFault("Cannot create new role, check the roleName already exists",roleName); + } + return rm; + } + + public boolean createRole(String roleName,String roleDescription, String groupName) throws UserManagementSystemException, GroupRetrievalFault, RoleRetrievalFault, UserManagementPortalException { + List roleModels = new ArrayList(); + //String roleDesc = validateRoleName(roleName, groupId); + if(!roleName.equalsIgnoreCase(PRODUCTION_SUPPORT)){ + roleName = roleName +"-"+groupName; + } + + roleModels.add(this.createRoleUtil(roleName, roleDescription)); + return true; + } + + public void createRole(String groupName) throws UserManagementSystemException, GroupRetrievalFault, RoleRetrievalFault, UserManagementPortalException, UserManagementFileNotFoundException, UserManagementIOException{ + GroupManager gm = new LiferayGroupManager(); + Organization org; + HashMap allowedRolesConfig; + try { + String groupId = gm.getGroupId(groupName); + allowedRolesConfig = listAllowedRoles(groupName); + org = OrganizationLocalServiceUtil.getOrganization(this.convertType(groupId)); + }catch (SystemException e) { + throw new UserManagementSystemException("Error creating roles for group ", groupName , e); + } catch (PortalException e) { + throw new GroupRetrievalFault("No group exists with group Name ", groupName, e); + } + String orgName = org.getName(); + Set allowedRoles = allowedRolesConfig.keySet(); + Collection allowedRolesDesc = allowedRolesConfig.values(); + Iterator rolesDescIter = allowedRolesDesc.iterator(); + + for(String allowedRole : allowedRoles){ + if(!allowedRole.equalsIgnoreCase(PRODUCTION_SUPPORT)){ + allowedRole = allowedRole+ "-"+ orgName; + } + this.createRoleUtil(allowedRole, rolesDescIter.next()); + } + } + + + + public void deleteRole(String roleName, String groupName)throws UserManagementSystemException, RoleRetrievalFault{ + try { + String roleId = this.getRoleId(roleName, groupName); + RoleLocalServiceUtil.deleteRole(this.convertType(roleId)); + } catch (SystemException e) { + throw new UserManagementSystemException("Error deleting role ", roleName , e); + } catch (PortalException e) { + throw new RoleRetrievalFault("No role exists with role name ", roleName, e); + } + } + + public void dismissRoleFromUser(String groupIdn, String roleIdn, + String userIdn) throws UserManagementSystemException, RoleRetrievalFault, GroupRetrievalFault, UserRetrievalFault{ + //boolean isMember = false; + long roleId = this.convertType(roleIdn); + long[] roleIds = {roleId}; + long userId = this.convertType(userIdn); + long groupId = this.convertType(groupIdn); + String orgName; + Role role; + try { + role = RoleLocalServiceUtil.getRole(roleId); + }catch (PortalException e) { + throw new RoleRetrievalFault("No role exists with roleId ", roleIdn, e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error dismissing roles from userc", userIdn, e); + } + Organization org; + try { + org = OrganizationLocalServiceUtil.getOrganization(groupId); + } catch (PortalException e) { + throw new GroupRetrievalFault("No group exists with group Name ", groupIdn, e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error dismissing roles from userc", userIdn, e); + } + orgName = org.getName(); + if(!role.getName().equalsIgnoreCase(PRODUCTION_SUPPORT)){ + if(role.getName().contains(orgName)){ + try { + if(UserLocalServiceUtil.hasRoleUser(roleId, userId)){ + RoleLocalServiceUtil.unsetUserRoles(userId, roleIds); + } + } catch (SystemException e) { + throw new UserManagementSystemException("Error dismissing roles from user ", userIdn, e); + } catch (PortalException e) { + throw new UserRetrievalFault("No User exists with userId ",userIdn,e); + } + } + }else{ + try { + if(UserLocalServiceUtil.hasRoleUser(roleId, userId)){ + RoleLocalServiceUtil.unsetUserRoles(userId, roleIds); + } + }catch (SystemException e) { + throw new UserManagementSystemException("Error dismissing roles from user ", userIdn, e); + } catch (PortalException e) { + throw new UserRetrievalFault("No User exists with userId ",userIdn,e); + } + } + + //remove user from VO if no roles relevant to the VO are present + // removed as requested by massi as this removes the Organization-member role for the user + /* List userRoles = RoleLocalServiceUtil.getUserRoles(userId); + for(Role userRole : userRoles){ + if(userRole.getName().contains(orgName)){ + isMember = true; + break; + } + }*/ + // if the user does nt have other roles in the group, remove the user from the group + /* if(!isMember){ + long[] userIds = {userId}; + UserLocalServiceUtil.unsetOrganizationUsers(groupId, userIds); + }*/ + + } + + public RoleModel getRole(String roleId) throws UserManagementSystemException, RoleRetrievalFault{ + Role role = null; + RoleModel rm = null; + String roleName; + String completeRoleName; + try { + role = RoleLocalServiceUtil.getRole(this.convertType(roleId)); + } catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving role ", roleId , e); + } catch (PortalException e) { + throw new RoleRetrievalFault("No role exists with roleId ", roleId, e); + } + completeRoleName = role.getName(); + roleName = getRoleName(completeRoleName); + rm = new RoleModel(roleName,String.valueOf(role.getRoleId()),role.getDescription()); + rm.setCompleteName(completeRoleName); + + return rm; + } + + @Deprecated + public List listRoles() throws UserManagementSystemException { + List roles = null; + String roleName; + List roleNames = new ArrayList(); + try { + roles = RoleLocalServiceUtil.getRoles(0, RoleLocalServiceUtil.getRolesCount()); + for(Role role:roles){ + roleName = role.getName(); + if(roleName.contains("-")){ + roleName = getRoleName(roleName); + if(!roleNames.contains(roleName)){ + roleNames.add(roleName); + } + } + } + } catch (SystemException e) { + throw new UserManagementSystemException("Error listing roles ", e); + } + return roleNames; + } + + public List listAllRoles() throws UserManagementSystemException { + List roles = null; + String roleName; + String completeRoleName; + List roleModels = new ArrayList(); + try { + roles = RoleLocalServiceUtil.getRoles(0, RoleLocalServiceUtil.getRolesCount()); + for(Role role:roles){ + completeRoleName = role.getName(); + if(!completeRoleName.equalsIgnoreCase(PRODUCTION_SUPPORT)){ + roleName = getRoleName(completeRoleName); + } + else roleName = completeRoleName; + + RoleModel rm = new RoleModel(roleName,String.valueOf(role.getRoleId()),role.getDescription()); + rm.setCompleteName(completeRoleName); + roleModels.add(rm); + } + } catch (SystemException e) { + throw new UserManagementSystemException("Error listing roles ", e); + } + return roleModels; + } + + public List listRolesByUser(String userId) throws UserManagementSystemException { + List roles = null; + List roleModels = new ArrayList(); + String roleName; + String completeRoleName; + try { + roles = RoleLocalServiceUtil.getUserRoles(this.convertType(userId)); + for(Role role:roles){ + completeRoleName = role.getName(); + if(!completeRoleName.equalsIgnoreCase(PRODUCTION_SUPPORT)){ + roleName = getRoleName(completeRoleName); + } + else roleName = completeRoleName; + + RoleModel rm = new RoleModel(roleName,String.valueOf(role.getRoleId()),role.getDescription()); + rm.setCompleteName(completeRoleName); + roleModels.add(rm); + + } + } catch (SystemException e) { + throw new UserManagementSystemException("Error listing roles for user ",userId, e); + } + return roleModels; + } + + public List listRolesByUserAndGroup(String groupId, String userId) throws UserManagementSystemException, GroupRetrievalFault{ + List userRoles = new ArrayList(); + List userRoleModels = new ArrayList(); + List roles = null; + String roleName; + String completeRoleName; + String orgName; + Organization org = null; + try { + roles = RoleLocalServiceUtil.getUserRoles(this.convertType(userId)); + }catch (SystemException e) { + throw new UserManagementSystemException("Error listing roles by user and group ", e); + } + + try { + org = OrganizationLocalServiceUtil.getOrganization(this.convertType(groupId)); + } catch (PortalException e) { + throw new GroupRetrievalFault("No group exists with group Id ", groupId, e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error listing roles by user and group ", e); + } + orgName = org.getName(); + for(Role role : roles){ + if(role.getName().contains(orgName)){ + userRoles.add(role); + completeRoleName = role.getName(); + roleName = getRoleName(completeRoleName); + RoleModel rm = new RoleModel(roleName,String.valueOf(role.getRoleId()),role.getDescription()); + rm.setCompleteName(completeRoleName); + userRoleModels.add(rm); + + } + } + + return userRoleModels; + } + + public List listRolesByGroup(String groupId) throws UserManagementSystemException, GroupRetrievalFault, UserManagementFileNotFoundException, UserManagementIOException{ + + List groupRoles = new ArrayList(); + List groupRoleModels = new ArrayList(); + GroupManager gm = new LiferayGroupManager(); + List roles = null; + String orgName; + String roleName; + String completeRoleName; + String groupType = null; + try { + roles = RoleLocalServiceUtil.getRoles(0, RoleLocalServiceUtil.getRolesCount()); + + } catch (SystemException e) { + + throw new UserManagementSystemException("Error listing roles for group ", groupId , e); + } + Organization org; + try { + org = OrganizationLocalServiceUtil.getOrganization(this.convertType(groupId)); + + } catch (PortalException e) { + throw new GroupRetrievalFault("No group exists with group Id ", groupId, e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error listing roles for group ", groupId , e); + } + orgName = org.getName(); + if(gm.isRootVO(groupId)){ + groupType = ROOT_VO; + }else if(gm.isVO(groupId)){ + groupType = VO; + }else if(gm.isVRE(groupId)){ + groupType = VRE; + } + for(Role role : roles){ + if(role.getName().endsWith(orgName)){ + groupRoles.add(role); + completeRoleName = role.getName(); + roleName = getRoleName(completeRoleName); + if(ParseXML.getRoles(groupType).containsKey(roleName)){ + String roleDesc; + if(role.getDescription()==""){ + roleDesc = ParseXML.getRoles(groupType).get(roleName); + role.setDescription(roleDesc); + try { + RoleLocalServiceUtil.updateRole(role); + }catch (SystemException e) { + e.printStackTrace(); + throw new UserManagementSystemException("Error updating role ",role.getName(), e); + } + }else{ + roleDesc = role.getDescription(); + } + RoleModel rm = new RoleModel(roleName,String.valueOf(role.getRoleId()),roleDesc); + rm.setCompleteName(completeRoleName); + groupRoleModels.add(rm); + }else{ + + RoleModel rm = new RoleModel(roleName,String.valueOf(role.getRoleId()),role.getDescription()); + groupRoleModels.add(rm); + } + + + } + } + Role role = this.getCommonRole(); + if(role!=null){ + String roleDesc; + try { + if(role.getDescription()==""){ + roleDesc = ParseXML.getRoles(VO).get(role.getName()); + role.setDescription(roleDesc); + RoleLocalServiceUtil.updateRole(role); + }else{ + roleDesc = role.getDescription(); + } + + } catch (SystemException e) { + throw new UserManagementSystemException("Error updating role Production-Support", e); + } + groupRoleModels.add(new RoleModel(role.getName(),String.valueOf(role.getRoleId()),roleDesc)); + } + + return groupRoleModels; + } + + protected Role getCommonRole() throws UserManagementSystemException{ + List roles; + try { + roles = RoleLocalServiceUtil.getRoles(0, RoleLocalServiceUtil.getRolesCount()); + } catch (SystemException e) { + throw new UserManagementSystemException("Error listing roles ", e); + } + + for(Role role : roles){ + if(role.getName().equalsIgnoreCase(PRODUCTION_SUPPORT)){ + return role; + } + } + return null; + } + + private List getGroupsByType(String groupType) throws UserManagementSystemException, GroupRetrievalFault{ + LiferayGroupManager gm = new LiferayGroupManager(); + List groups = gm.listGroups(); + List groupsByType = new ArrayList(); + + if(groupType.equals(VO)){ + for(GroupModel group:groups){ + if(gm.isVO(group.getGroupId())){ + groupsByType.add(group); + } + } + }else if(groupType.equals(VRE)){ + for(GroupModel group:groups){ + if(gm.isVRE(group.getGroupId())){ + groupsByType.add(group); + } + } + }else if(groupType.equals(ROOT_VO)){ + for(GroupModel group:groups){ + if(gm.isRootVO(group.getGroupId())){ + groupsByType.add(group); + } + } + + } + return groupsByType; + } + + + + public void updateRole(String initialRoleName, String newRoleName, String roleDescription, String groupName) throws UserManagementSystemException, RoleRetrievalFault, NumberFormatException, UserManagementFileNotFoundException, UserManagementIOException, GroupRetrievalFault, UserManagementPortalException { + + Role role = null; + boolean isSystemRole = false; + String roleId; + String[] groupTypes = {VO,VRE,ROOT_VO}; + if(!initialRoleName.equalsIgnoreCase(PRODUCTION_SUPPORT)){ + roleId = this.getRoleId(initialRoleName, groupName); + }else{ + roleId = String.valueOf(this.getCommonRole().getRoleId()); + for(String groupType : groupTypes){ + HashMap hMap = ParseXML.getRoles(groupType); + hMap.put(initialRoleName, roleDescription); + ParseXML.updateRoles(hMap, groupType); + } + Role prod_supp_role; + try { + prod_supp_role = RoleLocalServiceUtil.getRole(Long.parseLong(roleId)); + prod_supp_role.setDescription(roleDescription); + RoleLocalServiceUtil.updateRole(prod_supp_role); + } catch (PortalException e1) { + throw new UserManagementPortalException("Error retrieving role ", initialRoleName , e1); + } catch (SystemException e1) { + throw new UserManagementSystemException("Error updating role ", initialRoleName , e1); + } + + + return; + + } + + try { + role = RoleLocalServiceUtil.getRole(Long.parseLong(roleId)); + } catch (PortalException e2) { + throw new UserManagementPortalException("Error retrieving role ", initialRoleName , e2); + } catch (SystemException e2) { + throw new UserManagementSystemException("Error updating role ", initialRoleName , e2); + } + + + if(ParseXML.getRoles(VO).containsKey(initialRoleName)){ + isSystemRole = true; + // update the predefined config file + HashMap hMap = ParseXML.getRoles(VO); + if(hMap.containsKey(initialRoleName)){ + hMap.put(initialRoleName, roleDescription); + + ParseXML.updateRoles(hMap, VO); + // update the actual roles + List voGroups = this.getGroupsByType(VO); + + for(GroupModel group:voGroups){ + List rm = this.listRolesByGroup(group.getGroupId()); + for(RoleModel roleModel : rm){ + if(roleModel.getRoleName().equals(initialRoleName)){ + String voroleId = this.getRoleId(initialRoleName, group.getGroupName()); + Role affectedRole; + try { + try { + affectedRole = RoleLocalServiceUtil.getRole(Long.parseLong(voroleId)); + } catch (SystemException e) { + throw new UserManagementSystemException("Error updating role ", initialRoleName , e); + } + } catch (PortalException e) { + throw new RoleRetrievalFault("Error retrieving role with name ", initialRoleName, e); + } + affectedRole.setDescription(roleDescription); + try { + RoleLocalServiceUtil.updateRole(affectedRole); + } catch (SystemException e) { + throw new UserManagementSystemException("Error updating role ", initialRoleName , e); + //break; + } + } + } + } + } + } if(ParseXML.getRoles(VRE).containsKey(initialRoleName)){ + isSystemRole = true; + HashMap hMap = ParseXML.getRoles(VRE); + if(hMap.containsKey(initialRoleName)){ + hMap.put(initialRoleName, roleDescription); + ParseXML.updateRoles(hMap, VRE); + + List vreGroups = this.getGroupsByType(VRE); + + for(GroupModel group:vreGroups){ + List rm = this.listRolesByGroup(group.getGroupId()); + for(RoleModel roleModel : rm){ + if(roleModel.getRoleName().equals(initialRoleName)){ + if(this.listRolesByGroup(group.getGroupId()).contains(initialRoleName)){ + String vreroleId = this.getRoleId(initialRoleName, group.getGroupName()); + Role affectedRole; + try { + try { + affectedRole = RoleLocalServiceUtil.getRole(Long.parseLong(vreroleId)); + } catch (SystemException e) { + throw new UserManagementSystemException("Error updating role ", initialRoleName , e); + } + } catch (PortalException e) { + throw new RoleRetrievalFault("Error retrieving role with name ", initialRoleName, e); + } + affectedRole.setDescription(roleDescription); + try { + RoleLocalServiceUtil.updateRole(affectedRole); + } catch (SystemException e) { + throw new UserManagementSystemException("Error updating role ", initialRoleName , e); + } + } + } + } + } + } + } if(ParseXML.getRoles(ROOT_VO).containsKey(initialRoleName)){ + isSystemRole = true; + HashMap hMap = ParseXML.getRoles(ROOT_VO); + if(hMap.containsKey(initialRoleName)){ + ParseXML.updateRoles(hMap, ROOT_VO); + + List rootvoGroups = this.getGroupsByType(ROOT_VO); + for(GroupModel group:rootvoGroups){ + List rm = this.listRolesByGroup(group.getGroupId()); + for(RoleModel roleModel : rm){ + if(roleModel.getRoleName().equals(initialRoleName)){ + String rootVoroleId = this.getRoleId(initialRoleName, group.getGroupName()); + Role affectedRole; + try { + try { + affectedRole = RoleLocalServiceUtil.getRole(Long.parseLong(rootVoroleId)); + } catch (SystemException e) { + throw new UserManagementSystemException("Error updating role ", initialRoleName , e); + } + } catch (PortalException e) { + throw new RoleRetrievalFault("Error retrieving role with name ", initialRoleName, e); + } + affectedRole.setDescription(roleDescription); + try { + RoleLocalServiceUtil.updateRole(affectedRole); + } catch (SystemException e) { + throw new UserManagementSystemException("Error updating role ", initialRoleName , e); + } + } + } + } + } + }if(!isSystemRole){ + role.setDescription(roleDescription); + newRoleName = newRoleName + "-" + groupName; + role.setName(newRoleName); + try { + RoleLocalServiceUtil.updateRole(role); + } catch (SystemException e) { + throw new UserManagementSystemException("Error updating role ", initialRoleName , e); + } + } + + /* role.setName(roleModel.getRoleName()); + role.setDescription(roleModel.getDescription());*/ + + + } + + + + public void updatePredefinedRoles(HashMap rolesMap, String groupType) + throws UserManagementIOException, UserManagementFileNotFoundException { + if(groupType.equals(VRE)){ + ParseXML.updateRoles(rolesMap, VRE); + }else if (groupType.equals(VO)){ + ParseXML.updateRoles(rolesMap, VO); + }else if(groupType.equals(ROOT_VO)){ + ParseXML.updateRoles(rolesMap, ROOT_VO); + } + + } + +} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/LiferayUserManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/LiferayUserManager.java new file mode 100644 index 0000000..4f2407d --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/LiferayUserManager.java @@ -0,0 +1,969 @@ +package org.gcube.vomanagement.usermanagement.impl.liferay; + +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; + +import org.gcube.vomanagement.usermanagement.GroupManager; +import org.gcube.vomanagement.usermanagement.UserManager; +import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.RoleRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException; +import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; +import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; +import org.gcube.vomanagement.usermanagement.impl.liferay.utils.ExpandoClassCodeManager; +import org.gcube.vomanagement.usermanagement.impl.liferay.utils.ExpandoDefaultTableManager; +import org.gcube.vomanagement.usermanagement.model.GroupModel; +import org.gcube.vomanagement.usermanagement.model.RoleModel; +import org.gcube.vomanagement.usermanagement.model.UserModel; + + +import com.liferay.portal.kernel.exception.PortalException; +import com.liferay.portal.kernel.exception.SystemException; +import com.liferay.portal.model.MembershipRequest; +import com.liferay.portal.model.Organization; +import com.liferay.portal.model.Role; +import com.liferay.portal.model.User; +import com.liferay.portal.service.MembershipRequestLocalServiceUtil; +import com.liferay.portal.service.OrganizationLocalServiceUtil; +import com.liferay.portal.service.RoleLocalServiceUtil; +import com.liferay.portal.service.ServiceContext; +import com.liferay.portal.service.UserLocalServiceUtil; +import com.liferay.portlet.expando.model.ExpandoColumn; +import com.liferay.portlet.expando.model.ExpandoTable; +import com.liferay.portlet.expando.model.ExpandoValue; +import com.liferay.portlet.expando.service.ExpandoColumnLocalServiceUtil; +import com.liferay.portlet.expando.service.ExpandoValueLocalServiceUtil; + +/** + * Liferay plugin for the UserManager interface, this implementation interacts with Liferay through a LocalService. + * + * @author Giulio Galiero + * + */ + + +public class LiferayUserManager implements UserManager { + + private final String DEFAULT_STRING = "_"; + + private long convertStringToLong(String id){ + return Long.parseLong(id); + } + + + public List getAllUsers () throws UserManagementSystemException, UserRetrievalFault + { + List users = null; + List response = new ArrayList(); + + try { + users = UserLocalServiceUtil.getUsers(0, UserLocalServiceUtil.getUsersCount()); + } catch (SystemException e) { + throw new UserManagementSystemException("Error getting the user list",e); + } + for(User user: users) + { + + response.add(new UserModel(String.valueOf(user.getUserId()),user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName(), user.getCreateDate().getTime() ,this.getUserCustomAttributes(String.valueOf(user.getUserId())))); + + } + + return response; + } + + public String getUserId(String userName) throws UserManagementSystemException{ + List users = null; + long userId = 0; + try { + users = UserLocalServiceUtil.getUsers(0, UserLocalServiceUtil.getUsersCount()); + } catch (SystemException e) { + throw new UserManagementSystemException("Error getting the User Id of user ",userName, e); + } + for(User user: users){ + if(user.getScreenName().equalsIgnoreCase(userName)){ + userId = user.getUserId(); + break; + } + } + return String.valueOf(userId); + } + + public void assignUserToGroup(String groupIdn, String userIdn) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault, UserManagementPortalException { + long userId = this.convertStringToLong(userIdn); + List memberRequests = null; + long groupId = this.convertStringToLong(groupIdn); + long[] userIds = {userId}; + GroupManager groupManager = new LiferayGroupManager(); + Organization org = null; + + // Add the user to Parent Organization if they are not already added + try { + org = OrganizationLocalServiceUtil.getOrganization(groupId); + } catch (SystemException e) { + throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); + } catch (PortalException e) { + throw new GroupRetrievalFault("No group exists with groupId ",groupIdn, e); + } + User user = null; + List orgs = null; + try { + user = UserLocalServiceUtil.getUser(userId); + orgs = user.getOrganizations(); + } catch (PortalException e) { + throw new UserRetrievalFault("No user exists with userId ",userIdn, e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); + } + + if(groupManager.isRootVO(groupIdn)){ + //RootVO + try { + UserLocalServiceUtil.addOrganizationUsers(groupId, userIds); + } catch (SystemException e) { + throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); + } catch (PortalException e) { + throw new UserManagementPortalException("Check if user already exists in group ", groupIdn , e); + } + + }else if (groupManager.isVO(groupIdn)){ + //VO + try { + UserLocalServiceUtil.addOrganizationUsers(groupId, userIds); + } catch (PortalException e) { + throw new UserManagementPortalException("Check if user already exists in group ", groupIdn , e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); + } + long parentOrgId = org.getParentOrganizationId(); + Organization parentOrg = null; + try { + parentOrg = OrganizationLocalServiceUtil.getOrganization(parentOrgId); + } catch (PortalException e) { + throw new GroupRetrievalFault("No group exists with groupId ",String.valueOf(parentOrgId), e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); + } + if(!orgs.contains(parentOrg)){ + try { + UserLocalServiceUtil.addOrganizationUsers(parentOrgId, userIds); + } catch (PortalException e) { + throw new UserManagementPortalException("Check if user already exists in group ", String.valueOf(parentOrgId) , e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); + } + } + + }else if (groupManager.isVRE(groupIdn)){ + //VRE + try { + UserLocalServiceUtil.addOrganizationUsers(groupId, userIds); + } catch (PortalException e) { + throw new UserManagementPortalException("Check if user already exists in group ", String.valueOf(groupId) , e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); + } + long parentOrgId = org.getParentOrganizationId(); + Organization parentOrg = null; + try { + parentOrg = OrganizationLocalServiceUtil.getOrganization(parentOrgId); + } catch (PortalException e) { + throw new GroupRetrievalFault("No group exists with groupId ",String.valueOf(parentOrgId), e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); + } + if(!orgs.contains(parentOrg)){ + try { + UserLocalServiceUtil.addOrganizationUsers(parentOrgId, userIds); + } catch (PortalException e) { + throw new GroupRetrievalFault("Check if user already exists in group ",String.valueOf(parentOrgId), e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); + } + } + + try { + parentOrgId = org.getParentOrganization().getParentOrganizationId(); + } catch (PortalException e) { + throw new GroupRetrievalFault("No group exists with groupId ",String.valueOf(parentOrgId), e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); + } + try { + parentOrg = OrganizationLocalServiceUtil.getOrganization(parentOrgId); + } catch (PortalException e) { + throw new GroupRetrievalFault("No group exists with groupId ",String.valueOf(parentOrgId), e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); + } + if(!orgs.contains(parentOrg)){ + try { + UserLocalServiceUtil.addOrganizationUsers(parentOrgId, userIds); + } catch (PortalException e) { + throw new GroupRetrievalFault("Check if user already exists in group ",String.valueOf(parentOrgId), e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error assigning user to Group ", groupIdn , e); + } + } + + + } + //delete the corresponding member request from the MembershipRequest table + try { + memberRequests = MembershipRequestLocalServiceUtil.getMembershipRequests(0, MembershipRequestLocalServiceUtil.getMembershipRequestsCount()); + } catch (SystemException e) { + throw new UserManagementSystemException("Error getting membership request ", e); + } + for(MembershipRequest memberRequest: memberRequests){ + if(memberRequest.getUserId()==userId && memberRequest.getGroupId()==org.getGroup().getGroupId()){ + try { + MembershipRequestLocalServiceUtil.deleteMembershipRequest(memberRequest); + } catch (SystemException e) { + throw new UserManagementSystemException("Error deleting membership request ", String.valueOf(memberRequest.getMembershipRequestId()) , e); + } + } + } + + + } + + public void requestMembership(String userIdn, String groupIdn,String comment) throws UserManagementSystemException, GroupRetrievalFault{ + long userId = this.convertStringToLong(userIdn); + long organizationId = this.convertStringToLong(groupIdn); + Organization org = null; + try { + org = OrganizationLocalServiceUtil.getOrganization(organizationId); + } catch (SystemException e) { + throw new UserManagementSystemException("Error adding membership request to group ", groupIdn , e); + } catch (PortalException e) { + throw new GroupRetrievalFault("No group exists with groupId ",groupIdn, e); + } + try { + if (!checkString(comment)) comment = DEFAULT_STRING; + MembershipRequest mr = MembershipRequestLocalServiceUtil.addMembershipRequest(userId, org.getGroup().getGroupId(), comment); + } catch (PortalException e) { + throw new GroupRetrievalFault("error adding membership request for user id ",userIdn, e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error adding membership request to group ", groupIdn , e); + } + + } + + /** + * + * If the string is null, empty or a digit returns false + * + * @param string + * @return false if the string is empty, null or a digit, true otherwise + */ + private boolean checkString (String string) + { + boolean response = true; + + try + { + Double.parseDouble(string); + response = false; + + } catch (NullPointerException e) + { + response = false; + } catch (NumberFormatException e) + { + if (string.trim().length() ==0) return false; + } + + return response; + } + + + public List getMembershipRequests(String groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault{ + List memberRequests = null; + List users = new ArrayList(); + Organization org = null; + UserModel um = null; + try { + memberRequests = MembershipRequestLocalServiceUtil.getMembershipRequests(0, MembershipRequestLocalServiceUtil.getMembershipRequestsCount()); + } catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving Membership requests of group ",groupId, e); + } + try { + org = OrganizationLocalServiceUtil.getOrganization(convertStringToLong(groupId)); + } catch (PortalException e) { + throw new GroupRetrievalFault("error retrieving group for group Id ",groupId, e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving Membership requests of group ",groupId, e); + } + for(MembershipRequest memberRequest: memberRequests){ + if(memberRequest.getGroupId() == org.getGroup().getGroupId()){ + long userId = memberRequest.getUserId(); + User user = null; + try { + user = UserLocalServiceUtil.getUser(userId); + } catch (PortalException e) { + throw new UserRetrievalFault("Error retrieving user for user Id ",String.valueOf(userId),e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving Membership requests of group ",groupId, e); + } + um = new UserModel(String.valueOf(user.getUserId()),user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName(),user.getCreateDate().getTime(),this.getUserCustomAttributes(String.valueOf(user.getUserId()))); + users.add(um); + break; + } + } + + return users; + + } + + + public void createUser(UserModel userModel) throws UserManagementSystemException, UserRetrievalFault { + String password1 = null; + Locale locale = new Locale("en_US"); + ServiceContext serviceContext = new ServiceContext(); + String password2 = null; + try { + UserLocalServiceUtil.addUser(0L, 1L, true, password1,password2, false, userModel.getScreenName(),userModel.getEmail(), 0L,"", + locale, userModel.getFirstname(), "mn", userModel.getLastname(), 0, 0, true, 1, 1, 1940, "", null, null, null, null, true, serviceContext); + }catch (SystemException e) { + throw new UserManagementSystemException("Error creating user ",userModel.getScreenName(), e); + } catch (PortalException e) { + throw new UserRetrievalFault("Error adding user with screen name ",userModel.getScreenName(),e); + } + } + + public void deleteUser(String userId)throws UserManagementSystemException, UserRetrievalFault { + try { + UserLocalServiceUtil.deleteUser(this.convertStringToLong(userId)); + }catch (SystemException e) { + throw new UserManagementSystemException("Error deleting user ",userId, e); + } catch (PortalException e) { + throw new UserRetrievalFault("Error deleting user with user Id ",userId,e); + } + + } + + + public void dismissUserFromGroup(String groupId, String userId) throws UserManagementSystemException, NumberFormatException, GroupRetrievalFault, UserRetrievalFault { + long[] userIds = {this.convertStringToLong(userId)}; + GroupManager groupManager = new LiferayGroupManager(); + long groupIdL = this.convertStringToLong(groupId); + List dismissedGroups = new ArrayList(); + List userOrgs = null; + try{ + + userOrgs = OrganizationLocalServiceUtil.getUserOrganizations(this.convertStringToLong(userId)); + } catch (SystemException e) { + throw new UserManagementSystemException("Error dismissing user from group ",groupId, e); + } catch (PortalException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // Remove the user from sub organizations + if(groupManager.isRootVO(groupId)){ + //RootVO + // Remove the user from all groups + for(Organization userOrg : userOrgs){ + try { + UserLocalServiceUtil.unsetOrganizationUsers(userOrg.getOrganizationId(), userIds); + } catch (PortalException e) { + throw new UserRetrievalFault("Check the validity userId /Group Id ",e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error dismissing user from group ",groupId, e); + } + dismissedGroups.add(userOrg); + } + + }else if (groupManager.isVO(groupId)){ + //VO + //Remove user from VREs under the VO + //Remove user from VO + try { + UserLocalServiceUtil.unsetOrganizationUsers(groupIdL, userIds); + } catch (PortalException e) { + throw new UserRetrievalFault("Check the validity of userId /Group Id ",e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error dismissing user from group ",groupId, e); + } + try { + dismissedGroups.add(OrganizationLocalServiceUtil.getOrganization(groupIdL)); + } catch (PortalException e) { + throw new GroupRetrievalFault("Error retrieving group with group Id ",String.valueOf(groupIdL), e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error dismissing user from group ",groupId, e); + } + //Remove user from subgroups + List VREGroups = groupManager.listSubGroupsByGroup(groupId); + for(GroupModel VREGroup : VREGroups){ + try { + UserLocalServiceUtil.unsetOrganizationUsers(Long.parseLong(VREGroup.getGroupId()), userIds); + } catch (PortalException e) { + throw new UserRetrievalFault("Check the validity of userId /Group Id ",e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error dismissing user from group ",groupId, e); + } + try { + dismissedGroups.add(OrganizationLocalServiceUtil.getOrganization(Long.parseLong(VREGroup.getGroupId()))); + } catch (PortalException e) { + throw new GroupRetrievalFault("Error retrieving group with group Id ",VREGroup.getGroupId(), e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error dismissing user from group ",groupId, e); + } + } + }else if(groupManager.isVRE(groupId)){ + //VRE + //Remove user from the VRE + try { + UserLocalServiceUtil.unsetOrganizationUsers(groupIdL, userIds); + } catch (PortalException e) { + throw new UserRetrievalFault("Check the validity of userId /Group Id ",e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error dismissing user from group ",groupId, e); + } + try { + dismissedGroups.add(OrganizationLocalServiceUtil.getOrganization(groupIdL)); + } catch (PortalException e) { + throw new GroupRetrievalFault("Error retrieving group with group Id ",String.valueOf(groupIdL), e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error dismissing user from group ",groupId, e); + } + } + + // Remove all roles from the user that is relevant to the group + List userRoles = null; + try { + userRoles = RoleLocalServiceUtil.getUserRoles(this.convertStringToLong(userId)); + } catch (SystemException e) { + throw new UserManagementSystemException("Error dismissing user from group ",groupId, e); + } + for(Organization dismissedGroup : dismissedGroups){ + String dismissedGroupName = dismissedGroup.getName(); + for(Role userRole : userRoles){ + if(userRole.getName().contains(dismissedGroupName)){ + long[] roleIds ={userRole.getRoleId()}; + try { + RoleLocalServiceUtil.unsetUserRoles(this.convertStringToLong(userId), roleIds); + } catch (PortalException e) { + throw new UserRetrievalFault("Error unsetting user roles for user ",userId, e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error dismissing user from group ",groupId, e); + } + } + } + } + } + + + public UserModel getUser(String userId) throws UserManagementSystemException, UserRetrievalFault { + User user = null; + UserModel um = new UserModel(); + try { + user = UserLocalServiceUtil.getUser(this.convertStringToLong(userId)); + }catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving user ",userId, e); + } catch (PortalException e) { + throw new UserRetrievalFault("Error retrieving user for user Id ",userId, e); + } + um = new UserModel(String.valueOf(user.getUserId()),user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName(),user.getCreateDate().getTime(),this.getUserCustomAttributes(String.valueOf(user.getUserId()))); + return um; + } + + + public List listUsers() throws UserManagementSystemException, UserRetrievalFault { + List users = null; + List userModels = new ArrayList(); + try { + users = UserLocalServiceUtil.getUsers(0, UserLocalServiceUtil.getUsersCount()); + for(User user : users){ + UserModel um = new UserModel(String.valueOf(user.getUserId()),user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName(),user.getCreateDate().getTime(),this.getUserCustomAttributes(String.valueOf(user.getUserId()))); + userModels.add(um); + } + }catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving list of users ", e); + } + return userModels; + } + + + public HashMap> listUsersAndGroupsByRole(String roleIdn) throws UserManagementSystemException, RoleRetrievalFault, UserRetrievalFault { + List users; + long userId; + HashMap> hMap = new HashMap>(); + HashMap> hMapCustom = new HashMap>(); + UserModel um = null; + long roleId = this.convertStringToLong(roleIdn); + try { + users = UserLocalServiceUtil.getRoleUsers(roleId); + for(User user : users){ + userId = user.getUserId(); + um = new UserModel(String.valueOf(user.getUserId()),user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName(),user.getCreateDate().getTime(),this.getUserCustomAttributes(String.valueOf(user.getUserId()))); + Role role = null; + List group = new ArrayList(); + List groupModel = new ArrayList(); + List orgs = null; + try { + role = RoleLocalServiceUtil.getRole(roleId); + orgs = OrganizationLocalServiceUtil.getUserOrganizations(userId); + } catch (PortalException e) { + throw new RoleRetrievalFault("Error retrieving role for role Id",String.valueOf(roleId),e); + } + String roleName = role.getName(); + for(Organization org : orgs){ + if(roleName.contains(org.getName())){ + group.add(org); + GroupModel gm = new GroupModel(String.valueOf(org.getOrganizationId()),String.valueOf(org.getParentOrganizationId()),org.getName(),org.getComments(),org.getLogoId()); + groupModel.add(gm); + hMap.put(user, group); + + } + } + hMapCustom.put(um, groupModel); + } + }catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving list of users and groups for role ",roleIdn, e); + } + return hMapCustom; + } + + + public HashMap> listUsersAndRolesByGroup(String orgIdn) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault { + List users = null; + List roles = null; + UserModel um = null; + String orgName = null; + String roleName = null; + String completeRoleName = null; + HashMap> hMap = new HashMap>(); + long orgId = this.convertStringToLong(orgIdn); + LiferayRoleManager roleMan = new LiferayRoleManager(); + try { + users = UserLocalServiceUtil.getOrganizationUsers(orgId); + Organization org = OrganizationLocalServiceUtil.getOrganization(orgId); + orgName = org.getName(); + } catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving list of users for group Id ",orgIdn, e); + } catch (PortalException e) { + throw new GroupRetrievalFault("Error retrieving group with group Id ",orgIdn, e); + } + for(User user : users){ + List userRoles = new ArrayList(); + um = new UserModel(String.valueOf(user.getUserId()),user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName(),user.getCreateDate().getTime(),this.getUserCustomAttributes(String.valueOf(user.getUserId()))); + try { + roles = user.getRoles(); + } catch (SystemException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Role Prod_Supp_role = roleMan.getCommonRole(); + if(Prod_Supp_role!=null){ + if(roles.contains(Prod_Supp_role)){ + RoleModel rm = new RoleModel(Prod_Supp_role.getName(),String.valueOf(Prod_Supp_role.getRoleId()),Prod_Supp_role.getDescription()); + userRoles.add(rm); + } + } + + + for(Role role : roles){ + if(role.getName().contains(orgName)){ + completeRoleName = role.getName(); + roleName = roleMan.getRoleName(completeRoleName); + RoleModel rm = new RoleModel(roleName,String.valueOf(role.getRoleId()),role.getDescription()); + rm.setCompleteName(completeRoleName); + userRoles.add(rm); + } + } + hMap.put(um,userRoles); + } + return hMap; + } + + + public List listUsersByGroup(String groupId) throws UserManagementSystemException, UserRetrievalFault { + List users = null; + List userModels = new ArrayList(); + try { + users = UserLocalServiceUtil.getOrganizationUsers(this.convertStringToLong(groupId)); + for(User user : users){ + UserModel um = new UserModel(String.valueOf(user.getUserId()),user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName(),user.getCreateDate().getTime(),this.getUserCustomAttributes(String.valueOf(user.getUserId()))); + userModels.add(um); + } + } catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving list of group users for group Id ",groupId, e); + } + return userModels; + } + + + public List listUsersByGroupAndRole(String groupIdn, String roleIdn) throws UserManagementSystemException, UserRetrievalFault { + List users = new ArrayList(); + List userModels = new ArrayList(); + List groupUsers = null; + long userId; + long roleId = this.convertStringToLong(roleIdn); + long groupId = this.convertStringToLong(groupIdn); + try { + groupUsers = UserLocalServiceUtil.getOrganizationUsers(groupId); + for(User user : groupUsers){ + userId = user.getUserId(); + if(RoleLocalServiceUtil.hasUserRole(userId, roleId)){ + if(OrganizationLocalServiceUtil.hasUserOrganization(userId, groupId)){ + users.add(user); + UserModel um = new UserModel(String.valueOf(user.getUserId()),user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName(),user.getCreateDate().getTime(),this.getUserCustomAttributes(String.valueOf(user.getUserId()))); + userModels.add(um); + } + } + } + } catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving list of users by group and role", e); + } + return userModels; + } + + + public List listPendingUsersByGroup(String groupIdn) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault { + List userModels = new ArrayList(); + List memberRequests = null; + //List usermodels = new HashMap (); + long groupId = this.convertStringToLong(groupIdn); + Organization org; + try { + org = OrganizationLocalServiceUtil.getOrganization(groupId); + memberRequests = MembershipRequestLocalServiceUtil.getMembershipRequests(0, MembershipRequestLocalServiceUtil.getMembershipRequestsCount()); + }catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving pending users for group ",groupIdn, e); + } catch (PortalException e) { + throw new GroupRetrievalFault("Error retrieving group with group Id ",groupIdn, e); + } + + for(MembershipRequest memberRequest: memberRequests){ + if(memberRequest.getGroupId()==org.getGroup().getGroupId()){ + long userId = memberRequest.getUserId(); + User user = null; + try { + user = UserLocalServiceUtil.getUser(userId); + } catch (PortalException e) { + throw new UserRetrievalFault("Error retrieving user for user Id ",String.valueOf(userId), e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving pending users for group ",groupIdn, e); + } + UserModel um = new UserModel(String.valueOf(user.getUserId()),user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName(),user.getCreateDate().getTime(),this.getUserCustomAttributes(String.valueOf(user.getUserId()))); + userModels.add(um); + } + } + return userModels; + } + + + public void updateUser(UserModel usermodel) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException { + try { + User user = null; + LiferayGroupManager gm = new LiferayGroupManager(); + long companyId = gm.getCompanyId(); + try { + user = UserLocalServiceUtil.getUserByScreenName(companyId, usermodel.getScreenName()); + user.setEmailAddress(usermodel.getEmail()); + user.setFirstName(usermodel.getFirstname()); + user.setLastName(usermodel.getLastname()); + }catch (PortalException e) { + throw new UserRetrievalFault("Error retrieving user by screen name ",usermodel.getScreenName(), e); + } + UserLocalServiceUtil.updateUser(user); + } catch (SystemException e) { + throw new UserManagementSystemException("Error updating user ",usermodel.getScreenName(), e); + } + + } + + + public List listUnregisteredUsersByGroup(String groupIdn) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault{ + List users = new ArrayList(); + List unregisteredUsers = new ArrayList(); + List unregisteredUserModels = new ArrayList(); + + long groupId = this.convertStringToLong(groupIdn); + Organization org; + try { + org = OrganizationLocalServiceUtil.getOrganization(groupId); + users = UserLocalServiceUtil.getUsers(0, UserLocalServiceUtil.getUsersCount()); + } catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving unregistered users for group ",groupIdn, e); + } catch (PortalException e) { + throw new GroupRetrievalFault("Error retrieving group with group Id ",groupIdn, e); + } + + for(User user : users){ + boolean isRegistered = false; + //System.out.println(user.getFirstName()); + List userOrgs = null; + try { + userOrgs = user.getOrganizations(); + } catch (PortalException e) { + e.printStackTrace(); + } catch (SystemException e) { + e.printStackTrace(); + } + for(Organization userOrg : userOrgs){ + if(userOrg.getOrganizationId()==org.getOrganizationId()){ + isRegistered = true; + } + } + if(!isRegistered){ + unregisteredUsers.add(user); + UserModel um = new UserModel(String.valueOf(user.getUserId()),user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName(),user.getCreateDate().getTime(),this.getUserCustomAttributes(String.valueOf(user.getUserId()))); + unregisteredUserModels.add(um); + } + } + return unregisteredUserModels; + } + + public String getMembershipRequestComment(String userId, String groupId) throws UserManagementSystemException, GroupRetrievalFault { + long userIdL = convertStringToLong(userId); + long groupIdL = convertStringToLong(groupId); + String comment = null; + List memberRequests = null; + try { + Organization org = OrganizationLocalServiceUtil.getOrganization(groupIdL); + memberRequests = MembershipRequestLocalServiceUtil.getMembershipRequests(0, MembershipRequestLocalServiceUtil.getMembershipRequestsCount()); + for(MembershipRequest memberRequest: memberRequests){ + if(memberRequest.getGroupId()==org.getGroup().getGroupId() && memberRequest.getUserId() == userIdL){ + comment = memberRequest.getComments(); + break; + } + } + }catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving membership request comment ", e); + } catch (PortalException e) { + throw new GroupRetrievalFault("Error retrieving group with group Id ",groupId, e); + } + return comment; + } + + public UserModel getUserByScreenName(String screenName) throws UserManagementSystemException, UserManagementPortalException, UserRetrievalFault { + User user = null; + UserModel um = null; + LiferayGroupManager gm = new LiferayGroupManager(); + long companyId = gm.getCompanyId(); + try { + user = UserLocalServiceUtil.getUserByScreenName(companyId, screenName); + um = new UserModel(String.valueOf(user.getUserId()),user.getFirstName(),user.getLastName(),user.getFullName(),user.getEmailAddress(),user.getScreenName(),user.getCreateDate().getTime(),this.getUserCustomAttributes(String.valueOf(user.getUserId()))); + } catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving user by screename ",screenName, e); + } catch (PortalException e) { + throw new UserManagementPortalException("Error retrieving user by screename ",screenName, e); + } + return um; + } + + + + public HashMap getUserCustomAttributes(String userId) throws UserManagementSystemException, UserRetrievalFault{ + + User user = null; + HashMap hMap = new HashMap(); + try { + user = UserLocalServiceUtil.getUser(Long.parseLong(userId)); + } catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving custom attributes of user ",userId, e); + } catch (PortalException e) { + throw new UserRetrievalFault("Error retrieving user for user Id ",userId, e); + } + + try { + + long id = ExpandoClassCodeManager.getInstance().getClassCode(User.class); + ExpandoTable table = ExpandoDefaultTableManager.getInstance().getExpandoDefaultTable(id); + + if (table != null) + { + long tableID = table.getTableId(); + List columns = ExpandoColumnLocalServiceUtil.getColumns(tableID); + + for (ExpandoColumn column : columns) + { + ExpandoValue value = ExpandoValueLocalServiceUtil.getValue(tableID, column.getColumnId(), user.getUserId()); + String valueString = ""; + + if (value != null && value.getString() != null) valueString = value.getString(); + + //System.out.println(valueString); + + hMap.put(column.getName(), valueString); + } + + } + + } catch (Exception e) + { + e.printStackTrace(); + } + return hMap; + } + + + public String getUserCustomAttributeByName(String userId, String attrName) throws UserManagementSystemException, UserRetrievalFault{ + User user = null; + try { + user = UserLocalServiceUtil.getUser(this.convertStringToLong(userId)); + }catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving custom attributes of user ",userId, e); + } catch (PortalException e) { + throw new UserRetrievalFault("Error retrieving user for user Id ",userId, e); + } + + String response = null; + + long id = ExpandoClassCodeManager.getInstance().getClassCode(User.class); + ExpandoTable table = ExpandoDefaultTableManager.getInstance().getExpandoDefaultTable(id); + + + if (table != null) + { + long tableID = table.getTableId(); + try { + + ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(tableID, attrName); + + if (column != null) + { + ExpandoValue value = ExpandoValueLocalServiceUtil.getValue(tableID, column.getColumnId(), user.getUserId()); + + if (value != null) response = value.getString(); + + } + } catch (SystemException e) + { + throw new UserManagementSystemException("Error retriving custom attributes",userId, e); + } catch (PortalException e) + { + throw new UserRetrievalFault("Error retriving custom attributes ",userId, e); + } + } + + + return response; + } + + public void setUserCustomAttributeByName(String userId, String attrName, String attrValue) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException{ + User user = null; + boolean attrPresent = false; + try { + user = UserLocalServiceUtil.getUser(this.convertStringToLong(userId)); + }catch (SystemException e) { + throw new UserManagementSystemException("Error setting custom attributes of user ",userId, e); + } catch (PortalException e) { + throw new UserRetrievalFault("Error retrieving user for user Id ",userId, e); + } + Enumeration attrNamesExist = user.getExpandoBridge().getAttributeNames(); + while(attrNamesExist.hasMoreElements()){ + if(attrNamesExist.nextElement().equals(attrName)){ + attrPresent = true; + break; + } + } + if(attrPresent){ + user.getExpandoBridge().setAttribute(attrName, attrValue); + }else{ + try { + user.getExpandoBridge().addAttribute(attrName); + user.getExpandoBridge().setAttribute(attrName, attrValue); + } catch (PortalException e) { + throw new UserManagementPortalException("Error setting custom attributes of user ",userId, e); + } + + } + + } + + public void setUserCustomAttributes(String userId, HashMap hMap) throws UserManagementSystemException, UserRetrievalFault, UserManagementPortalException{ + User user = null; + String attrName = null ; + boolean attrPresent = false; + try { + user = UserLocalServiceUtil.getUser(this.convertStringToLong(userId)); + }catch (SystemException e) { + throw new UserManagementSystemException("Error setting custom attributes of user ",userId, e); + } catch (PortalException e) { + throw new UserRetrievalFault("Error retrieving user for user Id ",userId, e); + } + + Iterator customAttributesIterNew = hMap.keySet().iterator(); + Enumeration attrNamesExist = user.getExpandoBridge().getAttributeNames(); + while(customAttributesIterNew.hasNext()){ + attrPresent = false; + String customAttribute = customAttributesIterNew.next(); + while(attrNamesExist.hasMoreElements()){ + attrName = attrNamesExist.nextElement(); + if(attrName.equals(customAttribute)){ + attrPresent = true; + break; + } + } + if(attrPresent){ + user.getExpandoBridge().setAttribute(attrName ,hMap.get(attrName) ); + }else{ + try { + user.getExpandoBridge().addAttribute(customAttribute); + user.getExpandoBridge().setAttribute(customAttribute, hMap.get(customAttribute)); + } catch (PortalException e) { + throw new UserManagementPortalException("Error setting custom attributes of user ",userId, e); + } + } + + } + + } + + public void denyMembershipRequest(String userId, String groupId) throws UserManagementSystemException, GroupRetrievalFault, UserManagementPortalException { + List memberRequests; + Organization org; + try { + memberRequests = MembershipRequestLocalServiceUtil.getMembershipRequests(0, MembershipRequestLocalServiceUtil.getMembershipRequestsCount()); + } catch (SystemException e) { + throw new UserManagementSystemException("Error retrieving Membership requests ", e); + } + try { + org = OrganizationLocalServiceUtil.getOrganization(this.convertStringToLong(groupId)); + } catch (SystemException e) { + throw new UserManagementSystemException("Error deleting membership request of user ", userId , e); + } catch (PortalException e) { + throw new GroupRetrievalFault("No group exists with groupId ",groupId, e); + } + for(MembershipRequest memberRequest:memberRequests){ + if(memberRequest.getGroupId()==org.getGroup().getGroupId() && memberRequest.getUserId() == this.convertStringToLong(userId)){ + try { + MembershipRequestLocalServiceUtil.deleteMembershipRequest(memberRequest.getMembershipRequestId()); + } catch (PortalException e) { + throw new UserManagementPortalException("Error deleting membership request of user ", userId , e); + } catch (SystemException e) { + throw new UserManagementSystemException("Error deleting membership request of user ", userId , e); + } + break; + } + } + //MembershipRequestLocalServiceUtil.updateStatus(replierUserId, membershipRequestId, replyComments, statusId) + } + +// public List getUserCustomAttributes(String userId) +// throws UserManagementSystemException, UserRetrievalFault +// { +// HashMap map = internalGetUserCustomAttributes(userId); +// List response = new ArrayList(); +// +// if (map != null) +// { +// Iterator keys = map.keySet().iterator(); +// +// while (keys.hasNext()) +// { +// String key = keys.next(); +// response.add(new CustomFieldModel(key, map.get(key))); +// } +// } +// +// return response; +// } + + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/ParseXML.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/ParseXML.java new file mode 100644 index 0000000..2f74066 --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/ParseXML.java @@ -0,0 +1,144 @@ +package org.gcube.vomanagement.usermanagement.impl.liferay; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; + +import java.io.FileWriter; +import java.io.IOException; + +import java.util.HashMap; +import java.util.Iterator; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.gcube.vomanagement.usermanagement.exception.UserManagementFileNotFoundException; +import org.gcube.vomanagement.usermanagement.exception.UserManagementIOException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; + +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; + +public class ParseXML { + + + private static Document convertStringToDocument (FileInputStream inputFile) throws IOException { + + InputSource in = null; + try { + in = new InputSource (inputFile); + } catch (Exception e) { + e.printStackTrace(); + } + DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); + Document doc = null; + try { + doc = dfactory.newDocumentBuilder().parse(in); + } catch (Exception e) { + e.printStackTrace(); + } + inputFile.close(); + return doc; + } + + private static String document2String(Document document) throws Exception { + ByteArrayOutputStream baos; + Transformer t; + + baos = new ByteArrayOutputStream(); + t = TransformerFactory.newInstance().newTransformer(); + t.transform(new DOMSource(document), new StreamResult(baos)); + return baos.toString(); + + } + + protected static HashMap getRoles(String groupType) throws UserManagementFileNotFoundException, UserManagementIOException { + HashMap hMap = new HashMap(); + File file = new File (Settings.getInstance().getProperty("sharedDir")+ File.separator + "roles-config.xml"); + + Document dom = null; + try { + FileInputStream in = new FileInputStream(file); + dom = convertStringToDocument(in); + in.close(); + } catch (FileNotFoundException e) { + throw new UserManagementFileNotFoundException("Roles config file not found. Check if the config file exists", e); + } catch (IOException e) { + throw new UserManagementIOException("Error writing to the roles config file", e); + } + Element elem = dom.getDocumentElement(); + + NodeList nl = elem.getElementsByTagName(groupType); + for(int i=0;i rolesMap, String groupType) throws UserManagementIOException, UserManagementFileNotFoundException{ + File file = new File (Settings.getInstance().getProperty("sharedDir")+ File.separator + "roles-config.xml"); + Document dom; + Iterator keyIter = rolesMap.keySet().iterator(); + try { + dom = convertStringToDocument(new FileInputStream(file)); + } catch (FileNotFoundException e) { + throw new UserManagementFileNotFoundException("Roles config file not found. Check if the config file exists", e); + } catch (IOException e) { + throw new UserManagementIOException("Error writing to the roles config file", e); + } + Element elem = dom.getDocumentElement(); + NodeList nl = elem.getElementsByTagName(groupType); + for(int i=0;i0){ + Element el2 = (Element)nl2.item(nl2.getLength()-1); + el.removeChild(el2); + } + + while(keyIter.hasNext()){ + Element role = dom.createElement("role"); + + Element roleNode = (Element)el.appendChild(role); + String roleName = keyIter.next(); + roleNode.setAttribute("name", roleName); + + roleNode.setAttribute("description", rolesMap.get(roleName)); + } + } + FileWriter out = null; + try { + out = new FileWriter(file); + } catch (IOException e) { + throw new UserManagementIOException("Error writing to the roles config file", e); + } + try { + out.write(document2String(dom)); + out.flush(); + out.close(); + } catch (IOException e) { + throw new UserManagementIOException("Error writing to the roles config file", e); + } catch (Exception e) { + e.printStackTrace(); + } + + } +} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/Settings.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/Settings.java new file mode 100644 index 0000000..8322b39 --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/Settings.java @@ -0,0 +1,57 @@ +package org.gcube.vomanagement.usermanagement.impl.liferay; + +import java.io.*; +import java.util.*; + +public class Settings { + + static Properties props = new Properties(); + static Settings settings = null; + + Settings() + { + try + { + props.load(Settings.class.getResourceAsStream("/etc/settings.properties")); + + } + catch (FileNotFoundException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + catch (IOException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public static Settings getInstance() + { + if (settings == null) + settings = new Settings(); + return settings; + } + + /** + * @return the props + */ + public String getProperty(String key) { + String value = props.getProperty(key); + if(value.contains("${")) + { + int start = 0; + int i; + while((i= value.indexOf("${", start)) != -1) + { + start = value.indexOf("}", i) +1; + String reg = value.substring(i, start); + //System.out.println(reg); + //System.out.println(reg.substring(2, reg.length() -1)); + value = value.replace(reg, (System.getProperty(reg.substring(2, reg.length() -1)) != null)?System.getProperty(reg.substring(2, reg.length() -1)):""); + } + } + return value; + } +} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/utils/ExpandoClassCodeManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/utils/ExpandoClassCodeManager.java new file mode 100644 index 0000000..4fc9846 --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/utils/ExpandoClassCodeManager.java @@ -0,0 +1,47 @@ +package org.gcube.vomanagement.usermanagement.impl.liferay.utils; + +import java.util.HashMap; +import java.util.Map; + +import com.liferay.portal.service.ClassNameLocalServiceUtil; + +/** + * + * Utility class to load the classes of custom field + * + * @author Ciro Formisano + * + */ +public class ExpandoClassCodeManager +{ + private Map map; + + private static ExpandoClassCodeManager instance; + + public static ExpandoClassCodeManager getInstance () + { + if (instance == null) instance = new ExpandoClassCodeManager(); + + return instance; + } + + public ExpandoClassCodeManager() + { + this.map = new HashMap (); + } + + public long getClassCode (Class type) + { + String className = type.getName(); + Long code = this.map.get(className); + + if (code == null) + { + code = ClassNameLocalServiceUtil.getClassNameId(type); + this.map.put(className, code); + } + + return code; + } + +} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/utils/ExpandoDefaultTableManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/utils/ExpandoDefaultTableManager.java new file mode 100644 index 0000000..aaa86d8 --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/impl/liferay/utils/ExpandoDefaultTableManager.java @@ -0,0 +1,86 @@ +package org.gcube.vomanagement.usermanagement.impl.liferay.utils; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import com.liferay.portlet.expando.model.ExpandoTable; +import com.liferay.portlet.expando.service.ExpandoTableLocalServiceUtil; + + +/** + * + * Utility class to load the table of custom fields + * + * @author Ciro Formisano + * + */ +public class ExpandoDefaultTableManager +{ + + private Map tableMap; + private final String DEFAULT_TABLE_NAME = "DEFAULT_TABLE"; + + private static ExpandoDefaultTableManager instance; + + public static ExpandoDefaultTableManager getInstance () + { + if (instance == null) + { + instance = new ExpandoDefaultTableManager(); + } + + return instance; + } + + public ExpandoDefaultTableManager() + { + this.tableMap = new HashMap (); + } + + public ExpandoTable getExpandoDefaultTable (long classId) + { + ExpandoTable response = this.tableMap.get(classId); + + if (response == null) + { + try + { + response = getExpandoDefaultTableFromDatabase(classId); + + if (response != null) this.tableMap.put(classId, response); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + return response; + } + + private ExpandoTable getExpandoDefaultTableFromDatabase (long classId) throws Exception + { + int numberOfTables = ExpandoTableLocalServiceUtil.getExpandoTablesCount(); + List tables = ExpandoTableLocalServiceUtil .getExpandoTables(0, numberOfTables); + ExpandoTable response = null; + + if (tables != null) + { + Iterator tableIterator = tables.iterator(); + + + while (tableIterator.hasNext() && response == null) + { + ExpandoTable currentTable = tableIterator.next(); + + if (currentTable.getName().equals(DEFAULT_TABLE_NAME) && currentTable.getClassNameId() == classId) response = currentTable; + } + } + + return response; + + } + +} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/voms/VOMSGroupManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/voms/VOMSGroupManager.java new file mode 100644 index 0000000..135e59a --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/impl/voms/VOMSGroupManager.java @@ -0,0 +1,129 @@ +package org.gcube.vomanagement.usermanagement.impl.voms; + +import java.util.HashMap; +import java.util.List; + +import org.gcube.vomanagement.usermanagement.GroupManager; +import org.gcube.vomanagement.usermanagement.model.GroupModel; +import org.gcube.vomanagement.usermanagement.model.RoleModel; + +/** + * VOMS plugin for the GroupManager interface. + * + * @author Giulio Galiero + * + */ +public class VOMSGroupManager implements GroupManager { + + public void assignSubGrouptoParentGroup(String subGroupId, + String parentGroupId) { + // TODO Auto-generated method stub + + } + + public GroupModel createRootVO(String RootVOName, String userId, String description) { + // TODO Auto-generated method stub + return null; + } + + public GroupModel createVO(String VOName, String rootVOGroupId, + String userId, String description) { + // TODO Auto-generated method stub + return null; + } + + public GroupModel createVRE(String VREName, String VOGroupId, String userId, String description) { + // TODO Auto-generated method stub + return null; + } + + public void deleteGroup(String groupId) { + // TODO Auto-generated method stub + + } + + public void dismissSubGroupFromParentGroup(String subGroupId, + String parentGroupId) { + // TODO Auto-generated method stub + + } + + public GroupModel getGroup(String groupId) { + // TODO Auto-generated method stub + return null; + } + + public String getGroupId(String groupName) { + // TODO Auto-generated method stub + return null; + } + + public long getGroupParentId(String groupId) { + // TODO Auto-generated method stub + return 0; + } + + public GroupModel getRootVO() { + // TODO Auto-generated method stub + return null; + } + + public String getRootVOName() { + // TODO Auto-generated method stub + return null; + } + + public String getScope(String groupId) { + // TODO Auto-generated method stub + return null; + } + + public Boolean isRootVO(String groupId) { + // TODO Auto-generated method stub + return null; + } + + public Boolean isVO(String groupId) { + // TODO Auto-generated method stub + return null; + } + + public Boolean isVRE(String groupId) { + // TODO Auto-generated method stub + return null; + } + + public List listGroups() { + // TODO Auto-generated method stub + return null; + } + + public HashMap> listGroupsAndRolesByUser( + String userId) { + // TODO Auto-generated method stub + return null; + } + + public List listGroupsByUser(String userId) { + // TODO Auto-generated method stub + return null; + } + + public List listPendingGroupsByUser(String userId) { + // TODO Auto-generated method stub + return null; + } + + public List listSubGroupsByGroup(String groupId) { + // TODO Auto-generated method stub + return null; + } + + public void updateGroup(GroupModel group) { + // TODO Auto-generated method stub + + } + + + +} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/voms/VOMSRoleManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/voms/VOMSRoleManager.java new file mode 100644 index 0000000..9daf67f --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/impl/voms/VOMSRoleManager.java @@ -0,0 +1,135 @@ +package org.gcube.vomanagement.usermanagement.impl.voms; + +import java.util.HashMap; +import java.util.List; + +import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.RoleRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.UserManagementFileNotFoundException; +import org.gcube.vomanagement.usermanagement.exception.UserManagementIOException; +import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException; +import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; +import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; +import org.gcube.vomanagement.usermanagement.model.RoleModel; + + + +/** + * VOMS plugin for the RoleManager interface. + * + * @author Giulio Galiero + * + */ +public class VOMSRoleManager implements + org.gcube.vomanagement.usermanagement.RoleManager { + + public void assignRoleToUser(String groupId, String roleId, String userId) + throws UserManagementSystemException, UserRetrievalFault, + GroupRetrievalFault, RoleRetrievalFault { + // TODO Auto-generated method stub + + } + + public void createRole(String groupName) + throws UserManagementSystemException, GroupRetrievalFault, + RoleRetrievalFault, UserManagementPortalException, + UserManagementFileNotFoundException, UserManagementIOException { + // TODO Auto-generated method stub + + } + + public boolean createRole(String roleName, String roleDescription, + String groupName) throws UserManagementSystemException, + RoleRetrievalFault, GroupRetrievalFault, + UserManagementPortalException { + // TODO Auto-generated method stub + return false; + } + + public void deleteRole(String roleName, String groupName) + throws UserManagementSystemException, RoleRetrievalFault { + // TODO Auto-generated method stub + + } + + public void dismissRoleFromUser(String groupId, String roleId, String userId) + throws UserManagementSystemException, UserRetrievalFault, + GroupRetrievalFault, RoleRetrievalFault { + // TODO Auto-generated method stub + + } + + public RoleModel getRole(String roleId) + throws UserManagementSystemException, RoleRetrievalFault { + // TODO Auto-generated method stub + return null; + } + + public String getRoleId(String roleName, String groupName) + throws UserManagementSystemException { + // TODO Auto-generated method stub + return null; + } + + public HashMap listAllowedRoles(String groupName) + throws UserManagementSystemException, GroupRetrievalFault, + UserManagementFileNotFoundException, UserManagementIOException { + // TODO Auto-generated method stub + return null; + } + + @Deprecated + public List listRoles() throws UserManagementSystemException { + // TODO Auto-generated method stub + return null; + } + + public List listRolesByGroup(String groupId) + throws UserManagementSystemException, GroupRetrievalFault { + // TODO Auto-generated method stub + return null; + } + + public List listRolesByUser(String userId) + throws UserManagementSystemException { + // TODO Auto-generated method stub + return null; + } + + public List listRolesByUserAndGroup(String groupId, String userId) + throws UserManagementSystemException, GroupRetrievalFault, + UserRetrievalFault { + // TODO Auto-generated method stub + return null; + } + + public void updatePredefinedRoles(HashMap rolesMap, + String groupType) throws UserManagementIOException, + UserManagementFileNotFoundException { + // TODO Auto-generated method stub + + } + + public void updateRole(String initialRoleName, String newRoleName, + String roleDescription, String groupName) + throws UserManagementSystemException, RoleRetrievalFault, + NumberFormatException, UserManagementFileNotFoundException, + UserManagementIOException, GroupRetrievalFault, + UserManagementPortalException { + // TODO Auto-generated method stub + + } + + public List listAllRoles() throws UserManagementSystemException { + // TODO Auto-generated method stub + return null; + } + + public boolean isAdmin(String userId) { + // TODO Auto-generated method stub + return false; + } + + + +} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/impl/voms/VOMSUserManager.java b/src/main/java/org/gcube/vomanagement/usermanagement/impl/voms/VOMSUserManager.java new file mode 100644 index 0000000..79d0904 --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/impl/voms/VOMSUserManager.java @@ -0,0 +1,155 @@ +package org.gcube.vomanagement.usermanagement.impl.voms; + +import java.util.HashMap; +import java.util.List; + +import org.gcube.vomanagement.usermanagement.UserManager; +import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException; +import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; +import org.gcube.vomanagement.usermanagement.model.GroupModel; +import org.gcube.vomanagement.usermanagement.model.RoleModel; +import org.gcube.vomanagement.usermanagement.model.UserModel; + +/** + * VOMS plugin for the UserManager interface. + * + * @author Giulio Galiero + * + */ +public class VOMSUserManager implements UserManager { + + public void assignUserToGroup(String groupName, String userId) { + // TODO Auto-generated method stub + + } + + public void createUser(UserModel usermodel) { + // TODO Auto-generated method stub + + } + + public void deleteUser(String userId) { + // TODO Auto-generated method stub + + } + + public void dismissUserFromGroup(String groupName, String userId) { + // TODO Auto-generated method stub + + } + + public UserModel getUser(String userId) { + // TODO Auto-generated method stub + return null; + } + + public List listPendingUsersByGroup(String groupId) { + // TODO Auto-generated method stub + return null; + } + + public List listUsers() { + // TODO Auto-generated method stub + return null; + } + + public HashMap> listUsersAndGroupsByRole( + String roleName) { + // TODO Auto-generated method stub + return null; + } + + public HashMap> listUsersAndRolesByGroup( + String groupName) { + // TODO Auto-generated method stub + return null; + } + + public List listUsersByGroup(String groupId) { + // TODO Auto-generated method stub + return null; + } + + public List listUsersByGroupAndRole(String groupName, + String roleName) { + // TODO Auto-generated method stub + return null; + } + + public void updateUser(UserModel user) { + // TODO Auto-generated method stub + + } + + public List listUnregisteredUsersByGroup(String groupId) { + // TODO Auto-generated method stub + return null; + } + + public void requestMembership(String userId, String groupId, String comment) { + // TODO Auto-generated method stub + + } + + public String getUserId(String userName) { + // TODO Auto-generated method stub + return null; + } + + public List getMembershipRequests(String groupId) { + // TODO Auto-generated method stub + return null; + } + + public String getMembershipRequestComment(String userId, String groupId) { + // TODO Auto-generated method stub + return null; + } + + public UserModel getUserByScreenName(String screenName) { + // TODO Auto-generated method stub + return null; + } + + public HashMap getCustomAttributes(String userId) { + // TODO Auto-generated method stub + return null; + } + + public String getUserCustomAttributeByName(String userId, String attrName) + throws UserManagementSystemException { + // TODO Auto-generated method stub + return null; + } + + public HashMap getUserCustomAttributes(String userId) + throws UserManagementSystemException { + // TODO Auto-generated method stub + return null; + } + + public void setUserCustomAttributeByName(String userId, String attrName, + String attrValue) throws UserManagementSystemException, + UserManagementPortalException { + // TODO Auto-generated method stub + + } + + public void setUserCustomAttributes(String userId, + HashMap hMap) throws UserManagementSystemException, + UserManagementPortalException { + // TODO Auto-generated method stub + + } + + public void denyMembershipRequest(String userId, String groupId) + throws UserManagementSystemException, GroupRetrievalFault, + UserManagementPortalException { + // TODO Auto-generated method stub + + } + + + +} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/model/GroupModel.java b/src/main/java/org/gcube/vomanagement/usermanagement/model/GroupModel.java new file mode 100644 index 0000000..1c0be50 --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/model/GroupModel.java @@ -0,0 +1,67 @@ +package org.gcube.vomanagement.usermanagement.model; + + +public class GroupModel { + + String groupId; + String parentGroupId; + String groupName; + String description; + long logoId; + + public GroupModel() { + this("","","","",0L); + } + + public GroupModel(String groupId,String parentGroupId, String groupName, String description, long logoId){ + this.groupId = groupId; + this.parentGroupId = parentGroupId; + this.groupName = groupName; + this.description = description; + this.logoId = logoId; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getParentGroupId() { + return parentGroupId; + } + + public void setParentGroupId(String parentGroupId) { + this.parentGroupId = parentGroupId; + } + + public String getGroupName() { + return groupName; + } + + public void setGroupName(String groupName) { + this.groupName = groupName; + } + + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public long getLogoId() { + return logoId; + } + + public void setLogoId(long logoId) { + this.logoId = logoId; + } + + + +} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/model/RoleModel.java b/src/main/java/org/gcube/vomanagement/usermanagement/model/RoleModel.java new file mode 100644 index 0000000..379c5b7 --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/model/RoleModel.java @@ -0,0 +1,49 @@ +package org.gcube.vomanagement.usermanagement.model; + +public class RoleModel { + + String roleName; + String roleId; + String description; + String completeName; + + + public RoleModel(){ + + } + public RoleModel(String roleName,String roleId, String description){ + this.roleName = roleName; + this.roleId = roleId; + this.description = description; + } + + public String getRoleName() { + return roleName; + } + public void setRoleName(String roleName) { + this.roleName = roleName; + } + public String getRoleId() { + return roleId; + } + public void setRoleId(String roleId) { + this.roleId = roleId; + } + + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + public String getCompleteName() { + return completeName; + } + public void setCompleteName(String completeName) { + this.completeName = completeName; + } + + + + +} diff --git a/src/main/java/org/gcube/vomanagement/usermanagement/model/UserModel.java b/src/main/java/org/gcube/vomanagement/usermanagement/model/UserModel.java new file mode 100644 index 0000000..2b65294 --- /dev/null +++ b/src/main/java/org/gcube/vomanagement/usermanagement/model/UserModel.java @@ -0,0 +1,94 @@ +package org.gcube.vomanagement.usermanagement.model; + +import java.util.HashMap; + + +/** + * Liferay User Object Model + * + */ +public class UserModel{ + + private String fullname; + + private String email; + + private String screenName; + + private String firstname; + + private String lastname; + + private String userId; + + private long registrationDate; + + private HashMap customAttrsMap; + + public HashMap getCustomAttrsMap() { + return customAttrsMap; + } + public void setCustomAttrsMap(HashMap customAttrsMap) { + this.customAttrsMap = customAttrsMap; + } + public String getUserId() { + return userId; + } + public void setUserId(String userId) { + this.userId = userId; + } + public String getFirstname() { + return firstname; + } + public void setFirstname(String firstname) { + this.firstname = firstname; + } + public String getLastname() { + return lastname; + } + public void setLastname(String lastname) { + this.lastname = lastname; + } + + + public String getFullname() { + return fullname; + } + public void setFullname(String fullname) { + this.fullname = fullname; + } + public String getEmail() { + return email; + } + public void setEmail(String email) { + this.email = email; + } + public String getScreenName() { + return screenName; + } + public void setScreenName(String screenName) { + this.screenName = screenName; + } + public UserModel() { + + } + + + public long getRegistrationDate() { + return registrationDate; + } + public void setRegistrationDate(long registrationDate) { + this.registrationDate = registrationDate; + } + public UserModel(String userId, String firstname, String lastname, String fullname,String email,String screenname,long registrationDate,HashMap customAttrsMap) { + this.userId = userId; + this.firstname=firstname; + this.lastname=lastname; + this.fullname= fullname; + this.email = email; + this.screenName = screenname; + this.customAttrsMap = customAttrsMap; + this.registrationDate = registrationDate; + + } +} \ No newline at end of file diff --git a/src/main/resources/settings.properties b/src/main/resources/settings.properties new file mode 100644 index 0000000..4d18fbb --- /dev/null +++ b/src/main/resources/settings.properties @@ -0,0 +1 @@ +sharedDir=${catalina.home}/shared/d4s