From 7107ac489290a890758042d07ffab9a9f6c7e36b Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Tue, 21 Jun 2016 14:12:27 +0000 Subject: [PATCH] added code to put list of VREs to ckan-connector git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@129210 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 17 ------ .settings/org.eclipse.wst.common.component | 5 +- pom.xml | 1 - .../GcubeCkanDataCatalogServiceImpl.java | 32 +++++++--- .../gcubeckandatacatalog/server/UserUtil.java | 60 +++++++++++++++++++ 5 files changed, 86 insertions(+), 29 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/UserUtil.java diff --git a/.classpath b/.classpath index f34bf36..46858fe 100644 --- a/.classpath +++ b/.classpath @@ -33,22 +33,5 @@ - - - - - - - - - - - - - - - - - diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index e448544..3d12c11 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -4,10 +4,7 @@ - - uses - - + uses diff --git a/pom.xml b/pom.xml index ce6e941..a6e2b89 100644 --- a/pom.xml +++ b/pom.xml @@ -128,7 +128,6 @@ org.gcube.dvos usermanagement-core - provided diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java index 3174cb8..c9751a2 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java @@ -28,7 +28,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.gwt.user.server.rpc.RemoteServiceServlet; -import com.liferay.portal.model.RoleModel; /** * The server side implementation of the RPC service. * @@ -38,10 +37,10 @@ import com.liferay.portal.model.RoleModel; @SuppressWarnings("serial") public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implements GcubeCkanDataCatalogService { - + private static final String LIST_OF_VRES_PARAMETER = "listOfVres"; private static final String PORT_HTTP = ":80"; private static final String PORT_HTTPS = ":443"; - private static final String GCUBE_TOKEN = "gcube-token"; + private static final String GCUBE_TOKEN_PARAMETER = "gcube-token"; private static final String HTTPS = "https"; private static final String HTTP = "http"; public static String CKANCONNECTORCONTEXT = "CkanConnectorContext"; @@ -52,6 +51,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem private final static String TEST_USER = "francesco.mangiacrapa"; private final static String TEST_SCOPE = "/gcube/devsec/devVRE"; + private final static String TEST_MAIL = "francesco.mangiacrapa@isti.cnr.it"; private final static String TEST_SEC_TOKEN = "4620e6d0-2313-4f48-9d54-eb3efd01a810"; // private final static String TEST_SEC_TOKEN = "f539884c-8697-4ac0-9bbf-2f4d595281f5"; @@ -115,8 +115,6 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem } - - /** * Gets the ckan connector parameters. * @@ -141,14 +139,33 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem String gcubeTokenParameter = null; if(SessionUtil.isIntoPortal()){ - gcubeTokenParameter = GCUBE_TOKEN+"="+getGcubeSecurityToken(); + gcubeTokenParameter = GCUBE_TOKEN_PARAMETER+"="+getGcubeSecurityToken(); }else{ logger.warn("******** Using TEST_USER security token!!!"); - gcubeTokenParameter = GCUBE_TOKEN+"="+TEST_SEC_TOKEN; + gcubeTokenParameter = GCUBE_TOKEN_PARAMETER+"="+TEST_SEC_TOKEN; } + //ADDING CKAN HH (HIDE HEADER PARAMETER) queryString = queryString.isEmpty()?"?"+ckanHideHeader:"&"+ckanHideHeader; + //ADDING GCUBE TOKEN PARAMETER queryString+="&"+gcubeTokenParameter; + + //ADDING LIST OF VRE TO WHICH USER BELONGS + ASLSession session = getASLSession(this.getThreadLocalRequest().getSession()); + List listVres = UserUtil.getListVreForUser(session.getUserEmailAddress()); + String vres = ""; + if(listVres!=null && listVres.size()>0){ + for (String vre : listVres) { + vres+=vre+","; + } + vres = vres.substring(0, vres.length()-1); //remove last "," + } + + logger.debug("List of VREs contains: " +vres); + if(vres.length()>0){ + queryString+="&"+LIST_OF_VRES_PARAMETER+"="+vres; + } + return pathInfo+queryString; } @@ -209,6 +226,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem httpSession.setAttribute(USERNAME_ATTRIBUTE, user); ASLSession session = SessionManager.getInstance().getASLSession(sessionID, user); session.setScope(TEST_SCOPE); + session.setUserEmailAddress(TEST_MAIL); //session.setScope("/gcube/devsec/devVRE"); return session; diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/UserUtil.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/UserUtil.java new file mode 100644 index 0000000..fc7c274 --- /dev/null +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/UserUtil.java @@ -0,0 +1,60 @@ +/** + * + */ +package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server; + +import java.util.ArrayList; +import java.util.List; + +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.UserManagementSystemException; +import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; +import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; +import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; +import org.gcube.vomanagement.usermanagement.model.GCubeGroup; +import org.gcube.vomanagement.usermanagement.model.GCubeUser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The Class UserUtil. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Jun 21, 2016 + */ +public class UserUtil { + + private static Logger logger = LoggerFactory.getLogger(UserUtil.class); + + /** + * Gets the list vre for user. + * retrieve the groups to whom a given user belongs (given the user EMail) + * + * @param userEMail the user e mail + * @return the list vre for user + */ + public static List getListVreForUser(String userEMail){ + + // Instanciate the manager + GroupManager groupManager = new LiferayGroupManager(); + // Instanciate the manager + UserManager userManager = new LiferayUserManager(); + GCubeUser user; + try { + user = userManager.getUserByEmail(userEMail); + // retrieve the groups to whom a given user belongs (given the user identifier) + List listOfGroups = groupManager.listGroupsByUser(user.getUserId()); + List vreNames = new ArrayList(listOfGroups.size()); + for (GCubeGroup gCubeGroup : listOfGroups) { + vreNames.add(gCubeGroup.getGroupName()); + } + return vreNames; + }catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) { + logger.error("An error occurred during get list of VREs for user: "+userEMail, e); + return null; + } + } +}