[java-identity-provider] branch master updated: IDP-1160 - Add activation condition to profile configs

Scott Cantor cantor.2 at osu.edu
Wed Apr 12 10:13:40 EDT 2017


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

scantor pushed a commit to branch master
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=2d26fd89bf64a1544b4213f37d36da1a32304c86

The following commit(s) were added to refs/heads/master by this push:
       new  2d26fd8   IDP-1160 - Add activation condition to profile configs
2d26fd8 is described below

commit 2d26fd89bf64a1544b4213f37d36da1a32304c86
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Apr 12 10:13:38 2017 -0400

    IDP-1160 - Add activation condition to profile configs
    
    https://issues.shibboleth.net/jira/browse/IDP-1160
---
 .../config/impl/AbstractProtocolConfiguration.java |  4 +-
 .../AbstractConditionalProfileConfiguration.java   | 67 ++++++++++++++++++++++
 .../config/ConditionalProfileConfiguration.java    | 40 +++++++++++++
 .../profile/impl/SelectProfileConfiguration.java   | 19 ++++--
 .../config/AbstractSAMLProfileConfiguration.java   |  4 +-
 5 files changed, 126 insertions(+), 8 deletions(-)

diff --git a/idp-cas-impl/src/main/java/net/shibboleth/idp/cas/config/impl/AbstractProtocolConfiguration.java b/idp-cas-impl/src/main/java/net/shibboleth/idp/cas/config/impl/AbstractProtocolConfiguration.java
index ac6cf72..dca1e61 100644
--- a/idp-cas-impl/src/main/java/net/shibboleth/idp/cas/config/impl/AbstractProtocolConfiguration.java
+++ b/idp-cas-impl/src/main/java/net/shibboleth/idp/cas/config/impl/AbstractProtocolConfiguration.java
@@ -23,7 +23,7 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import net.shibboleth.idp.cas.ticket.impl.TicketIdentifierGenerationStrategy;
-import net.shibboleth.idp.profile.config.AbstractProfileConfiguration;
+import net.shibboleth.idp.profile.config.AbstractConditionalProfileConfiguration;
 import net.shibboleth.idp.profile.config.SecurityConfiguration;
 import net.shibboleth.utilities.java.support.annotation.Duration;
 import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
@@ -43,7 +43,7 @@ import com.google.common.base.Predicates;
  * 
  * @author Marvin S. Addison
  */
