TASK #5615 completed

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@133899 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-11-04 12:01:35 +00:00
parent 56ed7f78bf
commit 3cd1cf0d52
11 changed files with 293 additions and 456 deletions

View File

@ -59,6 +59,11 @@
</dependencyManagement>
<dependencies>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
@ -85,7 +90,7 @@
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId>
<scope>provided</scope>
<scope>compile</scope>
</dependency>
<!-- END FWS -->
@ -106,7 +111,6 @@
<artifactId>common-authorization</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>

View File

@ -27,9 +27,13 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.CreateDatase
import com.github.gwtbootstrap.client.ui.Modal;
import com.github.gwtbootstrap.client.ui.event.HideEvent;
import com.github.gwtbootstrap.client.ui.event.HideHandler;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
* The Class CkanEventHandlerManager.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @author Costantino Perciante costantino.perciante@isti.cnr.it Jun 10, 2016
*/
@ -37,23 +41,28 @@ public class CkanEventHandlerManager {
private HandlerManager eventBus = new HandlerManager(null);
private GCubeCkanDataCatalogPanel panel;
private String logoutFromCKANURL;
/**
*
* Instantiates a new ckan event handler manager.
*/
public CkanEventHandlerManager() {
bind();
}
/**
* @param panel
* the panel to set
* Sets the panel.
*
* @param panel the panel to set
*/
public void setPanel(GCubeCkanDataCatalogPanel panel) {
this.panel = panel;
}
/**
* Bind.
*/
private void bind() {
// bind on show home event
@ -88,18 +97,18 @@ public class CkanEventHandlerManager {
eventBus.fireEvent(new CloseCreationFormEvent());
}
});
}
}
});
// bind on edit (TODO)
eventBus.addHandler(
EditMetadataEvent.TYPE, new EditMetadataEventHandler() {
eventBus.addHandler(EditMetadataEvent.TYPE, new EditMetadataEventHandler() {
@Override
public void onEditMetadata(EditMetadataEvent editMetadataEvent) {
@Override
public void onEditMetadata(EditMetadataEvent editMetadataEvent) {
// TODO Auto-generated method stub
}
});
// TODO Auto-generated method stub
}
});
// show datasets event
eventBus.addHandler(
ShowUserDatasetsEvent.TYPE, new ShowUserDatasetsEventHandler() {
@ -158,13 +167,22 @@ public class CkanEventHandlerManager {
eventBus.addHandler(IFrameInstanciedEvent.TYPE, new IFrameInstanciedEventHandler() {
@Override
public void onNewInstance(IFrameInstanciedEvent iFrameInstanciedEent) {
public void onNewInstance(IFrameInstanciedEvent iFrameInstanciedEvent) {
panel.updateSize();
if(logoutFromCKANURL==null)
instanceLogoutSystem();
}
});
}
/**
* Gets the ckan request.
*
* @param pathInfo the path info
* @param query the query
* @return the ckan request
*/
private String getCkanRequest(String pathInfo, String query){
CkanConnectorAccessPoint ckan = new CkanConnectorAccessPoint(panel.getBaseURLCKANConnector(),"");
ckan.addGubeToken(panel.getGcubeTokenValueToCKANConnector());
@ -175,23 +193,144 @@ public class CkanEventHandlerManager {
return ckan.buildURI();
}
private static native void logutWindow(String uri, boolean timeout)/*-{
var newWindow = window.open(uri, '_blank', 'width=50,height=50');
newWindow.onload = function() {
setTimeout();
};
setTimeout(function() {
newWindow.close();
}, 500);
return false;
/**
* Instance logout system.
*/
private void instanceLogoutSystem() {
GCubeCkanDataCatalog.service.logoutFromCkanURL(new AsyncCallback<String>() {
@Override
public void onSuccess(String result) {
logoutFromCKANURL = result;
GWT.log("Loaded logout url: "+logoutFromCKANURL);
performLogoutOnBrowserClosedEvent(logoutFromCKANURL);
}
@Override
public void onFailure(Throwable caught) {
}
});
}
/**
* Perform logout on browser closed event.
*
* @param logoutService the logout service
*/
private static native void performLogoutOnBrowserClosedEvent(String logoutService)/*-{
var validNavigation = false;
function wireUpEvents() {
console.log("wireUpEvents");
var dont_confirm_leave = 1; //set dont_confirm_leave to 1 when you want the user to be able to leave without confirmation
var leave_message = 'You sure you want to leave?'
function disconnect(e) {
if (!validNavigation) {
var logoutPerformed = false;
var ifrm = $doc.createElement("iframe");
ifrm.id = 'logout-iframe';
ifrm.onload = function() {
logoutPerformed = true;
console.log("ifrm loaded exit is: " + exit);
}
ifrm.style.width = "1px";
ifrm.style.height = "1px";
ifrm.src = logoutService;
$doc.body.appendChild(ifrm);
//sleep 500ms in order to loasad disconnect response performed by IFrame
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds || logoutPerformed) {
break;
}
}
}
//sleep 500ms in order to have time to load disconnect response returned by IFrame
sleep(500);
if (dont_confirm_leave !== 1) {
if (!e)
e = window.event;
//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = leave_message;
//e.stopPropagation works in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
//return works for Chrome and Safari
return leave_message;
}
}
}
window.onbeforeunload = disconnect;
// Attach the event keypress to exclude the F5 refresh
$wnd.$(document).bind('keypress', function(e) {
if (e.keyCode == 116) {
validNavigation = true;
console.log("keypress: " + validNavigation);
}
});
// Attach the event click for all links in the page
$wnd.$("a").bind("click", function() {
validNavigation = true;
console.log("click: " + validNavigation);
});
// Attach the event submit for all forms in the page
$wnd.$("form").bind("submit", function() {
validNavigation = true;
console.log("form: " + validNavigation);
});
// Attach the event click for all inputs in the page
$wnd.$("input[type=submit]").bind("click", function() {
validNavigation = true;
console.log("submit: " + validNavigation);
});
}
// Wire up the events as soon as the DOM tree is ready
$wnd.$(document).ready(function() {
wireUpEvents();
});
//wireUpEvents();
}-*/;
/**
* @return
* Gets the event bus.
*
* @return the event bus
*/
public HandlerManager getEventBus() {
return eventBus;
}
/**
* Gets the logout from ckanurl.
*
* @return the logoutFromCKANURL
*/
public String getLogoutFromCKANURL() {
return logoutFromCKANURL;
}
}

View File

@ -1,17 +1,18 @@
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view.CKanLeaveFrame;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view.GCubeCkanDataCatalogPanel;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.RootPanel;
/**
* Entry point classes define <code>onModuleLoad()</code>.
* The Class GCubeCkanDataCatalog.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Nov 4, 2016
*/
public class GCubeCkanDataCatalog implements EntryPoint {
@ -20,11 +21,9 @@ public class GCubeCkanDataCatalog implements EntryPoint {
* service.
*/
public static final GcubeCkanDataCatalogServiceAsync service = GWT.create(GcubeCkanDataCatalogService.class);
public static final String CKAN_LOGUT_SERVICE = GWT.getModuleBaseURL() + "gcubeckanlogout";
public static final String CKAN_LOGUT_SERVICE = GWT.getModuleBaseURL() +"gcubeckanlogout";
private final String DIV_PORTLET_ID = "gCubeCkanDataCatalog";
private CkanEventHandlerManager eventManager = new CkanEventHandlerManager();
private CKanLeaveFrame frame;
public static final String GET_PATH_PARAMETER = "path";
public static final String GET_QUERY_PARAMETER = "query";
public static final String GCUBE_CKAN_IFRAME = "gcube-ckan-iframe";
@ -33,131 +32,9 @@ public class GCubeCkanDataCatalog implements EntryPoint {
* This is the entry point method.
*/
public void onModuleLoad() {
performLogoutOnBrowserClosedEvent(CKAN_LOGUT_SERVICE);
/*Button butt = new Button("Click Me");
butt.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
performsLogout(CKAN_LOGUT_SERVICE);
}
});
RootPanel.get(DIV_PORTLET_ID).add(butt);*/
/*Window.addWindowClosingHandler(new Window.ClosingHandler() {
@Override
public void onWindowClosing(ClosingEvent closingEvent) {
// invoking logout
performLogout();
}
});*/
GCubeCkanDataCatalogPanel panel = new GCubeCkanDataCatalogPanel(RootPanel.get(DIV_PORTLET_ID), eventManager.getEventBus());
GCubeCkanDataCatalogPanel panel =new GCubeCkanDataCatalogPanel(RootPanel.get(DIV_PORTLET_ID), eventManager.getEventBus());
eventManager.setPanel(panel);
frame = new CKanLeaveFrame();
DOM.appendChild(RootPanel.getBodyElement(), frame.getElement());
}
// public static native void performsLogout(String logoutService)/*-{
//
//// var frame = $wnd.frames['i-frame-logout'];
//// console.log(frame);
//// frame.src = logoutService;
// // frame.contentWindow.location.reload();
//
// var xhttp = new XMLHttpRequest();
// xhttp.onreadystatechange = function() {
// if (this.readyState == 4 && this.status == 200) {
// console.log("OK");
// }
// };
// xhttp.open("GET", logoutService, false);
// xhttp.send();
// }-*/;
/**
* Perform logouton browser closed event.
*
* @param logoutService the logout service
*/
public static native void performLogoutOnBrowserClosedEvent(String logoutService)/*-{
var validNavigation = false;
function wireUpEvents() {
var dont_confirm_leave = 1; //set dont_confirm_leave to 1 when you want the user to be able to leave without confirmation
var leave_message = 'You sure you want to leave?'
function goodbye(e) {
if (!validNavigation) {
//PERFORMS A SYNCHRONOUS LOGOUT
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log("OK");
}
};
xhttp.open("GET", logoutService, false);
xhttp.send();
if (dont_confirm_leave!==1) {
if(!e) e = window.event;
//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = leave_message;
//e.stopPropagation works in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
//return works for Chrome and Safari
return leave_message;
}
}
}
window.onbeforeunload=goodbye;
// Attach the event keypress to exclude the F5 refresh
$wnd.$(document).bind('keypress', function(e) {
if (e.keyCode == 116){
validNavigation = true;
console.log("keypress: "+validNavigation);
}
});
// Attach the event click for all links in the page
$wnd.$("a").bind("click", function() {
validNavigation = true;
console.log("click: "+validNavigation);
});
// Attach the event submit for all forms in the page
$wnd.$("form").bind("submit", function() {
validNavigation = true;
console.log("form: "+validNavigation);
});
// Attach the event click for all inputs in the page
$wnd.$("input[type=submit]").bind("click", function() {
validNavigation = true;
console.log("submit: "+validNavigation);
});
}
// Wire up the events as soon as the DOM tree is ready
$wnd.$(document).ready(function() {
wireUpEvents();
});
}-*/;
}

View File

@ -9,54 +9,62 @@ import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanRole;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
/**
* The client side stub for the RPC service.
* The Interface GcubeCkanDataCatalogService.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 20, 2016
* Nov 4, 2016
*/
@RemoteServiceRelativePath("ckandatacatalogue")
public interface GcubeCkanDataCatalogService extends RemoteService {
/**
* Get the ckan connector access point
* @param pathInfoParameters
* @param queryStringParameters
* @param currentUrl
* @return
* @throws Exception
* Get the ckan connector access point.
*
* @param pathInfoParameters the path info parameters
* @param queryStringParameters the query string parameters
* @param currentUrl the current url
* @return the c kan connector
* @throws Exception the exception
*/
CkanConnectorAccessPoint getCKanConnector(
String pathInfoParameters, String queryStringParameters, String currentUrl) throws Exception;
/**
* Get the current role in CKAN for this user
* @return
* @throws Exception
* Get the current role in CKAN for this user.
*
* @return the my role
* @throws Exception the exception
*/
CkanRole getMyRole() throws Exception;
/**
* Retrieve the list of organizations to whom the user belongs and their urls
* @return
* Retrieve the list of organizations to whom the user belongs and their urls.
*
* @return the ckan organizations names and urls for user
*/
List<BeanUserInOrgRole> getCkanOrganizationsNamesAndUrlsForUser();
/**
* Logout from ckan
* Logout from ckan.
*
* @return the string
*/
void logoutFromCkan();
String logoutFromCkanURL();
/**
* Remove auth cookie for ckan of this user
* @return
* Remove auth cookie for ckan of this user.
*
* @return the string
*/
String logoutURIFromCkan();
/**
* Check if the there is a user logged in
* @return
* Check if the there is a user logged in.
*
* @return true, if successful
*/
boolean outsidePortal();
}

View File

@ -12,27 +12,64 @@ 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
* Jun 20, 2016
* Nov 4, 2016
*/
public interface GcubeCkanDataCatalogServiceAsync {
/**
* Gets the my role.
*
* @param callback the callback
* @return the my role
*/
void getMyRole(AsyncCallback<CkanRole> callback);
/**
* Gets the c kan connector.
*
* @param pathInfoParameters the path info parameters
* @param queryStringParameters the query string parameters
* @param currentUrl the current url
* @param callback the callback
* @return the c kan connector
*/
void getCKanConnector(
String pathInfoParameters, String queryStringParameters, String currentUrl,
AsyncCallback<CkanConnectorAccessPoint> callback);
void logoutFromCkan(AsyncCallback<Void> callback);
/**
* Logout from ckan url.
*
* @param callback the callback
*/
void logoutFromCkanURL(AsyncCallback<String> callback);
/**
* Logout uri from ckan.
*
* @param callback the callback
*/
void logoutURIFromCkan(AsyncCallback<String> callback);
/**
* Gets the ckan organizations names and urls for user.
*
* @param callback the callback
* @return the ckan organizations names and urls for user
*/
void getCkanOrganizationsNamesAndUrlsForUser(
AsyncCallback<List<BeanUserInOrgRole>> callback);
/**
* Outside portal.
*
* @param callback the callback
*/
void outsidePortal(AsyncCallback<Boolean> callback);
}

View File

@ -1,29 +0,0 @@
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.ui.Frame;
/**
* This iframe handles the onLeave page event in order to call the logout servlet
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class CKanLeaveFrame extends Frame{
public CKanLeaveFrame(){
try{
// GCubeCkanDataCatalogPanel.print("Instancing new IFRAME with uri: "+ url);
getElement().setId("i-frame-logout");
// make it smaller
getElement().getStyle().setWidth(1, Unit.PX);
getElement().getStyle().setHeight(1, Unit.PX);
}catch(Exception e){
GWT.log("exception " + e);
}
}
}

View File

@ -113,7 +113,7 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
@Override
public void onFailure(Throwable caught) {
showEditInsertButtons(false);
showEditInsertButtons(false);
}
@Override
@ -123,13 +123,13 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
showEditInsertButtons(true);
break;
case EDITOR:
showEditInsertButtons(true);
showEditInsertButtons(true);
break;
case MEMBER:
showEditInsertButtons(false);
break;
default:
showEditInsertButtons(false);
showEditInsertButtons(false);
break;
}

View File

@ -1,212 +0,0 @@
/**
*
*/
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.datacatalogue.ckanutillibrary.utils.SessionCatalogueAttributes;
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class CkanLogout.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 27, 2016
*/
public class CkanLogout extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 2793892309831716065L;
private static Logger logger = LoggerFactory.getLogger(CkanLogout.class);
/* (non-Javadoc)
* @see javax.servlet.http.HttpServlet#doDelete(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
HttpSession httpSession = req.getSession();
ASLSession session = getASLSession(httpSession);
String scope = (String) req.getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
String username = session.getUsername();
if(username.equals(GcubeCkanDataCatalogServiceImpl.TEST_USER))
return;
logger.info("CkanLogout performing...");
CkanConnectorAccessPoint ckanAP = SessionUtil.getCkanAccessPoint(req.getSession(), scope);
// String token = getGcubeSecurityToken();
logger.info("Logout from CKAN for: "+username );
logger.info(" by token: "+ckanAP.getGcubeTokenValue() +", the scope is: "+scope);
String ckanConnectorLogut = getServletContext().getInitParameter(GcubeCkanDataCatalogServiceImpl.CKANCONNECTORLOGOUT);
logger.debug(GcubeCkanDataCatalogServiceImpl.CKANCONNECTORLOGOUT + " is: "+ckanConnectorLogut);
CkanConnectorAccessPoint ckan = new CkanConnectorAccessPoint(ckanAP.getBaseUrl(), ckanConnectorLogut);
ckan.addGubeToken(ckanAP.getGcubeTokenValue());
String deleteURI = ckan.buildURI();
logger.debug(GcubeCkanDataCatalogServiceImpl.CKANCONNECTORLOGOUT + " calling: "+deleteURI);
resp.sendRedirect(deleteURI);
/*logger.debug(GcubeCkanDataCatalogServiceImpl.CKANCONNECTORLOGOUT + " is: "+ckanConnectorLogut);
CloseableHttpResponse httpResponse = null;
try {
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpget = new HttpGet(deleteURI);
httpResponse = httpclient.execute(httpget);
if(httpResponse.getStatusLine().getStatusCode()==HttpStatus.SC_OK){
resp.setStatus(HttpStatus.SC_OK);
Header[] headers = httpResponse.getAllHeaders();
for (Header header : headers) {
logger.trace("header key: "+header.getName() +", value: "+header.getValue());
if(header.getName()==null){
logger.trace("skip key: "+header.getName() +", value: "+header.getValue());
}else
resp.setHeader(header.getName(),header.getValue());
}
try {
HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
resp.setHeader("Content-Length", String.valueOf(entity.getContentLength()));
// resp.setContentLength(entity.getContentLength());
Header encoding = entity.getContentEncoding();
logger.trace("Encoding: "+encoding.getName() + ", "+encoding.getValue());
// String encod = encoding == null ? GcubeCkanDataCatalogServiceImpl.UTF_8 : encoding.getName();
// resp.setCharacterEncoding(encoding);
resp.setStatus(HttpStatus.SC_OK);
resp.setContentType(resp.getContentType());
InputStream in = entity.getContent();
try {
ServletOutputStream out = resp.getOutputStream();
IOUtils.copy(in, out);
logger.info("Logout Completed, response code: "+HttpStatus.SC_OK);
} finally {
in.close();
}
}
}catch(Exception e){
logger.warn("An error occurred during copying CKAN logout response",e);
}
}else{
logger.warn("An error occurred during perfoming CKAN logout, Response status is: "+httpResponse.getStatusLine().getStatusCode());
HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
InputStream in = entity.getContent();
if(in!=null){
logger.error("Response error: "+IOUtils.toString(in));
}
}
}
}catch(Exception e){
logger.warn("An error occurred during perfoming CKAN logout", e);
}finally {
if(httpResponse!=null)
httpResponse.close();
}*/
/*try {
logger.debug("Perfoming HTTP delete to URI: "+deleteURI);
url = new URL(deleteURI);
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
req.getCookies();
// httpCon.setDoOutput(true);
// httpCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded" );
// httpCon.setRequestProperty(key, value);
httpCon.setRequestMethod("GET");
// httpCon.setRequestMethod("DELETE");
httpCon.connect();
HttpServletResponse response = resp;
if(httpCon.getResponseCode()==HttpStatus.SC_OK){
response.setContentLength(httpCon.getContentLength());
Map<String, List<String>> map = httpCon.getHeaderFields();
for (String key : map.keySet()) {
String hf = httpCon.getHeaderField(key);
logger.trace("key: "+key +", value: "+hf);
if(key==null){
logger.trace("skip key: "+key +", value: "+hf);
}else
response.setHeader(key,hf);
}
response.setContentLength(httpCon.getContentLength());
String encoding = httpCon.getContentEncoding();
encoding = encoding == null ? GcubeCkanDataCatalogServiceImpl.UTF_8 : encoding;
response.setCharacterEncoding(encoding);
response.setStatus(HttpStatus.SC_OK);
response.setContentType(httpCon.getContentType());
// Cookie cookie = new Cookie("user", null); // Not necessary, but saves bandwidth.
// cookie.setPath("/MyApplication");
// cookie.setHttpOnly(true);
// cookie.setMaxAge(0); // Don't set to -1 or it will become a session cookie!
// response.addCookie(cookie);
InputStream in = httpCon.getInputStream();
ServletOutputStream out = response.getOutputStream();
IOUtils.copy(in, out);
logger.info("Logout Completed, response code: "+HttpStatus.SC_OK);
}else{
logger.warn("An error occurred during perfoming CKAN logout, Response status is: "+httpCon.getResponseCode());
logger.warn(IOUtils.toString(httpCon.getErrorStream()));
}
}
catch (IOException e) {
logger.error("An error occured during performing Logout from CKAN for: "+username +" by token: "+ckanAP.getGcubeTokenValue(), e);
}*/
}
/**
* Gets the ASL session.
*
* @param httpSession the http session
* @return the ASL session
*/
protected ASLSession getASLSession(HttpSession httpSession)
{
String sessionID = httpSession.getId();
String user = (String) httpSession.getAttribute(GcubeCkanDataCatalogServiceImpl.USERNAME_ATTRIBUTE);
if (user == null) {
logger.warn("****** STARTING IN TEST MODE - NO USER FOUND *******");
//for test only
user = GcubeCkanDataCatalogServiceImpl.TEST_USER;
httpSession.setAttribute(GcubeCkanDataCatalogServiceImpl.USERNAME_ATTRIBUTE, user);
ASLSession session = SessionManager.getInstance().getASLSession(sessionID, user);
session.setScope(GcubeCkanDataCatalogServiceImpl.TEST_SCOPE);
session.setUserEmailAddress(GcubeCkanDataCatalogServiceImpl.TEST_MAIL);
//session.setScope("/gcube/devsec/devVRE");
return session;
} else logger.trace("user found in session "+user);
return SessionManager.getInstance().getASLSession(sessionID, user);
}
}

View File

@ -2,20 +2,12 @@ package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server;
import static org.gcube.common.authorization.client.Constants.authorizationService;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.HttpStatus;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.common.authorization.library.provider.UserInfo;
@ -38,7 +30,6 @@ import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import eu.trentorise.opendata.jackan.model.CkanOrganization;
import eu.trentorise.opendata.traceprov.internal.org.apache.commons.io.IOUtils;
/**
* The server side implementation of the RPC service.
*
@ -59,10 +50,10 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
public static final String USERNAME_ATTRIBUTE = ScopeHelper.USERNAME_ATTRIBUTE;
private static Logger logger = LoggerFactory.getLogger(GcubeCkanDataCatalogServiceImpl.class);
public final static String TEST_USER = "test.user";
public final static String TEST_SCOPE = "/gcube/devsec/devVRE";
public final static String TEST_USER = "andrea.rossi";
public final static String TEST_SCOPE = "/gcube/devNext/NextNext";
public final static String TEST_MAIL = "test.user@test-com";
public final static String TEST_SEC_TOKEN = "4620e6d0-2313-4f48-9d54-eb3efd01a810";
public final static String TEST_SEC_TOKEN = "4d071434-021e-41ac-9aae-a3489fcf06d8-98187548";
/**
* Instanciate the ckan util library.
@ -79,7 +70,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
DataCatalogue instance = null;
try{
String scopeInWhichDiscover = (discoverScope != null && !discoverScope.isEmpty()) ? discoverScope : currentScope;
String scopeInWhichDiscover = discoverScope != null && !discoverScope.isEmpty() ? discoverScope : currentScope;
logger.debug("Discovering ckan utils library into scope " + scopeInWhichDiscover);
instance = DataCatalogueFactory.getFactory().getUtilsPerScope(scopeInWhichDiscover);
@ -196,7 +187,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
* Gets the gcube security token for the user in current session and for a given scope
*
* @return the gcube security token
* @throws Exception
* @throws Exception
*/
protected String getGcubeSecurityToken(String scope) throws Exception {
@ -212,7 +203,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
// * Temporary method to set the authorization token.
// *
// * @param session the new authorization token
// * @throws Exception
// * @throws Exception
// */
// private static void setAuthorizationToken(ASLSession session) throws Exception {
// String username = session.getUsername();
@ -247,8 +238,8 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
ASLSession session = SessionManager.getInstance().getASLSession(sessionID, user);
session.setScope(TEST_SCOPE);
return session;
}
else
}
else
logger.trace("user found in session "+user);
return SessionManager.getInstance().getASLSession(sessionID, user);
}
@ -285,7 +276,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
// get key per scope
String keyPerScopeRole = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_HIGHEST_ROLE, scopePerCurrentUrl);
String keyPerScopeOrganizations = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_ORGANIZATIONS_PUBLISH_KEY, scopePerCurrentUrl);
// check into session
if(httpSession.getAttribute(keyPerScopeRole) != null){
@ -301,7 +292,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
// we build up also a list that keeps track of the scopes (orgs) in which the user has at least role EDITOR
List<OrganizationBean> orgsInWhichAtLeastEditorRole = new ArrayList<OrganizationBean>();
toReturn = UserUtil.getHighestRole(scopePerCurrentUrl, username, groupName, this, orgsInWhichAtLeastEditorRole);
// put role in session
httpSession.setAttribute(keyPerScopeRole, toReturn);
logger.info("Set role " + toReturn + " into session for user " + username);
@ -328,10 +319,10 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
HttpSession httpSession = this.getThreadLocalRequest().getSession();
ASLSession session = getASLSession(httpSession);
String username = session.getUsername();
// get the scope from session
String scopePerCurrentUrl = (String)this.getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
CkanConnectorAccessPoint ckanAP = SessionUtil.getCkanAccessPoint(this.getThreadLocalRequest().getSession(), scopePerCurrentUrl);
logger.info("Logout from CKAN for: "+username +" by token: "+ckanAP.getGcubeTokenValue());
@ -348,10 +339,33 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
* @see org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GcubeCkanDataCatalogService#logoutFromCkan()
*/
@Override
public void logoutFromCkan() {
public String logoutFromCkanURL() {
HttpSession httpSession = this.getThreadLocalRequest().getSession();
ASLSession session = getASLSession(httpSession);
String username = session.getUsername();
logger.info("Getting CKAN Logout URL...");
String scopePerCurrentUrl = (String) this.getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
CkanConnectorAccessPoint ckanAP = SessionUtil.getCkanAccessPoint(httpSession, scopePerCurrentUrl);
// String token = getGcubeSecurityToken();
logger.info("Logout from CKAN for: "+username );
logger.info(" by token: "+ckanAP.getGcubeTokenValue() +", the scope is: "+scopePerCurrentUrl);
String ckanConnectorLogout = getServletContext().getInitParameter(CKANCONNECTORLOGOUT);
logger.debug(GcubeCkanDataCatalogServiceImpl.CKANCONNECTORLOGOUT + " is: "+ckanConnectorLogout);
CkanConnectorAccessPoint ckan = new CkanConnectorAccessPoint(ckanAP.getBaseUrl(), ckanConnectorLogout);
ckan.addGubeToken(ckanAP.getGcubeTokenValue());
String deleteURI = ckan.buildURI();
logger.debug(GcubeCkanDataCatalogServiceImpl.CKANCONNECTORLOGOUT + " returning: "+deleteURI);
return deleteURI;
/*HttpSession httpSession = this.getThreadLocalRequest().getSession();
ASLSession session = getASLSession(httpSession);
String username = session.getUsername();
// get the scope from session
String scopePerCurrentUrl = (String)this.getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
CkanConnectorAccessPoint ckanAP = SessionUtil.getCkanAccessPoint(this.getThreadLocalRequest().getSession(), scopePerCurrentUrl);
@ -364,7 +378,6 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
CkanConnectorAccessPoint ckan = new CkanConnectorAccessPoint(ckanAP.getBaseUrl(), ckanConnectorLogut);
ckan.addPathInfo(ckanConnectorLogut);
ckan.addGubeToken(ckanAP.getGcubeTokenValue());
URL url;
try {
String deleteURI = ckan.buildURI();
@ -407,7 +420,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
}
catch (IOException e) {
logger.error("An error occured during performing Logout from CKAN for: "+username +" by token: "+ckanAP.getGcubeTokenValue(), e);
}
}*/
}
@Override

View File

@ -24,8 +24,8 @@ public class CkanConnectorAccessPoint implements Serializable{
public static final String URL_PATH_SEPARATOR = "/";
private static final String LIST_OF_VRES_PARAMETER = "listOfVres";
private static final String GCUBE_TOKEN_PARAMETER = "gcube-token";
public static final String LIST_OF_VRES_PARAMETER = "listOfVres";
public static final String GCUBE_TOKEN_PARAMETER = "gcube-token";
private String baseUrl;
private String pathInfoParameter;
private String queryStringParameters;

View File

@ -29,10 +29,10 @@
<servlet-class>org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server.GcubeCkanDataCatalogServiceImpl</servlet-class>
</servlet>
<servlet>
<servlet-name>gcubeckanlogout</servlet-name>
<servlet-class>org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server.CkanLogout</servlet-class>
</servlet>
<!-- <servlet> -->
<!-- <servlet-name>gcubeckanlogout</servlet-name> -->
<!-- <servlet-class>org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server.CkanLogout</servlet-class> -->
<!-- </servlet> -->
<servlet>
<servlet-name>checkServlet</servlet-name>
@ -54,10 +54,10 @@
<url-pattern>/gCubeCkanDataCatalog/ckanservices</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>gcubeckanlogout</servlet-name>
<url-pattern>/gCubeCkanDataCatalog/gcubeckanlogout</url-pattern>
</servlet-mapping>
<!-- <servlet-mapping> -->
<!-- <servlet-name>gcubeckanlogout</servlet-name> -->
<!-- <url-pattern>/gCubeCkanDataCatalog/gcubeckanlogout</url-pattern> -->
<!-- </servlet-mapping> -->
<servlet-mapping>
<servlet-name>checkServlet</servlet-name>