[java-identity-provider] 01/02: IDP-2069 Null handling

Rod Widdowson rdw at steadingsoftware.com
Fri Feb 24 16:22:34 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=227fc487b368fb798c5ff6778b588a81131daeb8

commit 227fc487b368fb798c5ff6778b588a81131daeb8
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Feb 24 16:19:33 2023 +0000

    IDP-2069 Null handling
    
    https://shibboleth.atlassian.net/browse/IDP-2069
    
    Cleanup idp-profile-impl.  Tests still TBD
---
 .../profile/audit/impl/PopulateAuditContext.java   | 30 ++++++++++++-------
 .../idp/profile/audit/impl/WriteAuditLog.java      |  9 ++++--
 .../idp/profile/impl/FilterAttributes.java         | 35 +++++++++++++---------
 .../impl/InitializeProfileRequestContext.java      |  7 ++---
 .../idp/profile/impl/LogContextTree.java           |  4 ++-
 .../idp/profile/impl/LogSpringContextInfo.java     | 11 +++++--
 .../profile/impl/MetadataQueryRequestDecoder.java  | 13 ++------
 .../idp/profile/impl/PopulateUserAgentContext.java |  6 +++-
 .../ProfileActionBeanFactoryPostProcessor.java     |  3 +-
 .../impl/ProfileActionBeanPostProcessor.java       |  6 ++--
 .../idp/profile/impl/RecordResponseComplete.java   |  6 ++--
 .../profile/impl/ReloadServiceConfiguration.java   | 21 ++++++++-----
 .../idp/profile/impl/ResolveAttributes.java        | 11 +++++--
 .../profile/impl/ResolverTestPrincipalLookup.java  |  6 ++--
 .../profile/impl/ResolverTestRequestDecoder.java   | 10 ++-----
 .../profile/impl/SelectProfileConfiguration.java   | 22 +++++++-------
 .../impl/SelectRelyingPartyConfiguration.java      | 14 +++++----
 .../profile/impl/WebFlowMessageHandlerAdaptor.java | 25 ++++++++++++----
 .../impl/SelectProfileInterceptorFlow.java         | 14 +++++----
 .../WriteProfileInterceptorResultToStorage.java    | 12 +++++---
 .../messaging/impl/SelectProfileConfiguration.java | 20 +++++++------
 .../impl/SelectRelyingPartyConfiguration.java      | 14 +++++----
 22 files changed, 181 insertions(+), 118 deletions(-)

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 329cc81e1..d226c030b 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
@@ -22,7 +22,6 @@ import java.time.ZoneOffset;
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.TemporalAccessor;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -44,6 +43,7 @@ import net.shibboleth.shared.annotation.constraint.NonnullElements;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
 import net.shibboleth.shared.annotation.constraint.NotLive;
 import net.shibboleth.shared.annotation.constraint.Unmodifiable;
+import net.shibboleth.shared.collection.CollectionSupport;
 import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.logic.Constraint;
 import net.shibboleth.shared.primitive.LoggerFactory;