-public abstract class AbstractProtocolConfiguration extends AbstractProfileConfiguration implements
+public abstract class AbstractProtocolConfiguration extends AbstractConditionalProfileConfiguration implements
         InitializableComponent {
 
     /** CAS base protocol URI. */
diff --git a/idp-profile-api/src/main/java/net/shibboleth/idp/profile/config/AbstractConditionalProfileConfiguration.java b/idp-profile-api/src/main/java/net/shibboleth/idp/profile/config/AbstractConditionalProfileConfiguration.java
new file mode 100644
index 0000000..dec25f2
--- /dev/null
+++ b/idp-profile-api/src/main/java/net/shibboleth/idp/profile/config/AbstractConditionalProfileConfiguration.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.idp.profile.config;
+
+import javax.annotation.Nonnull;
+
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
+
+import net.shibboleth.utilities.java.support.annotation.ParameterName;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+import net.shibboleth.utilities.java.support.logic.Constraint;
+import org.opensaml.profile.context.ProfileRequestContext;
+
+/**
+ * Base class for {@link ConditionalProfileConfiguration} implementations.
+ *
+ * @since 3.4.0
+ */
+public abstract class AbstractConditionalProfileConfiguration extends AbstractProfileConfiguration
+        implements ConditionalProfileConfiguration {
+
+    /** Activation condition. */
+    @Nonnull private Predicate<ProfileRequestContext> activationCondition;
+
+    /**
+     * Constructor.
+     * 
+     * @param id ID of the communication profile, never null or empty
+     */
+    public AbstractConditionalProfileConfiguration(@Nonnull @NotEmpty @ParameterName(name="id") final String id) {
+        super(id);
+        
+        activationCondition = Predicates.alwaysTrue();
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    @Nonnull public Predicate<ProfileRequestContext> getActivationCondition() {
+        return activationCondition;
+    }
+
+    /**
+     * Set an activation condition to control this profile.
+     *
+     * @param condition condition to apply
+     */
+    public void setActivationCondition(@Nonnull final Predicate<ProfileRequestContext> condition) {
+        activationCondition = Constraint.isNotNull(condition, "Activation condition cannot be null");
+    }
+    
+}
\ No newline at end of file
diff --git a/idp-profile-api/src/main/java/net/shibboleth/idp/profile/config/ConditionalProfileConfiguration.java b/idp-profile-api/src/main/java/net/shibboleth/idp/profile/config/ConditionalProfileConfiguration.java
new file mode 100644
index 0000000..12c91a2
--- /dev/null
+++ b/idp-profile-api/src/main/java/net/shibboleth/idp/profile/config/ConditionalProfileConfiguration.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.idp.profile.config;
+
+import javax.annotation.Nonnull;
+
+import org.opensaml.profile.context.ProfileRequestContext;
+
+import com.google.common.base.Predicate;
+
+/**
+ * A {@link ProfileConfiguration} supporting an activation condition.
+ * 
+ * @since 3.4.0
+ */
+public interface ConditionalProfileConfiguration extends ProfileConfiguration {
+
+    /**
+     * Get the {@link SecurityConfiguration} to use with this profile.
+     * 
+     * @return security configuration to use with this profile
+     */
+    @Nonnull Predicate<ProfileRequestContext> getActivationCondition();
+    
+}
\ No newline at end of file
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/SelectProfileConfiguration.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/SelectProfileConfiguration.java
index fee3339..bbbbf80 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/SelectProfileConfiguration.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/SelectProfileConfiguration.java
@@ -22,6 +22,7 @@ import javax.annotation.Nullable;
 
 import net.shibboleth.idp.profile.AbstractProfileAction;
 import net.shibboleth.idp.profile.IdPEventIds;
+import net.shibboleth.idp.profile.config.ConditionalProfileConfiguration;
 import net.shibboleth.idp.profile.config.ProfileConfiguration;
 import net.shibboleth.idp.profile.context.RelyingPartyContext;
 import net.shibboleth.idp.relyingparty.RelyingPartyConfiguration;
@@ -83,6 +84,11 @@ public class SelectProfileConfiguration extends AbstractProfileAction {
     /** {@inheritDoc} */
     @Override
     protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+        
+        if (!super.doPreExecute(profileRequestContext)) {
+            return false;
+        }
+        
         rpCtx = relyingPartyContextLookupStrategy.apply(profileRequestContext);
         if (rpCtx == null) {
             log.debug("{} No relying party context associated with this profile request", getLogPrefix());
@@ -96,7 +102,7 @@ public class SelectProfileConfiguration extends AbstractProfileAction {
             return false;
         }
         
-        return super.doPreExecute(profileRequestContext);
+        return true;
     }
     
     /** {@inheritDoc} */
@@ -111,10 +117,15 @@ public class SelectProfileConfiguration extends AbstractProfileAction {
             log.warn("{} Profile {} is not available for RP configuration {} (RPID {})",
                     new Object[] {getLogPrefix(), profileId, rpConfig.getId(), rpCtx.getRelyingPartyId(),});
             ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_PROFILE_CONFIG);
-            return;
+        } else if (profileConfiguration instanceof ConditionalProfileConfiguration
+                && !((ConditionalProfileConfiguration) profileConfiguration).getActivationCondition().apply(
+                        profileRequestContext)) {
+            log.warn("{} Profile {} is not active for RP configuration {} (RPID {})",
+                    new Object[] {getLogPrefix(), profileId, rpConfig.getId(), rpCtx.getRelyingPartyId(),});
+            ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_PROFILE_CONFIG);
+        } else {
+            rpCtx.setProfileConfig(profileConfiguration);
         }
-
-        rpCtx.setProfileConfig(profileConfiguration);
     }
     
 }
\ No newline at end of file
diff --git a/idp-saml-api/src/main/java/net/shibboleth/idp/saml/profile/config/AbstractSAMLProfileConfiguration.java b/idp-saml-api/src/main/java/net/shibboleth/idp/saml/profile/config/AbstractSAMLProfileConfiguration.java
index 6e67e94..ec9bc80 100644
--- a/idp-saml-api/src/main/java/net/shibboleth/idp/saml/profile/config/AbstractSAMLProfileConfiguration.java
+++ b/idp-saml-api/src/main/java/net/shibboleth/idp/saml/profile/config/AbstractSAMLProfileConfiguration.java
@@ -26,7 +26,7 @@ import java.util.Set;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
-import net.shibboleth.idp.profile.config.AbstractProfileConfiguration;
+import net.shibboleth.idp.profile.config.AbstractConditionalProfileConfiguration;
 import net.shibboleth.utilities.java.support.annotation.Duration;
 import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
 import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
@@ -46,7 +46,7 @@ import com.google.common.base.Predicates;
 import com.google.common.collect.ImmutableSet;
 
 /** Base class for SAML profile configurations. */
-public abstract class AbstractSAMLProfileConfiguration extends AbstractProfileConfiguration implements
+public abstract class AbstractSAMLProfileConfiguration extends AbstractConditionalProfileConfiguration implements
         SAMLProfileConfiguration {
 
     /** Class logger. */

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


More information about the commits mailing list