[java-opensaml COMMIT] in /trunk/opensaml-saml-impl/src: main/java/org/opensaml/saml/saml2/profile/impl/DecryptNameID...

noreply at shibboleth.net noreply at shibboleth.net
Fri Mar 28 12:22:59 EDT 2014


Author: scantor
Date: Fri Mar 28 12:22:59 2014
New Revision: 3741

URL: http://svn.shibboleth.net/view/java-opensaml?rev=3741&view=rev
Log:
Relocate security parameters and enhance action with a predicate.

Modified:
    trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/profile/impl/DecryptNameIDs.java
    trunk/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/profile/impl/DecryptNameIDsTest.java

Modified: trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/profile/impl/DecryptNameIDs.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/profile/impl/DecryptNameIDs.java?rev=3741&r1=3740&r2=3741&view=diff
==============================================================================
--- trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/profile/impl/DecryptNameIDs.java (original)
+++ trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/profile/impl/DecryptNameIDs.java Fri Mar 28 12:22:59 2014
@@ -20,6 +20,7 @@
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
+import net.shibboleth.utilities.java.support.collection.Pair;
 import net.shibboleth.utilities.java.support.component.ComponentSupport;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 
@@ -38,6 +39,7 @@
 import org.opensaml.saml.saml2.core.Assertion;
 import org.opensaml.saml.saml2.core.AuthnRequest;
 import org.opensaml.saml.saml2.core.Condition;
+import org.opensaml.saml.saml2.core.EncryptedElementType;
 import org.opensaml.saml.saml2.core.EncryptedID;
 import org.opensaml.saml.saml2.core.LogoutRequest;
 import org.opensaml.saml.saml2.core.ManageNameIDRequest;
@@ -59,6 +61,8 @@
 
 import com.google.common.base.Function;
 import com.google.common.base.Functions;
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
 
 /**
  * Action to decrypt an {@link EncryptedID} element and replace it with the decrypted {@link NameID}
@@ -69,7 +73,7 @@
  * message.</p> 
  * 
  * <p>The {@link SecurityParametersContext} governing the decryption process is located by a lookup
- * strategy, by default a child of the profile request context.</p>
+ * strategy, by default a child of the inbound message context.</p>
  * 
  * @event {@link EventIds#PROCEED_EVENT_ID}
  * @event {@link EventIds#INVALID_MSG_CTX}
@@ -90,17 +94,22 @@
     /** Strategy used to locate the SAML message to operate on. */
     @Nonnull private Function<ProfileRequestContext, Object> messageLookupStrategy;
     
+    /** Predicate dertermining whether to attempt decryption. */
+    @Nonnull private Predicate<Pair<ProfileRequestContext,EncryptedElementType>> decryptionPredicate;
+    
     /** The decryption object. */
     @Nullable private Decrypter decrypter;
     
     /** Message to operate on. */
-    @Nullable private Object message;
+    @Nullable private SAMLObject message;
     
     /** Constructor. */
     public DecryptNameIDs() {
         errorFatal = true;
-        securityParamsLookupStrategy = new ChildContextLookup<>(SecurityParametersContext.class);
+        securityParamsLookupStrategy = Functions.compose(new ChildContextLookup<>(SecurityParametersContext.class),
+                new InboundMessageContextLookup());
         messageLookupStrategy = Functions.compose(new MessageLookup<>(Object.class), new InboundMessageContextLookup());
+        decryptionPredicate = Predicates.alwaysTrue();
     }
     
     /**
@@ -141,18 +150,32 @@
         messageLookupStrategy = Constraint.isNotNull(strategy, "Message lookup strategy cannot be null");
     }
     
+    /**
+     * Set the predicate used to determine whether to attempt decryption.
+     * 
+     * @param predicate predicate to use
+     */
+    public synchronized void setDecryptionPredicate(
+            @Nonnull final Predicate<Pair<ProfileRequestContext,EncryptedElementType>> predicate) {
+        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        
+        decryptionPredicate = Constraint.isNotNull(predicate, "Decryption predicate cannot be null");
+    }
+    
     /** {@inheritDoc} */
     @Override
     protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) throws ProfileException {
-        message = messageLookupStrategy.apply(profileRequestContext);
-        if (message == null) {
+        Object theMessage = messageLookupStrategy.apply(profileRequestContext);
+        if (theMessage == null) {
             log.debug("{} No message was returned by lookup strategy", getLogPrefix());
             ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_MSG_CTX);
             return false;
-        } else if (!(message instanceof SAMLObject)) {
+        } else if (!(theMessage instanceof SAMLObject)) {
             log.debug("{} Message was not a SAML construct, nothing to do", getLogPrefix());
             return false;
         }
+        
+        message = (SAMLObject) theMessage;
         

[... 562 lines stripped ...]


More information about the commits mailing list