3751: Create Ckan Data Catalogue Portlet
Task-Url: https://support.d4science.org/issues/3751 Added code to perfom logout during browser closing Updated and fixed CkanConnectorAccessPoint git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@129352 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
eb23d0318c
commit
7fe5e298b8
|
@ -2,6 +2,9 @@ package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server;
|
||||||
|
|
||||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -90,20 +93,10 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
||||||
logger.info("queryStringParameters detected like Base64 and decoded like: "+queryStringParameters);
|
logger.info("queryStringParameters detected like Base64 and decoded like: "+queryStringParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
String ckanContext = getServletContext().getInitParameter(CKANCONNECTORCONTEXT);
|
CkanConnectorAccessPoint ckAP = getCkanConnectorAccessPoint(pathInfoParameter, queryStringParameters);
|
||||||
logger.debug(CKANCONNECTORCONTEXT + " is: "+ckanContext);
|
SessionUtil.saveCkanAccessPoint(this.getThreadLocalRequest().getSession(), ckAP);
|
||||||
|
logger.info("Builded URI to CKAN Connector: "+ckAP.buildURI());
|
||||||
ASLSession session = getASLSession(this.getThreadLocalRequest().getSession());
|
logger.debug("returning ckanConnectorUri: "+ckAP);
|
||||||
GcoreEndpointReader ckanEndPoint = SessionUtil.getCkanEndPoint(session);
|
|
||||||
String ckanConnectorUri = ckanEndPoint.getCkanResourceEntyName();
|
|
||||||
logger.debug(ckanConnectorUri + "is : "+ckanConnectorUri);
|
|
||||||
ckanConnectorUri = ckanConnectorUri.startsWith(HTTP) && !ckanConnectorUri.startsWith(HTTPS)?ckanConnectorUri.replaceFirst(HTTP, HTTPS):ckanConnectorUri;
|
|
||||||
ckanConnectorUri = ckanConnectorUri.contains(PORT_HTTP)?ckanConnectorUri.replace(PORT_HTTP, PORT_HTTPS):ckanConnectorUri;
|
|
||||||
ckanConnectorUri+=ckanContext;
|
|
||||||
logger.debug("CKanConnector URI + Context: "+ckanConnectorUri);
|
|
||||||
logger.debug("adding parameters...");
|
|
||||||
CkanConnectorAccessPoint ckAP = getCkanConnectorAccessPoint(ckanConnectorUri, pathInfoParameter, queryStringParameters);
|
|
||||||
logger.info("returning ckanConnectorUri: "+ckAP);
|
|
||||||
return ckAP;
|
return ckAP;
|
||||||
// return "http://ckan-d-d4s.d4science.org";
|
// return "http://ckan-d-d4s.d4science.org";
|
||||||
}catch(Exception e ){
|
}catch(Exception e ){
|
||||||
|
@ -115,43 +108,42 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the ckan connector parameters.
|
* Gets the ckan connector access point.
|
||||||
*
|
*
|
||||||
* @param ckanConnectorBaseUrl the ckan connector base url
|
* @param pathInfoParameter the path info parameter
|
||||||
* @param pathInfoParameter the path info parameters
|
|
||||||
* @param queryStringParameters the query string parameters
|
* @param queryStringParameters the query string parameters
|
||||||
* @return the ckan connector parameters
|
* @return the ckan connector access point
|
||||||
*/
|
*/
|
||||||
private CkanConnectorAccessPoint getCkanConnectorAccessPoint(String ckanConnectorBaseUrl, String pathInfoParameter, String queryStringParameters) {
|
private CkanConnectorAccessPoint getCkanConnectorAccessPoint(String pathInfoParameter, String queryStringParameters) {
|
||||||
|
|
||||||
// String ckanHideHeader = getServletContext().getInitParameter(CKANHIDEHEADER);
|
|
||||||
// logger.debug(CKANHIDEHEADER + " is: "+ckanHideHeader);
|
|
||||||
|
|
||||||
|
//CKAN BASE URL
|
||||||
|
ASLSession session = getASLSession(this.getThreadLocalRequest().getSession());
|
||||||
|
GcoreEndpointReader ckanEndPoint = SessionUtil.getCkanEndPoint(session);
|
||||||
|
String ckanConnectorBaseUrl = ckanEndPoint.getCkanResourceEntyName();
|
||||||
|
ckanConnectorBaseUrl = ckanConnectorBaseUrl.startsWith(HTTP) && !ckanConnectorBaseUrl.startsWith(HTTPS)?ckanConnectorBaseUrl.replaceFirst(HTTP, HTTPS):ckanConnectorBaseUrl;
|
||||||
|
ckanConnectorBaseUrl = ckanConnectorBaseUrl.contains(PORT_HTTP)?ckanConnectorBaseUrl.replace(PORT_HTTP, PORT_HTTPS):ckanConnectorBaseUrl;
|
||||||
|
logger.debug("Base URL is: "+ckanConnectorBaseUrl);
|
||||||
CkanConnectorAccessPoint ckan = new CkanConnectorAccessPoint(ckanConnectorBaseUrl);
|
CkanConnectorAccessPoint ckan = new CkanConnectorAccessPoint(ckanConnectorBaseUrl);
|
||||||
|
|
||||||
//
|
//GET CONTEXT
|
||||||
// String pathInfo = "";
|
String ckanContext = getServletContext().getInitParameter(CKANCONNECTORCONTEXT);
|
||||||
// if(pathInfoParameter!=null && !pathInfoParameter.isEmpty()){
|
logger.debug(CKANCONNECTORCONTEXT + " is: "+ckanContext);
|
||||||
// pathInfo=pathInfoParameter.startsWith("/")?pathInfoParameter:"/"+pathInfoParameter;
|
|
||||||
// }
|
|
||||||
|
|
||||||
ckan.addPathInfo(pathInfoParameter);
|
ckanContext= ckanContext!=null?ckanContext:"";
|
||||||
|
|
||||||
|
if(pathInfoParameter!=null && pathInfoParameter.length()>0){
|
||||||
|
pathInfoParameter=pathInfoParameter.startsWith("/")?pathInfoParameter:"/"+pathInfoParameter;
|
||||||
|
}else
|
||||||
|
pathInfoParameter = "";
|
||||||
|
|
||||||
|
logger.debug("External Path Info parameter: "+pathInfoParameter);
|
||||||
|
|
||||||
|
//ADD PATH INFO
|
||||||
|
ckan.addPathInfo(ckanContext+pathInfoParameter);
|
||||||
|
logger.debug("CKanConnector pathInfo: "+ckan.getPathInfoParameter());
|
||||||
ckan.addQueryString(queryStringParameters);
|
ckan.addQueryString(queryStringParameters);
|
||||||
|
|
||||||
// String queryString ="";
|
//GET TOKEN
|
||||||
// if(queryStringParameters!=null && !queryStringParameters.isEmpty()){
|
|
||||||
// queryString = "?"+queryStringParameters;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// String gcubeTokenParameter = null;
|
|
||||||
// if(SessionUtil.isIntoPortal()){
|
|
||||||
// gcubeTokenParameter = GCUBE_TOKEN_PARAMETER+"="+getGcubeSecurityToken();
|
|
||||||
// }else{
|
|
||||||
// logger.warn("******** Using TEST_USER security token!!!");
|
|
||||||
// gcubeTokenParameter = GCUBE_TOKEN_PARAMETER+"="+TEST_SEC_TOKEN;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
String gcubeTokenValue = null;
|
String gcubeTokenValue = null;
|
||||||
if(SessionUtil.isIntoPortal()){
|
if(SessionUtil.isIntoPortal()){
|
||||||
gcubeTokenValue = getGcubeSecurityToken();
|
gcubeTokenValue = getGcubeSecurityToken();
|
||||||
|
@ -161,35 +153,13 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
||||||
}
|
}
|
||||||
|
|
||||||
ckan.addGubeToken(gcubeTokenValue);
|
ckan.addGubeToken(gcubeTokenValue);
|
||||||
// ckan.addGenericParameter(ckanHideHeader, "true");
|
|
||||||
|
|
||||||
// //ADDING CKAN HH (HIDE HEADER PARAMETER)
|
|
||||||
// queryString = queryString.isEmpty()?"?"+ckanHideHeader:"&"+ckanHideHeader;
|
|
||||||
// //ADDING GCUBE TOKEN PARAMETER
|
|
||||||
// queryString+="&"+gcubeTokenParameter;
|
|
||||||
|
|
||||||
//ADDING LIST OF VRE TO WHICH USER BELONGS
|
//ADDING LIST OF VRE TO WHICH USER BELONGS
|
||||||
if(!SessionUtil.isIntoPortal()){
|
if(!SessionUtil.isIntoPortal()){
|
||||||
return ckan;
|
return ckan;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASLSession session = getASLSession(this.getThreadLocalRequest().getSession());
|
|
||||||
List<String> listVres = UserUtil.getListVreForUser(session.getUserEmailAddress());
|
List<String> listVres = UserUtil.getListVreForUser(session.getUserEmailAddress());
|
||||||
// String vres = "";
|
|
||||||
// if(listVres!=null && listVres.size()>0){
|
|
||||||
// for (String vre : listVres) {
|
|
||||||
// vres+=vre+",";
|
|
||||||
// }
|
|
||||||
// vres = vres.substring(0, vres.length()-1).toLowerCase(); //remove last "," and to lower case. A CKAN Organization ID must be lower case
|
|
||||||
// }
|
|
||||||
|
|
||||||
// logger.debug("List of VREs contains: " +vres);
|
|
||||||
// if(vres.length()>0){
|
|
||||||
// queryString+="&"+LIST_OF_VRES_PARAMETER+"="+vres;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// ckan.addGubeToken(gcubeTokenParameter);
|
|
||||||
ckan.addListOfVREs(listVres);
|
ckan.addListOfVREs(listVres);
|
||||||
|
|
||||||
return ckan;
|
return ckan;
|
||||||
|
@ -396,11 +366,32 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
||||||
HttpSession httpSession = this.getThreadLocalRequest().getSession();
|
HttpSession httpSession = this.getThreadLocalRequest().getSession();
|
||||||
ASLSession session = getASLSession(httpSession);
|
ASLSession session = getASLSession(httpSession);
|
||||||
String username = session.getUsername();
|
String username = session.getUsername();
|
||||||
logger.debug("Logout from CKAN for: "+username);
|
CkanConnectorAccessPoint ckanAP = SessionUtil.getCkanAccessPoint(this.getThreadLocalRequest().getSession());
|
||||||
|
// String token = getGcubeSecurityToken();
|
||||||
|
logger.info("Logout from CKAN for: "+username +" by token: "+ckanAP.getGcubeTokenValue());
|
||||||
|
|
||||||
String ckanConnectorLogut = getServletContext().getInitParameter(CKANCONNECTORLOGOUT);
|
String ckanConnectorLogut = getServletContext().getInitParameter(CKANCONNECTORLOGOUT);
|
||||||
logger.debug(CKANCONNECTORLOGOUT + " is: "+ckanConnectorLogut);
|
logger.debug(CKANCONNECTORLOGOUT + " is: "+ckanConnectorLogut);
|
||||||
|
|
||||||
|
CkanConnectorAccessPoint ckan = new CkanConnectorAccessPoint(ckanAP.getBaseUrl());
|
||||||
|
ckan.addPathInfo(ckanConnectorLogut);
|
||||||
|
ckan.addGubeToken(ckanAP.getGcubeTokenValue());
|
||||||
|
|
||||||
|
URL url;
|
||||||
|
try {
|
||||||
|
String deleteURI = ckan.buildURI();
|
||||||
|
logger.debug("Perfoming HTTP delete to URI: "+deleteURI);
|
||||||
|
url = new URL(ckan.buildURI());
|
||||||
|
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
|
||||||
|
httpCon.setDoOutput(true);
|
||||||
|
httpCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded" );
|
||||||
|
httpCon.setRequestMethod("DELETE");
|
||||||
|
httpCon.connect();
|
||||||
|
logger.debug("Logout Completed");
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
logger.error("An error occured during performing Logout from CKAN for: "+username +" by token: "+ckanAP.getGcubeTokenValue(), e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,10 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server;
|
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
import org.gcube.application.framework.core.session.ASLSession;
|
import org.gcube.application.framework.core.session.ASLSession;
|
||||||
|
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -19,6 +22,7 @@ import com.liferay.portal.service.UserLocalServiceUtil;
|
||||||
public class SessionUtil {
|
public class SessionUtil {
|
||||||
|
|
||||||
public static final String CKAN_END_POINT = "CKAN_END_POINT";
|
public static final String CKAN_END_POINT = "CKAN_END_POINT";
|
||||||
|
public static final String CKAN_ACCESS_POINT = "CKAN_ACCESS_POINT";
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(SessionUtil.class);
|
private static Logger logger = LoggerFactory.getLogger(SessionUtil.class);
|
||||||
|
|
||||||
|
@ -55,4 +59,26 @@ public class SessionUtil {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ckAP
|
||||||
|
*/
|
||||||
|
public static void saveCkanAccessPoint(HttpSession session, CkanConnectorAccessPoint ckAP) {
|
||||||
|
|
||||||
|
session.setAttribute(CKAN_ACCESS_POINT, ckAP);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the ckan access point.
|
||||||
|
*
|
||||||
|
* @param session the session
|
||||||
|
* @return the ckan access point
|
||||||
|
*/
|
||||||
|
public static CkanConnectorAccessPoint getCkanAccessPoint(HttpSession session) {
|
||||||
|
|
||||||
|
return (CkanConnectorAccessPoint) session.getAttribute(CKAN_ACCESS_POINT);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class CkanConnectorAccessPoint implements Serializable{
|
||||||
private List<String> listOfVRes;
|
private List<String> listOfVRes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Instantiates a new ckan connector access point.
|
||||||
*/
|
*/
|
||||||
public CkanConnectorAccessPoint() {
|
public CkanConnectorAccessPoint() {
|
||||||
}
|
}
|
||||||
|
@ -118,15 +118,20 @@ public class CkanConnectorAccessPoint implements Serializable{
|
||||||
*/
|
*/
|
||||||
public String buildURI(){
|
public String buildURI(){
|
||||||
|
|
||||||
|
String path = "";
|
||||||
|
String query = "";
|
||||||
|
|
||||||
if(pathInfoParameter!=null && !pathInfoParameter.isEmpty())
|
if(pathInfoParameter!=null && !pathInfoParameter.isEmpty())
|
||||||
pathInfoParameter=pathInfoParameter.startsWith("/")?pathInfoParameter:"/"+pathInfoParameter;
|
path=pathInfoParameter.startsWith("/")?pathInfoParameter:"/"+pathInfoParameter;
|
||||||
else
|
else
|
||||||
pathInfoParameter="";
|
path="";
|
||||||
|
|
||||||
if(queryStringParameters==null)
|
if(queryStringParameters==null || queryStringParameters.isEmpty())
|
||||||
queryStringParameters="";
|
query="";
|
||||||
|
else
|
||||||
|
query = queryStringParameters;
|
||||||
|
|
||||||
return baseUrl+pathInfoParameter+"?"+queryStringParameters;
|
return baseUrl+path+"?"+query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -134,6 +139,8 @@ public class CkanConnectorAccessPoint implements Serializable{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the base url.
|
||||||
|
*
|
||||||
* @return the baseUrl
|
* @return the baseUrl
|
||||||
*/
|
*/
|
||||||
public String getBaseUrl() {
|
public String getBaseUrl() {
|
||||||
|
@ -143,6 +150,8 @@ public class CkanConnectorAccessPoint implements Serializable{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the path info parameter.
|
||||||
|
*
|
||||||
* @return the pathInfoParameter
|
* @return the pathInfoParameter
|
||||||
*/
|
*/
|
||||||
public String getPathInfoParameter() {
|
public String getPathInfoParameter() {
|
||||||
|
@ -152,6 +161,8 @@ public class CkanConnectorAccessPoint implements Serializable{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the query string parameters.
|
||||||
|
*
|
||||||
* @return the queryStringParameters
|
* @return the queryStringParameters
|
||||||
*/
|
*/
|
||||||
public String getQueryStringParameters() {
|
public String getQueryStringParameters() {
|
||||||
|
@ -161,6 +172,8 @@ public class CkanConnectorAccessPoint implements Serializable{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the gcube token value.
|
||||||
|
*
|
||||||
* @return the gcubeTokenValue
|
* @return the gcubeTokenValue
|
||||||
*/
|
*/
|
||||||
public String getGcubeTokenValue() {
|
public String getGcubeTokenValue() {
|
||||||
|
@ -170,6 +183,8 @@ public class CkanConnectorAccessPoint implements Serializable{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the list of v res.
|
||||||
|
*
|
||||||
* @return the listOfVRes
|
* @return the listOfVRes
|
||||||
*/
|
*/
|
||||||
public List<String> getListOfVRes() {
|
public List<String> getListOfVRes() {
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
<context-param>
|
<context-param>
|
||||||
<description>ckan connector logout from CKAN</description>
|
<description>ckan connector logout from CKAN</description>
|
||||||
<param-name>CkanConnectorLogout</param-name>
|
<param-name>CkanConnectorLogout</param-name>
|
||||||
<param-value>/gcube/service/connect</param-value>
|
<param-value>/gcube/service/disconnect</param-value>
|
||||||
</context-param>
|
</context-param>
|
||||||
|
|
||||||
<!-- Servlets -->
|
<!-- Servlets -->
|
||||||
|
|
Loading…
Reference in New Issue