[ 
https://issues.apache.org/jira/browse/KNOX-2554?focusedWorklogId=582399&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-582399
 ]

ASF GitHub Bot logged work on KNOX-2554:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 14/Apr/21 11:31
            Start Date: 14/Apr/21 11:31
    Worklog Time Spent: 10m 
      Work Description: smolnar82 commented on a change in pull request #433:
URL: https://github.com/apache/knox/pull/433#discussion_r613166024



##########
File path: 
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/TokenStateDatabase.java
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.services.token.impl;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import javax.sql.DataSource;
+
+import org.apache.knox.gateway.services.security.token.TokenMetadata;
+
+public class TokenStateDatabase {
+  private static final String TOKENS_TABLE_NAME = "KNOX_TOKENS";
+  private static final String ADD_TOKEN_SQL = "INSERT INTO " + 
TOKENS_TABLE_NAME + "(token_id, issue_time, expiration, max_lifetime) VALUES(?, 
?, ?, ?)";
+  private static final String REMOVE_TOKENS_SQL_PREFIX = "DELETE FROM " + 
TOKENS_TABLE_NAME + " WHERE token_id IN (";

Review comment:
       I found [this 
article](https://stackoverflow.com/questions/1661921/java-programming-where-should-sql-statements-be-stored)
 on SO. Let me quote the pros/cons of my approach and I do agree with them:
   ```
   Hardcoded/encapsulated in DAO layer
   
   Pros:
   
   SQL is kept in the objects that access data (encapsulation)
   SQL is easy to write (speed of development)
   SQL is easy to track down when changes are required
   A simple solution (no messy architecture)
   
   Cons:
   
   SQL cannot be reviewed/changed by DBA
   SQL is likely to become DB-specific
   SQL can become hard to maintain
   ```
   Given the fact we are going to keep authentication tokens in this DB table, 
I have the impression that these SQL statements should reside in the Java class 
so that they cannot be changed/manipulated/removed easily.
   
   At my previous workplaces, where pure JDBC was used, no ORM (Hibernate, 
EclipseLink, etc) frameworks, we followed this approach because of the 
above-listed `pros`.
   There was an exception where lots of business logic was written in PL/SQL 
but - to be honest - I really hated that part.




-- 
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.

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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 582399)
    Time Spent: 2h 10m  (was: 2h)

> Implement JDBC TokenStateService
> --------------------------------
>
>                 Key: KNOX-2554
>                 URL: https://issues.apache.org/jira/browse/KNOX-2554
>             Project: Apache Knox
>          Issue Type: Task
>            Reporter: Sandor Molnar
>            Assignee: Sandor Molnar
>            Priority: Major
>             Fix For: 1.6.0
>
>          Time Spent: 2h 10m
>  Remaining Estimate: 0h
>
> Add a new TokenStateService implementation that stores token metadata in a 
> relational database.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to