[java-opensaml] branch main updated: IDP-2069 - Null Handling Task

Scott Cantor cantor.2 at osu.edu
Wed Mar 8 20:13:45 UTC 2023


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch main
in repository java-opensaml.

View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=90a19a16b3eab7de4746b6bec54110b9d15b1880

The following commit(s) were added to refs/heads/main by this push:
     new 90a19a16b IDP-2069 - Null Handling Task
90a19a16b is described below

commit 90a19a16b3eab7de4746b6bec54110b9d15b1880
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Mar 8 15:13:42 2023 -0500

    IDP-2069 - Null Handling Task
    
    https://shibboleth.atlassian.net/browse/IDP-2069
    
    Cleanup of opensaml-profile-api.
---
 .../action/AbstractConditionalProfileAction.java   |  5 ++---
 .../profile/action/AbstractProfileAction.java      | 18 ++++++++++-------
 .../org/opensaml/profile/action/ActionSupport.java |  4 ++--
 .../opensaml/profile/action/EventException.java    |  2 +-
 .../opensaml/profile/context/MetricContext.java    | 23 ++++++++++++++++++----
 .../opensaml/profile/logic/IPRangePredicate.java   | 10 +++-------
 .../NoConfidentialityMessageChannelPredicate.java  |  2 +-
 .../logic/NoIntegrityMessageChannelPredicate.java  |  2 +-
 .../profile/logic/PredicateAccessControl.java      |  4 ++--
 .../profile/context/ProfileRequestContextTest.java |  1 +
 .../profile/logic/IPRangePredicateTest.java        |  3 +++
 .../logic/MessageContextPredicateAdapterTest.java  | 13 +++---------
 12 files changed, 49 insertions(+), 38 deletions(-)

diff --git a/opensaml-profile-api/src/main/java/org/opensaml/profile/action/AbstractConditionalProfileAction.java b/opensaml-profile-api/src/main/java/org/opensaml/profile/action/AbstractConditionalProfileAction.java
index 6a96056ca..23b9f266c 100644
--- a/opensaml-profile-api/src/main/java/org/opensaml/profile/action/AbstractConditionalProfileAction.java
+++ b/opensaml-profile-api/src/main/java/org/opensaml/profile/action/AbstractConditionalProfileAction.java
@@ -24,9 +24,8 @@ import javax.annotation.Nonnull;
 import org.opensaml.profile.context.ProfileRequestContext;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Predicates;
