[java-shib-attribute] branch main updated: IDP-1966 - Migrate PRC lookup out of plugins and into AttributeResolutionContext
Scott Cantor
cantor.2 at osu.edu
Wed Jun 22 13:36:03 UTC 2022
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-shib-attribute.
View the commit online:
http://git.shibboleth.net/view/?p=java-shib-attribute.git;a=commit;h=28b5b0f5ad46b1f374ac80be597914d97bb88cd5
The following commit(s) were added to refs/heads/main by this push:
new 28b5b0f5a IDP-1966 - Migrate PRC lookup out of plugins and into AttributeResolutionContext
28b5b0f5a is described below
commit 28b5b0f5ad46b1f374ac80be597914d97bb88cd5
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Jun 22 09:36:00 2022 -0400
IDP-1966 - Migrate PRC lookup out of plugins and into
AttributeResolutionContext
https://shibboleth.atlassian.net/browse/IDP-1966
---
.../policyrule/impl/PredicateRuleParser.java | 3 +-
.../attribute/resolver/AbstractResolverPlugin.java | 45 +++++-----------------
.../context/AttributeResolutionContext.java | 39 +++++++++++++++++++
.../schema/shibboleth-attribute-resolver.xsd | 2 +-
.../ad/impl/ScriptedAttributeDefinition.java | 30 ++-------------
.../resolver/spring/BaseResolverPluginParser.java | 6 ++-
6 files changed, 59 insertions(+), 66 deletions(-)
diff --git a/shib-attribute-filter-spring/src/main/java/net/shibboleth/idp/attribute/filter/spring/policyrule/impl/PredicateRuleParser.java b/shib-attribute-filter-spring/src/main/java/net/shibboleth/idp/attribute/filter/spring/policyrule/impl/PredicateRuleParser.java
index ce41d6263..1e4b96435 100644
--- a/shib-attribute-filter-spring/src/main/java/net/shibboleth/idp/attribute/filter/spring/policyrule/impl/PredicateRuleParser.java
+++ b/shib-attribute-filter-spring/src/main/java/net/shibboleth/idp/attribute/filter/spring/policyrule/impl/PredicateRuleParser.java
@@ -51,7 +51,8 @@ public class PredicateRuleParser extends BasePolicyRuleParser {
builder.addPropertyReference("rulePredicate",
StringSupport.trimOrNull(element.getAttributeNS(null, "rulePredicateRef")));
if (element.hasAttributeNS(null, "contextStrategyRef")) {
- DeprecationSupport.warn(ObjectType.ATTRIBUTE, "contextStrategyRef", parserContext.toString(), "(removed)");
+ DeprecationSupport.warn(ObjectType.ATTRIBUTE, "contextStrategyRef",
+ parserContext.getReaderContext().getResource().getDescription(), "(removed)");
}
}
}
diff --git a/shib-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/AbstractResolverPlugin.java b/shib-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/AbstractResolverPlugin.java
index e6e046323..d9a61588a 100644
--- a/shib-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/AbstractResolverPlugin.java
+++ b/shib-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/AbstractResolverPlugin.java
@@ -20,14 +20,12 @@ package net.shibboleth.idp.attribute.resolver;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;
-import java.util.function.Function;
import java.util.function.Predicate;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
-import org.opensaml.messaging.context.navigate.ParentContextLookup;
import org.opensaml.profile.context.MetricContext;
import org.opensaml.profile.context.ProfileRequestContext;
import org.slf4j.Logger;
@@ -68,9 +66,6 @@ public abstract class AbstractResolverPlugin<ResolvedType> extends AbstractIdent
/** Whether we add DisplayInformation to derived attributes. */
private boolean suppressDisplayInformation;
- /** Strategy to get the {@link ProfileRequestContext}. */
- @Nonnull private Function<AttributeResolutionContext, ProfileRequestContext> profileContextStrategy;
-
/** Criterion that must be met for this plugin to be active for the given request. */
@Nullable private Predicate<ProfileRequestContext> activationCondition;
@@ -82,7 +77,6 @@ public abstract class AbstractResolverPlugin<ResolvedType> extends AbstractIdent
/** Constructor. */
public AbstractResolverPlugin() {
- profileContextStrategy = new ParentContextLookup<>(ProfileRequestContext.class);
attributeDependencies = Collections.emptySet();
dataConnectorDependencies = Collections.emptySet();
}
@@ -108,7 +102,7 @@ public abstract class AbstractResolverPlugin<ResolvedType> extends AbstractIdent
}
/** {@inheritDoc} */
- @Override public boolean isPropagateResolutionExceptions() {
+ public boolean isPropagateResolutionExceptions() {
return propagateResolutionExceptions;
}
@@ -125,30 +119,8 @@ public abstract class AbstractResolverPlugin<ResolvedType> extends AbstractIdent
propagateResolutionExceptions = propagate;
}
-
- /**
- * Gets the mechanism to find out the {@link ProfileRequestContext}.
- *
- * @return the mechanism
- */
- public Function<AttributeResolutionContext, ProfileRequestContext> getProfileContextStrategy() {
- return profileContextStrategy;
- }
-
- /**
- * Sets the mechanism to find out the {@link ProfileRequestContext}.
- *
- * @param strategy the mechanism
- */
- public void setProfileContextStrategy(final Function<AttributeResolutionContext, ProfileRequestContext> strategy) {
- ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
- ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
-
- profileContextStrategy = Constraint.isNotNull(strategy, "Profile Context Strategy cannot be null");
- }
-
/** {@inheritDoc} */
- @Override @Nullable public Predicate<ProfileRequestContext> getActivationCondition() {
+ @Nullable public Predicate<ProfileRequestContext> getActivationCondition() {
return activationCondition;
}
@@ -179,7 +151,7 @@ public abstract class AbstractResolverPlugin<ResolvedType> extends AbstractIdent
*
* @return unmodifiable list of dependencies for this plugin, never null
*/
- @Override @NonnullAfterInit @NonnullElements @Unmodifiable public Set<ResolverDataConnectorDependency>
+ @NonnullAfterInit @NonnullElements @Unmodifiable public Set<ResolverDataConnectorDependency>
getDataConnectorDependencies() {
return dataConnectorDependencies;
}
@@ -231,7 +203,7 @@ public abstract class AbstractResolverPlugin<ResolvedType> extends AbstractIdent
*
* @throws ResolutionException thrown if there was a problem resolving the attributes
*/
- @Override @Nullable public final ResolvedType resolve(@Nonnull final AttributeResolutionContext resolutionContext)
+ @Nullable public final ResolvedType resolve(@Nonnull final AttributeResolutionContext resolutionContext)
throws ResolutionException {
ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this);
ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
@@ -242,7 +214,8 @@ public abstract class AbstractResolverPlugin<ResolvedType> extends AbstractIdent
try {
if (null != activationCondition) {
- final ProfileRequestContext profileRequestContext = profileContextStrategy.apply(resolutionContext);
+ final ProfileRequestContext profileRequestContext =
+ resolutionContext.getProfileRequestContextLookupStrategy().apply(resolutionContext);
if (!activationCondition.test(profileRequestContext)) {
log.debug("Resolver plugin '{}': activation criteria not met, nothing to do", getId());
return null;
@@ -390,7 +363,8 @@ public abstract class AbstractResolverPlugin<ResolvedType> extends AbstractIdent
* @return true iff the {@link #stopTimer(AttributeResolutionContext)} method needs to be called
*/
private boolean startTimer(@Nonnull final AttributeResolutionContext resolutionContext) {
- final ProfileRequestContext prc = profileContextStrategy.apply(resolutionContext);
+ final ProfileRequestContext prc =
+ resolutionContext.getProfileRequestContextLookupStrategy().apply(resolutionContext);
if (prc != null) {
final MetricContext timerCtx = prc.getSubcontext(MetricContext.class);
if (timerCtx != null) {
@@ -407,7 +381,8 @@ public abstract class AbstractResolverPlugin<ResolvedType> extends AbstractIdent
* @param resolutionContext attribute resolution context
*/
private void stopTimer(@Nonnull final AttributeResolutionContext resolutionContext) {
- final ProfileRequestContext prc = profileContextStrategy.apply(resolutionContext);
+ final ProfileRequestContext prc =
+ resolutionContext.getProfileRequestContextLookupStrategy().apply(resolutionContext);
if (prc != null) {
final MetricContext timerCtx = prc.getSubcontext(MetricContext.class);
if (timerCtx != null) {
diff --git a/shib-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/context/AttributeResolutionContext.java b/shib-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/context/AttributeResolutionContext.java
index 0a3a56776..e05e4a9fc 100644
--- a/shib-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/context/AttributeResolutionContext.java
+++ b/shib-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/context/AttributeResolutionContext.java
@@ -22,6 +22,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
@@ -29,6 +30,8 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
import org.opensaml.messaging.context.BaseContext;
+import org.opensaml.messaging.context.navigate.ParentContextLookup;
+import org.opensaml.profile.context.ProfileRequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -56,6 +59,9 @@ public final class AttributeResolutionContext extends BaseContext {
/** (internal) Names of the attributes that have been requested to be resolved. */
@Nonnull @NonnullElements private Set<String> requestedAttributeNames;
+ /** Strategy used to locate the {@link ProfileRequestContext} to use. */
+ @Nonnull private Function<AttributeResolutionContext,ProfileRequestContext> prcLookupStrategy;
+
/** The principal associated with this resolution. */
@Nullable private String principal;
@@ -79,6 +85,9 @@ public final class AttributeResolutionContext extends BaseContext {
/** Constructor. */
public AttributeResolutionContext() {
+ // Defaults to immediate parent of ARC.
+ prcLookupStrategy = new ParentContextLookup<>(ProfileRequestContext.class);
+
allowCachedResults = true;
requestedAttributeNames = new HashSet<>();
resolvedAttributes = Collections.emptyMap();
@@ -111,6 +120,36 @@ public final class AttributeResolutionContext extends BaseContext {
return this;
}
+ /**
+ * Gets the strategy used to locate the {@link ProfileRequestContext} associated with this context.
+ *
+ * @return lookup strategy
+ *
+ * @since 5.0.0
+ */
+ @Nonnull
+ public Function<AttributeResolutionContext,ProfileRequestContext> getProfileRequestContextLookupStrategy() {
+ return prcLookupStrategy;
+ }
+
+ /**
+ * Set the strategy used to locate the {@link ProfileRequestContext} associated with this context.
+ *
+ * @param strategy strategy used to locate the {@link ProfileRequestContext} associated with a given
+ * {@link AttributeResolutionContext}
+ *
+ * @return this context
+ *
+ * @since 5.0.0
+ */
+ public AttributeResolutionContext setProfileRequestContextLookupStrategy(
+ @Nonnull final Function<AttributeResolutionContext,ProfileRequestContext> strategy) {
+
+ prcLookupStrategy = Constraint.isNotNull(strategy, "ProfileRequestContext lookup strategy cannot be null");
+
+ return this;
+ }
+
/**
* Get whether to allow for results from cache (defaults to true).
*
diff --git a/shib-attribute-resolver-api/src/main/resources/schema/shibboleth-attribute-resolver.xsd b/shib-attribute-resolver-api/src/main/resources/schema/shibboleth-attribute-resolver.xsd
index e8cee12df..8126677ef 100644
--- a/shib-attribute-resolver-api/src/main/resources/schema/shibboleth-attribute-resolver.xsd
+++ b/shib-attribute-resolver-api/src/main/resources/schema/shibboleth-attribute-resolver.xsd
@@ -241,7 +241,7 @@
<attribute name="profileContextStrategyRef" type="resolver:string">
<annotation>
<documentation>
- A reference to a function to locate the profile context
+ DEPRECATED: A reference to a function to locate the profile context
</documentation>
</annotation>
</attribute>
diff --git a/shib-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/impl/ScriptedAttributeDefinition.java b/shib-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/impl/ScriptedAttributeDefinition.java
index 75abe0d42..e78c84bef 100644
--- a/shib-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/impl/ScriptedAttributeDefinition.java
+++ b/shib-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/impl/ScriptedAttributeDefinition.java
@@ -20,7 +20,6 @@ package net.shibboleth.idp.attribute.resolver.ad.impl;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.function.Function;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -28,7 +27,6 @@ import javax.annotation.concurrent.ThreadSafe;
import javax.script.ScriptContext;
import javax.script.ScriptException;
-import org.opensaml.messaging.context.navigate.ParentContextLookup;
import org.opensaml.profile.context.ProfileRequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -81,18 +79,9 @@ public class ScriptedAttributeDefinition extends AbstractAttributeDefinition {
/** Evaluator. */
@NonnullAfterInit private AttributeDefinitionScriptEvaluator scriptEvaluator;
- /** Strategy used to locate the {@link ProfileRequestContext} to use. */
- @Nonnull private Function<AttributeResolutionContext,ProfileRequestContext> prcLookupStrategy;
-
/** The custom object we inject into all scripts. */
@Nullable private Object customObject;
- /** Constructor. */
- public ScriptedAttributeDefinition() {
- // Defaults to ProfileRequestContext -> AttributeContext.
- prcLookupStrategy = new ParentContextLookup<>(ProfileRequestContext.class);
- }
-
/**
* Return the custom (externally provided) object.
*
@@ -135,21 +124,6 @@ public class ScriptedAttributeDefinition extends AbstractAttributeDefinition {
script = Constraint.isNotNull(definitionScript, "Attribute definition script cannot be null");
}
- /**
- * Set the strategy used to locate the {@link ProfileRequestContext} associated with a given
- * {@link AttributeResolutionContext}.
- *
- * @param strategy strategy used to locate the {@link ProfileRequestContext} associated with a given
- * {@link AttributeResolutionContext}
- */
- public void setProfileRequestContextLookupStrategy(
- @Nonnull final Function<AttributeResolutionContext,ProfileRequestContext> strategy) {
- ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
- ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
-
- prcLookupStrategy = Constraint.isNotNull(strategy, "ProfileRequestContext lookup strategy cannot be null");
- }
-
/** {@inheritDoc} */
@Override
protected void doInitialize() throws ComponentInitializationException {
@@ -236,7 +210,9 @@ public class ScriptedAttributeDefinition extends AbstractAttributeDefinition {
log.debug("{} Adding contexts to script context", getLogPrefix());
scriptContext.setAttribute("resolutionContext", input[0], ScriptContext.ENGINE_SCOPE);
- final ProfileRequestContext prc = prcLookupStrategy.apply((AttributeResolutionContext) input[0]);
+ final ProfileRequestContext prc =
+ ((AttributeResolutionContext) input[0]).getProfileRequestContextLookupStrategy().apply(
+ (AttributeResolutionContext) input[0]);
if (null == prc) {
log.error("{} ProfileRequestContext could not be located", getLogPrefix());
}
diff --git a/shib-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/BaseResolverPluginParser.java b/shib-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/BaseResolverPluginParser.java
index cb1ddbadc..c113d5aac 100644
--- a/shib-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/BaseResolverPluginParser.java
+++ b/shib-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/BaseResolverPluginParser.java
@@ -37,6 +37,8 @@ import net.shibboleth.idp.attribute.resolver.spring.impl.InputDataConnectorParse
import net.shibboleth.idp.profile.logic.RelyingPartyIdPredicate;
import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.logic.PredicateSupport;
+import net.shibboleth.utilities.java.support.primitive.DeprecationSupport;
+import net.shibboleth.utilities.java.support.primitive.DeprecationSupport.ObjectType;
import net.shibboleth.utilities.java.support.primitive.StringSupport;
import net.shibboleth.utilities.java.support.xml.ElementSupport;
@@ -89,8 +91,8 @@ public abstract class BaseResolverPluginParser extends AbstractCustomBeanDefinit
}
if (config.hasAttributeNS(null, "profileContextStrategyRef")) {
- builder.addPropertyReference("profileContextStrategy",
- StringSupport.trimOrNull(config.getAttributeNS(null, "profileContextStrategyRef")));
+ DeprecationSupport.warn(ObjectType.ATTRIBUTE, "profileContextStrategyRef",
+ parserContext.getReaderContext().getResource().getDescription(), "(removed)");
}
if (config.hasAttributeNS(null, "propagateResolutionExceptions")) {
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list