From 70a07ac0c7c6877fb21a1b7d8f47cc101847bd19 Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Fri, 25 Nov 2016 09:37:56 +0000 Subject: [PATCH] moved to version 1.2.0 due to several changes. Removed asl session too git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@134752 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 6 +- distro/changelog.xml | 3 +- pom.xml | 26 +- .../GCubeCkanDataCatalog.gwt.xml | 2 - .../view/GCubeCkanDataCatalogPanel.java | 4 - .../GcubeCkanDataCatalogServiceImpl.java | 247 +++++++----------- .../server/SessionUtil.java | 111 +++++++- .../GCubeCkanDataCatalog.gwt.xml | 34 --- 8 files changed, 217 insertions(+), 216 deletions(-) delete mode 100644 src/main/resources/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/GCubeCkanDataCatalog.gwt.xml diff --git a/.classpath b/.classpath index 0954c1d..e123609 100644 --- a/.classpath +++ b/.classpath @@ -1,12 +1,12 @@ - + - + @@ -33,5 +33,5 @@ - + diff --git a/distro/changelog.xml b/distro/changelog.xml index f2db5b8..f68ff4c 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,9 +1,10 @@ - Groups tab changed [Task #5615] Logout is performed before browser tab is closed Portlet's borders are removed by default + Removed asl session diff --git a/pom.xml b/pom.xml index 57a41d8..837ce2a 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.gcube.portlets.gcubeckan gcube-ckan-datacatalog war - 1.1.1-SNAPSHOT + 1.2.0-SNAPSHOT gCube CKAN Data Catalog The gCube CKAN Data Catalog portlet @@ -59,11 +59,11 @@ - - - - - + + + + + com.google.gwt gwt-user @@ -90,7 +90,7 @@ org.gcube.core common-scope-maps - compile + provided @@ -121,11 +121,6 @@ portal-manager provided - - org.gcube.applicationsupportlayer - aslcore - provided - javax.portlet portlet-api @@ -172,13 +167,6 @@ provided - - - org.gcube.portlets.widgets - session-checker - [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) - - diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/GCubeCkanDataCatalog.gwt.xml b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/GCubeCkanDataCatalog.gwt.xml index edaee34..8027926 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/GCubeCkanDataCatalog.gwt.xml +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/GCubeCkanDataCatalog.gwt.xml @@ -21,8 +21,6 @@ - - diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/view/GCubeCkanDataCatalogPanel.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/view/GCubeCkanDataCatalogPanel.java index e360dce..e2d663c 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/view/GCubeCkanDataCatalogPanel.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/view/GCubeCkanDataCatalogPanel.java @@ -13,7 +13,6 @@ import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.resource.CkanPor import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgGroupRole; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanRole; -import org.gcube.portlets.widgets.sessionchecker.client.CheckSession; import com.google.gwt.core.client.GWT; import com.google.gwt.event.logical.shared.ResizeEvent; @@ -107,9 +106,6 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate { } else { - // polling for session expired check - CheckSession.getInstance().startPolling(); - // MANAGE CKAN MANAGEMENT PANEL ACCORDING TO MY ROLE GCubeCkanDataCatalog.service.getMyRole(new AsyncCallback() { 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 5e2e36a..a794dd6 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 @@ -8,16 +8,12 @@ import java.util.List; import javax.servlet.http.HttpSession; import org.apache.commons.codec.binary.Base64; -import org.gcube.application.framework.core.session.ASLSession; -import org.gcube.application.framework.core.session.SessionManager; import org.gcube.common.authorization.client.exceptions.ObjectNotFound; import org.gcube.common.authorization.library.provider.UserInfo; -import org.gcube.datacatalogue.ckanutillibrary.ApplicationProfileScopePerUrlReader; import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue; import org.gcube.datacatalogue.ckanutillibrary.DataCatalogueFactory; import org.gcube.datacatalogue.ckanutillibrary.utils.SessionCatalogueAttributes; import org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods; -import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GcubeCkanDataCatalogService; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgGroupRole; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint; @@ -50,14 +46,8 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem private static final String HTTP = "http"; public static String CKANCONNECTORCONTEXT = "CkanConnectorContext"; public static String CKANCONNECTORLOGOUT = "CkanConnectorLogout"; - public static final String USERNAME_ATTRIBUTE = ScopeHelper.USERNAME_ATTRIBUTE; private static Logger logger = LoggerFactory.getLogger(GcubeCkanDataCatalogServiceImpl.class); - public final static String TEST_USER = "andrea.rossi"; - public final static String TEST_SCOPE = "/gcube/devNext/NextNext"; - public final static String TEST_MAIL = "test.user@test-com"; - public final static String TEST_SEC_TOKEN = "4d071434-021e-41ac-9aae-a3489fcf06d8-98187548"; - /** * Instanciate the ckan util library. * Since it needs the scope, we need to check if it is null or not @@ -65,11 +55,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem * @return */ public DataCatalogue getCatalogue(String discoverScope){ - - HttpSession httpSession = getThreadLocalRequest().getSession(); - ASLSession aslSession = getASLSession(httpSession); - String currentScope = aslSession.getScope(); - + String currentScope = SessionUtil.getCurrentContext(getThreadLocalRequest(), false); DataCatalogue instance = null; try{ String scopeInWhichDiscover = discoverScope != null && !discoverScope.isEmpty() ? discoverScope : currentScope; @@ -89,14 +75,11 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem logger.info("getCKanConnector [pathInfo: "+pathInfoParameter + ", query: "+queryStringParameters+"], current url is " + currentPortletUrl); try{ - // call asl session otherwise ScopeProvider.instance.get(); returns null - ASLSession aslSession = getASLSession(this.getThreadLocalRequest().getSession()); + // just get the current scope and set it into ScopeProvider... + SessionUtil.getCurrentContext(getThreadLocalRequest(), true); // retrieve scope per current portlet url - String scopePerCurrentUrl = ApplicationProfileScopePerUrlReader.getScopePerUrl(currentPortletUrl); - - // save it - this.getThreadLocalRequest().getSession().setAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL, scopePerCurrentUrl); + String scopePerCurrentUrl = SessionUtil.getScopeFromClientUrl(getThreadLocalRequest()); if(queryStringParameters!=null && Base64.isBase64(queryStringParameters.getBytes())){ byte[] valueDecoded=Base64.decodeBase64(queryStringParameters.getBytes()); @@ -133,7 +116,6 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem } //CKAN BASE URL - ASLSession session = getASLSession(this.getThreadLocalRequest().getSession()); GcoreEndpointReader ckanEndPoint = null; try{ ckanEndPoint = SessionUtil.getCkanEndPoint(this.getThreadLocalRequest().getSession(), scopePerCurrentUrl); @@ -162,12 +144,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem //GET TOKEN String gcubeTokenValue = null; - if(SessionUtil.isIntoPortal()){ - gcubeTokenValue = getGcubeSecurityToken(scopePerCurrentUrl); - }else{ - logger.warn("******** Using TEST_USER security token!!!"); - gcubeTokenValue = TEST_SEC_TOKEN; - } + gcubeTokenValue = getGcubeSecurityToken(scopePerCurrentUrl); // set the token into the CkanConnectorAccessPoint ckan.addGubeToken(gcubeTokenValue); @@ -178,7 +155,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem } // retrieve the list of VREs to whom the user belongs - List listVres = UserUtil.getListVreForUser(session.getUserEmailAddress()); + List listVres = UserUtil.getListVreForUser(SessionUtil.getCurrentUser(getThreadLocalRequest()).getEmail()); ckan.addListOfVREs(listVres); return ckan; @@ -193,8 +170,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem protected String getGcubeSecurityToken(String context) throws Exception { // ask it directly to the auth service - ASLSession session = getASLSession(this.getThreadLocalRequest().getSession()); - String username = session.getUsername(); + String username = SessionUtil.getCurrentUser(getThreadLocalRequest()).getUsername(); String token = null; try{ logger.debug("Checking if token for user " + username + " in context " + context + " already exists..."); @@ -209,32 +185,6 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem } - /** - * Gets the ASL session. - * - * @param httpSession the http session - * @return the ASL session - */ - protected ASLSession getASLSession(HttpSession httpSession) - { - String sessionID = httpSession.getId(); - String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE); - - if (user == null) { - logger.warn("****** STARTING IN TEST MODE - NO USER FOUND *******"); - //for test only - user = TEST_USER; - httpSession.setAttribute(USERNAME_ATTRIBUTE, user); - ASLSession session = SessionManager.getInstance().getASLSession(sessionID, user); - session.setScope(TEST_SCOPE); - return session; - } - else - logger.trace("user found in session "+user); - return SessionManager.getInstance().getASLSession(sessionID, user); - } - - /* (non-Javadoc) * @see org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GcubeCkanDataCatalogService#getMyRole() */ @@ -250,56 +200,50 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem }else{ HttpSession httpSession = this.getThreadLocalRequest().getSession(); - ASLSession session = getASLSession(httpSession); - String username = session.getUsername(); + String username = SessionUtil.getCurrentUser(getThreadLocalRequest()).getUsername(); + + // get the scope + String scopePerCurrentUrl = SessionUtil.getScopeFromClientUrl(getThreadLocalRequest()); + + // get key per scope + String keyPerScopeRole = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_HIGHEST_ROLE, scopePerCurrentUrl); + String keyPerScopeOrganizations = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_ORGANIZATIONS_PUBLISH_KEY, scopePerCurrentUrl); + String keyPerScopeGroups = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_GROUPS_MEMBER, scopePerCurrentUrl); + + // check into session + if(httpSession.getAttribute(keyPerScopeRole) != null){ + + toReturn = (CkanRole)httpSession.getAttribute(keyPerScopeRole); + logger.info("Found user role into session " + toReturn + " and it is going to be returned for user " + username); - // check if session expired - if(username.equals(TEST_USER)){ - logger.warn("Session expired, returning " + toReturn); }else{ - // get the scope - String scopePerCurrentUrl = (String)this.getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL); + try{ + GroupManager gm = new LiferayGroupManager(); + String groupName = gm.getGroup(gm.getGroupIdFromInfrastructureScope(scopePerCurrentUrl)).getGroupName(); - // get key per scope - String keyPerScopeRole = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_HIGHEST_ROLE, scopePerCurrentUrl); - String keyPerScopeOrganizations = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_ORGANIZATIONS_PUBLISH_KEY, scopePerCurrentUrl); - String keyPerScopeGroups = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_GROUPS_MEMBER, scopePerCurrentUrl); + // we build up also a list that keeps track of the scopes (orgs) in which the user has at least role EDITOR + List orgsInWhichAtLeastEditorRole = new ArrayList(); + toReturn = UserUtil.getHighestRole(scopePerCurrentUrl, username, groupName, this, orgsInWhichAtLeastEditorRole); - // check into session - if(httpSession.getAttribute(keyPerScopeRole) != null){ + // put role in session + httpSession.setAttribute(keyPerScopeRole, toReturn); + logger.info("Set role " + toReturn + " into session for user " + username); - toReturn = (CkanRole)httpSession.getAttribute(keyPerScopeRole); - logger.info("Found user role into session " + toReturn + " and it is going to be returned for user " + username); - - }else{ - - try{ - GroupManager gm = new LiferayGroupManager(); - String groupName = gm.getGroup(gm.getGroupIdFromInfrastructureScope(scopePerCurrentUrl)).getGroupName(); - - // we build up also a list that keeps track of the scopes (orgs) in which the user has at least role EDITOR - List orgsInWhichAtLeastEditorRole = new ArrayList(); - toReturn = UserUtil.getHighestRole(scopePerCurrentUrl, username, groupName, this, orgsInWhichAtLeastEditorRole); - - // put role in session - httpSession.setAttribute(keyPerScopeRole, toReturn); - logger.info("Set role " + toReturn + " into session for user " + username); - - // if he is an admin/editor preload: - // 1) organizations in which he can publish (the widget will find these info in session) - // 2) the list of groups - if(toReturn.equals(CkanRole.ADMIN) || toReturn.equals(CkanRole.EDITOR)){ - httpSession.setAttribute(keyPerScopeOrganizations, orgsInWhichAtLeastEditorRole); - httpSession.setAttribute(keyPerScopeGroups, fetchUserGroups(scopePerCurrentUrl, username)); - } - }catch(Exception e){ - logger.error("Error while retreving roles... returning " + toReturn, e); + // if he is an admin/editor preload: + // 1) organizations in which he can publish (the widget will find these info in session) + // 2) the list of groups + if(toReturn.equals(CkanRole.ADMIN) || toReturn.equals(CkanRole.EDITOR)){ + httpSession.setAttribute(keyPerScopeOrganizations, orgsInWhichAtLeastEditorRole); + httpSession.setAttribute(keyPerScopeGroups, fetchUserGroups(scopePerCurrentUrl, username)); } + }catch(Exception e){ + logger.error("Error while retreving roles... returning " + toReturn, e); } } } + // return the role return toReturn; } @@ -340,12 +284,10 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem @Override public String logoutURIFromCkan() { - HttpSession httpSession = this.getThreadLocalRequest().getSession(); - ASLSession session = getASLSession(httpSession); - String username = session.getUsername(); + String username = SessionUtil.getCurrentUser(getThreadLocalRequest()).getUsername(); // get the scope from session - String scopePerCurrentUrl = (String)this.getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL); + String scopePerCurrentUrl = SessionUtil.getScopeFromClientUrl(getThreadLocalRequest()); CkanConnectorAccessPoint ckanAP = SessionUtil.getCkanAccessPoint(this.getThreadLocalRequest().getSession(), scopePerCurrentUrl); logger.info("Logout from CKAN for: "+username +" by token: "+ckanAP.getGcubeTokenValue()); @@ -366,11 +308,16 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem public String logoutFromCkanURL() { HttpSession httpSession = this.getThreadLocalRequest().getSession(); - ASLSession session = getASLSession(httpSession); - String username = session.getUsername(); + String username = SessionUtil.getCurrentUser(getThreadLocalRequest()).getUsername(); + + if(username == null){ + logger.warn("User is null"); + return null; + } + logger.info("Getting CKAN Logout URL..."); - String scopePerCurrentUrl = (String) this.getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL); + String scopePerCurrentUrl = SessionUtil.getScopeFromClientUrl(getThreadLocalRequest()); CkanConnectorAccessPoint ckanAP = SessionUtil.getCkanAccessPoint(httpSession, scopePerCurrentUrl); // String token = getGcubeSecurityToken(); logger.info("Logout from CKAN for: "+username ); @@ -461,38 +408,35 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem }else{ HttpSession httpSession = this.getThreadLocalRequest().getSession(); - ASLSession session = getASLSession(httpSession); - String username = session.getUsername(); + String username = SessionUtil.getCurrentUser(getThreadLocalRequest()).getUsername(); // retrieve scope per current portlet url - String scopePerCurrentUrl = (String)this.getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL); + String scopePerCurrentUrl = SessionUtil.getScopeFromClientUrl(getThreadLocalRequest()); String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_ORGS_USER_KEY, scopePerCurrentUrl); - if(!username.equals(TEST_USER)){ - - // check if the aslsession already has such information - if(httpSession.getAttribute(keyPerScope) != null){ - toReturn = (List) httpSession.getAttribute(keyPerScope); - logger.debug("List of organizations was into the session " + toReturn); - }else{ - logger.debug("Organizations list wasn't into session, retrieving them"); - DataCatalogue catalogue = getCatalogue(scopePerCurrentUrl); - List organizations = catalogue.getOrganizationsByUser(username); - String apiKey = catalogue.getApiKeyFromUsername(username); - for (CkanOrganization ckanOrganization : organizations) { - String role = catalogue.getRoleOfUserInOrganization(username, ckanOrganization.getName(), apiKey); - BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole(ckanOrganization.getTitle(), "/organization/" + ckanOrganization.getName(), CkanRole.valueOf(role.toUpperCase())); - toReturn.add(org); - } - logger.debug("List of organizations to return for user " + username + " is " + toReturn); - httpSession.setAttribute(keyPerScope, toReturn); + // check if the aslsession already has such information + if(httpSession.getAttribute(keyPerScope) != null){ + toReturn = (List) httpSession.getAttribute(keyPerScope); + logger.debug("List of organizations was into the session " + toReturn); + }else{ + logger.debug("Organizations list wasn't into session, retrieving them"); + DataCatalogue catalogue = getCatalogue(scopePerCurrentUrl); + List organizations = catalogue.getOrganizationsByUser(username); + String apiKey = catalogue.getApiKeyFromUsername(username); + for (CkanOrganization ckanOrganization : organizations) { + String role = catalogue.getRoleOfUserInOrganization(username, ckanOrganization.getName(), apiKey); + BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole(ckanOrganization.getTitle(), "/organization/" + ckanOrganization.getName(), CkanRole.valueOf(role.toUpperCase())); + toReturn.add(org); } + logger.debug("List of organizations to return for user " + username + " is " + toReturn); + httpSession.setAttribute(keyPerScope, toReturn); + } } return toReturn; } - + @Override public List getCkanGroupsNamesAndUrlsForUser() { @@ -506,34 +450,31 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem }else{ - HttpSession httpSession = this.getThreadLocalRequest().getSession(); - ASLSession session = getASLSession(httpSession); - String username = session.getUsername(); + HttpSession httpSession = getThreadLocalRequest().getSession(); + String username = SessionUtil.getCurrentUser(getThreadLocalRequest()).getUsername(); // retrieve scope per current portlet url - String scopePerCurrentUrl = (String)this.getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL); + String scopePerCurrentUrl = SessionUtil.getScopeFromClientUrl(getThreadLocalRequest()); String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_GROUPS_USER_KEY, scopePerCurrentUrl); - if(!username.equals(TEST_USER)){ - - // check if the aslsession already has such information - if(httpSession.getAttribute(keyPerScope) != null){ - toReturn = (List) httpSession.getAttribute(keyPerScope); - logger.debug("List of groups was into the session " + toReturn); - }else{ - logger.debug("Groups list wasn't into session, retrieving them"); - DataCatalogue catalogue = getCatalogue(scopePerCurrentUrl); - List groups = catalogue.getGroupsByUser(username); - String apiKey = catalogue.getApiKeyFromUsername(username); - for (CkanGroup ckanGroup : groups) { - String role = catalogue.getRoleOfUserInGroup(username, ckanGroup.getName(), apiKey); - BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole(ckanGroup.getTitle(), "/group/" + ckanGroup.getName(), CkanRole.valueOf(role.toUpperCase())); - toReturn.add(org); - } - logger.debug("List of organizations to return for user " + username + " is " + toReturn); - httpSession.setAttribute(keyPerScope, toReturn); + // check if the aslsession already has such information + if(httpSession.getAttribute(keyPerScope) != null){ + toReturn = (List) httpSession.getAttribute(keyPerScope); + logger.debug("List of groups was into the session " + toReturn); + }else{ + logger.debug("Groups list wasn't into session, retrieving them"); + DataCatalogue catalogue = getCatalogue(scopePerCurrentUrl); + List groups = catalogue.getGroupsByUser(username); + String apiKey = catalogue.getApiKeyFromUsername(username); + for (CkanGroup ckanGroup : groups) { + String role = catalogue.getRoleOfUserInGroup(username, ckanGroup.getName(), apiKey); + BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole(ckanGroup.getTitle(), "/group/" + ckanGroup.getName(), CkanRole.valueOf(role.toUpperCase())); + toReturn.add(org); } + logger.debug("List of organizations to return for user " + username + " is " + toReturn); + httpSession.setAttribute(keyPerScope, toReturn); } + } return toReturn; @@ -550,11 +491,13 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem }else{ - HttpSession httpSession = this.getThreadLocalRequest().getSession(); - ASLSession session = getASLSession(httpSession); - String username = session.getUsername(); - return username.equals(TEST_USER); - + String username = null; + try{ + username = SessionUtil.getCurrentUser(getThreadLocalRequest()).getUsername(); + }catch(Exception e){ + logger.warn("Maybe there is no user "); + } + return username == null || username.isEmpty(); } } } diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/SessionUtil.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/SessionUtil.java index 94bfda7..9fff3be 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/SessionUtil.java @@ -3,9 +3,19 @@ */ package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; +import org.gcube.common.portal.PortalContext; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.datacatalogue.ckanutillibrary.ApplicationProfileScopePerUrlReader; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint; +import org.gcube.vomanagement.usermanagement.GroupManager; +import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; +import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; +import org.gcube.vomanagement.usermanagement.model.GCubeGroup; +import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,7 +32,7 @@ public class SessionUtil { public static final String CKAN_END_POINT = "CKAN_END_POINT"; public static final String CKAN_ACCESS_POINT = "CKAN_ACCESS_POINT"; - + public static final String GCUBE_REQUEST_URL = "gcube-request-url"; private static Logger logger = LoggerFactory.getLogger(SessionUtil.class); /** @@ -97,4 +107,103 @@ public class SessionUtil { String key = getKeyForSession(CKAN_ACCESS_POINT, scope); return (CkanConnectorAccessPoint) session.getAttribute(key); } + + /** + * Get the scope in which ckan information needs to be discovered from the url + * @param httpServletRequest + * @return + */ + public static String getScopeFromClientUrl(HttpServletRequest httpServletRequest){ + + if(httpServletRequest == null) + throw new IllegalArgumentException("HttpServletRequest is null!"); + + String scopeToReturn = null; + try{ + String clientUrl = getCurrentClientUrl(httpServletRequest).split("\\?")[0]; + logger.debug("Client url is " + clientUrl); + + // check if this information is in session, otherwise set it and return + HttpSession session = httpServletRequest.getSession(); + + if((scopeToReturn = (String) session.getAttribute(clientUrl)) != null){ + logger.debug("Scope to return is " + scopeToReturn); + }else{ + // ask to the ckan library and set it + scopeToReturn = ApplicationProfileScopePerUrlReader.getScopePerUrl(clientUrl); + logger.debug("Scope to return is " + scopeToReturn); + session.setAttribute(clientUrl, scopeToReturn); + } + }catch(Exception e){ + scopeToReturn = getCurrentContext(httpServletRequest, false); + logger.warn("Failed to determine the scope from the client url, returning the current one: " + scopeToReturn); + } + return scopeToReturn; + } + + /** + * Needed to get the url of the client + * @param httpServletRequest the httpServletRequest object + * @return the instance of the user + * @see the url at client side + */ + public static String getCurrentClientUrl(HttpServletRequest httpServletRequest) { + if(httpServletRequest == null) + throw new IllegalArgumentException("HttpServletRequest is null!"); + + return httpServletRequest.getHeader(GCUBE_REQUEST_URL); + } + + /** + * Retrieve the current user by using the portal manager + * @return a GcubeUser object + */ + public static GCubeUser getCurrentUser(HttpServletRequest request){ + + if(request == null) + throw new IllegalArgumentException("HttpServletRequest is null!"); + + PortalContext pContext = PortalContext.getConfiguration(); + GCubeUser user = pContext.getCurrentUser(request); + logger.debug("Returning user " + user); + return user; + } + + /** + * Retrieve the current scope by using the portal manager + * @param b + * @return a GcubeUser object + */ + public static String getCurrentContext(HttpServletRequest request, boolean setInThread){ + + if(request == null) + throw new IllegalArgumentException("HttpServletRequest is null!"); + + PortalContext pContext = PortalContext.getConfiguration(); + String context = pContext.getCurrentScope(request); + logger.debug("Returning context " + context); + + if(context != null && setInThread) + ScopeProvider.instance.set(context); + + return context; + } + + /** + * Retrieve the group given the scope + * @param scope + * @return + * @throws UserManagementSystemException + * @throws GroupRetrievalFault + */ + public static GCubeGroup getGroupFromScope(String scope) throws UserManagementSystemException, GroupRetrievalFault{ + + if(scope == null || scope.isEmpty()) + throw new IllegalArgumentException("Scope is missing here!!"); + + GroupManager gm = new LiferayGroupManager(); + long groupId = gm.getGroupIdFromInfrastructureScope(scope); + return gm.getGroup(groupId); + + } } diff --git a/src/main/resources/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/GCubeCkanDataCatalog.gwt.xml b/src/main/resources/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/GCubeCkanDataCatalog.gwt.xml deleted file mode 100644 index 680fe1e..0000000 --- a/src/main/resources/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/GCubeCkanDataCatalog.gwt.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -