From e189ae57b8ad03946bbc90f9b330c878bf5b9796 Mon Sep 17 00:00:00 2001 From: Lucio Lelii Date: Mon, 27 Jun 2016 14:34:45 +0000 Subject: [PATCH] git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-access/ckan-connector@129478 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 7 ++++ .../ckanconnector/ConnectorManager.java | 32 +++++++++++++------ src/main/resources/inactivesession.html | 3 ++ src/main/resources/logout.html | 5 +++ 4 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 src/main/resources/inactivesession.html create mode 100644 src/main/resources/logout.html diff --git a/pom.xml b/pom.xml index cc3b75e..13f5f83 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,13 @@ 4.0.0 + + + maven-parent + org.gcube.tools + 1.0.0 + + org.gcube.data.access ckan-connector 1.0.0-SNAPSHOT diff --git a/src/main/java/org/gcube/data/access/ckanconnector/ConnectorManager.java b/src/main/java/org/gcube/data/access/ckanconnector/ConnectorManager.java index e74ae27..a5e4cd8 100644 --- a/src/main/java/org/gcube/data/access/ckanconnector/ConnectorManager.java +++ b/src/main/java/org/gcube/data/access/ckanconnector/ConnectorManager.java @@ -5,8 +5,8 @@ import java.io.FileInputStream; import java.net.URI; import javax.servlet.ServletContext; +import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; @@ -45,19 +45,31 @@ public class ConnectorManager { @Path("disconnect") - @DELETE - public Response disconnect() { + @GET + public Response disconnect(@Context HttpServletRequest req) { log.info("disconnect called "); String hostname = context.getInitParameter("hostname"); try{ - return Response.ok() - .header( - "Set-Cookie", - String.format("auth_tkt=deleted;Domain=.%s;Path=/;Expires=Thu, 01-Jan-1970 00:00:01 GMT",hostname) - ).build(); + boolean found = false; + for (Cookie cookie : req.getCookies()) + if (cookie.getName().equals("auth_tkt")){ + found=true; + break; + } + if (found) + return Response.ok(context.getClassLoader().getResourceAsStream("logout.html")) + .header( + "Set-Cookie", + String.format("auth_tkt=deleted;Domain=%s;Path=/;Expires=Thu, 01-Jan-1970 00:00:01 GMT",hostname) + ) + .header("Set-Cookie", + String.format("ckan_hide_header=deleted;Domain=%s;Path=/;Expires=Thu, 01-Jan-1970 00:00:01 GMT",hostname) + ).build(); + else return Response.ok(context.getClassLoader().getResourceAsStream("inactivesession.html")).build(); + }catch(Exception e){ - e.printStackTrace(); - return null; + log.error("error disconnecting ",e); + return Response.serverError().build(); } } diff --git a/src/main/resources/inactivesession.html b/src/main/resources/inactivesession.html new file mode 100644 index 0000000..ad1bff3 --- /dev/null +++ b/src/main/resources/inactivesession.html @@ -0,0 +1,3 @@ + +

CKAN session is invalid

+ \ No newline at end of file diff --git a/src/main/resources/logout.html b/src/main/resources/logout.html new file mode 100644 index 0000000..c463e9d --- /dev/null +++ b/src/main/resources/logout.html @@ -0,0 +1,5 @@ + + +

Successfully logged out from CKAN

+ + \ No newline at end of file