[java-oidc-common] branch main updated: Extend ClientInformationManager with optional replacement.

Scott Cantor cantor.2 at osu.edu
Thu Mar 10 16:20:55 UTC 2022


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

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

View the commit online:
http://git.shibboleth.net/view/?p=java-oidc-common.git;a=commit;h=40e70ddb140925f2c66579d7476f470b886f812a

The following commit(s) were added to refs/heads/main by this push:
     new 40e70dd  Extend ClientInformationManager with optional replacement.
40e70dd is described below

commit 40e70ddb140925f2c66579d7476f470b886f812a
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Mar 10 11:20:31 2022 -0500

    Extend ClientInformationManager with optional replacement.
---
 .../oidc/metadata/ClientInformationManager.java    | 25 +++++++++++-
 .../StorageServiceClientInformationManager.java    | 44 ++++++++--------------
 ...StorageServiceClientInformationManagerTest.java | 19 ++++++++--
 3 files changed, 54 insertions(+), 34 deletions(-)

diff --git a/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/ClientInformationManager.java b/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/ClientInformationManager.java
index d3f002b..2cad8d1 100644
--- a/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/ClientInformationManager.java
+++ b/oidc-common-metadata-api/src/main/java/net/shibboleth/oidc/metadata/ClientInformationManager.java
@@ -34,12 +34,33 @@ public interface ClientInformationManager {
     /**
      * Store a {@link ClientInformation} object.
      * 
-     * @param clientInformation The client information to be stored.
-     * @param expiration The expiration for record, or null.
+     * <p>This method is deprecated, and is equivalent to calling the replacement method
+     * with replace set to false.</p>
+     * 
+     * @param clientInformation The client information to be stored
+     * @param expiration The expiration for record, or null
+     * 
      * @throws ClientInformationManagerException If the client information cannot be stored.
+     * 
+     * @deprecated
      */
+    @Deprecated(since="1.2.0", forRemoval=true)
     @Nonnull void storeClientInformation(@Nonnull final OIDCClientInformation clientInformation, 
             @Nullable final Instant expiration) throws ClientInformationManagerException;
+
+    /**
+     * Store a {@link ClientInformation} object.
+     * 
+     * @param clientInformation The client information to be stored
+     * @param expiration The expiration for record, or null
+     * @param replace whether to replace an existing entry
+     * 
+     * @throws ClientInformationManagerException If the client information cannot be stored.
+     */
+    @Nonnull default void storeClientInformation(@Nonnull final OIDCClientInformation clientInformation, 
+            @Nullable final Instant expiration, final boolean replace) throws ClientInformationManagerException {
+        storeClientInformation(clientInformation, expiration);
+    }
     
     /**
      * Invalidates or otherwise removes a {@link ClientInformation} from persistent storage.
diff --git a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/StorageServiceClientInformationManager.java b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/StorageServiceClientInformationManager.java
index 4cec426..8608b65 100644
--- a/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/StorageServiceClientInformationManager.java
+++ b/oidc-common-metadata-impl/src/main/java/net/shibboleth/oidc/metadata/impl/StorageServiceClientInformationManager.java
@@ -32,7 +32,6 @@ import com.nimbusds.openid.connect.sdk.rp.OIDCClientInformation;
 
 import net.shibboleth.oidc.metadata.ClientInformationManager;
 import net.shibboleth.oidc.metadata.ClientInformationManagerException;
-import net.shibboleth.utilities.java.support.component.ComponentSupport;
 
 /**
  * A {@link ClientInformationManager} exploiting {@link StorageService} for storing the data.
@@ -43,27 +42,11 @@ public class StorageServiceClientInformationManager extends BaseStorageServiceCl
     /** Class logger. */
     @Nonnull private final Logger log = LoggerFactory.getLogger(StorageServiceClientInformationResolver.class);
     
-    /** Whether to raise an exception when a duplicate is stored. */
-    private boolean ignoreDuplicates;
-    
-    /**
-     * Set whether attempts to insert a duplicate record should fail or be silently ignored.
-     * 
-     * <p>Defaults to true.</p>
-     * 
-     * @param flag flag to set
-     */
-    public void setIgnoreDuplicates(final boolean flag) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
-        
-        ignoreDuplicates = flag;
-    }
-    
     /** {@inheritDoc} */
