From 701f52ee42890943282a1bd968abee22238a0dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kv=C3=ADdera?= Date: Sun, 9 Feb 2020 12:02:28 +0100 Subject: [PATCH 01/10] #4281 Removed misleading javadoc - see javadoc in Session interface --- .../main/java/org/apache/catalina/session/StandardSession.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/appserver/web/web-core/src/main/java/org/apache/catalina/session/StandardSession.java b/appserver/web/web-core/src/main/java/org/apache/catalina/session/StandardSession.java index 362be20c6a2..61acac21c62 100644 --- a/appserver/web/web-core/src/main/java/org/apache/catalina/session/StandardSession.java +++ b/appserver/web/web-core/src/main/java/org/apache/catalina/session/StandardSession.java @@ -698,9 +698,6 @@ public StandardSessionFacade run(){ } - /** - * Return the isValid flag for this session. - */ @Override public boolean isValid() { From 80994470ae2528468e15d573a496e7edd1741ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kv=C3=ADdera?= Date: Sun, 9 Feb 2020 12:02:54 +0100 Subject: [PATCH 02/10] #4281 Removed commented code --- .../org/apache/catalina/session/StandardSession.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/appserver/web/web-core/src/main/java/org/apache/catalina/session/StandardSession.java b/appserver/web/web-core/src/main/java/org/apache/catalina/session/StandardSession.java index 61acac21c62..e1668a69e27 100644 --- a/appserver/web/web-core/src/main/java/org/apache/catalina/session/StandardSession.java +++ b/appserver/web/web-core/src/main/java/org/apache/catalina/session/StandardSession.java @@ -713,15 +713,6 @@ public boolean isValid() { return true; } - /* SJSAS 6329289 - if (maxInactiveInterval >= 0) { - long timeNow = System.currentTimeMillis(); - int timeIdle = (int) ((timeNow - thisAccessedTime) / 1000L); - if (timeIdle >= maxInactiveInterval) { - expire(true); - } - } - */ // START SJSAS 6329289 if (hasExpired()) { expire(true); From ec1e4c5ba6905e56812105449301498b35de1aa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kv=C3=ADdera?= Date: Sun, 9 Feb 2020 12:08:22 +0100 Subject: [PATCH 03/10] #4281 Replaced field access by getter call - improves encapsulation of parent class --- .../glassfish/web/ha/session/management/BaseHASession.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java b/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java index c94a87e8190..fc6661efc59 100644 --- a/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java +++ b/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java @@ -233,9 +233,9 @@ public String superToString() { sb.append("]"); sb.append("\n"); - sb.append("isValid:" + this.isValid); + sb.append("isValid:" + getIsValid()); - if (this.isValid) { + if (getIsValid()) { Enumeration attrNamesEnum = getAttributeNames(); while(attrNamesEnum.hasMoreElements()) { String nextAttrName = attrNamesEnum.nextElement(); From 117549e4abbb2cf107a31dd3dae3526c3b96caf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kv=C3=ADdera?= Date: Sun, 9 Feb 2020 12:10:08 +0100 Subject: [PATCH 04/10] #4281 Replaced isValid by getIsValid - partially fixes cyclic dependency between SingleSignOnEntry:121 and BaseHASession:239 --- .../java/org/apache/catalina/session/StandardSession.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/appserver/web/web-core/src/main/java/org/apache/catalina/session/StandardSession.java b/appserver/web/web-core/src/main/java/org/apache/catalina/session/StandardSession.java index e1668a69e27..465e6d98ae5 100644 --- a/appserver/web/web-core/src/main/java/org/apache/catalina/session/StandardSession.java +++ b/appserver/web/web-core/src/main/java/org/apache/catalina/session/StandardSession.java @@ -1345,10 +1345,10 @@ public Map getAttributes() { @Override public Enumeration getAttributeNames() { - if (!isValid()) + if (!getIsValid()) { throw new IllegalStateException - ("getAttributeNames: " + RESOURCE_BUNDLE.getString(LogFacade.SESSION_INVALIDATED_EXCEPTION)); - + ("getAttributeNames: " + RESOURCE_BUNDLE.getString(LogFacade.SESSION_INVALIDATED_EXCEPTION)); + } return (new Enumerator<>(attributes.keySet(), true)); From 4ff359bc4a661539823bedf6bb95d3d411d22ced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kv=C3=ADdera?= Date: Sun, 9 Feb 2020 12:13:41 +0100 Subject: [PATCH 05/10] #4281 Added missing @Deprecated annotations --- .../org/apache/catalina/session/StandardSession.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/appserver/web/web-core/src/main/java/org/apache/catalina/session/StandardSession.java b/appserver/web/web-core/src/main/java/org/apache/catalina/session/StandardSession.java index 465e6d98ae5..ac4230c14f4 100644 --- a/appserver/web/web-core/src/main/java/org/apache/catalina/session/StandardSession.java +++ b/appserver/web/web-core/src/main/java/org/apache/catalina/session/StandardSession.java @@ -1299,6 +1299,7 @@ public ServletContext getServletContext() { * Java Servlet API. */ @Override + @Deprecated public HttpSessionContext getSessionContext() { if (sessionContext == null) sessionContext = new StandardSessionContext(); @@ -1368,6 +1369,7 @@ public Enumeration getAttributeNames() { * getAttribute() */ @Override + @Deprecated public Object getValue(String name) { return (getAttribute(name)); } @@ -1384,6 +1386,7 @@ public Object getValue(String name) { * getAttributeNames() */ @Override + @Deprecated public String[] getValueNames() { if (!isValid()) @@ -1628,6 +1631,7 @@ public boolean isNew() { * setAttribute() */ @Override + @Deprecated public void putValue(String name, Object value) { setAttribute(name, value); } @@ -1775,6 +1779,7 @@ public void removeAttribute(String name, boolean notify, * removeAttribute() */ @Override + @Deprecated public void removeValue(String name) { removeAttribute(name); } @@ -2445,7 +2450,7 @@ private static Cache buildSerializableCache() { * @deprecated As of Java Servlet API 2.1 with no replacement. The * interface will be removed in a future version of this API. */ - +@Deprecated final class StandardSessionContext implements HttpSessionContext { @@ -2460,6 +2465,7 @@ final class StandardSessionContext implements HttpSessionContext { * and will be removed in a future version of the API. */ @Override + @Deprecated public Enumeration getIds() { return (new Enumerator<>(dummy)); } @@ -2476,6 +2482,7 @@ public Enumeration getIds() { * future version of the API. */ @Override + @Deprecated public HttpSession getSession(String id) { return (null); } From 4f53447f366b033ea5ecba6d32b8cb101fffdfb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kv=C3=ADdera?= Date: Sun, 9 Feb 2020 12:29:58 +0100 Subject: [PATCH 06/10] #4281 Introduced internal getter that does not cause deadlock - isValid has side effect described in Session interface - we cannot break contract --- .../apache/catalina/session/StandardSession.java | 13 +++++++++++-- .../web/ha/session/management/BaseHASession.java | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/appserver/web/web-core/src/main/java/org/apache/catalina/session/StandardSession.java b/appserver/web/web-core/src/main/java/org/apache/catalina/session/StandardSession.java index ac4230c14f4..0491da18ce9 100644 --- a/appserver/web/web-core/src/main/java/org/apache/catalina/session/StandardSession.java +++ b/appserver/web/web-core/src/main/java/org/apache/catalina/session/StandardSession.java @@ -1346,13 +1346,22 @@ public Map getAttributes() { @Override public Enumeration getAttributeNames() { - if (!getIsValid()) { + if (!isValid()) { throw new IllegalStateException ("getAttributeNames: " + RESOURCE_BUNDLE.getString(LogFacade.SESSION_INVALIDATED_EXCEPTION)); } - return (new Enumerator<>(attributes.keySet(), true)); + return getAttributeNamesInternal(); + + } + /** + * Returns names of attributes even for expired session. + * + * @return names of attributes ignoring state of session + */ + protected Enumerator getAttributeNamesInternal() { + return new Enumerator<>(attributes.keySet(), true); } diff --git a/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java b/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java index fc6661efc59..316375f9daf 100644 --- a/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java +++ b/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java @@ -236,7 +236,7 @@ public String superToString() { sb.append("isValid:" + getIsValid()); if (getIsValid()) { - Enumeration attrNamesEnum = getAttributeNames(); + Enumeration attrNamesEnum = getAttributeNamesInternal(); while(attrNamesEnum.hasMoreElements()) { String nextAttrName = attrNamesEnum.nextElement(); Object nextAttrValue = getAttributeInternal(nextAttrName); From 6f9b573a6380d8470e1ec7845508add375017bbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kv=C3=ADdera?= Date: Sun, 9 Feb 2020 12:33:53 +0100 Subject: [PATCH 07/10] #4281 Fixed usage of StringBuilder --- .../ha/session/management/BaseHASession.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java b/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java index 316375f9daf..ccc58d38bef 100644 --- a/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java +++ b/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java @@ -225,7 +225,7 @@ private void writeObject(ObjectOutputStream stream) throws IOException { /** * Return a string representation of this object. */ - public String superToString() { + private CharSequence superToString() { StringBuilder sb = new StringBuilder(1000); sb.append("BaseHASession["); @@ -233,7 +233,7 @@ public String superToString() { sb.append("]"); sb.append("\n"); - sb.append("isValid:" + getIsValid()); + sb.append("isValid:").append(getIsValid()); if (getIsValid()) { Enumeration attrNamesEnum = getAttributeNamesInternal(); @@ -241,23 +241,22 @@ public String superToString() { String nextAttrName = attrNamesEnum.nextElement(); Object nextAttrValue = getAttributeInternal(nextAttrName); sb.append("\n"); - sb.append("attrName = " + nextAttrName); - sb.append(" : attrValue = " + nextAttrValue); + sb.append("attrName = ").append(nextAttrName); + sb.append(" : attrValue = ").append(nextAttrValue); } } - return sb.toString(); + return sb; // END S1AS } public String toString() { - StringBuilder sb = new StringBuilder(200); - //sb.append(super.toString()); - sb.append(this.superToString()); - sb.append(" ssoid: " + this.getSsoId()); - sb.append(" userName: " + this.getUserName()); - sb.append(" version: " + this.getVersion()); - sb.append(" persistent: " + this.isPersistent()); + StringBuilder sb = new StringBuilder(1200); + sb.append(superToString()); + sb.append(" ssoid: ").append(getSsoId()); + sb.append(" userName: ").append(getUserName()); + sb.append(" version: ").append(getVersion()); + sb.append(" persistent: ").append(isPersistent()); return sb.toString(); } From 35d77d63330cb3aa057c0cc189ef5bdcb1d8372d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kv=C3=ADdera?= Date: Sun, 9 Feb 2020 12:38:30 +0100 Subject: [PATCH 08/10] #4281 Added missing final to StringBuilder --- .../glassfish/web/ha/session/management/BaseHASession.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java b/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java index ccc58d38bef..dd7de0e7971 100644 --- a/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java +++ b/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java @@ -227,7 +227,7 @@ private void writeObject(ObjectOutputStream stream) throws IOException { */ private CharSequence superToString() { - StringBuilder sb = new StringBuilder(1000); + final StringBuilder sb = new StringBuilder(1000); sb.append("BaseHASession["); sb.append(id); sb.append("]"); @@ -251,7 +251,7 @@ private CharSequence superToString() { } public String toString() { - StringBuilder sb = new StringBuilder(1200); + final StringBuilder sb = new StringBuilder(1200); sb.append(superToString()); sb.append(" ssoid: ").append(getSsoId()); sb.append(" userName: ").append(getUserName()); From 6577c67af9c3a93d948aa4b0c2097bcaecce0bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kv=C3=ADdera?= Date: Sun, 9 Feb 2020 12:38:47 +0100 Subject: [PATCH 09/10] #4281 Added missing @Override annotation --- .../org/glassfish/web/ha/session/management/BaseHASession.java | 1 + 1 file changed, 1 insertion(+) diff --git a/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java b/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java index dd7de0e7971..4991bd3657e 100644 --- a/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java +++ b/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java @@ -250,6 +250,7 @@ private CharSequence superToString() { // END S1AS } + @Override public String toString() { final StringBuilder sb = new StringBuilder(1200); sb.append(superToString()); From f6a945b33163a9bb61c624d71ea999bd19a986a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kv=C3=ADdera?= Date: Sun, 9 Feb 2020 12:54:26 +0100 Subject: [PATCH 10/10] #4281 Added another missing final keywords to edited code --- .../glassfish/web/ha/session/management/BaseHASession.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java b/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java index 4991bd3657e..80dbc3c975e 100644 --- a/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java +++ b/appserver/web/web-ha/src/main/java/org/glassfish/web/ha/session/management/BaseHASession.java @@ -236,10 +236,10 @@ private CharSequence superToString() { sb.append("isValid:").append(getIsValid()); if (getIsValid()) { - Enumeration attrNamesEnum = getAttributeNamesInternal(); + final Enumeration attrNamesEnum = getAttributeNamesInternal(); while(attrNamesEnum.hasMoreElements()) { - String nextAttrName = attrNamesEnum.nextElement(); - Object nextAttrValue = getAttributeInternal(nextAttrName); + final String nextAttrName = attrNamesEnum.nextElement(); + final Object nextAttrValue = getAttributeInternal(nextAttrName); sb.append("\n"); sb.append("attrName = ").append(nextAttrName); sb.append(" : attrValue = ").append(nextAttrValue);