[java-oidc-common] branch main updated: Add adaptor to allow functions using the PRC to work when passed Msg Ctx
Phil Smart
philip.smart at jisc.ac.uk
Mon Jan 9 12:42:53 UTC 2023
This is an automated email from the git hooks/post-receive script.
philsmart pushed a commit to branch main
in repository java-oidc-common.
View the commit online:
http://git.shibboleth.net/view/?p=java-oidc-common.git;a=commit;h=dd0dfd4336b75a517be17e96ce11525cc84366d7
The following commit(s) were added to refs/heads/main by this push:
new dd0dfd4 Add adaptor to allow functions using the PRC to work when passed Msg Ctx
dd0dfd4 is described below
commit dd0dfd4336b75a517be17e96ce11525cc84366d7
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Mon Jan 9 12:42:50 2023 +0000
Add adaptor to allow functions using the PRC to work when passed Msg Ctx
---
.../MessageContextLookupFunctionAdaptor.java | 87 ++++++++++++++++++++++
1 file changed, 87 insertions(+)
diff --git a/oidc-common-profile-api/src/main/java/net/shibboleth/oidc/profile/config/navigate/MessageContextLookupFunctionAdaptor.java b/oidc-common-profile-api/src/main/java/net/shibboleth/oidc/profile/config/navigate/MessageContextLookupFunctionAdaptor.java
new file mode 100644
index 0000000..48ef6fb
--- /dev/null
+++ b/oidc-common-profile-api/src/main/java/net/shibboleth/oidc/profile/config/navigate/MessageContextLookupFunctionAdaptor.java
@@ -0,0 +1,87 @@
+/*
+ * 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.oidc.profile.config.navigate;
+
+import java.util.function.Function;
+
+import javax.annotation.Nonnull;
+import javax.annotation.concurrent.GuardedBy;
+import javax.annotation.concurrent.ThreadSafe;
+
+import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.messaging.context.navigate.RecursiveTypedParentContextLookup;
+import org.opensaml.profile.context.ProfileRequestContext;
+
+import net.shibboleth.utilities.java.support.logic.Constraint;
+
+/**
+ * Adaptor function that allows a profile request context lookup function to work inside a message handler.
+ *
+ * @param <ResultType> the result type of the adapted (composed) function
+ */
+ at ThreadSafe
+public class MessageContextLookupFunctionAdaptor<ResultType> implements Function<MessageContext, ResultType> {
+
+ /**
+ * Strategy used to locate the {@link ProfileRequestContext} associated with a given {@link MessageContext}.
+ */
+ @Nonnull
+ @GuardedBy("this") private Function<MessageContext,ProfileRequestContext> profileRequestContextLookupStrategy;
+
+ /** The adapted function. */
+ @Nonnull private final Function<ProfileRequestContext, ResultType> adaptedFunction;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param function the composed function that is adapted to work inside a MessageContext input.
+ */
+ public MessageContextLookupFunctionAdaptor(@Nonnull final Function<ProfileRequestContext, ResultType> function) {
+ adaptedFunction = Constraint.isNotNull(function, "Adapted function can not be null");
+ profileRequestContextLookupStrategy =
+ new RecursiveTypedParentContextLookup<>(ProfileRequestContext.class);
+ }
+
+ /**
+ * Set the strategy used to locate the {@link ProfileRequestContext} associated with a given
+ * {@link MessageContext}.
+ *
+ * @param strategy lookup strategy
+ */
+ public synchronized void setProfileRequestContextLookupStrategy(
+ @Nonnull final Function<MessageContext,ProfileRequestContext> strategy) {
+ profileRequestContextLookupStrategy =
+ Constraint.isNotNull(strategy, "ProfileRequestContext lookup strategy cannot be null");
+ }
+
+ /**
+ * Get the profile request context lookup strategy used to adapt the message context.
+ *
+ * @return the profile request context lookup strategy
+ */
+ private synchronized Function<MessageContext, ProfileRequestContext> getProfileRequestContextLookupStrategy() {
+ return profileRequestContextLookupStrategy;
+ }
+
+ @Override
+ public ResultType apply(final MessageContext messageContext) {
+ return adaptedFunction.apply(getProfileRequestContextLookupStrategy().apply(messageContext));
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list