[java-opensaml COMMIT] /trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/binding/artifact/StorageServi...

noreply at shibboleth.net noreply at shibboleth.net
Mon Jul 8 14:15:27 EDT 2013


Author: scantor
Date: Mon Jul  8 14:15:27 2013
New Revision: 3406

URL: http://svn.shibboleth.net/view/java-opensaml?rev=3406&view=rev
Log:
Honor storage limits.

Modified:
    trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/binding/artifact/StorageServiceSAMLArtifactMap.java

Modified: trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/binding/artifact/StorageServiceSAMLArtifactMap.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/binding/artifact/StorageServiceSAMLArtifactMap.java?rev=3406&r1=3405&r2=3406&view=diff
==============================================================================
--- trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/binding/artifact/StorageServiceSAMLArtifactMap.java (original)
+++ trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/binding/artifact/StorageServiceSAMLArtifactMap.java Mon Jul  8 14:15:27 2013
@@ -25,6 +25,7 @@
 import net.shibboleth.utilities.java.support.annotation.constraint.NonnullAfterInit;
 import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
 import net.shibboleth.utilities.java.support.component.AbstractDestructableIdentifiableInitializableComponent;
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
 import net.shibboleth.utilities.java.support.component.ComponentValidationException;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 
@@ -47,6 +48,9 @@
 
     /** Artifact mapping storage. */
     @NonnullAfterInit private StorageService artifactStore;
+    
+    /** Maximum size of artifacts we can handle. */
+    private int artifactStoreKeySize;
 
     /** Lifetime of an artifact in milliseconds. */
     private long artifactLifetime;
@@ -71,6 +75,13 @@
         artifactStore.validate();
     }
     
+    /** {@inheritDoc} */
+    protected void doInitialize() throws ComponentInitializationException {
+        // We can't shorten the artifacts as lookup keys at the moment because
+        // the key is used to recreate the original artifact value.
+        artifactStoreKeySize = getStorageService().getCapabilities().getKeySize();
+    }
+    
     /**
      * Get the artifact store.
      * 
@@ -133,12 +144,19 @@
     
     /** {@inheritDoc} */
     public boolean contains(@Nonnull @NotEmpty final String artifact) throws IOException {
+        if (artifact.length() > artifactStoreKeySize) {
+            throw new IOException("Length of artifact (" + artifact.length() + ") exceeds storage capabilities");
+        }
         return getStorageService().read(STORAGE_CONTEXT, artifact) != null;
     }
 
     /** {@inheritDoc} */
     @Nullable public SAMLArtifactMapEntry get(@Nonnull @NotEmpty final String artifact) throws IOException {
         log.debug("Attempting to retrieve entry for artifact: {}", artifact);
+        
+        if (artifact.length() > artifactStoreKeySize) {
+            throw new IOException("Length of artifact (" + artifact.length() + ") exceeds storage capabilities");
+        }
         
         StorageRecord record = getStorageService().read(STORAGE_CONTEXT, artifact);
         
@@ -154,6 +172,10 @@
     /** {@inheritDoc} */
     public void put(@Nonnull @NotEmpty final String artifact, @Nonnull @NotEmpty final String relyingPartyId,
             @Nonnull @NotEmpty final String issuerId, @Nonnull final SAMLObject samlMessage) throws IOException {
+
+        if (artifact.length() > artifactStoreKeySize) {
+            throw new IOException("Length of artifact (" + artifact.length() + ") exceeds storage capabilities");
+        }
 
         SAMLArtifactMapEntry artifactEntry =
                 getEntryFactory().newEntry(artifact, issuerId, relyingPartyId, samlMessage);
@@ -174,6 +196,10 @@
     public void remove(@Nonnull @NotEmpty final String artifact) throws IOException {
         log.debug("Removing artifact entry: {}", artifact);
         
+        if (artifact.length() > artifactStoreKeySize) {
+            throw new IOException("Length of artifact (" + artifact.length() + ") exceeds storage capabilities");
+        }
+
         getStorageService().delete(STORAGE_CONTEXT, artifact);
     }
 



More information about the commits mailing list