[java-plugin-storage-jdbc] branch main updated: IDP-2047 - Get list of locked accounts

Scott Cantor cantor.2 at osu.edu
Mon Aug 7 16:35:59 UTC 2023


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch main
in repository java-plugin-storage-jdbc.

View the commit online:
http://git.shibboleth.net/view/?p=java-plugin-storage-jdbc.git;a=commit;h=93e434285ebdbed3eaf8854ed75201650cd38e40

The following commit(s) were added to refs/heads/main by this push:
     new 93e4342  IDP-2047 - Get list of locked accounts
93e4342 is described below

commit 93e434285ebdbed3eaf8854ed75201650cd38e40
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Aug 7 12:35:35 2023 -0400

    IDP-2047 - Get list of locked accounts
    
    https://shibboleth.atlassian.net/browse/IDP-2047
    
    Add filtering parameter to new method.
    Implement via like/wildcard.
---
 .../storage/jdbc/impl/JDBCStorageService.java      | 38 ++++++++++++++++------
 .../storage/jdbc/impl/JDBCStorageServiceTest.java  | 10 +++---
 2 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/jdbc-storage-impl/src/main/java/net/shibboleth/plugin/storage/jdbc/impl/JDBCStorageService.java b/jdbc-storage-impl/src/main/java/net/shibboleth/plugin/storage/jdbc/impl/JDBCStorageService.java
index 0a9b6e2..ccaac7e 100644
--- a/jdbc-storage-impl/src/main/java/net/shibboleth/plugin/storage/jdbc/impl/JDBCStorageService.java
+++ b/jdbc-storage-impl/src/main/java/net/shibboleth/plugin/storage/jdbc/impl/JDBCStorageService.java
@@ -111,15 +111,20 @@ public final class JDBCStorageService extends AbstractStorageService
 
     /** The SQL to update the expiration for a given context.  */
     static final String DEFAULT_UPDATE_EXPIRES_BY_CONTEXT_SQL =
-        "UPDATE StorageRecords SET expires=? WHERE context = ? AND expires > ? ";
+        "UPDATE StorageRecords SET expires=? WHERE context = ? AND expires > ?";
 
     /** The SQL to delete a given context.  */
-    static final String DEFAULT_DELETE_BY_CONTEXT_SQL = "DELETE FROM StorageRecords WHERE context=? ";
-    
+    static final String DEFAULT_DELETE_BY_CONTEXT_SQL = "DELETE FROM StorageRecords WHERE context=?";
+
     /** The SQL to fetch the keys in a context. */
     static final String DEFAULT_GET_CONTEXT_KEYS_SQL =
             "SELECT id FROM StorageRecords WHERE context=? AND (expires IS NULL OR expires > ?)";
 
+    /** The SQL to fetch matching keys in a context.  */
+    static final String DEFAULT_GET_CONTEXT_KEYS_WITH_PREFIX_SQL =
+            "SELECT id FROM StorageRecords WHERE context=? AND id like ? AND (expires IS NULL OR expires > ?)";
+
+
     /** Class logger. */
     @Nonnull private final Logger log = LoggerFactory.getLogger(JDBCStorageService.class);
     
@@ -240,6 +245,12 @@ public final class JDBCStorageService extends AbstractStorageService
      */
     @Nonnull @NotEmpty private String getContextKeysSQL = DEFAULT_GET_CONTEXT_KEYS_SQL;
 
+    /**
+     * The SQL to fetch the keys in a context with a prefix.
+     * Default: {@value #DEFAULT_GET_CONTEXT_KEYS_WITH_PREFIX_SQL}
+     */
+    @Nonnull @NotEmpty private String getContextKeysWithPrefixSQL = DEFAULT_GET_CONTEXT_KEYS_WITH_PREFIX_SQL;
+
     /** Constructor.
      * Set the defaults so that they can be over-ridden by Spring.
      */
@@ -1070,18 +1081,27 @@ public final class JDBCStorageService extends AbstractStorageService
     }
     
     /** {@inheritDoc} */
