[java-identity-provider] branch main updated: IDP-2069 Null handling

Rod Widdowson rdw at steadingsoftware.com
Fri Feb 24 14:33:51 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=54764b538d27ed2c6c8c9c398f6857ff14b6a2d5

The following commit(s) were added to refs/heads/main by this push:
     new 54764b538 IDP-2069 Null handling
54764b538 is described below

commit 54764b538d27ed2c6c8c9c398f6857ff14b6a2d5
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Feb 24 14:36:47 2023 +0000

    IDP-2069 Null handling
    
    https://shibboleth.atlassian.net/browse/IDP-2069
    
    Cleanup idp-ui, including tests
---
 .../idp/ui/context/RelyingPartyUIContext.java      |  6 ++----
 .../shibboleth/idp/ui/csrf/CSRFTokenManager.java   |  3 ++-
 .../csrf/impl/CSRFTokenFlowExecutionListener.java  | 19 ++++++++++--------
 ...tEventRequiresCSRFTokenValidationPredicate.java |  5 ++---
 .../DefaultViewRequiresCSRFTokenPredicate.java     |  4 ++--
 .../idp/ui/csrf/impl/SimpleCSRFToken.java          |  4 ++--
 .../shibboleth/idp/ui/impl/SetRPUIInformation.java | 16 ++++++++++-----
 .../idp/ui/taglib/OrganizationDisplayNameTag.java  |  6 ++++--
 .../idp/ui/taglib/OrganizationNameTag.java         |  6 ++++--
 .../idp/ui/taglib/OrganizationURLTag.java          |  6 ++++--
 .../idp/ui/taglib/ServiceContactTag.java           |  6 ++++--
 .../idp/ui/taglib/ServiceDescriptionTag.java       |  6 ++++--
 .../idp/ui/taglib/ServiceInformationURLTag.java    | 11 +++++++----
 .../shibboleth/idp/ui/taglib/ServiceLogoTag.java   |  6 ++++--
 .../idp/ui/taglib/ServicePrivacyURLTag.java        | 11 +++++++----
 .../idp/ui/taglib/ServiceTagSupport.java           | 11 +++++++----
 .../idp/ui/context/RelyingPartyUIContextTest.java  | 18 +++++++++++------
 .../idp/ui/csrf/CSRFTokenManagerTest.java          |  9 ++++++---
 .../impl/CSRFTokenFlowExecutionListenerTest.java   | 23 +++++++++++++++++-----
 .../idp/ui/csrf/impl/SimpleCSRFTokenTest.java      | 13 +++++++++---
 20 files changed, 123 insertions(+), 66 deletions(-)

diff --git a/idp-ui/src/main/java/net/shibboleth/idp/ui/context/RelyingPartyUIContext.java b/idp-ui/src/main/java/net/shibboleth/idp/ui/context/RelyingPartyUIContext.java
index 9d0b707a6..05738557a 100644
--- a/idp-ui/src/main/java/net/shibboleth/idp/ui/context/RelyingPartyUIContext.java
+++ b/idp-ui/src/main/java/net/shibboleth/idp/ui/context/RelyingPartyUIContext.java
@@ -20,9 +20,7 @@ package net.shibboleth.idp.ui.context;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.List;
 import java.util.Locale;
 import java.util.Locale.LanguageRange;
@@ -43,7 +41,6 @@ import org.opensaml.saml.saml2.metadata.EntityDescriptor;
 import org.opensaml.saml.saml2.metadata.Organization;
 import org.opensaml.saml.saml2.metadata.SPSSODescriptor;
 import org.slf4j.Logger;
-import net.shibboleth.shared.primitive.LoggerFactory;
 
 import jakarta.servlet.http.HttpServletRequest;
 import net.shibboleth.idp.attribute.AttributesMapContainer;
@@ -58,6 +55,7 @@ import net.shibboleth.shared.collection.CollectionSupport;
 import net.shibboleth.shared.logic.Constraint;
 import net.shibboleth.shared.primitive.DeprecationSupport;
 import net.shibboleth.shared.primitive.DeprecationSupport.ObjectType;
+import net.shibboleth.shared.primitive.LoggerFactory;
 import net.shibboleth.shared.primitive.NonnullSupplier;
 import net.shibboleth.shared.primitive.StringSupport;
 import net.shibboleth.shared.spring.util.SpringSupport;
@@ -865,7 +863,7 @@ public final class RelyingPartyUIContext extends BaseContext {
                 }
             }
         }
