[java-opensaml] branch main updated: IDP-2047 - Get list of locked accounts

Scott Cantor cantor.2 at osu.edu
Mon Aug 7 16:33:09 UTC 2023


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

scantor pushed a commit to branch main
in repository java-opensaml.

View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=2949fa1e1a0bdddc1ed5eb44138f6ec9e2fb5a00

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

commit 2949fa1e1a0bdddc1ed5eb44138f6ec9e2fb5a00
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Aug 7 12:33:06 2023 -0400

    IDP-2047 - Get list of locked accounts
    
    https://shibboleth.atlassian.net/browse/IDP-2047
    
    Extend storage interface with filtering parameter.
---
 .../storage/AbstractMapBackedStorageService.java   |  7 +++--
 .../storage/EnumeratableStorageService.java        |  5 +++-
 .../storage/testing/StorageServiceTest.java        | 32 ++++++++++++++++++++--
 3 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/opensaml-storage-api/src/main/java/org/opensaml/storage/AbstractMapBackedStorageService.java b/opensaml-storage-api/src/main/java/org/opensaml/storage/AbstractMapBackedStorageService.java
index 6fb304da4..9404cbef4 100644
--- a/opensaml-storage-api/src/main/java/org/opensaml/storage/AbstractMapBackedStorageService.java
+++ b/opensaml-storage-api/src/main/java/org/opensaml/storage/AbstractMapBackedStorageService.java
@@ -247,7 +247,8 @@ public abstract class AbstractMapBackedStorageService extends AbstractStorageSer
     }
     
     /** {@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 Lock readLock = getLock().readLock();
         
         try {
@@ -267,9 +268,9 @@ public abstract class AbstractMapBackedStorageService extends AbstractStorageSer
                 return CollectionSupport.emptyList();
             }
             
-            final long now = System.currentTimeMillis();            
+            final long now = System.currentTimeMillis();         
             return dataMap.entrySet().stream()
-                    .filter(e -> e.getValue().isValid(now))
+                    .filter(e -> e.getValue().isValid(now) && (prefix != null ? e.getKey().startsWith(prefix) : true))
                     .map(Map.Entry::getKey)
                     .collect(CollectionSupport.nonnullCollector(Collectors.toUnmodifiableList())).get();
             
diff --git a/opensaml-storage-api/src/main/java/org/opensaml/storage/EnumeratableStorageService.java b/opensaml-storage-api/src/main/java/org/opensaml/storage/EnumeratableStorageService.java
index 62fe558ed..dac0a60db 100644
--- a/opensaml-storage-api/src/main/java/org/opensaml/storage/EnumeratableStorageService.java
+++ b/opensaml-storage-api/src/main/java/org/opensaml/storage/EnumeratableStorageService.java
@@ -17,6 +17,7 @@ package org.opensaml.storage;
 import java.io.IOException;
 
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
 
@@ -36,11 +37,13 @@ public interface EnumeratableStorageService extends StorageService {
      * Return an iterable collection of the keys stored in a context.
      * 
      * @param context the context to enumerate
+     * @param prefix optional prefix to filter keys
      * 
      * @return keys stored in a context
      * 
      * @throws IOException on error 
      */
-    @Nonnull Iterable<String> getContextKeys(@Nonnull @NotEmpty final String context) throws IOException;
+    @Nonnull Iterable<String> getContextKeys(@Nonnull @NotEmpty final String context, @Nullable final String prefix)
+            throws IOException;
     
 }
\ No newline at end of file
diff --git a/opensaml-testing/src/main/java/org/opensaml/storage/testing/StorageServiceTest.java b/opensaml-testing/src/main/java/org/opensaml/storage/testing/StorageServiceTest.java
index 8d5a56b16..66be3665b 100644
--- a/opensaml-testing/src/main/java/org/opensaml/storage/testing/StorageServiceTest.java
+++ b/opensaml-testing/src/main/java/org/opensaml/storage/testing/StorageServiceTest.java
@@ -91,7 +91,7 @@ public abstract class StorageServiceTest {
         }
         
         final List<String> keylist = new ArrayList<>();
-        Iterable<String> keys = shared.getContextKeys(context);
+        Iterable<String> keys = shared.getContextKeys(context, null);
         keys.forEach(keylist::add);
         Assert.assertEquals(keylist.size(), 100);
         
@@ -124,7 +124,7 @@ public abstract class StorageServiceTest {
         }
         
         keylist.clear();
-        keys = shared.getContextKeys(context);
+        keys = shared.getContextKeys(context, null);
         keys.forEach(keylist::add);
         Assert.assertEquals(keylist.size(), 0);
     }
@@ -146,7 +146,7 @@ public abstract class StorageServiceTest {
             Assert.assertNull(rec);
         }
         
-        Assert.assertFalse(shared.getContextKeys(context).iterator().hasNext());
+        Assert.assertFalse(shared.getContextKeys(context, null).iterator().hasNext());
     }
     
     @Test
@@ -226,6 +226,31 @@ public abstract class StorageServiceTest {
         Assert.assertNull(shared.read(o2));
     }
     
+    @Test
+    public void enumerate() throws IOException {
+        final String context = "zork";
+        shared.create(context, "foo", "bar", null);
+        shared.create(context, "foo2", "bar", null);
+        shared.create(context, "foo3", "bar", null);
+        shared.create(context, "foo33", "bar", null);
+        shared.create(context + "2", "foo3", "bar", null);
+        
+        final List<String> copy = new ArrayList<>();
+        Iterable<String> keys = shared.getContextKeys(context, null);
+        keys.forEach(copy::add);
+        Assert.assertEquals(copy.size(), 4);
+        
+        copy.clear();
+        keys = shared.getContextKeys(context, "foo");
+        keys.forEach(copy::add);
+        Assert.assertEquals(copy.size(), 4);
+
+        copy.clear();
+        keys = shared.getContextKeys(context, "foo3");
+        keys.forEach(copy::add);
+        Assert.assertEquals(copy.size(), 2);
+    }
+    
     @Context("context")
     @Key("key")
     @Value("value")
@@ -277,4 +302,5 @@ public abstract class StorageServiceTest {
         }
         
     }
+
 }
\ No newline at end of file

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


More information about the commits mailing list