[java-identity-provider] 01/02: IDP-2069 - Null Handling Task
Rod Widdowson
rdw at steadingsoftware.com
Tue Apr 11 14:00:45 UTC 2023
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch main
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=208e31bc919a16631ae46083a0c485b8e6057959
commit 208e31bc919a16631ae46083a0c485b8e6057959
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Mon Apr 10 16:56:14 2023 +0100
IDP-2069 - Null Handling Task
https://shibboleth.atlassian.net/browse/IDP-2069
Continue adding and exploiting the @NonnullBeforeExec annotations
idp-profile-api
idp-profile-impl
---
.../AbstractProfileInterceptorAction.java | 22 ++++--
.../profile/audit/impl/PopulateAuditContext.java | 11 ++-
.../idp/profile/impl/FilterAttributes.java | 81 ++++++++++++----------
.../idp/profile/impl/PopulateSubjectContext.java | 4 +-
.../idp/profile/impl/RecordResponseComplete.java | 10 ++-
.../profile/impl/ReloadServiceConfiguration.java | 4 +-
.../profile/impl/SelectProfileConfiguration.java | 17 +++--
.../impl/SelectRelyingPartyConfiguration.java | 27 +++++---
.../profile/impl/WebFlowMessageHandlerAdaptor.java | 13 ++--
9 files changed, 102 insertions(+), 87 deletions(-)
diff --git a/idp-profile-api/src/main/java/net/shibboleth/idp/profile/interceptor/AbstractProfileInterceptorAction.java b/idp-profile-api/src/main/java/net/shibboleth/idp/profile/interceptor/AbstractProfileInterceptorAction.java
index 242924fd2..06e2b60ad 100644
--- a/idp-profile-api/src/main/java/net/shibboleth/idp/profile/interceptor/AbstractProfileInterceptorAction.java
+++ b/idp-profile-api/src/main/java/net/shibboleth/idp/profile/interceptor/AbstractProfileInterceptorAction.java
@@ -30,6 +30,7 @@ import org.slf4j.Logger;
import net.shibboleth.idp.profile.AbstractProfileAction;
import net.shibboleth.idp.profile.context.ProfileInterceptorContext;
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.LoggerFactory;
@@ -52,7 +53,7 @@ public abstract class AbstractProfileInterceptorAction extends
@Nonnull private Function<ProfileRequestContext, ProfileInterceptorContext> interceptorContextlookupStrategy;
/** The {@link ProfileInterceptorContext} to operate on. */
- @Nullable private ProfileInterceptorContext profileInterceptorContext;
+ @NonnullBeforeExec private ProfileInterceptorContext profileInterceptorContext;
/** Constructor. */
public AbstractProfileInterceptorAction() {
@@ -68,18 +69,26 @@ public abstract class AbstractProfileInterceptorAction extends
checkSetterPreconditions();
interceptorContextlookupStrategy = Constraint.isNotNull(strategy, "Strategy cannot be null");
}
+
+ /** null safe getter.
+ * @return Returns the profileInterceptorContext.
+ */
+ @SuppressWarnings("null")
+ @Nonnull private ProfileInterceptorContext getProfileInterceptorContext() {
+ assert isPreExecuteCalled();
+ return profileInterceptorContext;
+ }
/** {@inheritDoc} */
@Override protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
- profileInterceptorContext = interceptorContextlookupStrategy.apply(profileRequestContext);
- if (profileInterceptorContext == null) {
+ final ProfileInterceptorContext pic = profileInterceptorContext = interceptorContextlookupStrategy.apply(profileRequestContext);
+ if (pic == null) {
log.error("{} Unable to create or locate profile interceptor context", getLogPrefix());
ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_PROFILE_CTX);
return false;
}
- assert profileInterceptorContext != null;
- return doPreExecute(profileRequestContext, profileInterceptorContext)
+ return doPreExecute(profileRequestContext, pic )
&& super.doPreExecute(profileRequestContext);
}
@@ -99,8 +108,7 @@ public abstract class AbstractProfileInterceptorAction extends
/** {@inheritDoc} */
@Override protected final void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
- assert profileInterceptorContext != null;
- doExecute(profileRequestContext, profileInterceptorContext);
+ doExecute(profileRequestContext, getProfileInterceptorContext());
}
/**
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/audit/impl/PopulateAuditContext.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/audit/impl/PopulateAuditContext.java
index d226c030b..1be154ee2 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/audit/impl/PopulateAuditContext.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/audit/impl/PopulateAuditContext.java
@@ -39,6 +39,7 @@ import org.slf4j.Logger;
import net.shibboleth.idp.profile.AbstractProfileAction;
import net.shibboleth.profile.context.AuditContext;
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
import net.shibboleth.shared.annotation.constraint.NonnullElements;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
import net.shibboleth.shared.annotation.constraint.NotLive;
@@ -90,7 +91,7 @@ public class PopulateAuditContext extends AbstractProfileAction {
private boolean clearAuditContext;
/** {@link AuditContext} to populate. */
- @Nullable private AuditContext auditCtx;
+ @NonnullBeforeExec private AuditContext auditCtx;
/** Constructor. */
@SuppressWarnings("null")
@@ -238,7 +239,6 @@ public class PopulateAuditContext extends AbstractProfileAction {
protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
if (clearAuditContext) {
- assert auditCtx != null;
auditCtx.getFields().clear();
}
@@ -277,18 +277,17 @@ public class PopulateAuditContext extends AbstractProfileAction {
*/
private void addField(@Nonnull @NotEmpty final String key, @Nullable final Object value) {
- final AuditContext ctx = auditCtx;
- assert ctx != null;
+ assert isPreExecuteCalled();
if (value != null) {
if (value instanceof TemporalAccessor) {
- ctx.getFieldValues(key).add(dateTimeFormatter.format((TemporalAccessor) value));
+ auditCtx.getFieldValues(key).add(dateTimeFormatter.format((TemporalAccessor) value));
} else {
String s = value.toString();
if (fieldReplacements.containsKey(s)) {
s = fieldReplacements.get(s);
}
if (s != null) {
- ctx.getFieldValues(key).add(s);
+ auditCtx.getFieldValues(key).add(s);
}
}
}
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/FilterAttributes.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/FilterAttributes.java
index d4de0d82f..d1c009d0e 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/FilterAttributes.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/FilterAttributes.java
@@ -46,6 +46,7 @@ import net.shibboleth.idp.profile.IdPEventIds;
import net.shibboleth.profile.context.RelyingPartyContext;
import net.shibboleth.profile.context.navigate.IssuerLookupFunction;
import net.shibboleth.profile.context.navigate.RelyingPartyIdLookupFunction;
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.shared.service.ReloadableService;
@@ -105,30 +106,24 @@ public class FilterAttributes extends AbstractProfileAction {
* associated with a given {@link AttributeFilterContext}.
*/
@Nullable private Function<AttributeFilterContext,SAMLMetadataContext> issuerMetadataFromFilterLookupStrategy;
-
- /**
- * Strategy used to locate the {@link SAMLMetadataContext} for the recipient
- * associated with a given {@link ProfileRequestContext}.
- */
- @Nullable private Function<ProfileRequestContext,SAMLMetadataContext> metadataContextLookupStrategy;
-
+
/**
* Strategy used to locate the {@link SAMLMetadataContext} for the recipient
* associated with a given {@link AttributeFilterContext}.
*/
- @Nullable private Function<AttributeFilterContext,SAMLMetadataContext> metadataFromFilterLookupStrategy;
+ @Nonnull private Function<AttributeFilterContext,SAMLMetadataContext> metadataFromFilterLookupStrategy;
/**
* Strategy used to locate the {@link ProxiedRequesterContext} associated with a given
* {@link ProfileRequestContext}.
*/
- @Nullable private Function<ProfileRequestContext,ProxiedRequesterContext> proxiedRequesterContextLookupStrategy;
+ @Nonnull private Function<ProfileRequestContext,ProxiedRequesterContext> proxiedRequesterContextLookupStrategy;
/**
* Strategy used to locate the {@link ProxiedRequesterContext} associated with a given
* {@link AttributeFilterContext}.
*/
- @Nullable private Function<AttributeFilterContext,ProxiedRequesterContext> proxiesFromFilterLookupStrategy;
+ @Nonnull private Function<AttributeFilterContext,ProxiedRequesterContext> proxiesFromFilterLookupStrategy;
/** Strategy used to locate the {@link SAMLMetadataContext} for the proxied requester. */
@Nullable private Function<ProfileRequestContext,SAMLMetadataContext> proxiedRequesterMetadataLookupStrategy;
@@ -143,53 +138,61 @@ public class FilterAttributes extends AbstractProfileAction {
private boolean maskFailures;
/** AttributeContext to filter. */
- @Nullable private AttributeContext attributeContext;
+ @NonnullBeforeExec private AttributeContext attributeContext;
/**
* Constructor.
*
* @param filterService engine used to filter attributes
*/
- @SuppressWarnings("null")
public FilterAttributes(@Nonnull final ReloadableService<AttributeFilter> filterService) {
attributeFilterService = Constraint.isNotNull(filterService, "Service cannot be null");
issuerLookupStrategy = new IssuerLookupFunction();
recipientLookupStrategy = new RelyingPartyIdLookupFunction();
- attributeContextLookupStrategy = new ChildContextLookup<>(AttributeContext.class).compose(
+ final Function<ProfileRequestContext,AttributeContext> acls = new ChildContextLookup<>(AttributeContext.class).compose(
new ChildContextLookup<>(RelyingPartyContext.class));
+ assert acls != null;
+ attributeContextLookupStrategy = acls;
- principalNameLookupStrategy =
- new SubjectContextPrincipalLookupFunction().compose(
- new ChildContextLookup<>(SubjectContext.class));
+ final Function<ProfileRequestContext,String> pnls = new SubjectContextPrincipalLookupFunction().compose(
+ new ChildContextLookup<>(SubjectContext.class));
+ assert pnls != null;
+ principalNameLookupStrategy = pnls;
// Default is to locate the overall root.
profileRequestContextFromFilterLookupStrategy = new RootContextLookup<>(ProfileRequestContext.class);
// Default: inbound msg context -> SAMLPeerEntityContext -> SAMLMetadataContext
- metadataContextLookupStrategy =
- new ChildContextLookup<>(SAMLMetadataContext.class).compose(
- new ChildContextLookup<>(SAMLPeerEntityContext.class).compose(
- new InboundMessageContextLookup()));
+ final Function<ProfileRequestContext,SAMLMetadataContext> metadataContextLookupStrategy = new ChildContextLookup<>(SAMLMetadataContext.class).compose(
+ new ChildContextLookup<>(SAMLPeerEntityContext.class).compose(
+ new InboundMessageContextLookup()));
+ assert metadataContextLookupStrategy != null;
// This is always set to navigate to the PRC and then apply the previous function.
- assert metadataContextLookupStrategy != null;
- metadataFromFilterLookupStrategy = metadataContextLookupStrategy.compose(
+ Function<AttributeFilterContext,SAMLMetadataContext> mffls = metadataContextLookupStrategy.compose(
profileRequestContextFromFilterLookupStrategy);
+ assert mffls != null;
+ metadataFromFilterLookupStrategy = mffls;
// Default: inbound msg context -> child
- proxiedRequesterContextLookupStrategy =
+ final Function<ProfileRequestContext,ProxiedRequesterContext> prcls =
new ChildContextLookup<>(ProxiedRequesterContext.class).compose(new InboundMessageContextLookup());
+ assert prcls != null;
+ proxiedRequesterContextLookupStrategy = prcls;
// This is always set to navigate to the PRC and then apply the previous function.
- assert proxiedRequesterContextLookupStrategy!=null;
- proxiesFromFilterLookupStrategy = proxiedRequesterContextLookupStrategy.compose(
+ final Function<AttributeFilterContext,ProxiedRequesterContext> pffls = proxiedRequesterContextLookupStrategy.compose(
profileRequestContextFromFilterLookupStrategy);
+ assert pffls != null;
+ proxiesFromFilterLookupStrategy = pffls;
// Defaults to ProfileRequestContext -> RelyingPartyContext -> AttributeFilterContext.
- filterContextCreationStrategy = new ChildContextLookup<>(AttributeFilterContext.class, true).compose(
+ final Function<ProfileRequestContext,AttributeFilterContext> fccs = new ChildContextLookup<>(AttributeFilterContext.class, true).compose(
new ChildContextLookup<>(RelyingPartyContext.class));
+ assert fccs != null;
+ filterContextCreationStrategy = fccs;
maskFailures = true;
}
@@ -278,8 +281,7 @@ public class FilterAttributes extends AbstractProfileAction {
}
/**
- * Sets the strategy used to locate the {@link SAMLMetadataContext} for the recipient associated with a
- * given {@link ProfileRequestContext}. Also sets the strategy to find the {@link SAMLMetadataContext}
+ * Sets the strategy to find the {@link SAMLMetadataContext}
* from the {@link AttributeFilterContext}.
*
* @param strategy lookup strategy
@@ -287,8 +289,10 @@ public class FilterAttributes extends AbstractProfileAction {
public void setMetadataContextLookupStrategy(
@Nonnull final Function<ProfileRequestContext,SAMLMetadataContext> strategy) {
checkSetterPreconditions();
- metadataFromFilterLookupStrategy = strategy != null ?
- strategy.compose(profileRequestContextFromFilterLookupStrategy) : null;
+ final Function<AttributeFilterContext,SAMLMetadataContext> mffls = strategy.compose(profileRequestContextFromFilterLookupStrategy);
+ assert mffls!=null;
+ metadataFromFilterLookupStrategy = mffls;
+
}
/**
@@ -304,8 +308,10 @@ public class FilterAttributes extends AbstractProfileAction {
@Nonnull final Function<ProfileRequestContext,ProxiedRequesterContext> strategy) {
checkSetterPreconditions();
proxiedRequesterContextLookupStrategy = strategy;
- proxiesFromFilterLookupStrategy = strategy != null ?
- proxiedRequesterContextLookupStrategy.compose(profileRequestContextFromFilterLookupStrategy) : null;
+ final Function<AttributeFilterContext,ProxiedRequesterContext> pffls = strategy.compose(
+ profileRequestContextFromFilterLookupStrategy);
+ assert pffls != null;
+ proxiesFromFilterLookupStrategy = pffls;
}
/**
@@ -363,14 +369,13 @@ public class FilterAttributes extends AbstractProfileAction {
// Get the filter context from the profile request
// this may already exist but if not, auto-create it.
- final AttributeContext ac = attributeContext;
- assert ac != null;
+
final AttributeFilterContext filterContext = filterContextCreationStrategy.apply(profileRequestContext);
if (filterContext == null) {
log.error("{} Unable to locate or create AttributeFilterContext", getLogPrefix());
if (maskFailures) {
log.warn("Filter error masked, clearing resolved attributes");
- ac.setIdPAttributes(null);
+ attributeContext.setIdPAttributes(null);
} else {
ActionSupport.buildEvent(profileRequestContext, IdPEventIds.UNABLE_FILTER_ATTRIBS);
}
@@ -383,12 +388,12 @@ public class FilterAttributes extends AbstractProfileAction {
final AttributeFilter filter = component.getComponent();
filter.filterAttributes(filterContext);
filterContext.removeFromParent();
- ac.setIdPAttributes(filterContext.getFilteredIdPAttributes().values());
+ attributeContext.setIdPAttributes(filterContext.getFilteredIdPAttributes().values());
} catch (final AttributeFilterException e) {
log.error("{} Error encountered while filtering attributes", getLogPrefix(), e);
if (maskFailures) {
log.warn("Filter error masked, clearing resolved attributes");
- ac.setIdPAttributes(Collections.emptySet());
+ attributeContext.setIdPAttributes(Collections.emptySet());
} else {
ActionSupport.buildEvent(profileRequestContext, IdPEventIds.UNABLE_FILTER_ATTRIBS);
}
@@ -396,7 +401,7 @@ public class FilterAttributes extends AbstractProfileAction {
log.error("{} Invalid Attribute Filter service configuration", getLogPrefix(), e);
if (maskFailures) {
log.warn("Filter error masked, clearing resolved attributes");
- ac.setIdPAttributes(null);
+ attributeContext.setIdPAttributes(null);
} else {
ActionSupport.buildEvent(profileRequestContext, IdPEventIds.UNABLE_FILTER_ATTRIBS);
}
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/PopulateSubjectContext.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/PopulateSubjectContext.java
index 65831c17c..8e2af18e9 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/PopulateSubjectContext.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/PopulateSubjectContext.java
@@ -20,7 +20,6 @@ package net.shibboleth.idp.profile.impl;
import java.util.function.Function;
import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import org.opensaml.profile.action.ActionSupport;
import org.opensaml.profile.action.EventIds;
@@ -30,6 +29,7 @@ import org.slf4j.Logger;
import net.shibboleth.idp.authn.context.SubjectContext;
import net.shibboleth.idp.profile.AbstractProfileAction;
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.LoggerFactory;
@@ -53,7 +53,7 @@ public class PopulateSubjectContext extends AbstractProfileAction {
@NonnullAfterInit private Function<ProfileRequestContext,String> principalNameLookupStrategy;
/** The principal name extracted from the context tree. */
- @Nullable private String principalName;
+ @NonnullBeforeExec private String principalName;
/**
* Set lookup strategy for the principal name to use.
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/RecordResponseComplete.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/RecordResponseComplete.java
index b99c9bf61..423c24c47 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/RecordResponseComplete.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/RecordResponseComplete.java
@@ -18,7 +18,6 @@
package net.shibboleth.idp.profile.impl;
import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import org.opensaml.profile.action.ActionSupport;
import org.opensaml.profile.action.EventIds;
@@ -29,6 +28,7 @@ import org.springframework.webflow.execution.RequestContext;
import net.shibboleth.idp.profile.AbstractProfileAction;
import net.shibboleth.idp.profile.context.SpringRequestContext;
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
import net.shibboleth.shared.primitive.LoggerFactory;
/**
@@ -53,7 +53,7 @@ public class RecordResponseComplete extends AbstractProfileAction {
@Nonnull private Logger log = LoggerFactory.getLogger(RecordResponseComplete.class);
/** ExternalContext to operate on. */
- @Nullable private ExternalContext externalContext;
+ @NonnullBeforeExec private ExternalContext externalContext;
/** {@inheritDoc} */
@Override protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
@@ -85,11 +85,9 @@ public class RecordResponseComplete extends AbstractProfileAction {
/** {@inheritDoc} */
@Override
protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
- final ExternalContext ec = externalContext;
- assert ec != null;
- if (!ec.isResponseComplete()) {
+ if (!externalContext.isResponseComplete()) {
log.debug("{} Record response complete", getLogPrefix());
- ec.recordResponseComplete();
+ externalContext.recordResponseComplete();
}
}
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ReloadServiceConfiguration.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ReloadServiceConfiguration.java
index b547b8b53..733416366 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ReloadServiceConfiguration.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ReloadServiceConfiguration.java
@@ -32,6 +32,7 @@ import org.springframework.webflow.execution.RequestContext;
import net.shibboleth.idp.profile.AbstractProfileAction;
import net.shibboleth.idp.profile.context.SpringRequestContext;
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
import net.shibboleth.shared.component.IdentifiedComponent;
import net.shibboleth.shared.logic.Constraint;
@@ -67,7 +68,7 @@ public class ReloadServiceConfiguration extends AbstractProfileAction {
@Nonnull private Function<ProfileRequestContext,ReloadableService<?>> serviceLookupStrategy;
/** The service to reload. */
- @Nullable private ReloadableService<?> service;
+ @NonnullBeforeExec private ReloadableService<?> service;
/** Constructor. */
public ReloadServiceConfiguration() {
@@ -126,7 +127,6 @@ public class ReloadServiceConfiguration extends AbstractProfileAction {
assert response != null;
try {
- assert service != null;
service.reload();
log.debug("{} Reloaded configuration for '{}'", getLogPrefix(), id);
response.setStatus(HttpServletResponse.SC_OK);
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 0ec222716..c5a042899 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
@@ -33,6 +33,7 @@ import net.shibboleth.profile.config.ConditionalProfileConfiguration;
import net.shibboleth.profile.config.ProfileConfiguration;
import net.shibboleth.profile.context.RelyingPartyContext;
import net.shibboleth.profile.relyingparty.RelyingPartyConfiguration;
+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;
@@ -61,7 +62,7 @@ public class SelectProfileConfiguration extends AbstractProfileAction {
@Nullable @NotEmpty private String profileId;
/** The RelyingPartyContext to operate on. */
- @Nullable private RelyingPartyContext rpCtx;
+ @NonnullBeforeExec private RelyingPartyContext rpCtx;
/** Fail if no profile configuration is found. */
private boolean failIfMissing;
@@ -148,9 +149,7 @@ public class SelectProfileConfiguration extends AbstractProfileAction {
targetId = profileRequestContext.getProfileId();
}
- final RelyingPartyContext ctx = rpCtx;
- assert ctx != null;
- final RelyingPartyConfiguration rpConfig = ctx.getConfiguration();
+ final RelyingPartyConfiguration rpConfig = rpCtx.getConfiguration();
assert rpConfig != null;
ProfileConfiguration profileConfiguration = rpConfig.getProfileConfiguration(profileRequestContext, targetId);
if (profileConfiguration == null && profileId == null && profileRequestContext.getLegacyProfileId() != null) {
@@ -166,25 +165,25 @@ public class SelectProfileConfiguration extends AbstractProfileAction {
if (profileConfiguration == null) {
if (failIfMissing) {
log.warn("{} Profile {} is not available for RP configuration {} (RPID {})",
- new Object[] {getLogPrefix(), targetId, rpConfig.getId(), ctx.getRelyingPartyId(),});
+ new Object[] {getLogPrefix(), targetId, rpConfig.getId(), rpCtx.getRelyingPartyId(),});
ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_PROFILE_CONFIG);
} else {
log.debug("{} Profile {} is not available for RP configuration {} (RPID {})",
- new Object[] {getLogPrefix(), targetId, rpConfig.getId(), ctx.getRelyingPartyId(),});
+ new Object[] {getLogPrefix(), targetId, rpConfig.getId(), rpCtx.getRelyingPartyId(),});
}
} else if (profileConfiguration instanceof ConditionalProfileConfiguration
&& !((ConditionalProfileConfiguration) profileConfiguration).getActivationCondition().test(
profileRequestContext)) {
if (failIfMissing) {
log.warn("{} Profile {} is not active for RP configuration {} (RPID {})",
- new Object[] {getLogPrefix(), targetId, rpConfig.getId(), ctx.getRelyingPartyId(),});
+ new Object[] {getLogPrefix(), targetId, rpConfig.getId(), rpCtx.getRelyingPartyId(),});
ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_PROFILE_CONFIG);
} else {
log.debug("{} Profile {} is not active for RP configuration {} (RPID {})",
- new Object[] {getLogPrefix(), targetId, rpConfig.getId(), ctx.getRelyingPartyId(),});
+ new Object[] {getLogPrefix(), targetId, rpConfig.getId(), rpCtx.getRelyingPartyId(),});
}
} else {
- ctx.setProfileConfig(profileConfiguration);
+ rpCtx.setProfileConfig(profileConfiguration);
}
}
// Checkstyle: CyclomaticComplexity ON
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/SelectRelyingPartyConfiguration.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/SelectRelyingPartyConfiguration.java
index 39044df5e..50609a745 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/SelectRelyingPartyConfiguration.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/SelectRelyingPartyConfiguration.java
@@ -20,7 +20,6 @@ package net.shibboleth.idp.profile.impl;
import java.util.function.Function;
import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import org.opensaml.messaging.context.BaseContext;
import org.opensaml.messaging.context.navigate.ChildContextLookup;
@@ -36,6 +35,7 @@ import net.shibboleth.profile.relyingparty.RelyingPartyConfiguration;
import net.shibboleth.profile.relyingparty.RelyingPartyConfigurationResolver;
import net.shibboleth.profile.relyingparty.VerifiedProfileCriterion;
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.LoggerFactory;
@@ -72,7 +72,7 @@ public final class SelectRelyingPartyConfiguration extends AbstractProfileAction
@Nonnull private Function<ProfileRequestContext,RelyingPartyContext> relyingPartyContextLookupStrategy;
/** The {@link RelyingPartyContext} to manipulate. */
- @Nullable private RelyingPartyContext relyingPartyCtx;
+ @NonnullBeforeExec private RelyingPartyContext relyingPartyCtx;
/** Constructor. */
public SelectRelyingPartyConfiguration() {
@@ -105,6 +105,15 @@ public final class SelectRelyingPartyConfiguration extends AbstractProfileAction
relyingPartyContextLookupStrategy =
Constraint.isNotNull(strategy, "RelyingPartyContext lookup strategy cannot be null");
}
+
+ /** Null safe getter.
+ * @return Returns the relyingPartyCtx.
+ */
+ @SuppressWarnings("null")
+ @Nonnull private RelyingPartyContext getRelyingPartyCtx() {
+ assert isPreExecuteCalled();
+ return relyingPartyCtx;
+ }
/** {@inheritDoc} */
@Override
@@ -137,17 +146,15 @@ public final class SelectRelyingPartyConfiguration extends AbstractProfileAction
@Override
public void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
- final RelyingPartyContext rpCtx = relyingPartyCtx;
- assert rpCtx != null;
try (final ServiceableComponent<RelyingPartyConfigurationResolver> resolver =
rpConfigResolver.getServiceableComponent()) {
final RelyingPartyConfiguration config;
final CriteriaSet criteria = new CriteriaSet();
- if (rpCtx.isVerified()) {
+ if (getRelyingPartyCtx().isVerified()) {
criteria.add(new VerifiedProfileCriterion(true));
}
- if (rpCtx.getParent() == profileRequestContext) {
+ if (getRelyingPartyCtx().getParent() == profileRequestContext) {
// Works as is.
criteria.add(new ProfileRequestContextCriterion(profileRequestContext));
config = resolver.getComponent().resolveSingle(criteria);
@@ -156,12 +163,12 @@ public final class SelectRelyingPartyConfiguration extends AbstractProfileAction
// TODO: I think this *may* be moot now with the addition of the
// explicit VerifiedProfileCriterion.
final ProfileRequestContext newPRC = new ProfileRequestContext();
- final BaseContext originalParent = rpCtx.getParent();
- newPRC.addSubcontext(rpCtx);
+ final BaseContext originalParent = getRelyingPartyCtx().getParent();
+ newPRC.addSubcontext(getRelyingPartyCtx());
criteria.add(new ProfileRequestContextCriterion(newPRC));
config = resolver.getComponent().resolveSingle(criteria);
if (originalParent != null) {
- originalParent.addSubcontext(rpCtx);
+ originalParent.addSubcontext(getRelyingPartyCtx());
}
}
@@ -172,7 +179,7 @@ public final class SelectRelyingPartyConfiguration extends AbstractProfileAction
}
log.debug("{} Found relying party configuration {} for request", getLogPrefix(), config.getId());
- rpCtx.setConfiguration(config);
+ getRelyingPartyCtx().setConfiguration(config);
} catch (final ResolverException e) {
log.error("{} Error trying to resolve relying party configuration", getLogPrefix(), e);
ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_RELYING_PARTY_CONFIG);
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/WebFlowMessageHandlerAdaptor.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/WebFlowMessageHandlerAdaptor.java
index 8f35a56b5..d810002d1 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/WebFlowMessageHandlerAdaptor.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/WebFlowMessageHandlerAdaptor.java
@@ -33,6 +33,7 @@ import org.slf4j.Logger;
import net.shibboleth.idp.profile.AbstractProfileAction;
import net.shibboleth.shared.annotation.ParameterName;
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.shared.primitive.StringSupport;
@@ -79,7 +80,7 @@ public class WebFlowMessageHandlerAdaptor extends AbstractProfileAction {
@Nullable private Function<ProfileRequestContext,MessageHandler> handlerLookupStrategy;
/** The message handler being adapted. */
- @Nullable private MessageHandler handler;
+ @NonnullBeforeExec private MessageHandler handler;
/** The direction of execution for this action instance. */
private final Direction direction;
@@ -170,19 +171,17 @@ public class WebFlowMessageHandlerAdaptor extends AbstractProfileAction {
//CheckStyle: ReturnCount OFF
@Override public void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
- final MessageHandler msgHandler = handler;
- assert msgHandler != null;
- MessageContext target = null;
+ final MessageContext target;
switch (direction) {
case INBOUND:
target = profileRequestContext.getInboundMessageContext();
log.debug("{} Invoking message handler of type '{}' on INBOUND message context", getLogPrefix(),
- msgHandler.getClass().getName());
+ handler.getClass().getName());
break;
case OUTBOUND:
target = profileRequestContext.getOutboundMessageContext();
log.debug("{} Invoking message handler of type '{}' on OUTBOUND message context", getLogPrefix(),
- msgHandler.getClass().getName());
+ handler.getClass().getName());
break;
default:
log.warn("{} Specified direction '{}' was unknown, skipping handler invocation", getLogPrefix(),
@@ -203,7 +202,7 @@ public class WebFlowMessageHandlerAdaptor extends AbstractProfileAction {
}
try {
- msgHandler.invoke(target);
+ handler.invoke(target);
} catch (final MessageHandlerException e) {
log.warn("{} Exception handling message", getLogPrefix(), e);
if (errorEvent != null) {
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list