-    @Override
-    public void storeClientInformation(final OIDCClientInformation clientInformation,
-            @Nullable final Instant expiration) throws ClientInformationManagerException {
-        log.debug("Attempting to store client information");
+    public void storeClientInformation(@Nonnull final OIDCClientInformation clientInformation,
+            @Nullable final Instant expiration, boolean replace) throws ClientInformationManagerException {
+        
+        log.debug("Attempting to store client information (replace={})", replace ? "true" : "false");
         final String clientId = clientInformation.getID().getValue();
         //TODO: configurable serialization
         final String serialized = clientInformation.toJSONObject().toJSONString();
@@ -71,13 +54,12 @@ public class StorageServiceClientInformationManager extends BaseStorageServiceCl
             if (getStorageService().create(CONTEXT_NAME, clientId, serialized,
                     expiration != null ? expiration.toEpochMilli() : null)) {
                 log.info("Successfully stored the client information for ID {}", clientId);
+            } else if (replace) {
+                getStorageService().update(CONTEXT_NAME, clientId, serialized,
+                        expiration != null ? expiration.toEpochMilli() : null);
             } else {
-                if (ignoreDuplicates) {
-                    log.warn("Attempt to store duplicate client information for ID {}", clientId);
-                } else {
-                    throw new ClientInformationManagerException(
-                            "Attempt to store duplicate client information for ID " + clientId);
-                }
+                throw new ClientInformationManagerException(
+                        "Attempt to store duplicate client information for ID " + clientId);
             }
         } catch (final IOException e) {
             throw new ClientInformationManagerException("Could not store the client information", e);
@@ -85,7 +67,13 @@ public class StorageServiceClientInformationManager extends BaseStorageServiceCl
     }
 
     /** {@inheritDoc} */
-    @Override
+    @Deprecated
+    public void storeClientInformation(@Nonnull final OIDCClientInformation clientInformation,
+            @Nullable final Instant expiration) throws ClientInformationManagerException {
+        storeClientInformation(clientInformation, expiration, false);
+    }
+
+    /** {@inheritDoc} */
     public void destroyClientInformation(final ClientID clientId) {
         if (clientId == null) {
             log.warn("The null clientId cannot be destroyed, nothing to do");
diff --git a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/StorageServiceClientInformationManagerTest.java b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/StorageServiceClientInformationManagerTest.java
index c121e94..7633e64 100644
--- a/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/StorageServiceClientInformationManagerTest.java
+++ b/oidc-common-metadata-impl/src/test/java/net/shibboleth/oidc/metadata/impl/StorageServiceClientInformationManagerTest.java
@@ -29,6 +29,7 @@ import com.nimbusds.oauth2.sdk.id.ClientID;
 import com.nimbusds.openid.connect.sdk.rp.OIDCClientInformation;
 import com.nimbusds.openid.connect.sdk.rp.OIDCClientMetadata;
 
+import net.shibboleth.oidc.metadata.ClientInformationManagerException;
 import net.shibboleth.oidc.metadata.criterion.ClientIDCriterion;
 import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
 
@@ -66,7 +67,17 @@ public class StorageServiceClientInformationManagerTest {
     @Test
     public void testStore() throws Exception {
         final OIDCClientInformation clientInformation = initializeInformation();
-        manager.storeClientInformation(clientInformation, null);
+        manager.storeClientInformation(clientInformation, null, false);
+        
+        try {
+            manager.storeClientInformation(clientInformation, null, false);
+            Assert.fail("Expected ClientInformationManagerException");
+        } catch (final ClientInformationManagerException e) {
+            // should throw
+        }
+        
+        manager.storeClientInformation(clientInformation, null, true);
+        
         final CriteriaSet criteria = initializeCriteria();
         final OIDCClientInformation result = resolver.resolveSingle(criteria);
         Assert.assertNotNull(result);
@@ -76,7 +87,7 @@ public class StorageServiceClientInformationManagerTest {
     @Test
     public void testNullDestroy() throws Exception {
         final OIDCClientInformation clientInformation = initializeInformation();
-        manager.storeClientInformation(clientInformation, null);
+        manager.storeClientInformation(clientInformation, null, false);
         manager.destroyClientInformation(null);
         final CriteriaSet criteria = initializeCriteria();
         final OIDCClientInformation result = resolver.resolveSingle(criteria);
@@ -87,7 +98,7 @@ public class StorageServiceClientInformationManagerTest {
     @Test
     public void testDestroy() throws Exception {
         final OIDCClientInformation clientInformation = initializeInformation();
-        manager.storeClientInformation(clientInformation, null);
+        manager.storeClientInformation(clientInformation, null, false);
         manager.destroyClientInformation(new ClientID(clientIdValue));
         final CriteriaSet criteria = initializeCriteria();
         final OIDCClientInformation result = resolver.resolveSingle(criteria);
@@ -97,7 +108,7 @@ public class StorageServiceClientInformationManagerTest {
     @Test
     public void testExpiration() throws Exception {
         final OIDCClientInformation clientInformation = initializeInformation();
-        manager.storeClientInformation(clientInformation, Instant.now().plusSeconds(2));
+        manager.storeClientInformation(clientInformation, Instant.now().plusSeconds(2), false);
         final CriteriaSet criteria = initializeCriteria();
         final OIDCClientInformation result = resolver.resolveSingle(criteria);
         Assert.assertNotNull(result);

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


More information about the commits mailing list