-
 import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.logic.PredicateSupport;
 
 /**
  * Base class for conditional profile actions.
@@ -42,7 +41,7 @@ public abstract class AbstractConditionalProfileAction extends AbstractProfileAc
     
     /** Constructor. */
     public AbstractConditionalProfileAction() {
-        activationCondition = Predicates.alwaysTrue();
+        activationCondition = PredicateSupport.alwaysTrue();
     }
     
     /**
diff --git a/opensaml-profile-api/src/main/java/org/opensaml/profile/action/AbstractProfileAction.java b/opensaml-profile-api/src/main/java/org/opensaml/profile/action/AbstractProfileAction.java
index dc4332f24..cd90b0617 100644
--- a/opensaml-profile-api/src/main/java/org/opensaml/profile/action/AbstractProfileAction.java
+++ b/opensaml-profile-api/src/main/java/org/opensaml/profile/action/AbstractProfileAction.java
@@ -56,10 +56,11 @@ public abstract class AbstractProfileAction extends AbstractInitializableCompone
      * @return current HTTP request
      */
     @Nullable public HttpServletRequest getHttpServletRequest() {
-        if (httpServletRequestSupplier == null) {
-            return null;
+        if (httpServletRequestSupplier != null) {
+            return httpServletRequestSupplier.get();
         }
-        return httpServletRequestSupplier.get();
+        
+        return null;
     }
 
     /**
@@ -87,10 +88,11 @@ public abstract class AbstractProfileAction extends AbstractInitializableCompone
      * @return current HTTP response or null
      */
     @Nullable public HttpServletResponse getHttpServletResponse() {
-        if (httpServletResponseSupplier == null) {
-            return null;
+        if (httpServletResponseSupplier != null) {
+            return httpServletResponseSupplier.get();
         }
-        return httpServletResponseSupplier.get();
+        
+        return null;
     }
 
     /**
@@ -121,7 +123,7 @@ public abstract class AbstractProfileAction extends AbstractInitializableCompone
         // because it may be from an earlier error of interest to other actions.
         final EventContext previousEvent = profileRequestContext.getSubcontext(EventContext.class);
         if (previousEvent != null) {
-            profileRequestContext.getSubcontext(PreviousEventContext.class, true).setEvent(previousEvent.getEvent());
+            profileRequestContext.getOrCreateSubcontext(PreviousEventContext.class).setEvent(previousEvent.getEvent());
             profileRequestContext.removeSubcontext(EventContext.class);
         }
 
@@ -205,6 +207,7 @@ public abstract class AbstractProfileAction extends AbstractInitializableCompone
         final MetricContext metricCtx = profileRequestContext.getSubcontext(MetricContext.class);
         if (metricCtx != null) {
             final String name = getClass().getSimpleName();
+            assert name != null;
             metricCtx.stop(name);
             metricCtx.inc(name);
         }
@@ -246,6 +249,7 @@ public abstract class AbstractProfileAction extends AbstractInitializableCompone
         if (logPrefix == null) {
             logPrefix = "Profile Action " + getClass().getSimpleName() + ":";
         }
+        assert logPrefix != null;
         return logPrefix;
     }
 
diff --git a/opensaml-profile-api/src/main/java/org/opensaml/profile/action/ActionSupport.java b/opensaml-profile-api/src/main/java/org/opensaml/profile/action/ActionSupport.java
index 3e40043af..78cc43877 100644
--- a/opensaml-profile-api/src/main/java/org/opensaml/profile/action/ActionSupport.java
+++ b/opensaml-profile-api/src/main/java/org/opensaml/profile/action/ActionSupport.java
@@ -56,7 +56,7 @@ public final class ActionSupport {
         final String trimmedEventId =
                 Constraint.isNotNull(StringSupport.trimOrNull(eventId), "ID of event cannot be null or empty");
         
-        profileRequestContext.getSubcontext(EventContext.class, true).setEvent(trimmedEventId);
+        profileRequestContext.getOrCreateSubcontext(EventContext.class).setEvent(trimmedEventId);
     }
     
     /**
@@ -71,7 +71,7 @@ public final class ActionSupport {
         Constraint.isNotNull(profileRequestContext, "Profile request context cannot be null");
         Constraint.isNotNull(event, "Event cannot be null");
         
-        profileRequestContext.getSubcontext(EventContext.class, true).setEvent(event);
+        profileRequestContext.getOrCreateSubcontext(EventContext.class).setEvent(event);
     }
 
 }
\ No newline at end of file
diff --git a/opensaml-profile-api/src/main/java/org/opensaml/profile/action/EventException.java b/opensaml-profile-api/src/main/java/org/opensaml/profile/action/EventException.java
index b6900c96a..49d9fa615 100644
--- a/opensaml-profile-api/src/main/java/org/opensaml/profile/action/EventException.java
+++ b/opensaml-profile-api/src/main/java/org/opensaml/profile/action/EventException.java
@@ -32,7 +32,7 @@ public class EventException extends Exception {
     private static final long serialVersionUID = -6394047591957378161L;
     
     /** The event ID. */
-    private final String eventID;
+    @Nonnull private final String eventID;
 
     /**
      * Constructor.
diff --git a/opensaml-profile-api/src/main/java/org/opensaml/profile/context/MetricContext.java b/opensaml-profile-api/src/main/java/org/opensaml/profile/context/MetricContext.java
index aef3c2d9c..ba67b451d 100644
--- a/opensaml-profile-api/src/main/java/org/opensaml/profile/context/MetricContext.java
+++ b/opensaml-profile-api/src/main/java/org/opensaml/profile/context/MetricContext.java
@@ -27,6 +27,7 @@ import javax.annotation.Nonnull;
 import org.opensaml.core.metrics.MetricsSupport;
 import org.opensaml.messaging.context.BaseContext;
 
+import com.codahale.metrics.MetricRegistry;
 import com.codahale.metrics.Timer;
 import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.Multimap;
@@ -139,10 +140,14 @@ public final class MetricContext extends BaseContext {
      */
     public void start(@Nonnull @NotEmpty final String objectId) {
         
+        final MetricRegistry registry = MetricsSupport.getMetricRegistry();
+        if (registry == null) {
+            return;
+        }
+        
         for (final Pair<String,String> timer : timerMap.get(objectId)) {
             if (timer != null) {
-                timerContextMap.put(timer.getSecond(),
-                        MetricsSupport.getMetricRegistry().timer(timer.getFirst()).time());
+                timerContextMap.put(timer.getSecond(), registry.timer(timer.getFirst()).time());
             }
         }
     }
@@ -170,9 +175,14 @@ public final class MetricContext extends BaseContext {
      * @param objectId ID of object
      */
     public void inc(@Nonnull @NotEmpty final String objectId) {
+        final MetricRegistry registry = MetricsSupport.getMetricRegistry();
+        if (registry == null) {
+            return;
+        }
+
         final String name = counterMap.get(objectId);
         if (name != null) {
-            MetricsSupport.getMetricRegistry().counter(name).inc();
+            registry.counter(name).inc();
         }
     }
 
@@ -182,9 +192,14 @@ public final class MetricContext extends BaseContext {
      * @param objectId ID of object
      */
     public void dec(@Nonnull @NotEmpty final String objectId) {
+        final MetricRegistry registry = MetricsSupport.getMetricRegistry();
+        if (registry == null) {
+            return;
+        }
+
         final String name = counterMap.get(objectId);
         if (name != null) {
-            MetricsSupport.getMetricRegistry().counter(name).dec();
+            registry.counter(name).dec();
         }
     }
 
diff --git a/opensaml-profile-api/src/main/java/org/opensaml/profile/logic/IPRangePredicate.java b/opensaml-profile-api/src/main/java/org/opensaml/profile/logic/IPRangePredicate.java
index 27388be98..bb8d2d0a6 100644
--- a/opensaml-profile-api/src/main/java/org/opensaml/profile/logic/IPRangePredicate.java
+++ b/opensaml-profile-api/src/main/java/org/opensaml/profile/logic/IPRangePredicate.java
@@ -18,8 +18,6 @@
 package org.opensaml.profile.logic;
 
 import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
 import java.util.function.Predicate;
 import java.util.function.Supplier;
 
@@ -32,11 +30,9 @@ import com.google.common.net.InetAddresses;
 
 import jakarta.servlet.http.HttpServletRequest;
 import net.shibboleth.shared.annotation.constraint.NonnullElements;
+import net.shibboleth.shared.collection.CollectionSupport;
 import net.shibboleth.shared.logic.Constraint;
 import net.shibboleth.shared.net.IPRange;
-import net.shibboleth.shared.primitive.DeprecationSupport;
-import net.shibboleth.shared.primitive.DeprecationSupport.ObjectType;
-import net.shibboleth.shared.primitive.NonnullSupplier;
 import net.shibboleth.shared.servlet.HttpServletSupport;
 
 /**
@@ -52,7 +48,7 @@ public class IPRangePredicate implements Predicate<BaseContext> {
 
     /** Constructor. */
     IPRangePredicate() {
-        addressRanges = Collections.emptyList();
+        addressRanges = CollectionSupport.emptyList();
     }
     
     /**
@@ -65,7 +61,7 @@ public class IPRangePredicate implements Predicate<BaseContext> {
     public void setRanges(@Nonnull @NonnullElements final Collection<IPRange> ranges) {
         Constraint.isNotNull(ranges, "Address range collection cannot be null");
         
-        addressRanges = List.copyOf(ranges);
+        addressRanges = CollectionSupport.copyToList(ranges);
     }
 
     /**
diff --git a/opensaml-profile-api/src/main/java/org/opensaml/profile/logic/NoConfidentialityMessageChannelPredicate.java b/opensaml-profile-api/src/main/java/org/opensaml/profile/logic/NoConfidentialityMessageChannelPredicate.java
index 940786649..c06e1cfb8 100644
--- a/opensaml-profile-api/src/main/java/org/opensaml/profile/logic/NoConfidentialityMessageChannelPredicate.java
+++ b/opensaml-profile-api/src/main/java/org/opensaml/profile/logic/NoConfidentialityMessageChannelPredicate.java
@@ -35,7 +35,7 @@ public class NoConfidentialityMessageChannelPredicate implements Predicate<Profi
     /** {@inheritDoc} */
     public boolean test(@Nullable final ProfileRequestContext input) {
         return input == null
-                || !input.getSubcontext(MessageChannelSecurityContext.class, true).isConfidentialityActive();
+                || !input.getOrCreateSubcontext(MessageChannelSecurityContext.class).isConfidentialityActive();
     }
     
 }
\ No newline at end of file
diff --git a/opensaml-profile-api/src/main/java/org/opensaml/profile/logic/NoIntegrityMessageChannelPredicate.java b/opensaml-profile-api/src/main/java/org/opensaml/profile/logic/NoIntegrityMessageChannelPredicate.java
index b5825647a..f6a381c88 100644
--- a/opensaml-profile-api/src/main/java/org/opensaml/profile/logic/NoIntegrityMessageChannelPredicate.java
+++ b/opensaml-profile-api/src/main/java/org/opensaml/profile/logic/NoIntegrityMessageChannelPredicate.java
@@ -34,7 +34,7 @@ public class NoIntegrityMessageChannelPredicate implements Predicate<ProfileRequ
 
     /** {@inheritDoc} */
     public boolean test(@Nullable final ProfileRequestContext input) {
-        return input == null || !input.getSubcontext(MessageChannelSecurityContext.class, true).isIntegrityActive();
+        return input == null || !input.getOrCreateSubcontext(MessageChannelSecurityContext.class).isIntegrityActive();
     }
     
 }
\ No newline at end of file
diff --git a/opensaml-profile-api/src/main/java/org/opensaml/profile/logic/PredicateAccessControl.java b/opensaml-profile-api/src/main/java/org/opensaml/profile/logic/PredicateAccessControl.java
index e72502c15..2bc68d430 100644
--- a/opensaml-profile-api/src/main/java/org/opensaml/profile/logic/PredicateAccessControl.java
+++ b/opensaml-profile-api/src/main/java/org/opensaml/profile/logic/PredicateAccessControl.java
@@ -25,12 +25,12 @@ import javax.annotation.Nullable;
 import org.opensaml.profile.context.AccessControlContext;
 import org.opensaml.profile.context.ProfileRequestContext;
 import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import jakarta.servlet.ServletRequest;
 import net.shibboleth.shared.annotation.ParameterName;
 import net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent;
 import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
 import net.shibboleth.shared.security.AccessControl;
 
 /**
@@ -71,7 +71,7 @@ public class PredicateAccessControl extends AbstractIdentifiableInitializableCom
         final Object attribute = request.getAttribute(ProfileRequestContext.BINDING_KEY);
         if (attribute != null && attribute instanceof ProfileRequestContext) {
             final ProfileRequestContext prc = (ProfileRequestContext) attribute;
-            final AccessControlContext acc = prc.getSubcontext(AccessControlContext.class, true);
+            final AccessControlContext acc = prc.getOrCreateSubcontext(AccessControlContext.class);
             acc.setOperation(operation);
             acc.setResource(resource);
             if (predicate.test(prc)) {
diff --git a/opensaml-profile-api/src/test/java/org/opensaml/profile/context/ProfileRequestContextTest.java b/opensaml-profile-api/src/test/java/org/opensaml/profile/context/ProfileRequestContextTest.java
index 4771c55ab..66b43efdd 100644
--- a/opensaml-profile-api/src/test/java/org/opensaml/profile/context/ProfileRequestContextTest.java
+++ b/opensaml-profile-api/src/test/java/org/opensaml/profile/context/ProfileRequestContextTest.java
@@ -21,6 +21,7 @@ import org.testng.Assert;
 import org.testng.annotations.Test;
 
 /** Unit test for {@link ProfileRequestContext}. */
+ at SuppressWarnings("javadoc")
 public class ProfileRequestContextTest {
 
     @Test public void testBrowserProfile() {
diff --git a/opensaml-profile-api/src/test/java/org/opensaml/profile/logic/IPRangePredicateTest.java b/opensaml-profile-api/src/test/java/org/opensaml/profile/logic/IPRangePredicateTest.java
index d17dc6e9d..2dcc299e4 100644
--- a/opensaml-profile-api/src/test/java/org/opensaml/profile/logic/IPRangePredicateTest.java
+++ b/opensaml-profile-api/src/test/java/org/opensaml/profile/logic/IPRangePredicateTest.java
@@ -37,6 +37,9 @@ import jakarta.servlet.http.HttpServletRequest;
  */
 public class IPRangePredicateTest {
 
+    /**
+     * Tests.
+     */
     @Test public void testRanges() {
 
         final GenericApplicationContext ctx = new ApplicationContextBuilder()
diff --git a/opensaml-profile-api/src/test/java/org/opensaml/profile/logic/MessageContextPredicateAdapterTest.java b/opensaml-profile-api/src/test/java/org/opensaml/profile/logic/MessageContextPredicateAdapterTest.java
index f9715dea3..c04ef8b83 100644
--- a/opensaml-profile-api/src/test/java/org/opensaml/profile/logic/MessageContextPredicateAdapterTest.java
+++ b/opensaml-profile-api/src/test/java/org/opensaml/profile/logic/MessageContextPredicateAdapterTest.java
@@ -27,11 +27,10 @@ import org.opensaml.profile.context.ProfileRequestContext;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
-import net.shibboleth.shared.logic.ConstraintViolationException;
-
 /**
- *
+ * Unit test for {@link MessageContextPredicateAdapter}.
  */
+ at SuppressWarnings("javadoc")
 public class MessageContextPredicateAdapterTest {
     
     @Test
@@ -62,12 +61,6 @@ public class MessageContextPredicateAdapterTest {
         Assert.assertTrue(adapter.test(mc));
     }
     
-    @Test(expectedExceptions=ConstraintViolationException.class)
-    public void testCtor() {
-        new MessageContextPredicateAdapter(null);
-    }
-
-    
     // Helpers
     
     public static class MockContext extends BaseContext {
@@ -79,7 +72,7 @@ public class MessageContextPredicateAdapterTest {
             if (input == null || input.getOutboundMessageContext() == null) {
                 return false;
             }
-            return input.getOutboundMessageContext().containsSubcontext(MockContext.class);
+            return input.ensureOutboundMessageContext().containsSubcontext(MockContext.class);
         }
     }
 }

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


More information about the commits mailing list