-    @Nonnull public Iterable<String> getContextKeys(@Nonnull @NotEmpty final String context) throws IOException {
+    @Nonnull public Iterable<String> getContextKeys(@Nonnull @NotEmpty final String context,
+            @Nullable final String prefix) throws IOException {
         
         final List<String> result = new ArrayList<>();
 
         try (final ConnectionWithLock connection= new ConnectionWithLock(true, false)) {
-            final PreparedStatement query = connection.prepareStatement(getContextKeysSQL);
+            final PreparedStatement query =
+                    connection.prepareStatement(prefix != null ? getContextKeysWithPrefixSQL : getContextKeysSQL);
             query.setString(1, context);
 
             final Long now = System.currentTimeMillis();
-            setExpires(query, 2, now);
-
-            log.trace("GetContextKeys:: '{}': 1: '{}', 2: '{}'", deleteByContextSQL, context, now);
+            
+            if (prefix != null) {
+                query.setString(2, prefix + "%");
+                setExpires(query, 3, now);
+                log.trace("GetContextKeyWithPrefixs:: '{}': 1: '{}', 2: '{}', 3: '{}'", getContextKeysWithPrefixSQL,
+                        context, prefix, now);
+            } else {
+                setExpires(query, 2, now);
+                log.trace("GetContextKeys:: '{}': 1: '{}', 2: '{}'", getContextKeysSQL, context, now);
+            }
             
             final ResultSet results = query.executeQuery();
             
@@ -1257,6 +1277,4 @@ public final class JDBCStorageService extends AbstractStorageService
         }
     }
 
-    /** {@inheritDoc} */
-
 }
\ No newline at end of file
diff --git a/jdbc-storage-impl/src/test/java/net/shibboleth/plugin/storage/jdbc/impl/JDBCStorageServiceTest.java b/jdbc-storage-impl/src/test/java/net/shibboleth/plugin/storage/jdbc/impl/JDBCStorageServiceTest.java
index 80ea28e..ebbc53d 100644
--- a/jdbc-storage-impl/src/test/java/net/shibboleth/plugin/storage/jdbc/impl/JDBCStorageServiceTest.java
+++ b/jdbc-storage-impl/src/test/java/net/shibboleth/plugin/storage/jdbc/impl/JDBCStorageServiceTest.java
@@ -48,13 +48,14 @@ import net.shibboleth.shared.component.ComponentInitializationException;
 /**
  * Test of {@link JDBCStorageService} implementation.
  */
+ at SuppressWarnings("javadoc")
 public class JDBCStorageServiceTest extends StorageServiceTest {
 
     @NonnullBeforeTest private JDBCStorageService storageService;
 
     private final boolean USE_SQLSERVER = false;
 
-    private static final String INIT_SQL_SQLSERVER="CREATE TABLE StorageRecords (\r\n"
+    @Nonnull private static final String INIT_SQL_SQLSERVER="CREATE TABLE StorageRecords (\r\n"
    		+ "  context varchar(255) COLLATE  Latin1_General_100_CS_AS  NOT NULL,\n"
    		+ "  id varchar(255) COLLATE Latin1_General_100_CS_AS NOT NULL,\n"
    		+ "  expires bigint DEFAULT NULL,\n"
@@ -63,7 +64,7 @@ public class JDBCStorageServiceTest extends StorageServiceTest {
    		+ "  PRIMARY KEY (context,id)\n"
    		+ ")";
     
-    private static final String INIT_SQL_HSQLDB="CREATE TABLE StorageRecords (\r\n"
+    @Nonnull private static final String INIT_SQL_HSQLDB="CREATE TABLE StorageRecords (\r\n"
    		+ "  context varchar(255) NOT NULL,\n"
    		+ "  id varchar(255) NOT NULL,\n"
    		+ "  expires bigint DEFAULT NULL,\n"
@@ -72,13 +73,14 @@ public class JDBCStorageServiceTest extends StorageServiceTest {
    		+ "  PRIMARY KEY (context,id)\n"
    		+ ")";
 
-    private static final String CLEANUP_SQL = "DROP TABLE StorageRecords;";
+    @Nonnull private static final String CLEANUP_SQL = "DROP TABLE StorageRecords;";
 
     /** Contexts used for testing. */
     private Object[][] contexts;
     
     @NonnullBeforeTest private BasicDataSource dataSource;
 
+    /** Constructor. */
     public JDBCStorageServiceTest() { 
         final SecureRandom random1 = new SecureRandom();
         contexts = new Object[10][1];
@@ -165,7 +167,7 @@ public class JDBCStorageServiceTest extends StorageServiceTest {
     }
 
     @Nonnull protected EnumeratableStorageService getStorageService() {
-        assert storageService!=null;
+        assert storageService != null;
         return storageService;
     }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list