[java-plugin-shibd] branch main updated: Refactor actions with base classes for agent lookup.
Scott Cantor
cantor.2 at osu.edu
Wed Jun 12 20:13:56 UTC 2024
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-plugin-shibd.
View the commit online:
http://git.shibboleth.net/view/?p=java-plugin-shibd.git;a=commit;h=3e0722fa20344fec6267294dbb7cb8b5530c469b
The following commit(s) were added to refs/heads/main by this push:
new 3e0722f Refactor actions with base classes for agent lookup.
3e0722f is described below
commit 3e0722fa20344fec6267294dbb7cb8b5530c469b
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Jun 12 16:13:54 2024 -0400
Refactor actions with base classes for agent lookup.
---
.../sp/authn/impl/ValidateAgentAddress.java | 55 +-------------
.../authn/impl/ValidateCachedAuthentication.java | 49 ++-----------
.../sp/profile/impl/AbstractAgentAction.java | 85 ++++++++++++++++++++++
...sponse.java => AbstractAgentRequestAction.java} | 73 +++++++++----------
.../sp/profile/impl/DecodeAgentRequest.java | 51 +------------
.../net/shibboleth/sp/profile/impl/DoPing.java | 6 +-
.../sp/profile/impl/EncodeAgentResponse.java | 31 +-------
.../sp/profile/impl/PrepareAgentErrorResponse.java | 36 +--------
8 files changed, 139 insertions(+), 247 deletions(-)
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/authn/impl/ValidateAgentAddress.java b/sp-server-impl/src/main/java/net/shibboleth/sp/authn/impl/ValidateAgentAddress.java
index 6256a03..7637d38 100644
--- a/sp-server-impl/src/main/java/net/shibboleth/sp/authn/impl/ValidateAgentAddress.java
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/authn/impl/ValidateAgentAddress.java
@@ -15,11 +15,9 @@
package net.shibboleth.sp.authn.impl;
import java.net.InetAddress;
-import java.util.function.Function;
import javax.annotation.Nonnull;
-import org.opensaml.messaging.context.navigate.ChildContextLookup;
import org.opensaml.profile.action.ActionSupport;
import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
@@ -28,13 +26,10 @@ import org.slf4j.Logger;
import com.google.common.net.InetAddresses;
import jakarta.servlet.http.HttpServletRequest;
-import net.shibboleth.idp.profile.AbstractProfileAction;
-import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
-import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.shared.servlet.HttpServletSupport;
import net.shibboleth.sp.Agent;
-import net.shibboleth.sp.context.AgentRequestContext;
+import net.shibboleth.sp.profile.impl.AbstractAgentAction;
/**
* An action that validates the requesting client address is allowed for the identified
@@ -43,60 +38,18 @@ import net.shibboleth.sp.context.AgentRequestContext;
* @event {@link EventIds#PROCEED_EVENT_ID}
* @event {@link EventIds#INVALID_PROFILE_CTX}
* @event {@link EventIds#ACCESS_DENIED}
- * @pre <pre>ProfileRequestContext.ensureSubcontext(AgentRequestContext.class).getAgent() != null</pre>
*/
-public class ValidateAgentAddress extends AbstractProfileAction {
+public class ValidateAgentAddress extends AbstractAgentAction {
/** Class logger. */
@Nonnull private final Logger log = LoggerFactory.getLogger(ValidateAgentAddress.class);
- /** Lookup strategy for {@link AgentRequestContext}. */
- @Nonnull private Function<ProfileRequestContext,AgentRequestContext> agentRequestContextLookupStrategy;
-
- /** Cached agent from context. */
- @NonnullBeforeExec private Agent agent;
-
- /** Constructor. */
- public ValidateAgentAddress() {
- agentRequestContextLookupStrategy = new ChildContextLookup<>(AgentRequestContext.class);
- }
-
- /**
- * Sets the lookup strategy for the {@link AgentRequestContext}.
- *
- * @param strategy lookup strategy
- */
- public void setAgentRequestContextLookupStrategy(
- @Nonnull final Function<ProfileRequestContext,AgentRequestContext> strategy) {
- checkSetterPreconditions();
-
- agentRequestContextLookupStrategy = Constraint.isNotNull(strategy,
- "AgentRequestContext lookup strategy cannot be null");
- }
-
/** {@inheritDoc} */
@Override
- protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
-
- if (!super.doPreExecute(profileRequestContext)) {
- return false;
- }
+ protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
- final AgentRequestContext agentCtx = agentRequestContextLookupStrategy.apply(profileRequestContext);
-
- agent = agentCtx != null ? agentCtx.getAgent() : null;
- if (agent == null) {
- log.error("{} No Agent found in context", getLogPrefix());
- ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_PROFILE_CTX);
- return false;
- }
+ final Agent agent = ensureAgent();
- return true;
- }
-
- /** {@inheritDoc} */
- @Override
- protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
final HttpServletRequest request = getHttpServletRequest();
if (request == null) {
log.warn("{} Request denied from agent '{}', no servlet request available", getLogPrefix(), agent.getId());
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/authn/impl/ValidateCachedAuthentication.java b/sp-server-impl/src/main/java/net/shibboleth/sp/authn/impl/ValidateCachedAuthentication.java
index c37baa1..c5621e9 100644
--- a/sp-server-impl/src/main/java/net/shibboleth/sp/authn/impl/ValidateCachedAuthentication.java
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/authn/impl/ValidateCachedAuthentication.java
@@ -15,11 +15,9 @@
package net.shibboleth.sp.authn.impl;
import java.time.Instant;
-import java.util.function.Function;
import javax.annotation.Nonnull;
-import org.opensaml.messaging.context.navigate.ChildContextLookup;
import org.opensaml.profile.action.ActionSupport;
import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
@@ -27,14 +25,11 @@ import org.slf4j.Logger;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
-import net.shibboleth.idp.profile.AbstractProfileAction;
-import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
-import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.shared.servlet.HttpServletSupport;
import net.shibboleth.sp.Agent;
-import net.shibboleth.sp.context.AgentRequestContext;
+import net.shibboleth.sp.profile.impl.AbstractAgentAction;
/**
* An action that checks for a record in the {@link HttpSession} to bypass agent authentication.
@@ -45,9 +40,8 @@ import net.shibboleth.sp.context.AgentRequestContext;
* @event {@link EventIds#PROCEED_EVENT_ID}
* @event {@link EventIds#INVALID_PROFILE_CTX}
* @event {@link #BYPASS_AUTHENTICATION}
- * @pre <pre>ProfileRequestContext.ensureSubcontext(AgentRequestContext.class).getAgent() != null</pre>
*/
-public class ValidateCachedAuthentication extends AbstractProfileAction {
+public class ValidateCachedAuthentication extends AbstractAgentAction {
/** Session attribute holding agent session record. */
@Nonnull @NotEmpty public static final String AGENT_SESSION_ATTRIBUTE = "net.shibboleth.sp.agent.cachedAuthentication";
@@ -58,30 +52,6 @@ public class ValidateCachedAuthentication extends AbstractProfileAction {
/** Class logger. */
@Nonnull private final Logger log = LoggerFactory.getLogger(ValidateCachedAuthentication.class);
- /** Lookup strategy for {@link AgentRequestContext}. */
- @Nonnull private Function<ProfileRequestContext,AgentRequestContext> agentRequestContextLookupStrategy;
-
- /** Cached agent from context. */
- @NonnullBeforeExec private Agent agent;
-
- /** Constructor. */
- public ValidateCachedAuthentication() {
- agentRequestContextLookupStrategy = new ChildContextLookup<>(AgentRequestContext.class);
- }
-
- /**
- * Sets the lookup strategy for the {@link AgentRequestContext}.
- *
- * @param strategy lookup strategy
- */
- public void setAgentRequestContextLookupStrategy(
- @Nonnull final Function<ProfileRequestContext,AgentRequestContext> strategy) {
- checkSetterPreconditions();
-
- agentRequestContextLookupStrategy = Constraint.isNotNull(strategy,
- "AgentRequestContext lookup strategy cannot be null");
- }
-
/** {@inheritDoc} */
@Override
protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
@@ -90,16 +60,9 @@ public class ValidateCachedAuthentication extends AbstractProfileAction {
return false;
}
- final AgentRequestContext agentCtx = agentRequestContextLookupStrategy.apply(profileRequestContext);
- agent = agentCtx != null ? agentCtx.getAgent() : null;
- if (agent == null) {
- log.error("{} No Agent found in context", getLogPrefix());
- ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_PROFILE_CTX);
- return false;
- }
-
- if (!agent.isSupportsCachedAuthentication()) {
- log.debug("{} Agent '{}' does not support cached authentication, skipping", getLogPrefix(), agent.getId());
+ if (!ensureAgent().isSupportsCachedAuthentication()) {
+ log.debug("{} Agent '{}' does not support cached authentication, skipping", getLogPrefix(),
+ ensureAgent().getId());
return false;
}
@@ -110,6 +73,8 @@ public class ValidateCachedAuthentication extends AbstractProfileAction {
@Override
protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+ final Agent agent = ensureAgent();
+
final HttpServletRequest request = getHttpServletRequest();
final HttpSession session = request != null ? request.getSession(false) : null;
if (session == null) {
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/AbstractAgentAction.java b/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/AbstractAgentAction.java
new file mode 100644
index 0000000..2c5fa8e
--- /dev/null
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/AbstractAgentAction.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed 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.sp.profile.impl;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.opensaml.profile.action.ActionSupport;
+import org.opensaml.profile.action.EventIds;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.slf4j.Logger;
+
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
+import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
+import net.shibboleth.sp.Agent;
+import net.shibboleth.sp.context.AgentRequestContext;
+
+/**
+ * Base class for actions that need access to the {@link Agent} in an {@link AgentRequestContext}.
+ *
+ * <p>This class guarantees that the context exists after {@link #doPreExecute(ProfileRequestContext)}
+ * runs and returns true.</p>
+ *
+ * @event {@link EventIds#PROCEED_EVENT_ID}
+ * @event {@link EventIds#INVALID_PROFILE_CTX}
+ * @pre <pre>ensureAgentRequestContext().getAgent() != null</pre>
+ */
+public abstract class AbstractAgentAction extends AbstractAgentRequestAction {
+
+ /** Class logger. */
+ @Nonnull private final Logger log = LoggerFactory.getLogger(AbstractAgentAction.class);
+
+ /** Cached agent from context. */
+ @NonnullBeforeExec private Agent agent;
+
+ /** {@inheritDoc} */
+ @Override
+ protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+
+ if (!super.doPreExecute(profileRequestContext)) {
+ return false;
+ }
+
+ agent = ensureAgentRequestContext().getAgent();
+ if (agent == null) {
+ log.error("{} No Agent found in context", getLogPrefix());
+ ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_PROFILE_CTX);
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Gets the {@link Agent} for this request.
+ *
+ * @return the agent, or null
+ */
+ @Nullable public Agent getAgent() {
+ return agent;
+ }
+
+ /**
+ * Gets the {@link Agent} for this request.
+ *
+ * @return the agent
+ */
+ @Nonnull public Agent ensureAgent() {
+ return Constraint.isNotNull(agent, "Agent was null");
+ }
+
+}
\ No newline at end of file
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/EncodeAgentResponse.java b/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/AbstractAgentRequestAction.java
similarity index 60%
copy from sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/EncodeAgentResponse.java
copy to sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/AbstractAgentRequestAction.java
index dc29855..da5adc5 100644
--- a/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/EncodeAgentResponse.java
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/AbstractAgentRequestAction.java
@@ -14,11 +14,10 @@
package net.shibboleth.sp.profile.impl;
-import java.io.IOException;
-import java.io.OutputStream;
import java.util.function.Function;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import org.opensaml.messaging.context.navigate.ChildContextLookup;
import org.opensaml.profile.action.ActionSupport;
@@ -26,37 +25,52 @@ import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
import org.slf4j.Logger;
-import jakarta.servlet.http.HttpServletResponse;
import net.shibboleth.idp.profile.AbstractProfileAction;
import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.sp.context.AgentRequestContext;
-import net.shibboleth.sp.ddf.DDF;
/**
- * A profile action to encode an agent response from the output {@link DDF} in the
- * {@link AgentRequestContext}.
+ * Base class for agent profile actions that handles lookup of the {@link AgentRequestContext}.
+ *
+ * <p>This class guarantees that the context exists after {@link #doPreExecute(ProfileRequestContext)}
+ * runs and returns true.</p>
*
* @event {@link EventIds#PROCEED_EVENT_ID}
* @event {@link EventIds#INVALID_PROFILE_CTX}
- * @event {@link EventIds#INVALID_MESSAGE}
- * @event {@link EventIds#IO_ERROR}
- * @pre <pre>AgentRequestContext.getOutput() != null</pre>
*/
-public class EncodeAgentResponse extends AbstractProfileAction {
+public abstract class AbstractAgentRequestAction extends AbstractProfileAction {
/** Class logger. */
- @Nonnull private final Logger log = LoggerFactory.getLogger(EncodeAgentResponse.class);
+ @Nonnull private final Logger log = LoggerFactory.getLogger(AbstractAgentRequestAction.class);
/** Lookup strategy for {@link AgentRequestContext}. */
@Nonnull private Function<ProfileRequestContext,AgentRequestContext> agentRequestContextLookupStrategy;
- /** Cached context containing the output message. */
- @NonnullBeforeExec private DDF outputMessage;
+ /** Cached context to populate. */
+ @NonnullBeforeExec private AgentRequestContext agentRequestContext;
+ /**
+ * Gets the cached request context located by the lookup strategy.
+ *
+ * @return cached request context or null
+ */
+ @Nullable public AgentRequestContext getAgentRequestContext() {
+ return agentRequestContext;
+ }
+
+ /**
+ * Gets the cached request context located by the lookup strategy.
+ *
+ * @return cached request context
+ */
+ @Nonnull public AgentRequestContext ensureAgentRequestContext() {
+ return Constraint.isNotNull(agentRequestContext, "AgentRequestContext was null");
+ }
+
/** Constructor. */
- public EncodeAgentResponse() {
+ public AbstractAgentRequestAction() {
agentRequestContextLookupStrategy = new ChildContextLookup<>(AgentRequestContext.class);
}
@@ -81,35 +95,14 @@ public class EncodeAgentResponse extends AbstractProfileAction {
return false;
}
- final AgentRequestContext agentRequestContext = agentRequestContextLookupStrategy.apply(profileRequestContext);
- outputMessage = agentRequestContext != null ? agentRequestContext.getOutput() : null;
- if (outputMessage == null) {
- log.error("{} No output message found", getLogPrefix());
- ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_MESSAGE);
+ agentRequestContext = agentRequestContextLookupStrategy.apply(profileRequestContext);
+ if (agentRequestContext == null) {
+ log.error("{} No AgentRequestContext found", getLogPrefix());
+ ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_PROFILE_CTX);
return false;
}
return true;
}
-
- /** {@inheritDoc} */
- @Override
- protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
-
- final HttpServletResponse response = getHttpServletResponse();
- if (response == null) {
- log.error("{} No HttpServletResponse available", getLogPrefix());
- ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_PROFILE_CTX);
- return;
- }
-
- try (final OutputStream out = response.getOutputStream()) {
- assert out != null;
- outputMessage.serialize(out);
- } catch (final IOException e) {
- log.warn("{} Unable to serialize output message", getLogPrefix(), e);
- ActionSupport.buildEvent(profileRequestContext, EventIds.IO_ERROR);
- }
- }
-
+
}
\ No newline at end of file
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/DecodeAgentRequest.java b/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/DecodeAgentRequest.java
index f1e3386..dc64c2d 100644
--- a/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/DecodeAgentRequest.java
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/DecodeAgentRequest.java
@@ -16,20 +16,15 @@ package net.shibboleth.sp.profile.impl;
import java.io.IOException;
import java.io.InputStream;
-import java.util.function.Function;
import javax.annotation.Nonnull;
-import org.opensaml.messaging.context.navigate.ChildContextLookup;
import org.opensaml.profile.action.ActionSupport;
import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
import org.slf4j.Logger;
import jakarta.servlet.http.HttpServletRequest;
-import net.shibboleth.idp.profile.AbstractProfileAction;
-import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
-import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.sp.context.AgentRequestContext;
import net.shibboleth.sp.ddf.DDF;
@@ -47,53 +42,11 @@ import net.shibboleth.sp.ddf.DDF;
* @event {@link EventIds#INVALID_MESSAGE}
* @post <pre>AgentRequestContext.getInput() != null</pre>
*/
-public class DecodeAgentRequest extends AbstractProfileAction {
+public class DecodeAgentRequest extends AbstractAgentRequestAction {
/** Class logger. */
@Nonnull private final Logger log = LoggerFactory.getLogger(DecodeAgentRequest.class);
- /** Lookup strategy for {@link AgentRequestContext}. */
- @Nonnull private Function<ProfileRequestContext,AgentRequestContext> agentRequestContextLookupStrategy;
-
- /** Cached context to populate. */
- @NonnullBeforeExec private AgentRequestContext agentRequestContext;
-
- /** Constructor. */
- public DecodeAgentRequest() {
- agentRequestContextLookupStrategy = new ChildContextLookup<>(AgentRequestContext.class);
- }
-
- /**
- * Sets the lookup strategy for the {@link AgentRequestContext}.
- *
- * @param strategy lookup strategy
- */
- public void setAgentRequestContextLookupStrategy(
- @Nonnull final Function<ProfileRequestContext,AgentRequestContext> strategy) {
- checkSetterPreconditions();
-
- agentRequestContextLookupStrategy = Constraint.isNotNull(strategy,
- "AgentRequestContext lookup strategy cannot be null");
- }
-
- /** {@inheritDoc} */
- @Override
- protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
-
- if (!super.doPreExecute(profileRequestContext)) {
- return false;
- }
-
- agentRequestContext = agentRequestContextLookupStrategy.apply(profileRequestContext);
- if (agentRequestContext == null) {
- log.error("{} No AgentRequestContext found", getLogPrefix());
- ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_PROFILE_CTX);
- return false;
- }
-
- return true;
- }
-
/** {@inheritDoc} */
@Override
protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
@@ -128,7 +81,7 @@ public class DecodeAgentRequest extends AbstractProfileAction {
try (final InputStream in = request.getInputStream()) {
assert in != null;
final DDF msg = DDF.deserialize(in);
- agentRequestContext.setInput(msg);
+ ensureAgentRequestContext().setInput(msg);
} catch (final IOException e) {
log.warn("{} Unable to parse input message from HttpServletRequest", getLogPrefix(), e);
ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_MESSAGE);
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/DoPing.java b/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/DoPing.java
index 8e161a1..48d465c 100644
--- a/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/DoPing.java
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/DoPing.java
@@ -20,21 +20,19 @@ import javax.annotation.Nonnull;
import org.opensaml.profile.context.ProfileRequestContext;
-import net.shibboleth.idp.profile.AbstractProfileAction;
-import net.shibboleth.sp.context.AgentRequestContext;
import net.shibboleth.sp.ddf.DDF;
/**
* Simple action for testing.
*/
-public class DoPing extends AbstractProfileAction {
+public class DoPing extends AbstractAgentRequestAction {
/** {@inheritDoc} */
@Override
protected void doExecute(@Nonnull ProfileRequestContext profileRequestContext) {
final DDF out = new DDF().longinteger(Instant.now().getEpochSecond());
- profileRequestContext.ensureSubcontext(AgentRequestContext.class).setOutput(out);
+ ensureAgentRequestContext().setOutput(out);
}
}
\ No newline at end of file
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/EncodeAgentResponse.java b/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/EncodeAgentResponse.java
index dc29855..86aaac5 100644
--- a/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/EncodeAgentResponse.java
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/EncodeAgentResponse.java
@@ -16,20 +16,16 @@ package net.shibboleth.sp.profile.impl;
import java.io.IOException;
import java.io.OutputStream;
-import java.util.function.Function;
import javax.annotation.Nonnull;
-import org.opensaml.messaging.context.navigate.ChildContextLookup;
import org.opensaml.profile.action.ActionSupport;
import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.ProfileRequestContext;
import org.slf4j.Logger;
import jakarta.servlet.http.HttpServletResponse;
-import net.shibboleth.idp.profile.AbstractProfileAction;
import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
-import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.sp.context.AgentRequestContext;
import net.shibboleth.sp.ddf.DDF;
@@ -44,34 +40,13 @@ import net.shibboleth.sp.ddf.DDF;
* @event {@link EventIds#IO_ERROR}
* @pre <pre>AgentRequestContext.getOutput() != null</pre>
*/
-public class EncodeAgentResponse extends AbstractProfileAction {
+public class EncodeAgentResponse extends AbstractAgentRequestAction {
/** Class logger. */
@Nonnull private final Logger log = LoggerFactory.getLogger(EncodeAgentResponse.class);
-
- /** Lookup strategy for {@link AgentRequestContext}. */
- @Nonnull private Function<ProfileRequestContext,AgentRequestContext> agentRequestContextLookupStrategy;
/** Cached context containing the output message. */
@NonnullBeforeExec private DDF outputMessage;
-
- /** Constructor. */
- public EncodeAgentResponse() {
- agentRequestContextLookupStrategy = new ChildContextLookup<>(AgentRequestContext.class);
- }
-
- /**
- * Sets the lookup strategy for the {@link AgentRequestContext}.
- *
- * @param strategy lookup strategy
- */
- public void setAgentRequestContextLookupStrategy(
- @Nonnull final Function<ProfileRequestContext,AgentRequestContext> strategy) {
- checkSetterPreconditions();
-
- agentRequestContextLookupStrategy = Constraint.isNotNull(strategy,
- "AgentRequestContext lookup strategy cannot be null");
- }
/** {@inheritDoc} */
@Override
@@ -81,8 +56,8 @@ public class EncodeAgentResponse extends AbstractProfileAction {
return false;
}
- final AgentRequestContext agentRequestContext = agentRequestContextLookupStrategy.apply(profileRequestContext);
- outputMessage = agentRequestContext != null ? agentRequestContext.getOutput() : null;
+ final AgentRequestContext agentRequestContext = ensureAgentRequestContext();
+ outputMessage = agentRequestContext.getOutput();
if (outputMessage == null) {
log.error("{} No output message found", getLogPrefix());
ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_MESSAGE);
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/PrepareAgentErrorResponse.java b/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/PrepareAgentErrorResponse.java
index f9f765a..e36307e 100644
--- a/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/PrepareAgentErrorResponse.java
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/PrepareAgentErrorResponse.java
@@ -19,17 +19,13 @@ import java.util.function.Function;
import javax.annotation.Nonnull;
import org.opensaml.messaging.context.navigate.ChildContextLookup;
-import org.opensaml.profile.action.ActionSupport;
import org.opensaml.profile.action.EventIds;
import org.opensaml.profile.context.EventContext;
import org.opensaml.profile.context.ProfileRequestContext;
import org.opensaml.profile.context.navigate.CurrentOrPreviousEventLookup;
-import org.slf4j.Logger;
-import net.shibboleth.idp.profile.AbstractProfileAction;
import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
import net.shibboleth.shared.logic.Constraint;
-import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.sp.context.AgentRequestContext;
import net.shibboleth.sp.ddf.DDF;
@@ -41,13 +37,7 @@ import net.shibboleth.sp.ddf.DDF;
* @event {@link EventIds#INVALID_PROFILE_CTX}
* @pre <pre>AgentRequestContext.getOutput() != null</pre>
*/
-public class PrepareAgentErrorResponse extends AbstractProfileAction {
-
- /** Class logger. */
- @Nonnull private final Logger log = LoggerFactory.getLogger(PrepareAgentErrorResponse.class);
-
- /** Lookup or creation strategy for {@link AgentRequestContext}. */
- @Nonnull private Function<ProfileRequestContext,AgentRequestContext> agentRequestContextCreationStrategy;
+public class PrepareAgentErrorResponse extends AbstractAgentRequestAction {
/** Strategy function for access to {@link EventContext} to check. */
@Nonnull private Function<ProfileRequestContext,EventContext> eventContextLookupStrategy;
@@ -57,22 +47,9 @@ public class PrepareAgentErrorResponse extends AbstractProfileAction {
/** Constructor. */
public PrepareAgentErrorResponse() {
- agentRequestContextCreationStrategy = new ChildContextLookup<>(AgentRequestContext.class, true);
+ setAgentRequestContextLookupStrategy(new ChildContextLookup<>(AgentRequestContext.class, true));
eventContextLookupStrategy = new CurrentOrPreviousEventLookup();
}
-
- /**
- * Sets the lookup or creation strategy for the {@link AgentRequestContext}.
- *
- * @param strategy lookup strategy
- */
- public void setAgentRequestContextCreationStrategy(
- @Nonnull final Function<ProfileRequestContext,AgentRequestContext> strategy) {
- checkSetterPreconditions();
-
- agentRequestContextCreationStrategy = Constraint.isNotNull(strategy,
- "AgentRequestContext lookup/creation strategy cannot be null");
- }
/**
* Set lookup strategy for {@link EventContext} to check.
@@ -93,15 +70,8 @@ public class PrepareAgentErrorResponse extends AbstractProfileAction {
return false;
}
- final AgentRequestContext agentRequestContext = agentRequestContextCreationStrategy.apply(profileRequestContext);
- if (agentRequestContext == null) {
- log.error("{} No AgentRequestContext created", getLogPrefix());
- ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_PROFILE_CTX);
- return false;
- }
-
outputMessage = new DDF();
- agentRequestContext.setOutput(outputMessage);
+ ensureAgentRequestContext().setOutput(outputMessage);
return true;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list