smolnar82 commented on code in PR #797:
URL: https://github.com/apache/knox/pull/797#discussion_r1343107208


##########
gateway-release/home/conf/topologies/knoxsso.xml:
##########
@@ -114,6 +114,11 @@
             <name>knoxsso.token.ttl</name>
             <value>86400000</value>
         </param>
+        <param>
+            <!-- since 2.1.0: KnoxSSO cookie validation -->
+            <name>knox.token.exp.server-managed</name>

Review Comment:
   The value is set to `false`.



##########
gateway-release/home/conf/topologies/homepage.xml:
##########
@@ -55,6 +55,11 @@
          <role>federation</role>
          <name>SSOCookieProvider</name>
          <enabled>true</enabled>
+         <param>
+            <!-- since 2.1.0: KnoxSSO cookie validation -->
+            <name>knox.token.exp.server-managed</name>

Review Comment:
   The value is set to `false`.



##########
gateway-spi/src/main/java/org/apache/knox/gateway/session/SessionInvalidator.java:
##########
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.knox.gateway.session;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public interface SessionInvalidator {

Review Comment:
   Fair enough; I'll add the missing docs.



##########
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/TokenStateDatabase.java:
##########
@@ -58,6 +58,9 @@ public class TokenStateDatabase {
   private static final String GET_TOKENS_CREATED_BY_USER_NAME_SQL = "SELECT 
kt.token_id, kt.issue_time, kt.expiration, kt.max_lifetime, ktm.md_name, 
ktm.md_value FROM " + TOKENS_TABLE_NAME
       + " kt, " + TOKEN_METADATA_TABLE_NAME + " ktm WHERE kt.token_id = 
ktm.token_id AND kt.token_id IN (SELECT token_id FROM " + 
TOKEN_METADATA_TABLE_NAME + " WHERE md_name = '" + TokenMetadata.CREATED_BY + 
"' AND md_value = ? )"
       + " ORDER BY kt.issue_time";
+  private static final String GET_DISABLED_SSO_COOKIE_TOKEN_IDS = "SELECT 
token_id FROM " + TOKEN_METADATA_TABLE_NAME + " meta1 WHERE meta1.md_name = 
'knoxSSOCookie' AND meta1.md_value = 'true' "
+      + "AND EXISTS (SELECT token_id FROM " + TOKEN_METADATA_TABLE_NAME + " 
meta2 WHERE meta1.token_id = meta2.token_id AND meta2.md_name = 'enabled' AND 
meta2.md_value = 'false')";
+  private static final String REMOVE_DISBLED_SSO_COOKIES_SQL = "DELETE FROM " 
+ TOKENS_TABLE_NAME + " WHERE token_id IN (" + 
GET_DISABLED_SSO_COOKIE_TOKEN_IDS + ")";

Review Comment:
   I'll fix that.



##########
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/TokenStateServiceMessages.java:
##########
@@ -202,6 +202,15 @@ public interface TokenStateServiceMessages {
   @Message(level = MessageLevel.ERROR, text = "An error occurred while 
removing expired tokens from the database : {0}")
   void errorRemovingTokensFromDatabase(String errorMessage, @StackTrace(level 
= MessageLevel.DEBUG) Exception e);
 
+  @Message(level = MessageLevel.INFO, text = "Removing {0} disabled KnoxSSO 
cookie(s) from the database: {1}")
+  void removingDisabledKnoxSsoCookiesFromDatabase(int size, String 
disabledKnoxSsoCookieList);
+
+  @Message(level = MessageLevel.DEBUG, text = "{0} disabled KnoxSSO cookies 
have been removed from the database")
+  void removedDisabledKnoxSsoCookiesFromDatabase(int size);
+
+  @Message(level = MessageLevel.ERROR, text = "An error occurred while 
removing disabled KnoxSSO cookies from the database : {0}")
+  void errorRemovingDisabledKnoxSsoCookiesFromDatabase(String errorMessage, 
@StackTrace(level = MessageLevel.DEBUG) Exception e);

Review Comment:
   The error itself is on the `ERROR` level. The stack trace which we bind to 
`DEBUG`, just like we do in many other cases across the code.



##########
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/DefaultTokenStateService.java:
##########
@@ -350,11 +350,12 @@ private String getTimestampDisplay(long timestamp) {
   }
 
   /**
-   * Method that deletes expired tokens based on the token timestamp.
+   * Method that deletes expired tokens based on the token timestamp as well 
as disabled KnoxSSO cookies.
    */
   protected void evictExpiredTokens() {
     if (readyForEviction()) {
       final Set<String> tokensToEvict = getExpiredTokens();
+      tokensToEvict.addAll(getDisabledKnoxSsoCookies());

Review Comment:
   It was working properly during my tests, but let me give it another 
try/thought.



##########
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/JDBCTokenStateService.java:
##########
@@ -224,6 +224,19 @@ protected void evictExpiredTokens() {
     } catch (SQLException e) {
       log.errorRemovingTokensFromDatabase(e.getMessage(), e);
     }
+
+    //removing disabled KnoxSSO cookies since they are no longer needed
+    try {
+      final Set<String> disabledKnoxSsoCookies = 
tokenDatabase.getDisabledKnoxSsoCookies();
+      if (!disabledKnoxSsoCookies.isEmpty()) {
+        
log.removingDisabledKnoxSsoCookiesFromDatabase(disabledKnoxSsoCookies.size(),
+            String.join(", ", disabledKnoxSsoCookies.stream().map(tokenId -> 
Tokens.getTokenIDDisplayText(tokenId)).collect(Collectors.toSet())));
+        final int numOfRemovedDisabledKnoxSsoCookies = 
tokenDatabase.deleteDisabledKnoxSsoCookies();

Review Comment:
   Yeah, there is a small chance for that. But this is also true for the 
expired tokens above too.



##########
gateway-release/home/conf/topologies/manager.xml:
##########
@@ -51,6 +51,11 @@
          <role>federation</role>
          <name>SSOCookieProvider</name>
          <enabled>true</enabled>
+         <param>
+            <!-- since 2.1.0: KnoxSSO cookie validation -->
+            <name>knox.token.exp.server-managed</name>

Review Comment:
   The value is set to `false`.



##########
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/DefaultTokenStateService.java:
##########
@@ -383,6 +384,23 @@ protected Set<String> getExpiredTokens() {
     return expiredTokens;
   }
 
+  protected Set<String> getDisabledKnoxSsoCookies() {
+    final Set<String> disbaledKnoxSsoCookies = new HashSet<>();

Review Comment:
   I'll fix it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to