@@ -93,11 +93,12 @@ public class PopulateAuditContext extends AbstractProfileAction {
     @Nullable private AuditContext auditCtx;
     
     /** Constructor. */
+    @SuppressWarnings("null")
     public PopulateAuditContext() {
         auditContextCreationStrategy = new ChildContextLookup<>(AuditContext.class, true);
-        fieldExtractors = Collections.emptyMap();
-        fieldsToExtract = Collections.emptySet();
-        fieldReplacements = Collections.emptyMap();
+        fieldExtractors = CollectionSupport.emptyMap();
+        fieldsToExtract = CollectionSupport.emptySet();
+        fieldReplacements = CollectionSupport.emptyMap();
         
         dateTimeFormatter = DateTimeFormatter.ISO_INSTANT;
     }
@@ -160,7 +161,7 @@ public class PopulateAuditContext extends AbstractProfileAction {
         if (map != null) {
             fieldReplacements = new HashMap<>(map);
         } else {
-            fieldReplacements = Collections.emptyMap();
+            fieldReplacements = CollectionSupport.emptyMap();
         }
     }
     
@@ -169,6 +170,7 @@ public class PopulateAuditContext extends AbstractProfileAction {
      * 
      * @param format formatting string
      */
+    @SuppressWarnings("null")
     public void setDateTimeFormat(@Nullable @NotEmpty final String format) {
         checkSetterPreconditions();
         if (format != null) {
@@ -201,6 +203,7 @@ public class PopulateAuditContext extends AbstractProfileAction {
     }
     
     /** {@inheritDoc} */
+    @SuppressWarnings("null")
     @Override
     protected void doInitialize() throws ComponentInitializationException {
         super.doInitialize();
@@ -235,12 +238,15 @@ public class PopulateAuditContext extends AbstractProfileAction {
     protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
         
         if (clearAuditContext) {
+            assert auditCtx != null;
             auditCtx.getFields().clear();
         }
         
         for (final Map.Entry<String,Function<ProfileRequestContext,Object>> entry : fieldExtractors.entrySet()) {
             
-            if (!fieldsToExtract.isEmpty() && !fieldsToExtract.contains(entry.getKey())) {
+            final String key = entry.getKey();
+            assert key != null;
+            if (!fieldsToExtract.isEmpty() && !fieldsToExtract.contains(key)) {
                 log.trace("{} Skipping field '{}' not included in audit format", getLogPrefix(), entry.getKey());
                 continue;
             }
@@ -252,12 +258,12 @@ public class PopulateAuditContext extends AbstractProfileAction {
                         log.trace("{} Adding {} value(s) for field '{}'", getLogPrefix(),
                                 ((Collection<?>) values).size(), entry.getKey());
                         for (final Object value : (Collection<?>) values) {
-                            addField(entry.getKey(), value);
+                            addField(key, value);
                         }
                     }
                 } else {
                     log.trace("{} Adding 1 value for field '{}'", getLogPrefix(), entry.getKey());
-                    addField(entry.getKey(), values);
+                    addField(key, values);
                 }
             }
         }
@@ -271,16 +277,18 @@ public class PopulateAuditContext extends AbstractProfileAction {
      */
     private void addField(@Nonnull @NotEmpty final String key, @Nullable final Object value) {
         
+        final AuditContext ctx = auditCtx;
+        assert ctx != null;
         if (value != null) {
             if (value instanceof TemporalAccessor) {
-                auditCtx.getFieldValues(key).add(dateTimeFormatter.format((TemporalAccessor) value));
+                ctx.getFieldValues(key).add(dateTimeFormatter.format((TemporalAccessor) value));
             } else {
                 String s = value.toString();
                 if (fieldReplacements.containsKey(s)) {
                     s = fieldReplacements.get(s);
                 }
                 if (s != null) {
-                    auditCtx.getFieldValues(key).add(s);
+                    ctx.getFieldValues(key).add(s);
                 }
             }
         }
@@ -330,7 +338,7 @@ public class PopulateAuditContext extends AbstractProfileAction {
                 }
             }
             
-            fields = Set.copyOf(fieldsToExtract);
+            fields = CollectionSupport.copyToSet(fieldsToExtract);
         }
         
         /**
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/audit/impl/WriteAuditLog.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/audit/impl/WriteAuditLog.java
index 17d7f21ff..00d03c1b1 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/audit/impl/WriteAuditLog.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/audit/impl/WriteAuditLog.java
@@ -90,6 +90,7 @@ public class WriteAuditLog extends AbstractProfileAction {
     @Nullable private AuditContext auditCtx;
 
     /** Constructor. */
+    @SuppressWarnings("null")
     public WriteAuditLog() {
         auditContextLookupStrategy = new ChildContextLookup<>(AuditContext.class);
         formattingMap = CollectionSupport.emptyMap();
@@ -202,6 +203,7 @@ public class WriteAuditLog extends AbstractProfileAction {
      * 
      * @param format formatting string
      */
+    @SuppressWarnings("null")
     public void setDateTimeFormat(@Nullable @NotEmpty final String format) {
         checkSetterPreconditions();
         if (format != null) {
@@ -234,6 +236,7 @@ public class WriteAuditLog extends AbstractProfileAction {
     }
     
     /** {@inheritDoc} */
+    @SuppressWarnings("null")
     @Override
     protected void doInitialize() throws ComponentInitializationException {
         super.doInitialize();
@@ -247,7 +250,7 @@ public class WriteAuditLog extends AbstractProfileAction {
 
     /** {@inheritDoc} */
     @Override
-    @Nonnull protected Event doExecute(@Nonnull final RequestContext springRequestContext,
+    @Nullable protected Event doExecute(@Nonnull final RequestContext springRequestContext,
             @Nonnull final ProfileRequestContext profileRequestContext) {
         requestContext = springRequestContext;
         return super.doExecute(springRequestContext, profileRequestContext);
@@ -291,6 +294,7 @@ public class WriteAuditLog extends AbstractProfileAction {
                         if (IdPAuditFields.EVENT_TIME.equals(field)) {
                             record.append(dateTimeFormatter.format(Instant.now()));
                         } else if (IdPAuditFields.EVENT_TYPE.equals(field)) {
+                            assert requestContext != null;
                             final Event event = requestContext.getCurrentEvent();
                             if (event != null && !event.getId().equals(EventIds.PROCEED_EVENT_ID)) {
                                 record.append(event.getId());
@@ -306,6 +310,7 @@ public class WriteAuditLog extends AbstractProfileAction {
                         } else if (IdPAuditFields.USER_AGENT.equals(field) && httpRequest != null) {
                             record.append(httpRequest.getHeader("User-Agent"));
                         } else if (auditCtx != null) {
+                            assert field != null;
                             final Iterator<String> iter = auditCtx.getFieldValues(field).iterator();
                             while (iter.hasNext()) {
                                 record.append(iter.next());
@@ -328,7 +333,7 @@ public class WriteAuditLog extends AbstractProfileAction {
             } else {
                 category = entry.getKey();
             }
-            
+            assert category != null;
             LoggerFactory.getLogger(category).info(record.toString());
         }
     }
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 4dd54ec84..a406e31cb 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
@@ -23,6 +23,7 @@ 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;
 import org.opensaml.messaging.context.navigate.RootContextLookup;
 import org.opensaml.profile.action.ActionSupport;
@@ -173,6 +174,7 @@ public class FilterAttributes extends AbstractProfileAction {
                                 new InboundMessageContextLookup()));
         
         // This is always set to navigate to the PRC and then apply the previous function.
+        assert metadataContextLookupStrategy != null;
         metadataFromFilterLookupStrategy = metadataContextLookupStrategy.compose(
                 profileRequestContextFromFilterLookupStrategy);
 
@@ -181,6 +183,7 @@ public class FilterAttributes extends AbstractProfileAction {
                 new ChildContextLookup<>(ProxiedRequesterContext.class).compose(new InboundMessageContextLookup());
         
         // This is always set to navigate to the PRC and then apply the previous function.
+        assert proxiedRequesterContextLookupStrategy!=null;
         proxiesFromFilterLookupStrategy = proxiedRequesterContextLookupStrategy.compose(
                 profileRequestContextFromFilterLookupStrategy);
         
@@ -267,7 +270,7 @@ public class FilterAttributes extends AbstractProfileAction {
      * @param strategy lookup strategy
      */
     public void setIssuerMetadataContextLookupStrategy(
-            @Nullable final Function<ProfileRequestContext,SAMLMetadataContext> strategy) {
+            @Nonnull final Function<ProfileRequestContext,SAMLMetadataContext> strategy) {
         checkSetterPreconditions();
         issuerMetadataContextLookupStrategy = strategy;
         issuerMetadataFromFilterLookupStrategy = strategy != null ?
@@ -282,11 +285,10 @@ public class FilterAttributes extends AbstractProfileAction {
      * @param strategy lookup strategy
      */
     public void setMetadataContextLookupStrategy(
-            @Nullable final Function<ProfileRequestContext,SAMLMetadataContext> strategy) {
+            @Nonnull final Function<ProfileRequestContext,SAMLMetadataContext> strategy) {
         checkSetterPreconditions();
-        metadataContextLookupStrategy = strategy;
         metadataFromFilterLookupStrategy = strategy != null ?
-                metadataContextLookupStrategy.compose(profileRequestContextFromFilterLookupStrategy) : null;
+                strategy.compose(profileRequestContextFromFilterLookupStrategy) : null;
     }
 
     /**
@@ -299,7 +301,7 @@ public class FilterAttributes extends AbstractProfileAction {
      * @since 3.4.0
      */
     public void setProxiedRequesterContextLookupStrategy(
-            @Nullable final Function<ProfileRequestContext,ProxiedRequesterContext> strategy) {
+            @Nonnull final Function<ProfileRequestContext,ProxiedRequesterContext> strategy) {
         checkSetterPreconditions();
         proxiedRequesterContextLookupStrategy = strategy;
         proxiesFromFilterLookupStrategy = strategy != null ?
@@ -314,7 +316,7 @@ public class FilterAttributes extends AbstractProfileAction {
      * @since 4.2.0
      */
     public void setProxiedRequesterMetadataContextLookupStrategy(
-            @Nullable final Function<ProfileRequestContext,SAMLMetadataContext> strategy) {
+            @Nonnull final Function<ProfileRequestContext,SAMLMetadataContext> strategy) {
         checkSetterPreconditions();
         proxiedRequesterMetadataLookupStrategy = strategy;
         proxiedMetadataFromFilterLookupStrategy = strategy != null ?
@@ -341,13 +343,13 @@ public class FilterAttributes extends AbstractProfileAction {
             return false;
         }
         
-        attributeContext = attributeContextLookupStrategy.apply(profileRequestContext);
-        if (attributeContext == null) {
+        final AttributeContext ctx = attributeContext = attributeContextLookupStrategy.apply(profileRequestContext);
+        if (ctx == null) {
             log.debug("{} No attribute context, no attributes to filter", getLogPrefix());
             return false;
         }
 
-        if (attributeContext.getIdPAttributes().isEmpty()) {
+        if (ctx.getIdPAttributes().isEmpty()) {
             log.debug("{} No attributes to filter", getLogPrefix());
             return false;
         }
@@ -361,12 +363,14 @@ 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");
-                attributeContext.setIdPAttributes(null);
+                ac.setIdPAttributes(null);
             } else {
                 ActionSupport.buildEvent(profileRequestContext, IdPEventIds.UNABLE_FILTER_ATTRIBS);
             }
@@ -378,13 +382,15 @@ public class FilterAttributes extends AbstractProfileAction {
         try (final ServiceableComponent<AttributeFilter> component = attributeFilterService.getServiceableComponent()) {
             final AttributeFilter filter = component.getComponent();
             filter.filterAttributes(filterContext);
-            filterContext.getParent().removeSubcontext(filterContext);
-            attributeContext.setIdPAttributes(filterContext.getFilteredIdPAttributes().values());
+            final BaseContext parent = filterContext.getParent();
+            assert parent != null;
+            parent.removeSubcontext(filterContext);
+            ac.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");
-                attributeContext.setIdPAttributes(Collections.emptySet());
+                ac.setIdPAttributes(Collections.emptySet());
             } else {
                 ActionSupport.buildEvent(profileRequestContext, IdPEventIds.UNABLE_FILTER_ATTRIBS);
             }
@@ -392,7 +398,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");
-                attributeContext.setIdPAttributes(null);
+                ac.setIdPAttributes(null);
             } else {
                 ActionSupport.buildEvent(profileRequestContext, IdPEventIds.UNABLE_FILTER_ATTRIBS);
             }
@@ -423,6 +429,7 @@ public class FilterAttributes extends AbstractProfileAction {
         // If the filter context doesn't have a set of attributes to filter already
         // then look for them in the AttributeContext.
         if (filterContext.getPrefilteredIdPAttributes().isEmpty()) {
+            assert attributeContext != null;
             filterContext.setPrefilteredIdPAttributes(attributeContext.getIdPAttributes().values());
         }
     }
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/InitializeProfileRequestContext.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/InitializeProfileRequestContext.java
index 4d402895d..caa8a4637 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/InitializeProfileRequestContext.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/InitializeProfileRequestContext.java
@@ -19,7 +19,6 @@ package net.shibboleth.idp.profile.impl;
 
 import java.util.Map;
 
-import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.annotation.concurrent.ThreadSafe;
 
@@ -119,10 +118,10 @@ public final class InitializeProfileRequestContext extends AbstractProfileAction
     
     /** {@inheritDoc} */
     @Override
-    @Nonnull public Event execute(@Nonnull final RequestContext springRequestContext) {
+    @Nullable public Event execute(final @Nullable RequestContext springRequestContext) {
 
+        assert springRequestContext != null;
         // We have to override execute() because the profile request context doesn't exist yet.
-        
         checkComponentActive();
         
         final ProfileRequestContext prc = new ProfileRequestContext();
@@ -145,7 +144,7 @@ public final class InitializeProfileRequestContext extends AbstractProfileAction
         if (captureQueryParameters) {
             final HttpServletRequest request = getHttpServletRequest();
             if (request != null) {
-                ((Map<Object,Object>) prc.getSubcontext(ScratchContext.class, true).getMap()).putAll(
+                ((Map<Object,Object>) prc.getOrCreateSubcontext(ScratchContext.class).getMap()).putAll(
                         request.getParameterMap());
             }
         }
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/LogContextTree.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/LogContextTree.java
index 9b6511a30..117ad29f6 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/LogContextTree.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/LogContextTree.java
@@ -17,6 +17,7 @@
 
 package net.shibboleth.idp.profile.impl;
 
+import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import org.opensaml.messaging.context.BaseContext;
@@ -71,7 +72,7 @@ public class LogContextTree extends AbstractProfileAction {
     }
 
     /** {@inheritDoc} */
-    protected void doExecute(final ProfileRequestContext profileRequestContext) {
+    protected void doExecute(final @Nonnull ProfileRequestContext profileRequestContext) {
         if (!log.isDebugEnabled()) {
             // short-circuit if not logging at debug
             return;
@@ -83,6 +84,7 @@ public class LogContextTree extends AbstractProfileAction {
                 profileRequestContext.getSubcontext(SpringRequestContext.class);
         if (springRequestContext != null && springRequestContext.getRequestContext() != null) {
             final RequestContext requestContext = springRequestContext.getRequestContext();
+            assert requestContext != null;
             contextualDescription = requestContext.getAttributes().getString(ATTRIB_DESC);
         }
         
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/LogSpringContextInfo.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/LogSpringContextInfo.java
index c0bcf4733..5b6aa8776 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/LogSpringContextInfo.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/LogSpringContextInfo.java
@@ -17,6 +17,7 @@
 
 package net.shibboleth.idp.profile.impl;
 
+import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import org.opensaml.profile.context.ProfileRequestContext;
@@ -75,12 +76,12 @@ public class LogSpringContextInfo extends AbstractProfileAction implements Appli
     }
     
     /** {@inheritDoc} */
-    public void setApplicationContext(final ApplicationContext context) throws BeansException {
+    public void setApplicationContext(final @Nonnull ApplicationContext context) throws BeansException {
         applicationContext = context;
     }
 
     /** {@inheritDoc} */
-    protected void doExecute(final ProfileRequestContext profileRequestContext) {
+    protected void doExecute(final @Nonnull ProfileRequestContext profileRequestContext) {
         if (!log.isDebugEnabled()) {
             // short-circuit if not logging at debug
             return;
@@ -92,6 +93,7 @@ public class LogSpringContextInfo extends AbstractProfileAction implements Appli
                 profileRequestContext.getSubcontext(SpringRequestContext.class);
         if (springRequestContext != null && springRequestContext.getRequestContext() != null) {
             final RequestContext requestContext = springRequestContext.getRequestContext();
+            assert requestContext!= null;
             contextualDescription = requestContext.getAttributes().getString(ATTRIB_DESC);
         }
         
@@ -117,9 +119,12 @@ public class LogSpringContextInfo extends AbstractProfileAction implements Appli
             log.debug("");
             
             for (final String beanName : current.getBeanDefinitionNames()) {
+                assert beanName != null;
+                final Class<?> type = current.getType(beanName);
+                assert type != null;
                 log.debug(String.format("Spring Bean id: %s, singleton?: %s, prototype?: %s, type: %s",
                         beanName, current.isSingleton(beanName), current.isPrototype(beanName), 
-                        current.getType(beanName).getName()));
+                        type.getName()));
             }
             
             log.debug("**********************************************************************************************");
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/MetadataQueryRequestDecoder.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/MetadataQueryRequestDecoder.java
index 6d30b3c07..3fea4f5fc 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/MetadataQueryRequestDecoder.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/MetadataQueryRequestDecoder.java
@@ -29,14 +29,11 @@ import org.opensaml.saml.common.messaging.context.SAMLProtocolContext;
 import org.opensaml.saml.common.xml.SAMLConstants;
 import org.opensaml.saml.metadata.resolver.DetectDuplicateEntityIDs;
 import org.opensaml.saml.saml2.metadata.SPSSODescriptor;
-import org.slf4j.Logger;
 
+import jakarta.servlet.http.HttpServletRequest;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
-import net.shibboleth.shared.primitive.LoggerFactory;
 import net.shibboleth.shared.primitive.StringSupport;
 
-import jakarta.servlet.http.HttpServletRequest;
-
 /**
  * Decodes an incoming metadata query request.
  */
@@ -59,10 +56,6 @@ public class MetadataQueryRequestDecoder extends AbstractHttpServletRequestMessa
     
     /** Name of the query parameter carrying the detectDuplicateEntityIDs: {@value} . */
     @Nonnull @NotEmpty public static final String DETECT_DUPLICATES_PARAM= "detectDuplicateEntityIDs";
-
-    /** Class logger. */
-    @Nonnull private final Logger log = LoggerFactory.getLogger(MetadataQueryRequestDecoder.class);
-    
     /** {@inheritDoc} */
     @Override
     protected void doDecode() throws MessageDecodingException {
@@ -86,11 +79,11 @@ public class MetadataQueryRequestDecoder extends AbstractHttpServletRequestMessa
         messageContext.addSubcontext(peerCtx, true);
         
         if (message.getProtocol() != null) {
-            messageContext.getSubcontext(SAMLProtocolContext.class, true).setProtocol(message.getProtocol());
+            messageContext.getOrCreateSubcontext(SAMLProtocolContext.class).setProtocol(message.getProtocol());
         }
         
         if (message.getDetectDuplicateEntityIDs() != null) {
-           messageContext.getSubcontext(SAMLMetadataLookupParametersContext.class, true)
+           messageContext.getOrCreateSubcontext(SAMLMetadataLookupParametersContext.class)
                .setDetectDuplicateEntityIDs(message.getDetectDuplicateEntityIDs());
         }
     }
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/PopulateUserAgentContext.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/PopulateUserAgentContext.java
index 0d7f6ec50..23d9cdab4 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/PopulateUserAgentContext.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/PopulateUserAgentContext.java
@@ -24,6 +24,8 @@ import net.shibboleth.idp.profile.AbstractProfileAction;
 import org.opensaml.profile.context.ProfileRequestContext;
 import org.opensaml.profile.logic.BrowserProfilePredicate;
 
+import jakarta.servlet.http.HttpServletRequest;
+
 /**
  * An action that conditionally populates a {@link UserAgentContext} as a child of the {@link ProfileRequestContext}.
  * By default, the action is activated by a {@link BrowserProfilePredicate} condition such that only browser profiles
@@ -42,7 +44,9 @@ public class PopulateUserAgentContext extends AbstractProfileAction {
     @Override
     protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
         final UserAgentContext uac = new UserAgentContext();
-        uac.setIdentifier(getHttpServletRequest().getHeader("User-Agent"));
+        final HttpServletRequest request = getHttpServletRequest();
+        assert request!= null;
+        uac.setIdentifier(request.getHeader("User-Agent"));
         profileRequestContext.addSubcontext(uac);
     }
 }
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ProfileActionBeanFactoryPostProcessor.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ProfileActionBeanFactoryPostProcessor.java
index ef2e66b19..d5c27719e 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ProfileActionBeanFactoryPostProcessor.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ProfileActionBeanFactoryPostProcessor.java
@@ -42,8 +42,9 @@ public class ProfileActionBeanFactoryPostProcessor implements BeanFactoryPostPro
 
     /** {@inheritDoc} */
     @Override
-    public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) {
+    public void postProcessBeanFactory(final @Nonnull ConfigurableListableBeanFactory beanFactory) {
         for (final String beanName : beanFactory.getBeanNamesForAnnotation(Prototype.class)) {
+            assert beanName != null;
             final BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
             if (!beanDefinition.isPrototype()) {
                 log.warn("Profile action '{}' is not '{}' scope but must be, please check your configuration.",
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ProfileActionBeanPostProcessor.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ProfileActionBeanPostProcessor.java
index 67b64f839..b44f5de83 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ProfileActionBeanPostProcessor.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ProfileActionBeanPostProcessor.java
@@ -17,6 +17,8 @@
 
 package net.shibboleth.idp.profile.impl;
 
+import javax.annotation.Nonnull;
+
 import org.opensaml.profile.action.ProfileAction;
 import org.springframework.beans.factory.BeanCreationException;
 import org.springframework.beans.factory.config.BeanPostProcessor;
@@ -31,13 +33,13 @@ public class ProfileActionBeanPostProcessor implements BeanPostProcessor {
 
     /** {@inheritDoc} */
     @Override
-    public Object postProcessBeforeInitialization(final Object bean, final String beanName) {
+    public Object postProcessBeforeInitialization(final @Nonnull Object bean, final @Nonnull String beanName) {
         return bean;
     }
 
     /** {@inheritDoc} */
     @Override
-    public Object postProcessAfterInitialization(final Object bean, final String beanName) {
+    public Object postProcessAfterInitialization(final @Nonnull Object bean, final @Nonnull String beanName) {
         if (bean instanceof ProfileAction && !(bean instanceof Action)) {
             final WebFlowProfileActionAdaptor wrapper = new WebFlowProfileActionAdaptor((ProfileAction) bean);
             try {
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 cacccd9e4..b99c9bf61 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
@@ -85,9 +85,11 @@ public class RecordResponseComplete extends AbstractProfileAction {
     /** {@inheritDoc} */
     @Override
     protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
-        if (!externalContext.isResponseComplete()) {
+        final ExternalContext ec = externalContext;
+        assert ec != null;
+        if (!ec.isResponseComplete()) {
             log.debug("{} Record response complete", getLogPrefix());
-            externalContext.recordResponseComplete();
+            ec.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 fc081f3e7..b547b8b53 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
@@ -85,7 +85,7 @@ public class ReloadServiceConfiguration extends AbstractProfileAction {
     }
     
     /** {@inheritDoc} */
-    @Override protected boolean doPreExecute(final ProfileRequestContext profileRequestContext) {
+    @Override protected boolean doPreExecute(final @Nonnull ProfileRequestContext profileRequestContext) {
         
         if (!super.doPreExecute(profileRequestContext)) {
             return false;
@@ -99,7 +99,9 @@ public class ReloadServiceConfiguration extends AbstractProfileAction {
         if (service == null) {
             log.warn("{} Unable to locate service to reload", getLogPrefix());
             try {
-                getHttpServletResponse().sendError(HttpServletResponse.SC_NOT_FOUND, "Service not found.");
+                final HttpServletResponse response = getHttpServletResponse();
+                assert response != null;
+                response.sendError(HttpServletResponse.SC_NOT_FOUND, "Service not found.");
             } catch (final IOException e) {
                 ActionSupport.buildEvent(profileRequestContext, EventIds.IO_ERROR);
             }
@@ -110,7 +112,7 @@ public class ReloadServiceConfiguration extends AbstractProfileAction {
     }
 
     /** {@inheritDoc} */
-    @Override protected void doExecute(final ProfileRequestContext profileRequestContext) {
+    @Override protected void doExecute(final @Nonnull ProfileRequestContext profileRequestContext) {
         
         final String id;
         if (service instanceof IdentifiedComponent) {
@@ -120,16 +122,19 @@ public class ReloadServiceConfiguration extends AbstractProfileAction {
         }
         
         log.debug("{} Reloading configuration for '{}'", getLogPrefix(), id);
-        
+        final HttpServletResponse response = getHttpServletResponse();
+        assert response != null;
+
         try {
+            assert service != null;
             service.reload();
             log.debug("{} Reloaded configuration for '{}'", getLogPrefix(), id);
-            getHttpServletResponse().setStatus(HttpServletResponse.SC_OK);
-            getHttpServletResponse().getWriter().println("Configuration reloaded for '" + id + "'");
+            response.setStatus(HttpServletResponse.SC_OK);
+            response.getWriter().println("Configuration reloaded for '" + id + "'");
         } catch (final ServiceException e) {
             log.error("{} Error reloading service configuration for '{}'", getLogPrefix(), id);
             try {
-                getHttpServletResponse().sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
+                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
             } catch (final IOException e2) {
                 log.error("{} I/O error responding to request", getLogPrefix(), e2);
                 ActionSupport.buildEvent(profileRequestContext, EventIds.IO_ERROR);
@@ -149,7 +154,7 @@ public class ReloadServiceConfiguration extends AbstractProfileAction {
         /** {@inheritDoc} */
         @Override
         @Nullable public ReloadableService<?> apply(@Nullable final ProfileRequestContext input) {
-            
+            assert input != null;
             final SpringRequestContext springRequestContext = input.getSubcontext(SpringRequestContext.class);
             if (springRequestContext == null) {
                 log.warn("{} Spring request context not found in profile request context", getLogPrefix());
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ResolveAttributes.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ResolveAttributes.java
index 25369e064..d582a3554 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ResolveAttributes.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ResolveAttributes.java
@@ -29,6 +29,7 @@ import org.opensaml.messaging.context.navigate.ChildContextLookup;
 import org.opensaml.profile.action.ActionSupport;
 import org.opensaml.profile.context.ProfileRequestContext;
 import org.slf4j.Logger;
+import org.springframework.webflow.execution.RequestContext;
 
 import net.shibboleth.idp.attribute.context.AttributeContext;
 import net.shibboleth.idp.attribute.resolver.AttributeResolver;
@@ -242,8 +243,9 @@ public final class ResolveAttributes extends AbstractProfileAction {
 
         if (resolutionLabel == null) {
             final SpringRequestContext springContext = profileRequestContext.getSubcontext(SpringRequestContext.class);
-            if (springContext != null && springContext.getRequestContext() != null) {
-                resolutionLabel = springContext.getRequestContext().getActiveFlow().getId();
+            final RequestContext requestContext = springContext != null ? springContext.getRequestContext() :null; 
+            if (requestContext != null) {
+                resolutionLabel = requestContext.getActiveFlow().getId();
             }
         }
         
@@ -308,7 +310,10 @@ public final class ResolveAttributes extends AbstractProfileAction {
         // Populate requested attributes, if not already set.
         if (resolutionContext.getRequestedIdPAttributeNames() == null
                 || resolutionContext.getRequestedIdPAttributeNames().isEmpty()) {
-            resolutionContext.setRequestedIdPAttributeNames(attributesLookupStrategy.apply(profileRequestContext));
+            assert attributesLookupStrategy != null;
+            final Collection<String> names = attributesLookupStrategy.apply(profileRequestContext);
+            assert names != null;
+            resolutionContext.setRequestedIdPAttributeNames(names);
         }
         
         if (null != principalNameLookupStrategy) {
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ResolverTestPrincipalLookup.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ResolverTestPrincipalLookup.java
index a1c051270..a825108ce 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ResolverTestPrincipalLookup.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ResolverTestPrincipalLookup.java
@@ -21,6 +21,7 @@ import java.util.function.Function;
 
 import javax.annotation.Nullable;
 
+import org.opensaml.messaging.context.MessageContext;
 import org.opensaml.profile.context.ProfileRequestContext;
 
 /**
@@ -31,8 +32,9 @@ public class ResolverTestPrincipalLookup implements Function<ProfileRequestConte
     /** {@inheritDoc} */
     @Nullable public String apply(@Nullable final ProfileRequestContext input) {
         
-        if (input != null && input.getInboundMessageContext() != null) {
-            final Object request = input.getInboundMessageContext().getMessage();
+        final MessageContext messageContext = input != null ? input.getInboundMessageContext() : null;  
+        if (messageContext != null) {
+            final Object request = messageContext .getMessage();
             if (request != null && request instanceof ResolverTestRequest) {
                 return ((ResolverTestRequest) request).getPrincipal();
             }
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ResolverTestRequestDecoder.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ResolverTestRequestDecoder.java
index d97696026..54f9b1f98 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ResolverTestRequestDecoder.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/ResolverTestRequestDecoder.java
@@ -27,14 +27,11 @@ import org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext;
 import org.opensaml.saml.common.messaging.context.SAMLProtocolContext;
 import org.opensaml.saml.common.xml.SAMLConstants;
 import org.opensaml.saml.saml2.metadata.SPSSODescriptor;
-import org.slf4j.Logger;
 
+import jakarta.servlet.http.HttpServletRequest;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
-import net.shibboleth.shared.primitive.LoggerFactory;
 import net.shibboleth.shared.primitive.StringSupport;
 
-import jakarta.servlet.http.HttpServletRequest;
-
 /**
  * Decodes an incoming resolver test message.
  */
@@ -58,9 +55,6 @@ public class ResolverTestRequestDecoder extends AbstractHttpServletRequestMessag
     /** Name of the query parameter for the SAML 2 protocol: {@value} . */
     @Nonnull @NotEmpty public static final String SAML2_PARAM = "saml2";
 
-    /** Class logger. */
-    @Nonnull private final Logger log = LoggerFactory.getLogger(ResolverTestRequestDecoder.class);
-    
     /** {@inheritDoc} */
     @Override
     protected void doDecode() throws MessageDecodingException {
@@ -81,7 +75,7 @@ public class ResolverTestRequestDecoder extends AbstractHttpServletRequestMessag
         messageContext.addSubcontext(peerCtx, true);
         
         if (message.getProtocol() != null) {
-            messageContext.getSubcontext(SAMLProtocolContext.class, true).setProtocol(message.getProtocol());
+            messageContext.getOrCreateSubcontext(SAMLProtocolContext.class).setProtocol(message.getProtocol());
         }
     }
 
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 6564074b0..0ec222716 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
@@ -122,14 +122,14 @@ public class SelectProfileConfiguration extends AbstractProfileAction {
             return false;
         }
         
-        rpCtx = relyingPartyContextLookupStrategy.apply(profileRequestContext);
-        if (rpCtx == null) {
+        RelyingPartyContext ctx = rpCtx = relyingPartyContextLookupStrategy.apply(profileRequestContext);
+        if (ctx  == null) {
             log.debug("{} No relying party context associated with this profile request", getLogPrefix());
             ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_RELYING_PARTY_CTX);
             return false;
         }
 
-        if (rpCtx.getConfiguration() == null) {
+        if (ctx.getConfiguration() == null) {
             log.debug("{} No relying party configuration associated with this profile request", getLogPrefix());
             ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_RELYING_PARTY_CONFIG);
             return false;
@@ -148,8 +148,10 @@ public class SelectProfileConfiguration extends AbstractProfileAction {
             targetId = profileRequestContext.getProfileId();
         }
         
-        final RelyingPartyConfiguration rpConfig = rpCtx.getConfiguration();
-
+        final RelyingPartyContext ctx = rpCtx;
+        assert ctx != null;
+        final RelyingPartyConfiguration rpConfig = ctx.getConfiguration();
+        assert rpConfig != null;
         ProfileConfiguration profileConfiguration = rpConfig.getProfileConfiguration(profileRequestContext, targetId);
         if (profileConfiguration == null && profileId == null && profileRequestContext.getLegacyProfileId() != null) {
             // Try the legacy ID.
@@ -164,25 +166,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(), rpCtx.getRelyingPartyId(),});
+                        new Object[] {getLogPrefix(), targetId, rpConfig.getId(), ctx.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(), rpCtx.getRelyingPartyId(),});
+                        new Object[] {getLogPrefix(), targetId, rpConfig.getId(), ctx.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(), rpCtx.getRelyingPartyId(),});
+                        new Object[] {getLogPrefix(), targetId, rpConfig.getId(), ctx.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(), rpCtx.getRelyingPartyId(),});
+                        new Object[] {getLogPrefix(), targetId, rpConfig.getId(), ctx.getRelyingPartyId(),});
             }
         } else {
-            rpCtx.setProfileConfig(profileConfiguration);
+            ctx.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 a300803f1..39044df5e 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
@@ -137,15 +137,17 @@ 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 (relyingPartyCtx.isVerified()) {
+            if (rpCtx.isVerified()) {
                 criteria.add(new VerifiedProfileCriterion(true));
             }
-            if (relyingPartyCtx.getParent() == profileRequestContext) {
+            if (rpCtx.getParent() == profileRequestContext) {
                 // Works as is.
                 criteria.add(new ProfileRequestContextCriterion(profileRequestContext));
                 config = resolver.getComponent().resolveSingle(criteria);
@@ -154,12 +156,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 = relyingPartyCtx.getParent();
-                newPRC.addSubcontext(relyingPartyCtx);
+                final BaseContext originalParent = rpCtx.getParent();
+                newPRC.addSubcontext(rpCtx);
                 criteria.add(new ProfileRequestContextCriterion(newPRC));
                 config = resolver.getComponent().resolveSingle(criteria);
                 if (originalParent != null) {
-                    originalParent.addSubcontext(relyingPartyCtx);
+                    originalParent.addSubcontext(rpCtx);
                 }
             }
             
@@ -170,7 +172,7 @@ public final class SelectRelyingPartyConfiguration extends AbstractProfileAction
             }
 
             log.debug("{} Found relying party configuration {} for request", getLogPrefix(), config.getId());
-            relyingPartyCtx.setConfiguration(config);
+            rpCtx.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 859e941a8..8f35a56b5 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
@@ -143,6 +143,11 @@ public class WebFlowMessageHandlerAdaptor extends AbstractProfileAction {
         }
 
         if (handler == null) {
+            if (handlerLookupStrategy == null) {
+                log.error("{} Neither c:messageHandler not c:lookupStrategy specified", getLogPrefix());
+                return false;
+            }
+            assert handlerLookupStrategy != null;
             handler = handlerLookupStrategy.apply(profileRequestContext);
             if (handler == null) {
                 log.debug("{} No message handler returned by lookup function, nothing to do", getLogPrefix());
@@ -152,7 +157,10 @@ public class WebFlowMessageHandlerAdaptor extends AbstractProfileAction {
         
         final MetricContext metricCtx = profileRequestContext.getSubcontext(MetricContext.class);
         if (metricCtx != null) {
-            metricCtx.start(handler.getClass().getSimpleName());
+            assert handler != null;
+            final String className = handler.getClass().getSimpleName();
+            assert className!=null; 
+            metricCtx.start(className);
         }
         
         return true;
@@ -162,17 +170,19 @@ 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;
         switch (direction) {
             case INBOUND:
                 target = profileRequestContext.getInboundMessageContext();
                 log.debug("{} Invoking message handler of type '{}' on INBOUND message context", getLogPrefix(), 
-                        handler.getClass().getName());
+                        msgHandler.getClass().getName());
                 break;
             case OUTBOUND:
                 target = profileRequestContext.getOutboundMessageContext();
                 log.debug("{} Invoking message handler of type '{}' on OUTBOUND message context", getLogPrefix(), 
-                        handler.getClass().getName());
+                        msgHandler.getClass().getName());
                 break;
             default:
                 log.warn("{} Specified direction '{}' was unknown, skipping handler invocation", getLogPrefix(),
@@ -186,13 +196,14 @@ public class WebFlowMessageHandlerAdaptor extends AbstractProfileAction {
             return;
         }
 
-        if (target.getMessage() != null) {
+        final Object message = target.getMessage();
+        if (message != null) {
             log.debug("{} Invoking message handler on message context containing a message of type '{}'",
-                    getLogPrefix(),  target.getMessage().getClass().getName());
+                    getLogPrefix(), message.getClass().getName());
         }
         
         try {
-            handler.invoke(target);
+            msgHandler.invoke(target);
         } catch (final MessageHandlerException e) {
             log.warn("{} Exception handling message", getLogPrefix(), e);
             if (errorEvent != null) {
@@ -210,7 +221,9 @@ public class WebFlowMessageHandlerAdaptor extends AbstractProfileAction {
         
         final MetricContext metricCtx = profileRequestContext.getSubcontext(MetricContext.class);
         if (metricCtx != null) {
+            assert handler != null;
             final String name = handler.getClass().getSimpleName();
+            assert name != null;
             metricCtx.stop(name);
             metricCtx.inc(name);
         }
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/interceptor/impl/SelectProfileInterceptorFlow.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/interceptor/impl/SelectProfileInterceptorFlow.java
index 1123ace7f..ab4641564 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/interceptor/impl/SelectProfileInterceptorFlow.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/interceptor/impl/SelectProfileInterceptorFlow.java
@@ -61,10 +61,11 @@ public class SelectProfileInterceptorFlow extends AbstractProfileInterceptorActi
 
         // Detect a previous attempted flow, and move it to the intermediate collection.
         // This will prevent re-selecting the same flow again.
-        if (interceptorContext.getAttemptedFlow() != null) {
+        final ProfileInterceptorFlowDescriptor attemptedFlow = interceptorContext.getAttemptedFlow();
+        if (attemptedFlow != null) {
             log.debug("{} Moving completed flow {} to completed set, selecting next one", getLogPrefix(),
-                    interceptorContext.getAttemptedFlow().getId());
-            interceptorContext.getAvailableFlows().remove(interceptorContext.getAttemptedFlow().getId());
+                    attemptedFlow.getId());
+            interceptorContext.getAvailableFlows().remove(attemptedFlow.getId());
             interceptorContext.setAttemptedFlow(null);
         }
 
@@ -80,9 +81,10 @@ public class SelectProfileInterceptorFlow extends AbstractProfileInterceptorActi
             log.debug("{} No flows available to choose from", getLogPrefix());
             return;
         }
-
-        log.debug("{} Selecting flow {}", getLogPrefix(), flow.getId());
-        ActionSupport.buildEvent(profileRequestContext, flow.getId());
+        final String id = flow.getId();
+        assert id != null;
+        log.debug("{} Selecting flow {}", getLogPrefix(), id);
+        ActionSupport.buildEvent(profileRequestContext, id);
     }
 
     /**
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/interceptor/impl/WriteProfileInterceptorResultToStorage.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/interceptor/impl/WriteProfileInterceptorResultToStorage.java
index 62bdd08fb..1b73f6059 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/interceptor/impl/WriteProfileInterceptorResultToStorage.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/interceptor/impl/WriteProfileInterceptorResultToStorage.java
@@ -69,12 +69,12 @@ public class WriteProfileInterceptorResultToStorage extends AbstractProfileInter
             return false;
         }
 
-        flowDescriptor = interceptorContext.getAttemptedFlow();
+         flowDescriptor = interceptorContext.getAttemptedFlow();
         if (flowDescriptor == null) {
             log.warn("{} No flow descriptor within interceptor context", getLogPrefix());
             return false;
         }
-
+        assert flowDescriptor != null;
         storageService = flowDescriptor.getStorageService();
         if (storageService == null) {
             log.warn("{} No storage service available from interceptor flow descriptor", getLogPrefix());
@@ -89,7 +89,9 @@ public class WriteProfileInterceptorResultToStorage extends AbstractProfileInter
             @Nonnull final ProfileInterceptorContext interceptorContext) {
 
         try {
+            assert results != null;
             for (final ProfileInterceptorResult result : results) {
+                assert result != null;
                 store(result);
             }
         } catch (final IOException e) {
@@ -114,10 +116,12 @@ public class WriteProfileInterceptorResultToStorage extends AbstractProfileInter
         int attempts = 10;
         boolean success = false;
         do {
-            success = storageService.create(context, key, value, expiration != null ? expiration.toEpochMilli() : null);
+            final StorageService service = storageService;
+            assert service != null;
+            success = service.create(context, key, value, expiration != null ? expiration.toEpochMilli() : null);
             if (!success) {
                 // The record already exists, so we need to overwrite via an update.
-                success = storageService.update(context, key, value,
+                success = service.update(context, key, value,
                         expiration != null ? expiration.toEpochMilli() : null);
             }
         } while (!success && attempts-- > 0);
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/messaging/impl/SelectProfileConfiguration.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/messaging/impl/SelectProfileConfiguration.java
index 593b8773b..1f89665a2 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/messaging/impl/SelectProfileConfiguration.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/messaging/impl/SelectProfileConfiguration.java
@@ -64,7 +64,7 @@ public class SelectProfileConfiguration extends AbstractMessageHandler {
     /**
      * Strategy used to locate the effective profile ID associated with a given {@link MessageContext}.
      */
-    @Nonnull private Function<MessageContext,String> profileIdLookupStrategy;
+    @NonnullAfterInit private Function<MessageContext,String> profileIdLookupStrategy;
 
     /** The RelyingPartyContext to operate on. */
     @Nullable private RelyingPartyContext rpCtx;
@@ -145,13 +145,13 @@ public class SelectProfileConfiguration extends AbstractMessageHandler {
             return false;
         }
         
-        rpCtx = relyingPartyContextLookupStrategy.apply(messageContext);
-        if (rpCtx == null) {
+        final RelyingPartyContext ctx = rpCtx = relyingPartyContextLookupStrategy.apply(messageContext);
+        if (ctx == null) {
             log.debug("{} No relying party context associated with this profile request", getLogPrefix());
             throw new MessageHandlerException("No relying party context associated with this message context");
         }
 
-        if (rpCtx.getConfiguration() == null) {
+        if (ctx.getConfiguration() == null) {
             log.debug("{} No relying party configuration associated with this profile request", getLogPrefix());
             throw new MessageHandlerException("No relying party configuration associated with this message context");
         }
@@ -163,12 +163,14 @@ public class SelectProfileConfiguration extends AbstractMessageHandler {
     @Override
     protected void doInvoke(@Nonnull final MessageContext messageContext) throws MessageHandlerException {
 
-        final RelyingPartyConfiguration rpConfig = rpCtx.getConfiguration();
-
+        final RelyingPartyContext ctx =  rpCtx = relyingPartyContextLookupStrategy.apply(messageContext);
+        assert ctx != null;
+        final RelyingPartyConfiguration rpConfig = ctx.getConfiguration();
+        assert rpConfig != null;
         final String profileId = profileIdLookupStrategy.apply(messageContext);
         if (profileId == null) {
             log.warn("{} Profile ID is not available from message context for RP configuration (RPID {})",
-                    new Object[] {getLogPrefix(), rpConfig.getId(), rpCtx.getRelyingPartyId(),});
+                    new Object[] {getLogPrefix(), rpConfig.getId(), ctx.getRelyingPartyId(),});
             throw new MessageHandlerException("Profile ID is not available from message context");
         }
         
@@ -176,10 +178,10 @@ public class SelectProfileConfiguration extends AbstractMessageHandler {
                 rpConfig.getProfileConfiguration(profileRequestContextLookupStrategy.apply(messageContext), profileId);
         if (profileConfiguration == null) {
             log.warn("{} Profile {} is not available for RP configuration {} (RPID {})",
-                    new Object[] {getLogPrefix(), profileId, rpConfig.getId(), rpCtx.getRelyingPartyId(),});
+                    new Object[] {getLogPrefix(), profileId, rpConfig.getId(), ctx.getRelyingPartyId(),});
             throw new MessageHandlerException("Profile is not available for RP configuration");
         }
-        rpCtx.setProfileConfig(profileConfiguration);
+        ctx.setProfileConfig(profileConfiguration);
     }
     
 }
\ No newline at end of file
diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/messaging/impl/SelectRelyingPartyConfiguration.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/messaging/impl/SelectRelyingPartyConfiguration.java
index 332d2b8f8..ac307f2d0 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/messaging/impl/SelectRelyingPartyConfiguration.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/messaging/impl/SelectRelyingPartyConfiguration.java
@@ -113,13 +113,13 @@ public final class SelectRelyingPartyConfiguration extends AbstractMessageHandle
     /** {@inheritDoc} */
     @Override
     public boolean doPreInvoke(@Nonnull final MessageContext messageContext) throws MessageHandlerException {
-        relyingPartyCtx = relyingPartyContextLookupStrategy.apply(messageContext);
-        if (relyingPartyCtx == null) {
+        final RelyingPartyContext ctx = relyingPartyCtx = relyingPartyContextLookupStrategy.apply(messageContext);
+        if (ctx == null) {
             log.debug("{} No relying party context available", getLogPrefix());
             throw new MessageHandlerException("No relying party context available");
         }
         
-        if (relyingPartyCtx.getRelyingPartyId() == null) {
+        if (ctx.getRelyingPartyId() == null) {
             log.debug("{} No relying party ID available", getLogPrefix());
             throw new MessageHandlerException("No relying party ID available");
         }
@@ -132,8 +132,12 @@ public final class SelectRelyingPartyConfiguration extends AbstractMessageHandle
     public void doInvoke(@Nonnull final MessageContext messageContext) throws MessageHandlerException {
 
         try {
+            final RelyingPartyContext ctx = relyingPartyCtx;
+            assert ctx!=null;
             // Implicitly "verified", so we include the criterion for that.
-            final CriteriaSet criteria = new CriteriaSet(new EntityIdCriterion(relyingPartyCtx.getRelyingPartyId()),
+            final String rpId =  ctx.getRelyingPartyId();
+            assert rpId != null;
+            final CriteriaSet criteria = new CriteriaSet(new EntityIdCriterion(rpId),
                     new VerifiedProfileCriterion(true));
             final RelyingPartyConfiguration config =
                     rpConfigResolver.getServiceableComponent().getComponent().resolveSingle(criteria);
@@ -143,7 +147,7 @@ public final class SelectRelyingPartyConfiguration extends AbstractMessageHandle
             }
 
             log.debug("{} Found relying party configuration {} for request", getLogPrefix(), config.getId());
-            relyingPartyCtx.setConfiguration(config);
+            ctx.setConfiguration(config);
         } catch (final ResolverException e) {
             log.error("{} Error trying to resolve relying party configuration: {}", getLogPrefix(), e.getMessage());
             throw new MessageHandlerException("Error trying to resolve relying party configuration", e);

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


More information about the commits mailing list