You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by il...@apache.org on 2019/06/27 11:29:11 UTC
[ignite] branch master updated: IGNITE-8772 Fix WebSessionFilter
after jetty 9.4 upgrade - Fixes #6612.
This is an automated email from the ASF dual-hosted git repository.
ilyak pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 5550e0e IGNITE-8772 Fix WebSessionFilter after jetty 9.4 upgrade - Fixes #6612.
5550e0e is described below
commit 5550e0ef029352efebf1e08237fcb5a8f3bcb7c9
Author: samaitra <sa...@gmail.com>
AuthorDate: Thu Jun 27 14:25:13 2019 +0300
IGNITE-8772 Fix WebSessionFilter after jetty 9.4 upgrade - Fixes #6612.
Signed-off-by: Ilya Kasnacheev <il...@gmail.com>
---
.../ignite/cache/websession/WebSessionFilter.java | 12 +-
.../internal/websession/WebSessionSelfTest.java | 121 +++++++++++++++++++++
2 files changed, 131 insertions(+), 2 deletions(-)
diff --git a/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionFilter.java b/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionFilter.java
index 9fa6de2..156a3f8 100644
--- a/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionFilter.java
+++ b/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionFilter.java
@@ -421,8 +421,12 @@ public class WebSessionFilter implements Filter {
private String doFilterV1(HttpServletRequest httpReq, ServletResponse res, FilterChain chain) throws IOException,
ServletException, CacheException {
WebSession cached = null;
+ String sesId;
- String sesId = httpReq.getRequestedSessionId();
+ if (httpReq.getSession(false) != null)
+ sesId = httpReq.getSession(false).getId();
+ else
+ sesId = httpReq.getRequestedSessionId();
if (sesId != null) {
sesId = transformSessionId(sesId);
@@ -503,8 +507,12 @@ public class WebSessionFilter implements Filter {
private String doFilterV2(HttpServletRequest httpReq, ServletResponse res, FilterChain chain)
throws IOException, ServletException, CacheException {
WebSessionV2 cached = null;
+ String sesId;
- String sesId = httpReq.getRequestedSessionId();
+ if (httpReq.getSession(false) != null)
+ sesId = httpReq.getSession(false).getId();
+ else
+ sesId = httpReq.getRequestedSessionId();
if (sesId != null) {
sesId = transformSessionId(sesId);
diff --git a/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionSelfTest.java b/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionSelfTest.java
index ba02ea7..8a5c27b 100644
--- a/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionSelfTest.java
+++ b/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionSelfTest.java
@@ -119,6 +119,11 @@ public class WebSessionSelfTest extends GridCommonAbstractTest {
testImplicitlyModification("ignite-webapp-config.xml");
}
+ @Test
+ public void testSessionCookie() throws Exception {
+ testSessionCookie("/modules/core/src/test/config/websession/example-cache.xml");
+ }
+
/**
* @throws Exception If failed.
*/
@@ -479,6 +484,122 @@ public class WebSessionSelfTest extends GridCommonAbstractTest {
}
/**
+ * Tests session cookie.
+ *
+ * @param cfg Configuration.
+ * @throws Exception If failed.
+ */
+ private void testSessionCookie(String cfg) throws Exception {
+ Server srv = null;
+ String sesId;
+
+ try {
+ srv = startServerWithLoginService(TEST_JETTY_PORT, cfg, null, new SessionLoginServlet());
+
+ URLConnection conn = new URL("http://localhost:" + TEST_JETTY_PORT + "/ignitetest/test").openConnection();
+
+ conn.connect();
+
+ String sesIdCookie1 = getSessionIdFromCookie(conn);
+
+ X.println(">>>", "Initial session Cookie: " + sesIdCookie1, ">>>");
+
+ assertTrue(sesIdCookie1.contains(".node0"));
+
+ try (BufferedReader rdr = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
+ sesId = rdr.readLine();
+
+ if (!keepBinary()) {
+ IgniteCache<String, HttpSession> cache = G.ignite().cache(getCacheName());
+
+ assertNotNull(cache);
+
+ HttpSession ses = cache.get(sesId);
+
+ assertNotNull(ses);
+
+ assertEquals("val1", ses.getAttribute("key1"));
+ }
+ else {
+ final IgniteCache<String, WebSessionEntity> cache = G.ignite().cache(getCacheName());
+
+ assertNotNull(cache);
+
+ final WebSessionEntity entity = cache.get(sesId);
+
+ assertNotNull(entity);
+
+ final byte[] data = entity.attributes().get("key1");
+
+ assertNotNull(data);
+
+ final Marshaller marshaller = G.ignite().configuration().getMarshaller();
+
+ final String val = marshaller.unmarshal(data, getClass().getClassLoader());
+
+ assertEquals("val1", val);
+ }
+ }
+
+ URLConnection conn2 = new URL("http://localhost:" + TEST_JETTY_PORT + "/ignitetest/login").openConnection();
+
+ HttpURLConnection con = (HttpURLConnection) conn2;
+
+ con.addRequestProperty("Cookie", "JSESSIONID=" + sesIdCookie1);
+
+ con.setRequestMethod("POST");
+
+ con.setDoOutput(true);
+
+ String sesIdCookie2 = getSessionIdFromCookie(con);
+
+ X.println(">>>", "Logged In session Cookie: " + sesIdCookie2, ">>>");
+
+ assertTrue(sesIdCookie2.contains(".node0"));
+
+ try (BufferedReader rdr = new BufferedReader(new InputStreamReader(con.getInputStream()))) {
+ String sesId2 = rdr.readLine();
+
+ if (!keepBinary()) {
+ IgniteCache<String, HttpSession> cache = G.ignite().cache(getCacheName());
+
+ assertNotNull(cache);
+
+ HttpSession ses = cache.get(sesId2);
+
+ assertNotNull(ses);
+
+ assertEquals("val1", ses.getAttribute("key1"));
+
+ }
+ else {
+ final IgniteCache<String, WebSessionEntity> cache = G.ignite().cache(getCacheName());
+
+ assertNotNull(cache);
+
+ final WebSessionEntity entity = cache.get(sesId2);
+
+ assertNotNull(entity);
+
+ final byte[] data = entity.attributes().get("key1");
+
+ assertNotNull(data);
+
+ final Marshaller marshaller = G.ignite().configuration().getMarshaller();
+
+ final String val = marshaller.unmarshal(data, getClass().getClassLoader());
+
+ assertEquals("val1", val);
+
+ }
+ }
+ }
+ finally {
+ stopServerWithLoginService(srv);
+ }
+ }
+
+ /**
* Tests invalidated sessions.
*
* @throws Exception Exception If failed.