-        for (final Logo logo : rpUIInfo.getNonLocaleLogos()) {
+        for (final Logo logo : info.getNonLocaleLogos()) {
             log.trace("Found logo in UIInfo, ({} x {})", logo.getWidth(), logo.getHeight());
             if (!logoFits(logo, minWidth, minHeight, maxWidth, maxHeight)) {
                 log.trace("Size Mismatch");
diff --git a/idp-ui/src/main/java/net/shibboleth/idp/ui/csrf/CSRFTokenManager.java b/idp-ui/src/main/java/net/shibboleth/idp/ui/csrf/CSRFTokenManager.java
index bd9cad79e..32659f136 100644
--- a/idp-ui/src/main/java/net/shibboleth/idp/ui/csrf/CSRFTokenManager.java
+++ b/idp-ui/src/main/java/net/shibboleth/idp/ui/csrf/CSRFTokenManager.java
@@ -26,6 +26,7 @@ import javax.annotation.Nullable;
 import javax.annotation.concurrent.ThreadSafe;
 
 import net.shibboleth.idp.ui.csrf.impl.SimpleCSRFToken;
+import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
 import net.shibboleth.shared.component.AbstractInitializableComponent;
 import net.shibboleth.shared.component.ComponentInitializationException;
@@ -44,7 +45,7 @@ public final class CSRFTokenManager extends AbstractInitializableComponent {
    @Nonnull private String csrfParameterName;
    
    /** The strategy used to generate a CSRF token value. */
-   @Nonnull private IdentifierGenerationStrategy tokenGenerationStrategy;
+   @NonnullAfterInit private IdentifierGenerationStrategy tokenGenerationStrategy;
    
    /** Predicate to validate the CSRF token.*/
    @Nonnull private BiPredicate<CSRFToken,String> csrfTokenValidationPredicate;
diff --git a/idp-ui/src/main/java/net/shibboleth/idp/ui/csrf/impl/CSRFTokenFlowExecutionListener.java b/idp-ui/src/main/java/net/shibboleth/idp/ui/csrf/impl/CSRFTokenFlowExecutionListener.java
index bd27d98f1..9a3adabd1 100644
--- a/idp-ui/src/main/java/net/shibboleth/idp/ui/csrf/impl/CSRFTokenFlowExecutionListener.java
+++ b/idp-ui/src/main/java/net/shibboleth/idp/ui/csrf/impl/CSRFTokenFlowExecutionListener.java
@@ -21,6 +21,7 @@ import java.util.function.BiPredicate;
 import java.util.function.Predicate;
 
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 
 import org.slf4j.Logger;
 import net.shibboleth.shared.primitive.LoggerFactory;
@@ -124,9 +125,9 @@ public class CSRFTokenFlowExecutionListener extends AbstractInitializableCompone
      * {@inheritDoc}
      */
     @Override
-    public void viewRendering(@Nonnull final RequestContext context, @Nonnull final View view, 
-            @Nonnull final StateDefinition viewState) {        
-      
+    public void viewRendering(final RequestContext context, final View view,
+            final StateDefinition viewState) {
+
         //state here should always be a view-state, but guard anyway.
         if (enabled && viewState.isViewState() && viewRequiresCSRFTokenPredicate.test(context)) {
             context.getViewScope().put(CSRF_TOKEN_VIEWSCOPE_NAME, csrfTokenManager.generateCSRFToken());            
@@ -146,8 +147,9 @@ public class CSRFTokenFlowExecutionListener extends AbstractInitializableCompone
      * {@inheritDoc}
      */
     @Override
-    public void eventSignaled(@Nonnull final RequestContext context, @Nonnull final Event event) {
+    public void eventSignaled(final @Nullable RequestContext context, final @Nullable Event event) {
 
+        assert context != null && event != null;
         //always make sure listener is enabled and the current state is an active view-state.
         if (enabled && context.inViewState() && 
                 eventRequiresCSRFTokenValidationPredicate.test(context,event)){            
@@ -157,11 +159,12 @@ public class CSRFTokenFlowExecutionListener extends AbstractInitializableCompone
             log.trace("Event '{}' signaled from view '{}' requires a CSRF token", event.getId(),stateId);
 
             final Object storedCsrfTokenObject = context.getViewScope().get(CSRF_TOKEN_VIEWSCOPE_NAME);
-            
+            final String activeFlowId = context.getActiveFlow().getId();
+            assert activeFlowId != null;
             if (storedCsrfTokenObject == null || (!(storedCsrfTokenObject instanceof CSRFToken))) {
                 log.warn("CSRF token is required but was not found in the view-scope; for "
                         + "view-state '{}' and event '{}'.",stateId,event.getId());
-                throw new InvalidCSRFTokenException(context.getActiveFlow().getId(), stateId,
+                throw new InvalidCSRFTokenException(activeFlowId, stateId,
                         "Invalid CSRF token");               
             }
 
@@ -174,7 +177,7 @@ public class CSRFTokenFlowExecutionListener extends AbstractInitializableCompone
             if (csrfTokenFromRequest == null || !(csrfTokenFromRequest instanceof String)) {    
                 log.warn("CSRF token is required but was not found in the request; for "
                         + "view-state '{}' and event '{}'.",stateId,event.getId());
-                throw new InvalidCSRFTokenException(context.getActiveFlow().getId(), stateId,
+                throw new InvalidCSRFTokenException(activeFlowId, stateId,
                         "Invalid CSRF token");
             }
 
@@ -184,7 +187,7 @@ public class CSRFTokenFlowExecutionListener extends AbstractInitializableCompone
             if (!csrfTokenManager.isValidCSRFToken(storedCsrfToken, (String) csrfTokenFromRequest)) {
                 log.warn("CSRF token in the request did not match that stored in the view-scope; for "
                         + "view-state '{}' and event '{}'.",stateId,event.getId());
-                throw new InvalidCSRFTokenException(context.getActiveFlow().getId(), stateId,
+                throw new InvalidCSRFTokenException(activeFlowId, stateId,
                         "Invalid CSRF token");
             }
 
diff --git a/idp-ui/src/main/java/net/shibboleth/idp/ui/csrf/impl/DefaultEventRequiresCSRFTokenValidationPredicate.java b/idp-ui/src/main/java/net/shibboleth/idp/ui/csrf/impl/DefaultEventRequiresCSRFTokenValidationPredicate.java
index 27f9f9995..8abdf60b5 100644
--- a/idp-ui/src/main/java/net/shibboleth/idp/ui/csrf/impl/DefaultEventRequiresCSRFTokenValidationPredicate.java
+++ b/idp-ui/src/main/java/net/shibboleth/idp/ui/csrf/impl/DefaultEventRequiresCSRFTokenValidationPredicate.java
@@ -19,7 +19,6 @@ package net.shibboleth.idp.ui.csrf.impl;
 
 
 import java.util.function.BiPredicate;
-import javax.annotation.Nonnull;
 
 import org.springframework.webflow.execution.Event;
 import org.springframework.webflow.execution.RequestContext;
@@ -46,9 +45,9 @@ public class DefaultEventRequiresCSRFTokenValidationPredicate
             extends BaseCSRFTokenPredicate implements BiPredicate<RequestContext,Event>{
     
    /** {@inheritDoc} */
-   public boolean test(@Nonnull final RequestContext context, @Nonnull final Event event) {
-       
+   public boolean test(final RequestContext context, final Event event) {
        
+       assert context != null && event != null;
        final boolean excluded = safeGetBooleanStateAttribute(context.getCurrentState(),
                CSRF_EXCLUDED_ATTRIBUTE_NAME,false);
        //if NOT excluded from CSRF checks, return true, else return false.
diff --git a/idp-ui/src/main/java/net/shibboleth/idp/ui/csrf/impl/DefaultViewRequiresCSRFTokenPredicate.java b/idp-ui/src/main/java/net/shibboleth/idp/ui/csrf/impl/DefaultViewRequiresCSRFTokenPredicate.java
index 31d2bcfc1..07c772ec5 100644
--- a/idp-ui/src/main/java/net/shibboleth/idp/ui/csrf/impl/DefaultViewRequiresCSRFTokenPredicate.java
+++ b/idp-ui/src/main/java/net/shibboleth/idp/ui/csrf/impl/DefaultViewRequiresCSRFTokenPredicate.java
@@ -18,7 +18,6 @@
 package net.shibboleth.idp.ui.csrf.impl;
 
 import java.util.function.Predicate;
-import javax.annotation.Nonnull;
 
 import org.springframework.webflow.execution.RequestContext;
 
@@ -38,8 +37,9 @@ public class DefaultViewRequiresCSRFTokenPredicate
             extends BaseCSRFTokenPredicate implements Predicate<RequestContext>{
     
     /** {@inheritDoc} */
-    public boolean test(@Nonnull final RequestContext context) {
+    public boolean test(final RequestContext context) {
         
+        assert context != null;
         final boolean excluded = safeGetBooleanStateAttribute(context.getCurrentState(),
                 CSRF_EXCLUDED_ATTRIBUTE_NAME,false);
         //if NOT excluded from CSRF checks, return true, else return false.
diff --git a/idp-ui/src/main/java/net/shibboleth/idp/ui/csrf/impl/SimpleCSRFToken.java b/idp-ui/src/main/java/net/shibboleth/idp/ui/csrf/impl/SimpleCSRFToken.java
index b747b8553..2572e15ea 100644
--- a/idp-ui/src/main/java/net/shibboleth/idp/ui/csrf/impl/SimpleCSRFToken.java
+++ b/idp-ui/src/main/java/net/shibboleth/idp/ui/csrf/impl/SimpleCSRFToken.java
@@ -54,12 +54,12 @@ public class SimpleCSRFToken implements CSRFToken{
     }
 
     /** {@inheritDoc} */
-    public String getParameterName() {
+    @Nonnull public String getParameterName() {
         return parameterName;
     }
 
     /** {@inheritDoc} */
-    public String getToken() {
+    public @Nonnull String getToken() {
        return token;
     }
 
diff --git a/idp-ui/src/main/java/net/shibboleth/idp/ui/impl/SetRPUIInformation.java b/idp-ui/src/main/java/net/shibboleth/idp/ui/impl/SetRPUIInformation.java
index 0567dad88..1a2af7168 100644
--- a/idp-ui/src/main/java/net/shibboleth/idp/ui/impl/SetRPUIInformation.java
+++ b/idp-ui/src/main/java/net/shibboleth/idp/ui/impl/SetRPUIInformation.java
@@ -38,6 +38,7 @@ import org.opensaml.saml.saml2.metadata.RoleDescriptor;
 import org.opensaml.saml.saml2.metadata.SPSSODescriptor;
 import org.slf4j.Logger;
 
+import jakarta.servlet.http.HttpServletRequest;
 import net.shibboleth.idp.authn.context.AuthenticationContext;
 import net.shibboleth.idp.profile.AbstractProfileAction;
 import net.shibboleth.idp.ui.context.RelyingPartyUIContext;
@@ -45,6 +46,7 @@ import net.shibboleth.saml.profile.context.navigate.SAMLMetadataContextLookupFun
 import net.shibboleth.shared.annotation.constraint.NonnullElements;
 import net.shibboleth.shared.logic.Constraint;
 import net.shibboleth.shared.primitive.LoggerFactory;
+import net.shibboleth.shared.primitive.NonnullSupplier;
 import net.shibboleth.shared.primitive.StringSupport;
 import net.shibboleth.shared.spring.util.SpringSupport;
 
@@ -154,7 +156,8 @@ public class SetRPUIInformation extends AbstractProfileAction {
         if (spSSODescriptor != null) {
             final Extensions exts = spSSODescriptor.getExtensions();
             if (exts != null) {
-                for (final XMLObject object : exts.getOrderedChildren()) {
+                final List<XMLObject> children = Constraint.isNotNull(exts.getOrderedChildren(), "Extension Object had no children");
+                for (final XMLObject object : children) {
                     if (object instanceof UIInfo) {
                         return (UIInfo) object;
                     }
@@ -165,7 +168,7 @@ public class SetRPUIInformation extends AbstractProfileAction {
     }
 
     /** {@inheritDoc} */
-    @Override protected boolean doPreExecute(final ProfileRequestContext profileRequestContext) {
+    @Override protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
 
         if (!super.doPreExecute(profileRequestContext)) {
             return false;
@@ -193,7 +196,7 @@ public class SetRPUIInformation extends AbstractProfileAction {
     }
 
     /** {@inheritDoc} */
-    @Override protected void doExecute(final ProfileRequestContext profileRequestContext) {
+    @Override protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
 
         rpUIContext = rpUIContextCreateStrategy.apply(profileRequestContext);
         if (rpUIContext == null) {
@@ -209,8 +212,11 @@ public class SetRPUIInformation extends AbstractProfileAction {
         rpUIContext.setRPSPSSODescriptor(spSSODescriptor);
         rpUIContext.setRPAttributeConsumingService(acsDesriptor);
         rpUIContext.setRPUInfo(getRPUInfo());
-        rpUIContext.setBrowserLanguageRanges(SpringSupport.getLanguageRange(getHttpServletRequest()));
-        rpUIContext.setRequestSupplier(getHttpServletRequestSupplier());
+        final HttpServletRequest request = getHttpServletRequest();
+        final NonnullSupplier<HttpServletRequest> supplier = getHttpServletRequestSupplier();
+        assert request != null && supplier!= null;;
+        rpUIContext.setBrowserLanguageRanges(SpringSupport.getLanguageRange(request));
+        rpUIContext.setRequestSupplier(supplier);
    }
 
 }
diff --git a/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/OrganizationDisplayNameTag.java b/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/OrganizationDisplayNameTag.java
index d1c1bb0ac..3dbcdec89 100644
--- a/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/OrganizationDisplayNameTag.java
+++ b/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/OrganizationDisplayNameTag.java
@@ -23,6 +23,7 @@ import javax.annotation.Nullable;
 
 import org.slf4j.Logger;
 
+import net.shibboleth.idp.ui.context.RelyingPartyUIContext;
 import net.shibboleth.shared.codec.HTMLEncoder;
 import net.shibboleth.shared.primitive.LoggerFactory;
 
@@ -45,10 +46,11 @@ public class OrganizationDisplayNameTag extends ServiceTagSupport {
      * @return null or an appropriate string
      */
     @Nullable private String getOrganizationDisplayName() {
-        if (getRelyingPartyUIContext() == null) {
+        final RelyingPartyUIContext ctx = getRelyingPartyUIContext();
+        if (ctx == null) {
             return null;
         }
-        return getRelyingPartyUIContext().getOrganizationDisplayName();
+        return ctx.getOrganizationDisplayName();
     }
 
     /** {@inheritDoc} */
diff --git a/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/OrganizationNameTag.java b/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/OrganizationNameTag.java
index 39a32557d..be7f92930 100644
--- a/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/OrganizationNameTag.java
+++ b/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/OrganizationNameTag.java
@@ -23,6 +23,7 @@ import javax.annotation.Nullable;
 import jakarta.servlet.jsp.JspException;
 import jakarta.servlet.jsp.JspWriter;
 import jakarta.servlet.jsp.tagext.BodyContent;
+import net.shibboleth.idp.ui.context.RelyingPartyUIContext;
 import net.shibboleth.shared.codec.HTMLEncoder;
 
 import org.slf4j.Logger;
@@ -43,10 +44,11 @@ public class OrganizationNameTag extends ServiceTagSupport {
      * @return null or an appropriate string
      */
     @Nullable private String getOrganizationName() {
-        if (getRelyingPartyUIContext() == null) {
+        final RelyingPartyUIContext ctx = getRelyingPartyUIContext();
+        if (ctx == null) {
             return null;
         }
-        return getRelyingPartyUIContext().getOrganizationName();
+        return ctx.getOrganizationName();
     }
 
     /** {@inheritDoc} */
diff --git a/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/OrganizationURLTag.java b/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/OrganizationURLTag.java
index a2e101c91..093e04e1e 100644
--- a/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/OrganizationURLTag.java
+++ b/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/OrganizationURLTag.java
@@ -23,6 +23,7 @@ import javax.annotation.Nullable;
 
 import org.slf4j.Logger;
 
+import net.shibboleth.idp.ui.context.RelyingPartyUIContext;
 import net.shibboleth.shared.primitive.LoggerFactory;
 
 import jakarta.servlet.jsp.JspException;
@@ -56,10 +57,11 @@ public class OrganizationURLTag extends ServiceTagSupport {
      * @return null or an appropriate string
      */
     @Nullable private String getOrganizationURL() {
-        if (getRelyingPartyUIContext() == null) {
+        final RelyingPartyUIContext ctx = getRelyingPartyUIContext();
+        if (ctx == null) {
             return null;
         }
-        return getRelyingPartyUIContext().getOrganizationURL();
+        return ctx.getOrganizationURL();
     }
 
     /** {@inheritDoc} */
diff --git a/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServiceContactTag.java b/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServiceContactTag.java
index 0e9548446..e8ffe7091 100644
--- a/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServiceContactTag.java
+++ b/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServiceContactTag.java
@@ -24,6 +24,7 @@ import javax.annotation.Nullable;
 import jakarta.servlet.jsp.JspException;
 import jakarta.servlet.jsp.JspWriter;
 import jakarta.servlet.jsp.tagext.BodyContent;
+import net.shibboleth.idp.ui.context.RelyingPartyUIContext;
 import net.shibboleth.shared.codec.HTMLEncoder;
 
 import org.opensaml.saml.saml2.metadata.ContactPerson;
@@ -149,10 +150,11 @@ public class ServiceContactTag extends ServiceTagSupport {
      */
     @Nullable protected String getContactFromEntity() {
 
-        if (getRelyingPartyUIContext() == null) {
+        final RelyingPartyUIContext ctx = getRelyingPartyUIContext();
+        if (ctx == null) {
             return null;
         }
-        final ContactPerson contact = getRelyingPartyUIContext().getContactPerson(contactType);
+        final ContactPerson contact = ctx.getContactPerson(contactType);
         if (null == contact) {
             return null;
         }
diff --git a/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServiceDescriptionTag.java b/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServiceDescriptionTag.java
index ebde2cacc..186e3ff23 100644
--- a/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServiceDescriptionTag.java
+++ b/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServiceDescriptionTag.java
@@ -22,6 +22,7 @@ import java.io.IOException;
 import jakarta.servlet.jsp.JspException;
 import jakarta.servlet.jsp.JspWriter;
 import jakarta.servlet.jsp.tagext.BodyContent;
+import net.shibboleth.idp.ui.context.RelyingPartyUIContext;
 import net.shibboleth.shared.codec.HTMLEncoder;
 
 import org.slf4j.Logger;
@@ -44,8 +45,9 @@ public class ServiceDescriptionTag extends ServiceTagSupport {
     @Override public int doEndTag() throws JspException {
 
         String result = null;
-        if (getRelyingPartyUIContext() != null) {
-            result = getRelyingPartyUIContext().getServiceDescription();
+        final RelyingPartyUIContext ctx = getRelyingPartyUIContext();
+        if (ctx != null) {
+            result = ctx.getServiceDescription();
         }
         try {
             if (null == result) {
diff --git a/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServiceInformationURLTag.java b/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServiceInformationURLTag.java
index 3d708065f..880667988 100644
--- a/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServiceInformationURLTag.java
+++ b/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServiceInformationURLTag.java
@@ -20,11 +20,13 @@ package net.shibboleth.idp.ui.taglib;
 import java.io.IOException;
 
 import javax.annotation.Nullable;
+
+import org.slf4j.Logger;
+
 import jakarta.servlet.jsp.JspException;
 import jakarta.servlet.jsp.JspWriter;
 import jakarta.servlet.jsp.tagext.BodyContent;
-
-import org.slf4j.Logger;
+import net.shibboleth.idp.ui.context.RelyingPartyUIContext;
 import net.shibboleth.shared.primitive.LoggerFactory;
 
 /** Service InformationURL - directly from the metadata if present. */
@@ -54,10 +56,11 @@ public class ServiceInformationURLTag extends ServiceTagSupport {
      * @return null or an appropriate string.
      */
     @Nullable private String getInformationURLFromUIIinfo() {
-        if (getRelyingPartyUIContext() == null) {
+        final RelyingPartyUIContext ctx = getRelyingPartyUIContext();
+        if (ctx == null) {
             return null;
         }
-        return getRelyingPartyUIContext().getInformationURL();
+        return ctx.getInformationURL();
     }
 
     /** {@inheritDoc} */
diff --git a/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServiceLogoTag.java b/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServiceLogoTag.java
index a9e2c01e1..a842de2eb 100644
--- a/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServiceLogoTag.java
+++ b/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServiceLogoTag.java
@@ -25,6 +25,7 @@ import javax.annotation.Nullable;
 import jakarta.servlet.jsp.JspException;
 import jakarta.servlet.jsp.JspWriter;
 import jakarta.servlet.jsp.tagext.BodyContent;
+import net.shibboleth.idp.ui.context.RelyingPartyUIContext;
 import net.shibboleth.shared.codec.HTMLEncoder;
 
 import org.slf4j.Logger;
@@ -112,10 +113,11 @@ public class ServiceLogoTag extends ServiceTagSupport {
      * 
      */
     @Nullable private String getLogoFromUIInfo() {
-        if (getRelyingPartyUIContext() == null) {
+        final RelyingPartyUIContext ctx = getRelyingPartyUIContext();
+        if (ctx == null) {
             return null;
         }
-        return getRelyingPartyUIContext().getLogo(minWidth, minHeight, maxWidth, maxHeight);
+        return ctx.getLogo(minWidth, minHeight, maxWidth, maxHeight);
   
     }
 
diff --git a/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServicePrivacyURLTag.java b/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServicePrivacyURLTag.java
index 2ed0c8515..c5afa87cc 100644
--- a/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServicePrivacyURLTag.java
+++ b/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServicePrivacyURLTag.java
@@ -20,11 +20,13 @@ package net.shibboleth.idp.ui.taglib;
 import java.io.IOException;
 
 import javax.annotation.Nullable;
+
+import org.slf4j.Logger;
+
 import jakarta.servlet.jsp.JspException;
 import jakarta.servlet.jsp.JspWriter;
 import jakarta.servlet.jsp.tagext.BodyContent;
-
-import org.slf4j.Logger;
+import net.shibboleth.idp.ui.context.RelyingPartyUIContext;
 import net.shibboleth.shared.primitive.LoggerFactory;
 
 /** Service PrivacyURL - directly from the metadata if present. */
@@ -54,10 +56,11 @@ public class ServicePrivacyURLTag extends ServiceTagSupport {
      * @return null or an appropriate string.
      */
     @Nullable private String getPrivacyURLFromUIIinfo() {
-        if (getRelyingPartyUIContext() == null) {
+        final RelyingPartyUIContext ctx = getRelyingPartyUIContext();
+        if (ctx == null) {
             return null;
         }
-        return getRelyingPartyUIContext().getPrivacyStatementURL();
+        return ctx.getPrivacyStatementURL();
     }
 
     @Override public int doEndTag() throws JspException {
diff --git a/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServiceTagSupport.java b/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServiceTagSupport.java
index 64217863f..f69124ed2 100644
--- a/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServiceTagSupport.java
+++ b/idp-ui/src/main/java/net/shibboleth/idp/ui/taglib/ServiceTagSupport.java
@@ -125,7 +125,7 @@ public class ServiceTagSupport extends BodyTagSupport {
      * @param text what to embed
      * @return the hyperlink.
      */
-    @Nonnull protected String buildHyperLink(@Nonnull final String url, @Nonnull final String text) {
+    @Nonnull protected String buildHyperLink(@Nonnull final String url, @Nullable final String text) {
         final String encodedUrl;
 
         try {
@@ -149,7 +149,9 @@ public class ServiceTagSupport extends BodyTagSupport {
         sb.append(encodedUrl).append('"');
         addClassAndId(sb);
         sb.append(">").append(HTMLEncoder.encodeForHTML(text)).append("</a>");
-        return sb.toString();
+        final String result = sb.toString();
+        assert result != null;
+        return result;
     }
 
     /**
@@ -180,10 +182,11 @@ public class ServiceTagSupport extends BodyTagSupport {
      */
     @Nullable protected String getServiceName() {
 
-        if (getRelyingPartyUIContext() == null) {
+        final RelyingPartyUIContext ctx = getRelyingPartyUIContext();
+        if (ctx == null) {
             return null;
         }
-        return getRelyingPartyUIContext().getServiceName();
+        return ctx.getServiceName();
     }
 
 }
\ No newline at end of file
diff --git a/idp-ui/src/test/java/net/shibboleth/idp/ui/context/RelyingPartyUIContextTest.java b/idp-ui/src/test/java/net/shibboleth/idp/ui/context/RelyingPartyUIContextTest.java
index 952003389..c3096e0d1 100644
--- a/idp-ui/src/test/java/net/shibboleth/idp/ui/context/RelyingPartyUIContextTest.java
+++ b/idp-ui/src/test/java/net/shibboleth/idp/ui/context/RelyingPartyUIContextTest.java
@@ -17,7 +17,7 @@
 
 package net.shibboleth.idp.ui.context;
 
-import java.util.Collections;
+import java.util.List;
 import java.util.Locale.LanguageRange;
 
 import org.opensaml.core.testing.XMLObjectBaseTestCase;
@@ -31,6 +31,8 @@ import org.testng.Assert;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
+import net.shibboleth.shared.collection.CollectionSupport;
+
 @SuppressWarnings({"javadoc", "removal"})
 public class RelyingPartyUIContextTest extends XMLObjectBaseTestCase {
 
@@ -58,7 +60,9 @@ public class RelyingPartyUIContextTest extends XMLObjectBaseTestCase {
         if (null != theUiInfos[which]) {
             result.setRPUInfo(theUiInfos[which]);
         }
-        result.setBrowserLanguageRanges(LanguageRange.parse("en,fr"));
+        final List<LanguageRange> r = LanguageRange.parse("en,fr");
+        assert r != null;
+        result.setBrowserLanguageRanges(r);
         return result;
     }
 
@@ -67,7 +71,9 @@ public class RelyingPartyUIContextTest extends XMLObjectBaseTestCase {
         theSPSSOs[0] = theEntities[0].getSPSSODescriptor("urn:oasis:names:tc:SAML:2.0:protocol");
         final Extensions exts = theSPSSOs[0].getExtensions();
         if (exts != null) {
-            for (XMLObject object : exts.getOrderedChildren()) {
+            final List<XMLObject> children = exts.getOrderedChildren();
+            assert children != null;
+            for (XMLObject object : children) {
                 if (object instanceof UIInfo) {
                     theUiInfos[0] = (UIInfo) object;
                 }
@@ -164,7 +170,7 @@ public class RelyingPartyUIContextTest extends XMLObjectBaseTestCase {
         Assert.assertNull(ctx.getLogo(66, 1, 100, 10000));
         Assert.assertEquals(ctx.getLogo(), "https://shibboleth.net/images/shibboleth.png");
         
-        ctx.setBrowserLanguages(Collections.singletonList("de"));
+        ctx.setBrowserLanguages(CollectionSupport.singletonList("de"));
         Assert.assertEquals(ctx.getLogo(), "https://shibboleth.net/images/shibboleth.pngde");
 
     }
@@ -172,9 +178,9 @@ public class RelyingPartyUIContextTest extends XMLObjectBaseTestCase {
     @Test public void fallbackLanguage() {
         RelyingPartyUIContext ctx = getContext();
         
-        ctx.setBrowserLanguages(Collections.singletonList("zh"));
+        ctx.setBrowserLanguages(CollectionSupport.singletonList("zh"));
         Assert.assertEquals(ctx.getLogo(), "https://shibboleth.net/images/shibboleth.png");
-        ctx.setFallbackLanguages(Collections.singletonList("de"));
+        ctx.setFallbackLanguages(CollectionSupport.singletonList("de"));
         Assert.assertEquals(ctx.getLogo(), "https://shibboleth.net/images/shibboleth.pngde");
 
     }
diff --git a/idp-ui/src/test/java/net/shibboleth/idp/ui/csrf/CSRFTokenManagerTest.java b/idp-ui/src/test/java/net/shibboleth/idp/ui/csrf/CSRFTokenManagerTest.java
index 48dabd32d..9c4184e88 100644
--- a/idp-ui/src/test/java/net/shibboleth/idp/ui/csrf/CSRFTokenManagerTest.java
+++ b/idp-ui/src/test/java/net/shibboleth/idp/ui/csrf/CSRFTokenManagerTest.java
@@ -34,7 +34,8 @@ public class CSRFTokenManagerTest {
     
     /** Test token manager instance.*/
     private CSRFTokenManager manager;
-    
+    /** Something to spoof the null checker.*/
+    private Object nullObj;
     /**
      * Test setup. 
      * @throws ComponentInitializationException 
@@ -45,9 +46,10 @@ public class CSRFTokenManagerTest {
     }
     
     /** Test setting an invalid csrf parameter name, which should trigger an exception.*/
+    @SuppressWarnings("null")
     @Test(expectedExceptions=ConstraintViolationException.class) public void testSetNullCsrfParameterName() {
         manager = new CSRFTokenManager();
-        manager.setCsrfParameterName(null);
+        manager.setCsrfParameterName((String) nullObj);
     }
     
     /** Test setting a valid csrf parameter name, which should not trigger an exception.*/
@@ -57,9 +59,10 @@ public class CSRFTokenManagerTest {
     }
     
     /** Test setting an invalid token generation strategy, which should trigger an exception.*/
+    @SuppressWarnings("null")
     @Test(expectedExceptions=ConstraintViolationException.class) public void testSetNullTokenGenerationStrategy() {
         manager = new CSRFTokenManager();
-        manager.setTokenGenerationStrategy(null);
+        manager.setTokenGenerationStrategy((IdentifierGenerationStrategy) nullObj);
     }
     
     /** Test setting a valid token generation strategy, which should not trigger an exception.*/
diff --git a/idp-ui/src/test/java/net/shibboleth/idp/ui/csrf/impl/CSRFTokenFlowExecutionListenerTest.java b/idp-ui/src/test/java/net/shibboleth/idp/ui/csrf/impl/CSRFTokenFlowExecutionListenerTest.java
index 968a3db8e..f44a76815 100644
--- a/idp-ui/src/test/java/net/shibboleth/idp/ui/csrf/impl/CSRFTokenFlowExecutionListenerTest.java
+++ b/idp-ui/src/test/java/net/shibboleth/idp/ui/csrf/impl/CSRFTokenFlowExecutionListenerTest.java
@@ -20,6 +20,7 @@ package net.shibboleth.idp.ui.csrf.impl;
 
 import java.util.UUID;
 import java.util.function.BiPredicate;
+import java.util.function.Predicate;
 
 import org.springframework.test.util.ReflectionTestUtils;
 import org.springframework.webflow.engine.ActionState;
@@ -54,6 +55,9 @@ public class CSRFTokenFlowExecutionListenerTest extends BaseCSRFTest{
     /** The listener instance to test.*/
     private CSRFTokenFlowExecutionListener listener;
 
+    /** Something to spoof the null checker. */
+    private Object nullObj;
+
     
     @BeforeMethod public void setup() throws ComponentInitializationException {
         
@@ -104,6 +108,7 @@ public class CSRFTokenFlowExecutionListenerTest extends BaseCSRFTest{
         MockViewState currentState = new MockViewState("testFlow", "a-view-state");
         flowSession.setState(currentState);
         
+        @SuppressWarnings("null")
         CSRFToken viewScopeToken = new SimpleCSRFToken(UUID.randomUUID().toString(), CSRF_PARAM_NAME);
         flowSession.getViewScope().put(CSRFTokenFlowExecutionListener.CSRF_TOKEN_VIEWSCOPE_NAME, viewScopeToken);
        
@@ -131,6 +136,7 @@ public class CSRFTokenFlowExecutionListenerTest extends BaseCSRFTest{
         MockViewState currentState = new MockViewState("testFlow", "a-view-state");
         flowSession.setState(currentState);
         
+        @SuppressWarnings("null")
         CSRFToken viewScopeToken = new SimpleCSRFToken(UUID.randomUUID().toString(), CSRF_PARAM_NAME);
         flowSession.getViewScope().put(CSRFTokenFlowExecutionListener.CSRF_TOKEN_VIEWSCOPE_NAME, viewScopeToken);
        
@@ -161,6 +167,7 @@ public class CSRFTokenFlowExecutionListenerTest extends BaseCSRFTest{
         currentState.getAttributes().put(BaseCSRFTokenPredicate.CSRF_EXCLUDED_ATTRIBUTE_NAME, true);
         flowSession.setState(currentState);
         
+        @SuppressWarnings("null")
         CSRFToken viewScopeToken = new SimpleCSRFToken(UUID.randomUUID().toString(), CSRF_PARAM_NAME);
         flowSession.getViewScope().put(CSRFTokenFlowExecutionListener.CSRF_TOKEN_VIEWSCOPE_NAME, viewScopeToken);
        
@@ -192,6 +199,7 @@ public class CSRFTokenFlowExecutionListenerTest extends BaseCSRFTest{
         MockViewState currentState = new MockViewState("testFlow", "a-view-state");
         flowSession.setState(currentState);
         
+        @SuppressWarnings("null")
         CSRFToken viewScopeToken = new SimpleCSRFToken(UUID.randomUUID().toString(), CSRF_PARAM_NAME);
         flowSession.getViewScope().put(CSRFTokenFlowExecutionListener.CSRF_TOKEN_VIEWSCOPE_NAME, viewScopeToken);
        
@@ -259,6 +267,7 @@ public class CSRFTokenFlowExecutionListenerTest extends BaseCSRFTest{
         MockViewState currentState = new MockViewState("testFlow", "a-view-state");
         flowSession.setState(currentState);
         
+        @SuppressWarnings("null")
         CSRFToken viewScopeToken = new SimpleCSRFToken(UUID.randomUUID().toString(), "csrf_token");
         flowSession.getViewScope().put(CSRFTokenFlowExecutionListener.CSRF_TOKEN_VIEWSCOPE_NAME, viewScopeToken);
         
@@ -293,6 +302,7 @@ public class CSRFTokenFlowExecutionListenerTest extends BaseCSRFTest{
         MockViewState currentState = new MockViewState("testFlow", "a-view-state");
         flowSession.setState(currentState);
         
+        @SuppressWarnings("null")
         CSRFToken viewScopeToken = new SimpleCSRFToken(UUID.randomUUID().toString(), CSRF_PARAM_NAME);
         flowSession.getViewScope().put(CSRFTokenFlowExecutionListener.CSRF_TOKEN_VIEWSCOPE_NAME, viewScopeToken);
        
@@ -343,14 +353,14 @@ public class CSRFTokenFlowExecutionListenerTest extends BaseCSRFTest{
         CSRFTokenFlowExecutionListener theListener = new CSRFTokenFlowExecutionListener();
         // test default is false.
         Object enabledObject = ReflectionTestUtils.getField(theListener, "enabled");
-        Assert.assertNotNull(enabledObject);
+        assert enabledObject != null;
         Assert.assertTrue(enabledObject instanceof Boolean);
         Assert.assertFalse(((Boolean) enabledObject));
 
         // test enabling
         theListener.setEnabled(true);
         enabledObject = ReflectionTestUtils.getField(theListener, "enabled");
-        Assert.assertNotNull(enabledObject);
+        assert enabledObject != null;
         Assert.assertTrue(enabledObject instanceof Boolean);
         Assert.assertTrue(((Boolean) enabledObject));
     }
@@ -381,18 +391,21 @@ public class CSRFTokenFlowExecutionListenerTest extends BaseCSRFTest{
 
     
     /** Test setting a null CSRF token manager triggers a {@link ConstraintViolationException}.*/
+    @SuppressWarnings({ "null"})
     @Test(expectedExceptions = ConstraintViolationException.class) public void testSetNullCsrfTokenManager() {       
-        listener.setCsrfTokenManager(null);
+        listener.setCsrfTokenManager((CSRFTokenManager) nullObj);
     }
     
     /** Test setting a null event requires csrf validation predicate triggers a {@link ConstraintViolationException}.*/
+    @SuppressWarnings({ "null", "unchecked" })
     @Test(expectedExceptions = ConstraintViolationException.class) public void testSetNullEventRequiresCSRFValidationPredicate() {       
-        listener.setEventRequiresCSRFTokenValidationPredicate(null);
+        listener.setEventRequiresCSRFTokenValidationPredicate((BiPredicate<RequestContext, Event>) nullObj);
     }
     
     /** Test setting a null view requires csrf token predicate triggers a {@link ConstraintViolationException}.*/
+    @SuppressWarnings({ "null", "unchecked" })
     @Test(expectedExceptions = ConstraintViolationException.class) public void testSetNullViewRequiresCSRFTokenPredicate() {       
-        listener.setViewRequiresCSRFTokenPredicate(null);
+        listener.setViewRequiresCSRFTokenPredicate((Predicate<RequestContext>) nullObj);
     }
     
     /**
diff --git a/idp-ui/src/test/java/net/shibboleth/idp/ui/csrf/impl/SimpleCSRFTokenTest.java b/idp-ui/src/test/java/net/shibboleth/idp/ui/csrf/impl/SimpleCSRFTokenTest.java
index 898f360c1..f7511b209 100644
--- a/idp-ui/src/test/java/net/shibboleth/idp/ui/csrf/impl/SimpleCSRFTokenTest.java
+++ b/idp-ui/src/test/java/net/shibboleth/idp/ui/csrf/impl/SimpleCSRFTokenTest.java
@@ -28,37 +28,44 @@ import net.shibboleth.shared.logic.ConstraintViolationException;
  * Test the {@link SimpleCSRFToken}.
  */
 public class SimpleCSRFTokenTest {
+
+    /** Something to spoof the null checker. */
+    private Object nullObj;
     
     /** Test token construction with valid parameters.*/
     @Test public void testTokenConstruction() {
         
         final String tokenValue = UUID.randomUUID().toString();
         final String paramName = "csrf_token";
+        assert tokenValue != null;
         SimpleCSRFToken token = new SimpleCSRFToken(tokenValue, paramName);
         Assert.assertEquals(tokenValue, token.getToken());
         Assert.assertEquals(paramName, token.getParameterName());
     }
     
     /** Test token construction with an invalid null token value parameter.*/
+    @SuppressWarnings("null")
     @Test(expectedExceptions=ConstraintViolationException.class) public void testNullValueConstruction() {        
        
         final String paramName = "csrf_token";
-        new SimpleCSRFToken(null, paramName);
+        new SimpleCSRFToken((String) nullObj, paramName);
       
     }
     
     /** Test token construction with an invalid null parameter name parameter.*/
+    @SuppressWarnings("null")
     @Test(expectedExceptions=ConstraintViolationException.class) public void testNullParamConstruction() {        
         
         final String tokenValue = UUID.randomUUID().toString();
-        new SimpleCSRFToken(tokenValue, null);
+        new SimpleCSRFToken(tokenValue, (String) nullObj);
       
     }
     
     /** Test token construction with all invalid null parameters.*/
+    @SuppressWarnings("null")
     @Test(expectedExceptions=ConstraintViolationException.class) public void testNullValueAndParamConstruction() {        
     
-        new SimpleCSRFToken(null, null);
+        new SimpleCSRFToken((String) nullObj, (String) nullObj);
       
     }
 

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


More information about the commits mailing list