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

Scott Cantor cantor.2 at osu.edu
Mon Mar 27 17:44:56 UTC 2023


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

scantor 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=99105ee638319b572ed0597d553256603579d18d

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

commit 99105ee638319b572ed0597d553256603579d18d
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Mar 27 13:44:53 2023 -0400

    IDP-2069 - Null Handling Task
    
    SAML 1 annotation cleanup.
---
 .../idp/saml/audit/impl/NameIDAuditExtractor.java  | 35 +++++++++++++++-------
 .../audit/impl/NameIDFormatAuditExtractor.java     | 35 +++++++++++++++-------
 .../saml/audit/impl/StatusCodeAuditExtractor.java  |  5 +++-
 .../audit/impl/SubStatusCodeAuditExtractor.java    |  9 ++++--
 .../impl/ExtractSubjectFromRequestTest.java        |  2 +-
 .../AddAuthenticationStatementToAssertionTest.java | 11 +++++--
 6 files changed, 69 insertions(+), 28 deletions(-)

diff --git a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/audit/impl/NameIDAuditExtractor.java b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/audit/impl/NameIDAuditExtractor.java
index 9ab9e265d..48a66da6e 100644
--- a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/audit/impl/NameIDAuditExtractor.java
+++ b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/audit/impl/NameIDAuditExtractor.java
@@ -159,24 +159,39 @@ public class NameIDAuditExtractor implements Function<ProfileRequestContext,Stri
     @Nullable private String apply(@Nonnull final org.opensaml.saml.saml1.core.Assertion assertion) {
 
         for (final AuthenticationStatement statement : assertion.getAuthenticationStatements()) {
-            if (statement.getSubject() != null && statement.getSubject().getNameIdentifier() != null) {
-                return statement.getSubject().getNameIdentifier().getValue();
+            final org.opensaml.saml.saml1.core.Subject subject = statement.getSubject();
+            if (subject != null) {
+                final NameIdentifier nameID = subject.getNameIdentifier();
+                if (nameID != null) {
+                    return nameID.getValue();
+                }
             }
         }
         for (final AttributeStatement statement : assertion.getAttributeStatements()) {
-            if (statement.getSubject() != null && statement.getSubject().getNameIdentifier() != null) {
-                return statement.getSubject().getNameIdentifier().getValue();
+            final org.opensaml.saml.saml1.core.Subject subject = statement.getSubject();
+            if (subject != null) {
+                final NameIdentifier nameID = subject.getNameIdentifier();
+                if (nameID != null) {
+                    return nameID.getValue();
+                }
             }
         }
-        for (final AuthorizationDecisionStatement statement
-                : assertion.getAuthorizationDecisionStatements()) {
-            if (statement.getSubject() != null && statement.getSubject().getNameIdentifier() != null) {
-                return statement.getSubject().getNameIdentifier().getValue();
+        for (final AuthorizationDecisionStatement statement : assertion.getAuthorizationDecisionStatements()) {
+            final org.opensaml.saml.saml1.core.Subject subject = statement.getSubject();
+            if (subject != null) {
+                final NameIdentifier nameID = subject.getNameIdentifier();
+                if (nameID != null) {
+                    return nameID.getValue();
+                }
             }
         }
         for (final SubjectStatement statement : assertion.getSubjectStatements()) {
-            if (statement.getSubject() != null && statement.getSubject().getNameIdentifier() != null) {
-                return statement.getSubject().getNameIdentifier().getValue();
+            final org.opensaml.saml.saml1.core.Subject subject = statement.getSubject();
+            if (subject != null) {
+                final NameIdentifier nameID = subject.getNameIdentifier();
+                if (nameID != null) {
+                    return nameID.getValue();
+                }
             }
         }
         
diff --git a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/audit/impl/NameIDFormatAuditExtractor.java b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/audit/impl/NameIDFormatAuditExtractor.java
index 5b100e29b..43c7fdf9d 100644
--- a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/audit/impl/NameIDFormatAuditExtractor.java
+++ b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/audit/impl/NameIDFormatAuditExtractor.java
@@ -158,24 +158,39 @@ public class NameIDFormatAuditExtractor implements Function<ProfileRequestContex
     @Nullable private String apply(@Nonnull final org.opensaml.saml.saml1.core.Assertion assertion) {
 
         for (final AuthenticationStatement statement : assertion.getAuthenticationStatements()) {
-            if (statement.getSubject() != null && statement.getSubject().getNameIdentifier() != null) {
-                return statement.getSubject().getNameIdentifier().getFormat();
+            final org.opensaml.saml.saml1.core.Subject subject = statement.getSubject();
+            if (subject != null) {
+                final NameIdentifier nameID = subject.getNameIdentifier();
+                if (nameID != null) {
+                    return nameID.getFormat();
+                }
             }
         }
         for (final AttributeStatement statement : assertion.getAttributeStatements()) {
-            if (statement.getSubject() != null && statement.getSubject().getNameIdentifier() != null) {
-                return statement.getSubject().getNameIdentifier().getFormat();
+            final org.opensaml.saml.saml1.core.Subject subject = statement.getSubject();
+            if (subject != null) {
+                final NameIdentifier nameID = subject.getNameIdentifier();
+                if (nameID != null) {
+                    return nameID.getFormat();
+                }
             }
         }
-        for (final AuthorizationDecisionStatement statement
-                : assertion.getAuthorizationDecisionStatements()) {
-            if (statement.getSubject() != null && statement.getSubject().getNameIdentifier() != null) {
-                return statement.getSubject().getNameIdentifier().getFormat();
+        for (final AuthorizationDecisionStatement statement : assertion.getAuthorizationDecisionStatements()) {
+            final org.opensaml.saml.saml1.core.Subject subject = statement.getSubject();
+            if (subject != null) {
+                final NameIdentifier nameID = subject.getNameIdentifier();
+                if (nameID != null) {
+                    return nameID.getFormat();
+                }
             }
         }
         for (final SubjectStatement statement : assertion.getSubjectStatements()) {
-            if (statement.getSubject() != null && statement.getSubject().getNameIdentifier() != null) {
-                return statement.getSubject().getNameIdentifier().getFormat();
+            final org.opensaml.saml.saml1.core.Subject subject = statement.getSubject();
+            if (subject != null) {
+                final NameIdentifier nameID = subject.getNameIdentifier();
+                if (nameID != null) {
+                    return nameID.getFormat();
+                }
             }
         }
         
diff --git a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/audit/impl/StatusCodeAuditExtractor.java b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/audit/impl/StatusCodeAuditExtractor.java
index 979d60ad2..4f3b5928a 100644
--- a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/audit/impl/StatusCodeAuditExtractor.java
+++ b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/audit/impl/StatusCodeAuditExtractor.java
@@ -21,6 +21,7 @@ import java.util.function.Function;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
+import javax.xml.namespace.QName;
 
 import org.opensaml.profile.context.ProfileRequestContext;
 import org.opensaml.saml.common.SAMLObject;
@@ -52,7 +53,9 @@ public class StatusCodeAuditExtractor implements Function<ProfileRequestContext,
                 final org.opensaml.saml.saml1.core.Status status = r.getStatus();
                 final org.opensaml.saml.saml1.core.StatusCode sc = status != null ? status.getStatusCode() : null;
                 if (sc != null && sc.getValue() != null) {
-                    return sc.getValue().getLocalPart();
+                    final QName q = sc.getValue();
+                    assert q != null;
+                    return q.getLocalPart();
                 }
             } else if (response instanceof StatusResponseType srt) {
                 final org.opensaml.saml.saml2.core.Status status = srt.getStatus();
diff --git a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/audit/impl/SubStatusCodeAuditExtractor.java b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/audit/impl/SubStatusCodeAuditExtractor.java
index e639d39f6..3594439ac 100644
--- a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/audit/impl/SubStatusCodeAuditExtractor.java
+++ b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/audit/impl/SubStatusCodeAuditExtractor.java
@@ -24,6 +24,7 @@ import java.util.function.Function;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
+import javax.xml.namespace.QName;
 
 import org.opensaml.profile.context.ProfileRequestContext;
 import org.opensaml.saml.common.SAMLObject;
@@ -59,10 +60,12 @@ public class SubStatusCodeAuditExtractor implements Function<ProfileRequestConte
                     final Collection<String> values = new ArrayList<>(1);
                     do {
                         sc = sc.getStatusCode();
-                        if (sc.getValue() != null) {
-                            values.add(sc.getValue().getLocalPart());
+                        if (sc != null && sc.getValue() != null) {
+                            final QName q = sc.getValue();
+                            assert q != null;
+                            values.add(q.getLocalPart());
                         }
-                    } while (sc.getStatusCode() != null);
+                    } while (sc != null && sc.getStatusCode() != null);
                     return values;
                 }
             } else if (response instanceof StatusResponseType srt) {
diff --git a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/profile/impl/ExtractSubjectFromRequestTest.java b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/profile/impl/ExtractSubjectFromRequestTest.java
index 030900b7d..2fdfe66ed 100644
--- a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/profile/impl/ExtractSubjectFromRequestTest.java
+++ b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/profile/impl/ExtractSubjectFromRequestTest.java
@@ -147,7 +147,7 @@ public class ExtractSubjectFromRequestTest extends XMLObjectBaseTestCase {
         final org.opensaml.saml.saml1.core.Subject s = Constraint.isNotNull(request.getAttributeQuery(), "Query was null").getSubject();
         assert s != null;
         final NameIdentifier nameID = s.getNameIdentifier();
-                
+        assert nameID != null;
         nameID.setFormat(NameID.TRANSIENT);
         nameID.setNameQualifier("foo");
         Event event = action.execute(rc);
diff --git a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/saml1/profile/impl/AddAuthenticationStatementToAssertionTest.java b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/saml1/profile/impl/AddAuthenticationStatementToAssertionTest.java
index 7b6029d70..7dd1bbf1e 100644
--- a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/saml1/profile/impl/AddAuthenticationStatementToAssertionTest.java
+++ b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/saml1/profile/impl/AddAuthenticationStatementToAssertionTest.java
@@ -29,6 +29,7 @@ import org.opensaml.profile.context.ProfileRequestContext;
 import org.opensaml.saml.saml1.core.Assertion;
 import org.opensaml.saml.saml1.core.AuthenticationStatement;
 import org.opensaml.saml.saml1.core.Response;
+import org.opensaml.saml.saml1.core.SubjectLocality;
 import org.opensaml.storage.StorageSerializer;
 import org.springframework.mock.web.MockHttpServletRequest;
 import org.springframework.webflow.execution.Event;
@@ -175,11 +176,15 @@ public class AddAuthenticationStatementToAssertionTest extends OpenSAMLInitBaseT
         Assert.assertNotNull(assertion.getAuthenticationStatements().get(0));
 
         final AuthenticationStatement authenticationStatement = assertion.getAuthenticationStatements().get(0);
-        Assert.assertTrue(authenticationStatement.getAuthenticationInstant().isAfter(now));
+        assert authenticationStatement != null;
+        final Instant authnInstant = authenticationStatement.getAuthenticationInstant();
+        assert authnInstant != null;
+        Assert.assertTrue(authnInstant.isAfter(now));
         Assert.assertEquals(authenticationStatement.getAuthenticationMethod(), "Test");
         
-        Assert.assertNotNull(authenticationStatement.getSubjectLocality());
-        Assert.assertEquals(authenticationStatement.getSubjectLocality().getIPAddress(), "127.0.0.1");
+        final SubjectLocality locality = authenticationStatement.getSubjectLocality();
+        assert locality != null;
+        Assert.assertEquals(locality.getIPAddress(), "127.0.0.1");
     }
     
     /**

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


More information about the commits mailing list