|
|
|
@ -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{
|
|
|
|
|
|
|
|
|
|