[java-opensaml COMMIT] in /trunk: opensaml-core/src/main/java/org/opensaml/core/criterion/SatisfyAnyCriterion.java op...

noreply at shibboleth.net noreply at shibboleth.net
Wed Jun 1 16:26:46 EDT 2016


Author: putmanb
Date: Wed Jun  1 16:26:45 2016
New Revision: 4461

URL: http://svn.shibboleth.net/view/java-opensaml?rev=4461&view=rev
Log:
OSJ-130: Create metadata index impl for artifact sourceID

Refactor so that the entity descriptor indexing operation is performed by an injected function,
rather than being hardcoded to compute the SHA-1 digest of the entityID.
Move the SHA-1 impl into the default function.

Added:
    trunk/opensaml-core/src/main/java/org/opensaml/core/criterion/SatisfyAnyCriterion.java   (with props)
Modified:
    trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/index/impl/ArtifactSourceIDMetadataIndex.java

Modified: trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/index/impl/ArtifactSourceIDMetadataIndex.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/index/impl/ArtifactSourceIDMetadataIndex.java?rev=4461&r1=4460&r2=4461&view=diff
==============================================================================
--- trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/index/impl/ArtifactSourceIDMetadataIndex.java	(original)
+++ trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/index/impl/ArtifactSourceIDMetadataIndex.java	Wed Jun  1 16:26:45 2016
@@ -27,12 +27,6 @@
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
-import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
-import net.shibboleth.utilities.java.support.codec.Base64Support;
-import net.shibboleth.utilities.java.support.logic.Constraint;
-import net.shibboleth.utilities.java.support.primitive.StringSupport;
-import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
-
 import org.opensaml.saml.criterion.ArtifactSourceIDCriterion;
 import org.opensaml.saml.metadata.resolver.index.MetadataIndex;
 import org.opensaml.saml.metadata.resolver.index.MetadataIndexKey;
@@ -41,7 +35,14 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Function;
 import com.google.common.base.MoreObjects;
+
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+import net.shibboleth.utilities.java.support.codec.Base64Support;
+import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
+import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
 
 /**
  * An implementation of {@link MetadataIndex} which indexes entities by their artifact SourceID values.
@@ -51,32 +52,33 @@
     /** Logger. */
     private Logger log = LoggerFactory.getLogger(ArtifactSourceIDMetadataIndex.class);
     
+    /** Indexing function instance to use. */
+    private Function<EntityDescriptor, Set<MetadataIndexKey>> indexingFunction;
+    
+    /**
+     * Constructor.
+     * 
+     * <p>As the descriptor indexing function uses the default impl 
+     * {@link SHA1SourceIDEntityDescriptorIndexingFunction}.</p>
+     */
+    public ArtifactSourceIDMetadataIndex() {
+        this(new SHA1SourceIDEntityDescriptorIndexingFunction());
+    }
+    
+    /**
+     * Constructor.
+     *
+     * @param descriptorIndexingFunction the function used to produce index keys from an entity descriptor
+     */
+    public ArtifactSourceIDMetadataIndex(Function<EntityDescriptor, Set<MetadataIndexKey>> descriptorIndexingFunction) {
+        indexingFunction = Constraint.isNotNull(descriptorIndexingFunction, 
+                "EntityDescriptor indexing function may not be null");
+    }
+
     /** {@inheritDoc} */
     @Nullable public Set<MetadataIndexKey> generateKeys(@Nonnull EntityDescriptor descriptor) {
         Constraint.isNotNull(descriptor, "EntityDescriptor was null");
-        String entityID = StringSupport.trimOrNull(descriptor.getEntityID());
-        if (entityID == null) {
-            return null;
-        }
-        
-        try {
-            MessageDigest sha1Digester = MessageDigest.getInstance(JCAConstants.DIGEST_SHA1);
-            byte[] sourceID = sha1Digester.digest(entityID.getBytes("UTF-8"));
-            if (log.isTraceEnabled()) {
-                log.trace("For entityID '{}' produced artifact SourceID index value '{}'", 
-                        entityID, Base64Support.encode(sourceID, false));
-            }
-            return Collections.<MetadataIndexKey>singleton(new ArtifactSourceIDMetadataIndexKey(sourceID));
-        } catch (NoSuchAlgorithmException e) {
-            // SHA-1 should be supported in every JVM, so this should never happen.
-            log.error("Digest algorithm '{}' was invalid for encoding artifact SourceID", JCAConstants.DIGEST_SHA1, e);
-            return null;
-        } catch (UnsupportedEncodingException e) {
-            // UTF-8 should be supported in every JVM, this should never happen.
-            log.error("UTF-8 was unsupported for encoding artifact SourceID!");
-            return null;
-        }
-        
+        return indexingFunction.apply(descriptor);

[... 51 lines stripped ...]


More information about the commits mailing list