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
|
eclipse.preferences.version=1
|
||||||
jarsExcludedFromWebInfLib=
|
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
|
warSrcDir=src/main/webapp
|
||||||
warSrcDirIsOutput=false
|
warSrcDirIsOutput=false
|
||||||
|
|
5
pom.xml
5
pom.xml
|
@ -132,6 +132,11 @@
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-codec</groupId>
|
||||||
|
<artifactId>commons-codec</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- LOGGER -->
|
<!-- LOGGER -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>log4j</groupId>
|
<groupId>log4j</groupId>
|
||||||
|
|
|
@ -20,7 +20,8 @@ public class GCubeCkanDataCatalog implements EntryPoint {
|
||||||
public static final GcubeCkanDataCatalogServiceAsync service = GWT.create(GcubeCkanDataCatalogService.class);
|
public static final GcubeCkanDataCatalogServiceAsync service = GWT.create(GcubeCkanDataCatalogService.class);
|
||||||
private final String DIV_PORTLET_ID = "gCubeCkanDataCatalog";
|
private final String DIV_PORTLET_ID = "gCubeCkanDataCatalog";
|
||||||
private CkanEventHandlerManager eventManager = new CkanEventHandlerManager();
|
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.
|
* 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.
|
* The client side stub for the RPC service.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
|
* Jun 20, 2016
|
||||||
*/
|
*/
|
||||||
@RemoteServiceRelativePath("ckandatacatalogue")
|
@RemoteServiceRelativePath("ckandatacatalogue")
|
||||||
public interface GcubeCkanDataCatalogService extends RemoteService {
|
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
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
CkanRole getMyRole() throws Exception;
|
String getCKanConnector(
|
||||||
|
String pathInfoParameters, String queryStringParameters) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asks who is the current user
|
* Gets the my role.
|
||||||
* @return
|
*
|
||||||
|
* @return the my role
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
CkanRole getMyRole() throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asks who is the current user.
|
||||||
|
*
|
||||||
|
* @return the user
|
||||||
*/
|
*/
|
||||||
String getUser();
|
String getUser();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,16 +7,40 @@ import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanRole;
|
||||||
|
|
||||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The Interface GcubeCkanDataCatalogServiceAsync.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
* Apr 12, 2016
|
* Jun 20, 2016
|
||||||
*/
|
*/
|
||||||
public interface GcubeCkanDataCatalogServiceAsync {
|
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);
|
void getMyRole(AsyncCallback<CkanRole> callback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the user.
|
||||||
|
*
|
||||||
|
* @param callback the callback
|
||||||
|
* @return the user
|
||||||
|
*/
|
||||||
void getUser(AsyncCallback<String> callback);
|
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{
|
public class GCubeCkanDataCatalogPanel extends BaseViewTemplate{
|
||||||
|
|
||||||
|
|
||||||
private CkanMetadataManagementPanel managementPanel;
|
private CkanMetadataManagementPanel managementPanel;
|
||||||
private ScrollPanel centerScrollable = new ScrollPanel();
|
private ScrollPanel centerScrollable = new ScrollPanel();
|
||||||
private CkanFramePanel ckanFramePanel = new CkanFramePanel();
|
private CkanFramePanel ckanFramePanel = new CkanFramePanel();
|
||||||
|
@ -45,7 +46,10 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate{
|
||||||
this.eventBus = eventManager;
|
this.eventBus = eventManager;
|
||||||
managementPanel = new CkanMetadataManagementPanel(eventBus);
|
managementPanel = new CkanMetadataManagementPanel(eventBus);
|
||||||
initPanel();
|
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
|
@Override
|
||||||
public void onSuccess(String ckanUrlConnector) {
|
public void onSuccess(String ckanUrlConnector) {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||||
|
|
||||||
import javax.servlet.http.HttpSession;
|
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.ASLSession;
|
||||||
import org.gcube.application.framework.core.session.SessionManager;
|
import org.gcube.application.framework.core.session.SessionManager;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
@ -58,6 +59,9 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
||||||
// ckan utils methods
|
// ckan utils methods
|
||||||
private CKanUtilsImpl instance;
|
private CKanUtilsImpl instance;
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see javax.servlet.GenericServlet#init()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void init(){
|
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)
|
/* (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
|
@Override
|
||||||
public String getCKanConnector() throws Exception{
|
public String getCKanConnector(String pathInfoParameters, String queryStringParameters) throws Exception {
|
||||||
logger.trace("getCKanConnector...");
|
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{
|
try{
|
||||||
String ckanContext = getServletContext().getInitParameter(CKANCONNECTORCONTEXT);
|
String ckanContext = getServletContext().getInitParameter(CKANCONNECTORCONTEXT);
|
||||||
logger.debug(CKANCONNECTORCONTEXT + " is: "+ckanContext);
|
logger.debug(CKANCONNECTORCONTEXT + " is: "+ckanContext);
|
||||||
String ckanHideHeader = getServletContext().getInitParameter(CKANHIDEHEADER);
|
|
||||||
logger.debug(CKANHIDEHEADER + " is: "+ckanHideHeader);
|
|
||||||
|
|
||||||
ASLSession session = getASLSession(this.getThreadLocalRequest().getSession());
|
ASLSession session = getASLSession(this.getThreadLocalRequest().getSession());
|
||||||
GcoreEndpointReader ckanEndPoint = SessionUtil.getCkanEndPoint(session);
|
GcoreEndpointReader ckanEndPoint = SessionUtil.getCkanEndPoint(session);
|
||||||
|
@ -122,9 +104,11 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
||||||
ckanConnectorUri+="?"+GCUBE_TOKEN+"="+getGcubeSecurityToken();
|
ckanConnectorUri+="?"+GCUBE_TOKEN+"="+getGcubeSecurityToken();
|
||||||
}else{
|
}else{
|
||||||
logger.warn("******** Using TEST_USER security token!!!");
|
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);
|
logger.info("returning ckanConnectorUri: "+ckanConnectorUri);
|
||||||
return ckanConnectorUri;
|
return ckanConnectorUri;
|
||||||
// return "http://ckan-d-d4s.d4science.org";
|
// 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.
|
* Gets the gcube security token.
|
||||||
*
|
*
|
||||||
|
@ -214,6 +225,10 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
||||||
|
|
||||||
try{
|
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)
|
// 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());
|
boolean isSysAdmin = instance.isSysAdmin(username, getUserCKanTokenFromSession());
|
||||||
|
|
||||||
|
@ -266,9 +281,10 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map between roles
|
* Map between roles.
|
||||||
* @param mainRole
|
*
|
||||||
* @return
|
* @param mainRole the main role
|
||||||
|
* @return the ckan role
|
||||||
*/
|
*/
|
||||||
private CkanRole reMapRole(CkanRolesIntoLiferay mainRole) {
|
private CkanRole reMapRole(CkanRolesIntoLiferay mainRole) {
|
||||||
switch(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
|
@Override
|
||||||
public String getUser() {
|
public String getUser() {
|
||||||
|
|
||||||
|
@ -288,4 +307,31 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
||||||
return getASLSession(httpSession).getUsername();
|
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 {
|
try {
|
||||||
UserLocalServiceUtil.getService();
|
UserLocalServiceUtil.getService();
|
||||||
return true;
|
return true;
|
||||||
}
|
}catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
logger.debug("Development Mode ON");
|
||||||
logger.trace("Development Mode ON");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,14 +7,15 @@
|
||||||
|
|
||||||
<context-param>
|
<context-param>
|
||||||
<param-name>CkanConnectorContext</param-name>
|
<param-name>CkanConnectorContext</param-name>
|
||||||
<!-- <param-value>/connect</param-value> -->
|
|
||||||
<param-value>/gcube/service/connect</param-value>
|
<param-value>/gcube/service/connect</param-value>
|
||||||
|
<description>ckan connector context</description>
|
||||||
</context-param>
|
</context-param>
|
||||||
|
|
||||||
<context-param>
|
<context-param>
|
||||||
<param-name>CkanHideHeader</param-name>
|
<param-name>CkanHideHeader</param-name>
|
||||||
<!-- <param-value>/connect</param-value> -->
|
<!-- <param-value>/connect</param-value> -->
|
||||||
<param-value>hh=true</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>
|
</context-param>
|
||||||
|
|
||||||
<!-- Servlets -->
|
<!-- Servlets -->
|
||||||
|
|
Loading…
Reference in New Issue