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
This commit is contained in:
parent
f53c8d0c3b
commit
4f85011097
|
@ -108,7 +108,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
||||||
logger.info("List of organizations was into session " + orgsName);
|
logger.info("List of organizations was into session " + orgsName);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
String gatewayURL = GenericUtils.getCurrentClientUrl(getThreadLocalRequest());
|
String gatewayURL = GenericUtils.getGatewayClientHostname(getThreadLocalRequest());
|
||||||
logger.info("The Gateway URL is: "+gatewayURL);
|
logger.info("The Gateway URL is: "+gatewayURL);
|
||||||
CatalogueRoleManager.getHighestRole(scope, username, GenericUtils.getGroupFromScope(scope).getGroupName(), this, orgsName, gatewayURL);
|
CatalogueRoleManager.getHighestRole(scope, username, GenericUtils.getGroupFromScope(scope).getGroupName(), this, orgsName, gatewayURL);
|
||||||
httpSession.setAttribute(keyPerScope, orgsName);
|
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
|
// 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>();
|
List<OrganizationBean> orgsInWhichAtLeastEditorRole = new ArrayList<OrganizationBean>();
|
||||||
String gatewayURL = GenericUtils.getCurrentClientUrl(getThreadLocalRequest());
|
String gatewayURL = GenericUtils.getGatewayClientHostname(getThreadLocalRequest());
|
||||||
logger.info("The Gateway URL is: "+gatewayURL);
|
logger.info("The Gateway URL is: "+gatewayURL);
|
||||||
role = CatalogueRoleManager.getHighestRole(scopePerCurrentUrl, username, groupName, this, orgsInWhichAtLeastEditorRole, gatewayURL);
|
role = CatalogueRoleManager.getHighestRole(scopePerCurrentUrl, username, groupName, this, orgsInWhichAtLeastEditorRole, gatewayURL);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils;
|
package org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -57,17 +58,20 @@ public class CatalogueRoleManager {
|
||||||
// retrieve current group id
|
// retrieve current group id
|
||||||
long currentGroupId = groupManager.getGroupIdFromInfrastructureScope(currentScope);
|
long currentGroupId = groupManager.getGroupIdFromInfrastructureScope(currentScope);
|
||||||
|
|
||||||
logger.debug("Group id is " + currentGroupId + " and scope is " + currentScope);
|
logger.debug("Group id is " + currentGroupId + " and scope is " + currentScope + "and gateway is "+gatewayHostname);
|
||||||
|
|
||||||
// retrieve the flat list of organizations for the current user
|
|
||||||
//List<GCubeGroup> groups = groupManager.listGroupsByUser(userid);
|
|
||||||
|
|
||||||
|
Set<GCubeGroup> groups;
|
||||||
|
if(gatewayHostname!=null && !gatewayHostname.isEmpty()) {
|
||||||
// retrieve the list of organizations for the current user filtered for gateway
|
// retrieve the list of organizations for the current user filtered for gateway
|
||||||
Set<GCubeGroup> groups = groupManager.listGroupsByUserAndSite(userid, gatewayHostname);
|
groups = groupManager.listGroupsByUserAndSite(userid, gatewayHostname);
|
||||||
|
|
||||||
for (GCubeGroup gCubeGroup : groups) {
|
for (GCubeGroup gCubeGroup : groups) {
|
||||||
logger.info("Found group filter per "+gatewayHostname+": "+gCubeGroup.toString());
|
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)
|
// root (so check into the root, the VOs and the VRES)
|
||||||
if(groupManager.isRootVO(currentGroupId)){
|
if(groupManager.isRootVO(currentGroupId)){
|
||||||
|
|
|
@ -2,6 +2,8 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils;
|
||||||
|
|
||||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -25,7 +27,8 @@ import com.liferay.portal.kernel.log.Log;
|
||||||
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
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)
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||||
*/
|
*/
|
||||||
public class GenericUtils {
|
public class GenericUtils {
|
||||||
|
@ -36,9 +39,11 @@ public class GenericUtils {
|
||||||
public static final String GCUBE_REQUEST_URL = "gcube-request-url";
|
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, ...)
|
* @param organizationName (prevre, devvre, ...)
|
||||||
* @return the scope of the infrastructure
|
* @return the scope of the infrastructure
|
||||||
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
public static String retrieveScopeFromOrganizationName(String organizationName) throws 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
|
* First check to retrieve the token, else create it.
|
||||||
* @param username
|
*
|
||||||
* @param context
|
* @param username the username
|
||||||
|
* @param context the context
|
||||||
* @return the user token for the context
|
* @return the user token for the context
|
||||||
*/
|
*/
|
||||||
public static String tryGetElseCreateToken(String username, String 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
|
* Get the scope in which ckan information needs to be discovered from the url.
|
||||||
* @param httpServletRequest
|
*
|
||||||
* @return
|
* @param httpServletRequest the http servlet request
|
||||||
|
* @return the scope from client url
|
||||||
*/
|
*/
|
||||||
public static String getScopeFromClientUrl(HttpServletRequest httpServletRequest){
|
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
|
* @param httpServletRequest the httpServletRequest object
|
||||||
* @return the instance of the user
|
* @return the instance of the user
|
||||||
* @see the url at client side
|
* @see the url at client side
|
||||||
|
@ -121,8 +129,33 @@ public class GenericUtils {
|
||||||
return httpServletRequest.getHeader(GCUBE_REQUEST_URL);
|
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
|
* @return a GcubeUser object
|
||||||
*/
|
*/
|
||||||
public static GCubeUser getCurrentUser(HttpServletRequest request){
|
public static GCubeUser getCurrentUser(HttpServletRequest request){
|
||||||
|
@ -137,8 +170,10 @@ public class GenericUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the current scope by using the portal manager
|
* Retrieve the current scope by using the portal manager.
|
||||||
* @param b
|
*
|
||||||
|
* @param request the request
|
||||||
|
* @param setInThread the set in thread
|
||||||
* @return a GcubeUser object
|
* @return a GcubeUser object
|
||||||
*/
|
*/
|
||||||
public static String getCurrentContext(HttpServletRequest request, boolean setInThread){
|
public static String getCurrentContext(HttpServletRequest request, boolean setInThread){
|
||||||
|
@ -157,8 +192,10 @@ public class GenericUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the current token by using the portal manager
|
* Retrieve the current token by using the portal manager.
|
||||||
* @param b
|
*
|
||||||
|
* @param request the request
|
||||||
|
* @param setInThread the set in thread
|
||||||
* @return a GcubeUser object
|
* @return a GcubeUser object
|
||||||
*/
|
*/
|
||||||
public static String getCurrentToken(HttpServletRequest request, boolean setInThread){
|
public static String getCurrentToken(HttpServletRequest request, boolean setInThread){
|
||||||
|
@ -177,11 +214,12 @@ public class GenericUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the group given the scope
|
* Retrieve the group given the scope.
|
||||||
* @param scope
|
*
|
||||||
* @return
|
* @param scope the scope
|
||||||
* @throws UserManagementSystemException
|
* @return the group from scope
|
||||||
* @throws GroupRetrievalFault
|
* @throws UserManagementSystemException the user management system exception
|
||||||
|
* @throws GroupRetrievalFault the group retrieval fault
|
||||||
*/
|
*/
|
||||||
public static GCubeGroup getGroupFromScope(String scope) throws UserManagementSystemException, GroupRetrievalFault{
|
public static GCubeGroup getGroupFromScope(String scope) throws UserManagementSystemException, GroupRetrievalFault{
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue