Added logic to manage pathInfo and query in order to perform redirect to right URI from ckan-connector
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@129181 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
2a6eb5065e
commit
67faf855c2
|
@ -1,5 +1,5 @@
|
|||
eclipse.preferences.version=1
|
||||
jarsExcludedFromWebInfLib=
|
||||
lastWarOutDir=/home/costantino/workspace/gcube-ckan-datacatalog/target/gcube-ckan-datacatalog-1.0.0-SNAPSHOT
|
||||
lastWarOutDir=/home/francesco-mangiacrapa/wseclipseluna/gcube-ckan-datacatalog-TRUNK-1.0.0-SNAPSHOT/target/gcube-ckan-datacatalog-1.0.0-SNAPSHOT
|
||||
warSrcDir=src/main/webapp
|
||||
warSrcDirIsOutput=false
|
||||
|
|
5
pom.xml
5
pom.xml
|
@ -132,6 +132,11 @@
|
|||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- LOGGER -->
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
|
|
|
@ -20,7 +20,8 @@ public class GCubeCkanDataCatalog implements EntryPoint {
|
|||
public static final GcubeCkanDataCatalogServiceAsync service = GWT.create(GcubeCkanDataCatalogService.class);
|
||||
private final String DIV_PORTLET_ID = "gCubeCkanDataCatalog";
|
||||
private CkanEventHandlerManager eventManager = new CkanEventHandlerManager();
|
||||
|
||||
public static final String GET_PATH_PARAMETER = "path";
|
||||
public static final String GET_QUERY_PARAMETER = "query";
|
||||
|
||||
/**
|
||||
* This is the entry point method.
|
||||
|
|
|
@ -7,21 +7,36 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
|
|||
|
||||
/**
|
||||
* The client side stub for the RPC service.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Jun 20, 2016
|
||||
*/
|
||||
@RemoteServiceRelativePath("ckandatacatalogue")
|
||||
public interface GcubeCkanDataCatalogService extends RemoteService {
|
||||
|
||||
String getCKanConnector() throws Exception;
|
||||
|
||||
/**
|
||||
* @return
|
||||
* Gets the c kan connector.
|
||||
*
|
||||
* @param pathInfoParameters the path info parameters
|
||||
* @param queryStringParameters the query string parameters
|
||||
* @return the c kan connector
|
||||
* @throws Exception
|
||||
*/
|
||||
CkanRole getMyRole() throws Exception;
|
||||
|
||||
String getCKanConnector(
|
||||
String pathInfoParameters, String queryStringParameters) throws Exception;
|
||||
|
||||
/**
|
||||
* Asks who is the current user
|
||||
* @return
|
||||
* Gets the my role.
|
||||
*
|
||||
* @return the my role
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
CkanRole getMyRole() throws Exception;
|
||||
|
||||
/**
|
||||
* Asks who is the current user.
|
||||
*
|
||||
* @return the user
|
||||
*/
|
||||
String getUser();
|
||||
}
|
||||
|
|
|
@ -7,16 +7,40 @@ import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanRole;
|
|||
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
|
||||
|
||||
/**
|
||||
* The Interface GcubeCkanDataCatalogServiceAsync.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Apr 12, 2016
|
||||
* Jun 20, 2016
|
||||
*/
|
||||
public interface GcubeCkanDataCatalogServiceAsync {
|
||||
|
||||
void getCKanConnector(AsyncCallback<String> callback);
|
||||
|
||||
/**
|
||||
* Gets the my role.
|
||||
*
|
||||
* @param callback the callback
|
||||
* @return the my role
|
||||
*/
|
||||
void getMyRole(AsyncCallback<CkanRole> callback);
|
||||
|
||||
/**
|
||||
* Gets the user.
|
||||
*
|
||||
* @param callback the callback
|
||||
* @return the user
|
||||
*/
|
||||
void getUser(AsyncCallback<String> callback);
|
||||
|
||||
/**
|
||||
* Gets the c kan connector.
|
||||
*
|
||||
* @param queryStringParameters the query string parameters
|
||||
* @param pathInfoParameters the path info parameters
|
||||
* @param callback the callback
|
||||
* @return the c kan connector
|
||||
*/
|
||||
void getCKanConnector(
|
||||
String queryStringParameters, String pathInfoParameters,
|
||||
AsyncCallback<String> callback);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import com.google.gwt.user.client.ui.ScrollPanel;
|
|||
*/
|
||||
public class GCubeCkanDataCatalogPanel extends BaseViewTemplate{
|
||||
|
||||
|
||||
private CkanMetadataManagementPanel managementPanel;
|
||||
private ScrollPanel centerScrollable = new ScrollPanel();
|
||||
private CkanFramePanel ckanFramePanel = new CkanFramePanel();
|
||||
|
@ -45,7 +46,10 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate{
|
|||
this.eventBus = eventManager;
|
||||
managementPanel = new CkanMetadataManagementPanel(eventBus);
|
||||
initPanel();
|
||||
GCubeCkanDataCatalog.service.getCKanConnector(new AsyncCallback<String>() {
|
||||
final String pathParameter = Window.Location.getParameter(GCubeCkanDataCatalog.GET_PATH_PARAMETER);
|
||||
final String queryParameter = Window.Location.getParameter(GCubeCkanDataCatalog.GET_QUERY_PARAMETER);
|
||||
|
||||
GCubeCkanDataCatalog.service.getCKanConnector(pathParameter, queryParameter, new AsyncCallback<String>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(String ckanUrlConnector) {
|
||||
|
|
|
@ -7,6 +7,7 @@ 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.scope.api.ScopeProvider;
|
||||
|
@ -58,6 +59,9 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
// ckan utils methods
|
||||
private CKanUtilsImpl instance;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.servlet.GenericServlet#init()
|
||||
*/
|
||||
@Override
|
||||
public void init(){
|
||||
|
||||
|
@ -70,44 +74,22 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current user's token
|
||||
* @return String the ckan user's token
|
||||
*/
|
||||
private String getUserCKanTokenFromSession(){
|
||||
|
||||
HttpSession httpSession = this.getThreadLocalRequest().getSession();
|
||||
ASLSession session = getASLSession(httpSession);
|
||||
String username = session.getUsername();
|
||||
logger.debug("User in session is " + username);
|
||||
|
||||
String token = null;
|
||||
if(this.getThreadLocalRequest().getSession().getAttribute(CKAN_TOKEN_KEY) != null)
|
||||
token = (String)this.getThreadLocalRequest().getSession().getAttribute(CKAN_TOKEN_KEY);
|
||||
else{
|
||||
|
||||
token = instance.getApiKeyFromUsername(username);
|
||||
this.getThreadLocalRequest().getSession().setAttribute(CKAN_TOKEN_KEY, token);
|
||||
logger.debug("Ckan token has been set for user " + username);
|
||||
}
|
||||
|
||||
logger.debug("Found ckan token " + token + " for user " + username);
|
||||
return token;
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GcubeCkanDataCatalogService#getCKanConnector()
|
||||
* @see org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GcubeCkanDataCatalogService#getCKanConnector(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public String getCKanConnector() throws Exception{
|
||||
logger.trace("getCKanConnector...");
|
||||
public String getCKanConnector(String pathInfoParameters, String queryStringParameters) throws Exception {
|
||||
logger.info("getCKanConnector [pathInfo: "+pathInfoParameters + ", query: "+queryStringParameters+"]");
|
||||
if(Base64.isBase64(queryStringParameters.getBytes())){
|
||||
byte[] valueDecoded=Base64.decodeBase64(queryStringParameters.getBytes());
|
||||
queryStringParameters = new String(valueDecoded);
|
||||
logger.info("queryStringParameters detected like Base64 and decoded like: "+queryStringParameters);
|
||||
}
|
||||
|
||||
try{
|
||||
String ckanContext = getServletContext().getInitParameter(CKANCONNECTORCONTEXT);
|
||||
logger.debug(CKANCONNECTORCONTEXT + " is: "+ckanContext);
|
||||
String ckanHideHeader = getServletContext().getInitParameter(CKANHIDEHEADER);
|
||||
logger.debug(CKANHIDEHEADER + " is: "+ckanHideHeader);
|
||||
|
||||
ASLSession session = getASLSession(this.getThreadLocalRequest().getSession());
|
||||
GcoreEndpointReader ckanEndPoint = SessionUtil.getCkanEndPoint(session);
|
||||
|
@ -122,9 +104,11 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
ckanConnectorUri+="?"+GCUBE_TOKEN+"="+getGcubeSecurityToken();
|
||||
}else{
|
||||
logger.warn("******** Using TEST_USER security token!!!");
|
||||
ckanConnectorUri+="?"+GCUBE_TOKEN+"="+TEST_SEC_TOKEN +"&" +ckanHideHeader;
|
||||
ckanConnectorUri+="?"+GCUBE_TOKEN+"="+TEST_SEC_TOKEN;
|
||||
}
|
||||
ckanConnectorUri+="&" +ckanHideHeader; //added query string to hide header from portal
|
||||
|
||||
String fullPath = getCkanConnectorParameters(pathInfoParameters, queryStringParameters);
|
||||
ckanConnectorUri += ckanConnectorUri+fullPath;
|
||||
logger.info("returning ckanConnectorUri: "+ckanConnectorUri);
|
||||
return ckanConnectorUri;
|
||||
// return "http://ckan-d-d4s.d4science.org";
|
||||
|
@ -135,6 +119,33 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the ckan connector parameters.
|
||||
*
|
||||
* @param pathInfoParameters the path info parameters
|
||||
* @param queryStringParameters the query string parameters
|
||||
* @return the ckan connector parameters
|
||||
*/
|
||||
private String getCkanConnectorParameters(String pathInfoParameters, String queryStringParameters) {
|
||||
|
||||
String ckanHideHeader = getServletContext().getInitParameter(CKANHIDEHEADER);
|
||||
logger.debug(CKANHIDEHEADER + " is: "+ckanHideHeader);
|
||||
|
||||
String pathInfo = "";
|
||||
if(pathInfoParameters!=null && !pathInfoParameters.isEmpty()){
|
||||
pathInfo="/"+pathInfoParameters;
|
||||
}
|
||||
|
||||
String queryString ="";
|
||||
if(queryStringParameters!=null && !queryStringParameters.isEmpty()){
|
||||
queryString = "?"+queryStringParameters;
|
||||
}
|
||||
|
||||
queryString = queryString.isEmpty()?"?"+ckanHideHeader:"&"+ckanHideHeader;
|
||||
return pathInfo+queryString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the gcube security token.
|
||||
*
|
||||
|
@ -214,6 +225,10 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
|
||||
try{
|
||||
|
||||
if(!SessionUtil.isIntoPortal()){
|
||||
logger.warn("OUT FROM PORTAL DETECTED RETURNING ROLE: "+CkanRole.ADMIN);
|
||||
return CkanRole.ADMIN;
|
||||
}
|
||||
// first of all, check if the user is a sysadmin in the catalog (in this case he can do everything)
|
||||
boolean isSysAdmin = instance.isSysAdmin(username, getUserCKanTokenFromSession());
|
||||
|
||||
|
@ -266,9 +281,10 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
}
|
||||
|
||||
/**
|
||||
* Map between roles
|
||||
* @param mainRole
|
||||
* @return
|
||||
* Map between roles.
|
||||
*
|
||||
* @param mainRole the main role
|
||||
* @return the ckan role
|
||||
*/
|
||||
private CkanRole reMapRole(CkanRolesIntoLiferay mainRole) {
|
||||
switch(mainRole){
|
||||
|
@ -279,6 +295,9 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GcubeCkanDataCatalogService#getUser()
|
||||
*/
|
||||
@Override
|
||||
public String getUser() {
|
||||
|
||||
|
@ -288,4 +307,31 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
return getASLSession(httpSession).getUsername();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current user's token.
|
||||
*
|
||||
* @return String the ckan user's token
|
||||
*/
|
||||
private String getUserCKanTokenFromSession(){
|
||||
|
||||
HttpSession httpSession = this.getThreadLocalRequest().getSession();
|
||||
ASLSession session = getASLSession(httpSession);
|
||||
String username = session.getUsername();
|
||||
logger.debug("User in session is " + username);
|
||||
|
||||
String token = null;
|
||||
if(this.getThreadLocalRequest().getSession().getAttribute(CKAN_TOKEN_KEY) != null)
|
||||
token = (String)this.getThreadLocalRequest().getSession().getAttribute(CKAN_TOKEN_KEY);
|
||||
else{
|
||||
|
||||
token = instance.getApiKeyFromUsername(username);
|
||||
this.getThreadLocalRequest().getSession().setAttribute(CKAN_TOKEN_KEY, token);
|
||||
logger.debug("Ckan token has been set for user " + username);
|
||||
}
|
||||
|
||||
logger.debug("Found ckan token " + token + " for user " + username);
|
||||
return token;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,9 +50,8 @@ public class SessionUtil {
|
|||
try {
|
||||
UserLocalServiceUtil.getService();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
logger.trace("Development Mode ON");
|
||||
}catch (Exception ex) {
|
||||
logger.debug("Development Mode ON");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,14 +7,15 @@
|
|||
|
||||
<context-param>
|
||||
<param-name>CkanConnectorContext</param-name>
|
||||
<!-- <param-value>/connect</param-value> -->
|
||||
<param-value>/gcube/service/connect</param-value>
|
||||
<description>ckan connector context</description>
|
||||
</context-param>
|
||||
|
||||
<context-param>
|
||||
<param-name>CkanHideHeader</param-name>
|
||||
<!-- <param-value>/connect</param-value> -->
|
||||
<param-value>hh=true</param-value>
|
||||
<description>Used like GET parameter in order to hide header section of CKAN template from gCube Portal</description>
|
||||
</context-param>
|
||||
|
||||
<!-- Servlets -->
|
||||
|
|
Loading…
Reference in New Issue