added method getGatewayClientHostname

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@179795 82a268e6-3cf1-43bd-a215-b396298e98cf
migrate-to-catalogue-util-library_#19764
Francesco Mangiacrapa 5 years ago
parent f53c8d0c3b
commit 4f85011097

@ -108,7 +108,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
logger.info("List of organizations was into session " + orgsName);
}
else{
String gatewayURL = GenericUtils.getCurrentClientUrl(getThreadLocalRequest());
String gatewayURL = GenericUtils.getGatewayClientHostname(getThreadLocalRequest());
logger.info("The Gateway URL is: "+gatewayURL);
CatalogueRoleManager.getHighestRole(scope, username, GenericUtils.getGroupFromScope(scope).getGroupName(), this, orgsName, gatewayURL);
httpSession.setAttribute(keyPerScope, orgsName);
@ -623,7 +623,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
// we build up also a list that keeps track of the scopes (orgs) in which the user has role ADMIN/EDITOR
List<OrganizationBean> orgsInWhichAtLeastEditorRole = new ArrayList<OrganizationBean>();
String gatewayURL = GenericUtils.getCurrentClientUrl(getThreadLocalRequest());
String gatewayURL = GenericUtils.getGatewayClientHostname(getThreadLocalRequest());
logger.info("The Gateway URL is: "+gatewayURL);
role = CatalogueRoleManager.getHighestRole(scopePerCurrentUrl, username, groupName, this, orgsInWhichAtLeastEditorRole, gatewayURL);

@ -1,5 +1,6 @@
package org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -57,16 +58,19 @@ public class CatalogueRoleManager {
// retrieve current group id
long currentGroupId = groupManager.getGroupIdFromInfrastructureScope(currentScope);
logger.debug("Group id is " + currentGroupId + " and scope is " + currentScope);
// retrieve the flat list of organizations for the current user
//List<GCubeGroup> groups = groupManager.listGroupsByUser(userid);
// retrieve the list of organizations for the current user filtered for gateway
Set<GCubeGroup> groups = groupManager.listGroupsByUserAndSite(userid, gatewayHostname);
logger.debug("Group id is " + currentGroupId + " and scope is " + currentScope + "and gateway is "+gatewayHostname);
for (GCubeGroup gCubeGroup : groups) {
logger.info("Found group filter per "+gatewayHostname+": "+gCubeGroup.toString());
Set<GCubeGroup> groups;
if(gatewayHostname!=null && !gatewayHostname.isEmpty()) {
// retrieve the list of organizations for the current user filtered for gateway
groups = groupManager.listGroupsByUserAndSite(userid, gatewayHostname);
for (GCubeGroup gCubeGroup : groups) {
logger.info("Found group filter per "+gatewayHostname+": "+gCubeGroup.toString());
}
}else {
// retrieve the flat list of organizations for the current user
List<GCubeGroup> listGroups = groupManager.listGroupsByUser(userid);
groups = new HashSet<GCubeGroup>(listGroups);
}
// root (so check into the root, the VOs and the VRES)

@ -2,6 +2,8 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils;
import static org.gcube.common.authorization.client.Constants.authorizationService;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@ -25,7 +27,8 @@ import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
/**
* Util class with static methods
* Util class with static methods.
*
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class GenericUtils {
@ -36,9 +39,11 @@ public class GenericUtils {
public static final String GCUBE_REQUEST_URL = "gcube-request-url";
/**
* Given a ckan organization name retrieve the infrastructure scope
* Given a ckan organization name retrieve the infrastructure scope.
*
* @param organizationName (prevre, devvre, ...)
* @return the scope of the infrastructure
* @throws Exception the exception
*/
public static String retrieveScopeFromOrganizationName(String organizationName) throws Exception {
@ -55,9 +60,10 @@ public class GenericUtils {
}
/**
* First check to retrieve the token, else create it
* @param username
* @param context
* First check to retrieve the token, else create it.
*
* @param username the username
* @param context the context
* @return the user token for the context
*/
public static String tryGetElseCreateToken(String username, String context) {
@ -79,9 +85,10 @@ public class GenericUtils {
}
/**
* Get the scope in which ckan information needs to be discovered from the url
* @param httpServletRequest
* @return
* Get the scope in which ckan information needs to be discovered from the url.
*
* @param httpServletRequest the http servlet request
* @return the scope from client url
*/
public static String getScopeFromClientUrl(HttpServletRequest httpServletRequest){
@ -112,7 +119,8 @@ public class GenericUtils {
}
/**
* Needed to get the url of the client
* 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
@ -120,9 +128,34 @@ public class GenericUtils {
public static String getCurrentClientUrl(HttpServletRequest httpServletRequest) {
return httpServletRequest.getHeader(GCUBE_REQUEST_URL);
}
/**
* Retrieve the current user by using the portal manager
* Gets the gateway client hostname.
*
* @param httpServletRequest the http servlet request
* @return the gateway client hostname
*/
public static String getGatewayClientHostname(HttpServletRequest httpServletRequest) {
String clientURL = getCurrentClientUrl(httpServletRequest);
try {
URL gURL = new URL(clientURL);
StringBuilder theURL = new StringBuilder();
theURL.append(gURL.getProtocol());
theURL.append("://");
theURL.append(gURL.getHost());
return theURL.toString();
} catch (MalformedURLException e) {
logger.warn("Failed to determine the gateway from the client url: "+clientURL);
return null;
}
}
/**
* Retrieve the current user by using the portal manager.
*
* @param request the request
* @return a GcubeUser object
*/
public static GCubeUser getCurrentUser(HttpServletRequest request){
@ -137,8 +170,10 @@ public class GenericUtils {
}
/**
* Retrieve the current scope by using the portal manager
* @param b
* Retrieve the current scope by using the portal manager.
*
* @param request the request
* @param setInThread the set in thread
* @return a GcubeUser object
*/
public static String getCurrentContext(HttpServletRequest request, boolean setInThread){
@ -157,8 +192,10 @@ public class GenericUtils {
}
/**
* Retrieve the current token by using the portal manager
* @param b
* Retrieve the current token by using the portal manager.
*
* @param request the request
* @param setInThread the set in thread
* @return a GcubeUser object
*/
public static String getCurrentToken(HttpServletRequest request, boolean setInThread){
@ -177,11 +214,12 @@ public class GenericUtils {
}
/**
* Retrieve the group given the scope
* @param scope
* @return
* @throws UserManagementSystemException
* @throws GroupRetrievalFault
* Retrieve the group given the scope.
*
* @param scope the scope
* @return the group from scope
* @throws UserManagementSystemException the user management system exception
* @throws GroupRetrievalFault the group retrieval fault
*/
public static GCubeGroup getGroupFromScope(String scope) throws UserManagementSystemException, GroupRetrievalFault{

Loading…
Cancel
Save