[java-opensaml] branch master updated: OSJ-291 - Sweep SAML XMLObject interfaces for consistency

Scott Cantor cantor.2 at osu.edu
Tue Nov 19 10:34:35 EST 2019


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

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

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

The following commit(s) were added to refs/heads/master by this push:
       new  0bb1706   OSJ-291 - Sweep SAML XMLObject interfaces for consistency
0bb1706 is described below

commit 0bb1706ba2d550ab63a689f4e29064d498d541d2
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Nov 19 10:33:48 2019 -0500

    OSJ-291 - Sweep SAML XMLObject interfaces for consistency
    
    https://issues.shibboleth.net/jira/browse/OSJ-291
---
 .../org/opensaml/saml/saml2/core/Audience.java     | 47 ++++++++++++++++++----
 .../saml/saml2/core/impl/AudienceImpl.java         | 19 ++++++---
 .../saml/saml2/core/impl/AudienceMarshaller.java   |  4 +-
 .../saml/saml2/core/impl/AudienceUnmarshaller.java |  4 +-
 .../impl/AddProxyRestrictionToAssertions.java      |  2 +-
 .../opensaml/saml/saml2/core/AuthnRequestTest.java |  4 +-
 .../saml2/core/ResponseSuccessAuthnAttribTest.java |  4 +-
 .../impl/AddProxyRestrictionToAssertionsTest.java  | 12 +++---
 8 files changed, 67 insertions(+), 29 deletions(-)

diff --git a/opensaml-saml-api/src/main/java/org/opensaml/saml/saml2/core/Audience.java b/opensaml-saml-api/src/main/java/org/opensaml/saml/saml2/core/Audience.java
index 8618002..fa92230 100644
--- a/opensaml-saml-api/src/main/java/org/opensaml/saml/saml2/core/Audience.java
+++ b/opensaml-saml-api/src/main/java/org/opensaml/saml/saml2/core/Audience.java
@@ -17,41 +17,72 @@
 
 package org.opensaml.saml.saml2.core;
 
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 import javax.xml.namespace.QName;
 
 import org.opensaml.saml.common.SAMLObject;
 import org.opensaml.saml.common.xml.SAMLConstants;
 
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+
 /**
  * SAML 2.0 Core Audience.
  */
 public interface Audience extends SAMLObject {
 
     /** Element local name. */
-    public static final String DEFAULT_ELEMENT_LOCAL_NAME = "Audience";
+    @Nonnull @NotEmpty public static final String DEFAULT_ELEMENT_LOCAL_NAME = "Audience";
 
     /** Default element name. */
-    public static final QName DEFAULT_ELEMENT_NAME = new QName(SAMLConstants.SAML20_NS, DEFAULT_ELEMENT_LOCAL_NAME,
-            SAMLConstants.SAML20_PREFIX);
+    @Nonnull public static final QName DEFAULT_ELEMENT_NAME =
+            new QName(SAMLConstants.SAML20_NS, DEFAULT_ELEMENT_LOCAL_NAME, SAMLConstants.SAML20_PREFIX);
 
     /** Local name of the XSI type. */
-    public static final String TYPE_LOCAL_NAME = "AudienceType";
+    @Nonnull @NotEmpty public static final String TYPE_LOCAL_NAME = "AudienceType";
 
     /** QName of the XSI type. */
-    public static final QName TYPE_NAME = new QName(SAMLConstants.SAML20_NS, TYPE_LOCAL_NAME,
+    @Nonnull public static final QName TYPE_NAME = new QName(SAMLConstants.SAML20_NS, TYPE_LOCAL_NAME,
             SAMLConstants.SAML20_PREFIX);
 
     /**
      * Gets the URI of the audience for the assertion.
      * 
      * @return the URI of the audience for the assertion
+     * 
+     * @since 4.0.0
      */
-    public String getAudienceURI();
+    @Nullable String getURI();
 
     /**
      * Sets the URI of the audience for the assertion.
      * 
-     * @param newAudienceURI the URI of the audience for the assertion
+     * @param uri the URI of the audience for the assertion
+     * 
+     * @since 4.0.0
+     */
+    void setURI(@Nullable final String uri);
+
+    /**
+     * Gets the URI of the audience for the assertion.
+     * 
+     * @return the URI of the audience for the assertion
+     * 
+     * @deprecated
+     */
+    @Nullable default String getAudienceURI() {
+        return getURI();
+    }
+
+    /**
+     * Sets the URI of the audience for the assertion.
+     * 
+     * @param uri the URI of the audience for the assertion
+     * 
+     * @deprecated
      */
-    public void setAudienceURI(String newAudienceURI);
+    default void setAudienceURI(@Nullable final String uri) {
+        setURI(uri);
+    }
+    
 }
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/core/impl/AudienceImpl.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/core/impl/AudienceImpl.java
index ba507db..17494c9 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/core/impl/AudienceImpl.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/core/impl/AudienceImpl.java
@@ -23,12 +23,17 @@ package org.opensaml.saml.saml2.core.impl;
 
 import java.util.List;
 
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
 import org.opensaml.core.xml.AbstractXMLObject;
 import org.opensaml.core.xml.XMLObject;
 import org.opensaml.saml.saml2.core.Audience;
 
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+
 /**
- * Concrete implementation of {@link org.opensaml.saml.saml2.core.Audience}.
+ * Concrete implementation of {@link Audience}.
  */
 public class AudienceImpl extends AbstractXMLObject implements Audience {
 
@@ -42,22 +47,24 @@ public class AudienceImpl extends AbstractXMLObject implements Audience {
      * @param elementLocalName the local name of the XML element this Object represents
      * @param namespacePrefix the prefix for the given namespace
      */
-    protected AudienceImpl(final String namespaceURI, final String elementLocalName, final String namespacePrefix) {
+    protected AudienceImpl(@Nullable @NotEmpty final String namespaceURI,
+            @Nonnull @NotEmpty final String elementLocalName, @Nullable @NotEmpty final String namespacePrefix) {
         super(namespaceURI, elementLocalName, namespacePrefix);
     }
 
     /** {@inheritDoc} */
-    public String getAudienceURI() {
+    @Nullable public String getURI() {
         return audienceURI;
     }
 
     /** {@inheritDoc} */
-    public void setAudienceURI(final String newAudienceURI) {
-        this.audienceURI = prepareForAssignment(this.audienceURI, newAudienceURI);
+    public void setURI(@Nullable final String uri) {
+        audienceURI = prepareForAssignment(audienceURI, uri);
     }
 
     /** {@inheritDoc} */
-    public List<XMLObject> getOrderedChildren() {
+    @Nullable public List<XMLObject> getOrderedChildren() {
         return null;
     }
+    
 }
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/core/impl/AudienceMarshaller.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/core/impl/AudienceMarshaller.java
index 0e551bc..4d69fd7 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/core/impl/AudienceMarshaller.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/core/impl/AudienceMarshaller.java
@@ -30,7 +30,7 @@ import org.opensaml.saml.saml2.core.Audience;
 import org.w3c.dom.Element;
 
 /**
- * A thread safe Marshaller for {@link org.opensaml.saml.saml2.core.Audience} objects.
+ * A thread safe Marshaller for {@link Audience} objects.
  */
 public class AudienceMarshaller extends AbstractSAMLObjectMarshaller {
 
@@ -38,6 +38,6 @@ public class AudienceMarshaller extends AbstractSAMLObjectMarshaller {
     protected void marshallElementContent(final XMLObject samlObject, final Element domElement)
             throws MarshallingException {
         final Audience audience = (Audience) samlObject;
-        ElementSupport.appendTextContent(domElement, audience.getAudienceURI());
+        ElementSupport.appendTextContent(domElement, audience.getURI());
     }
 }
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/core/impl/AudienceUnmarshaller.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/core/impl/AudienceUnmarshaller.java
index c13f770..f4f688f 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/core/impl/AudienceUnmarshaller.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/core/impl/AudienceUnmarshaller.java
@@ -26,13 +26,13 @@ import org.opensaml.saml.common.AbstractSAMLObjectUnmarshaller;
 import org.opensaml.saml.saml2.core.Audience;
 
 /**
- * A thread-safe Unmarshaller for {@link org.opensaml.saml.saml2.core.Audience} objects.
+ * A thread-safe Unmarshaller for {@link Audience} objects.
  */
 public class AudienceUnmarshaller extends AbstractSAMLObjectUnmarshaller {
 
     /** {@inheritDoc} */
     protected void processElementContent(final XMLObject samlObject, final String elementContent) {
         final Audience audience = (Audience) samlObject;
-        audience.setAudienceURI(elementContent);
+        audience.setURI(elementContent);
     }
 }
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/profile/impl/AddProxyRestrictionToAssertions.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/profile/impl/AddProxyRestrictionToAssertions.java
index 464e423..e60d5b8 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/profile/impl/AddProxyRestrictionToAssertions.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/profile/impl/AddProxyRestrictionToAssertions.java
@@ -177,7 +177,7 @@ public class AddProxyRestrictionToAssertions extends AbstractConditionalProfileA
         for (final String audienceId : audiences) {
             log.debug("{} Adding {} as an Audience of the ProxyRestriction", getLogPrefix(), audienceId);
             final Audience audience = audienceBuilder.buildObject();
-            audience.setAudienceURI(audienceId);
+            audience.setURI(audienceId);
             condition.getAudiences().add(audience);
         }
         
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/core/AuthnRequestTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/core/AuthnRequestTest.java
index c3b1792..5ed970d 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/core/AuthnRequestTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/core/AuthnRequestTest.java
@@ -65,7 +65,7 @@ public class AuthnRequestTest extends BaseComplexSAMLObjectTestCase {
         Assert.assertEquals(request.getSubject().getNameID().getFormat(), NameIDType.EMAIL, "Subject/NameID/@NameIdFormat");
         Assert.assertEquals(request.getSubject().getNameID().getValue(), "j.doe at company.com", "Subject/NameID contents");
         Audience audience = request.getConditions().getAudienceRestrictions().get(0).getAudiences().get(0);
-        Assert.assertEquals(audience.getAudienceURI(), "urn:foo:sp.example.org", "Conditions/AudienceRestriction[1]/Audience[1] contents");
+        Assert.assertEquals(audience.getURI(), "urn:foo:sp.example.org", "Conditions/AudienceRestriction[1]/Audience[1] contents");
         AuthnContextClassRef classRef = request.getRequestedAuthnContext().getAuthnContextClassRefs().get(0);
         Assert.assertEquals(classRef.getURI(), AuthnContext.PPT_AUTHN_CTX, "RequestedAuthnContext/AuthnContextClassRef[1] contents");
     }
@@ -81,7 +81,7 @@ public class AuthnRequestTest extends BaseComplexSAMLObjectTestCase {
         subject.setNameID(nameid);
         
         Audience audience = (Audience) buildXMLObject(Audience.DEFAULT_ELEMENT_NAME);
-        audience.setAudienceURI("urn:foo:sp.example.org");
+        audience.setURI("urn:foo:sp.example.org");
         
         AudienceRestriction ar = (AudienceRestriction) buildXMLObject(AudienceRestriction.DEFAULT_ELEMENT_NAME);
         ar.getAudiences().add(audience);
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/core/ResponseSuccessAuthnAttribTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/core/ResponseSuccessAuthnAttribTest.java
index 0694d28..c19d8d0 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/core/ResponseSuccessAuthnAttribTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/core/ResponseSuccessAuthnAttribTest.java
@@ -82,7 +82,7 @@ public class ResponseSuccessAuthnAttribTest extends BaseComplexSAMLObjectTestCas
         Assert.assertEquals(assertion.getConditions().getNotBefore(), Instant.parse("2006-01-26T13:35:05.000Z"), "Assertion/Condition/@NotBefore");
         Assert.assertEquals(assertion.getConditions().getNotOnOrAfter(), Instant.parse("2006-01-26T13:45:05.000Z"), "Assertion/Condition/@NotOnOrAfter");
         Audience audience = assertion.getConditions().getAudienceRestrictions().get(0).getAudiences().get(0);
-        Assert.assertEquals(audience.getAudienceURI(), "https://sp.example.org", "Assertion/Conditions/AudienceRestriction/Audience contents");
+        Assert.assertEquals(audience.getURI(), "https://sp.example.org", "Assertion/Conditions/AudienceRestriction/Audience contents");
         
         AuthnStatement authnStatement = assertion.getAuthnStatements().get(0);
         Assert.assertEquals(authnStatement.getAuthnInstant(), Instant.parse("2006-01-26T13:35:05.000Z"), "Assertion/AuthnStatement/@AuthnInstant");
@@ -149,7 +149,7 @@ public class ResponseSuccessAuthnAttribTest extends BaseComplexSAMLObjectTestCas
         
         AudienceRestriction audienceRestriction = (AudienceRestriction) buildXMLObject(AudienceRestriction.DEFAULT_ELEMENT_NAME);
         Audience audience = (Audience) buildXMLObject(Audience.DEFAULT_ELEMENT_NAME);
-        audience.setAudienceURI("https://sp.example.org");
+        audience.setURI("https://sp.example.org");
         
         AuthnStatement authnStatement = (AuthnStatement) buildXMLObject(AuthnStatement.DEFAULT_ELEMENT_NAME);
         authnStatement.setAuthnInstant(Instant.parse("2006-01-26T13:35:05.000Z"));
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/profile/impl/AddProxyRestrictionToAssertionsTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/profile/impl/AddProxyRestrictionToAssertionsTest.java
index 2b75bda..d390367 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/profile/impl/AddProxyRestrictionToAssertionsTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/profile/impl/AddProxyRestrictionToAssertionsTest.java
@@ -93,8 +93,8 @@ public class AddProxyRestrictionToAssertionsTest extends OpenSAMLInitBaseTestCas
         final ProxyRestriction proxy = assertion.getConditions().getProxyRestriction();
         Assert.assertEquals(proxy.getProxyCount(), Integer.valueOf(1));
         Assert.assertEquals(proxy.getAudiences().size(), 2);
-        Assert.assertEquals(proxy.getAudiences().get(0).getAudienceURI(), AUDIENCE1);
-        Assert.assertEquals(proxy.getAudiences().get(1).getAudienceURI(), AUDIENCE2);
+        Assert.assertEquals(proxy.getAudiences().get(0).getURI(), AUDIENCE1);
+        Assert.assertEquals(proxy.getAudiences().get(1).getURI(), AUDIENCE2);
     }
 
     /**
@@ -123,8 +123,8 @@ public class AddProxyRestrictionToAssertionsTest extends OpenSAMLInitBaseTestCas
         final ProxyRestriction proxy = assertion.getConditions().getProxyRestriction();
         Assert.assertEquals(proxy.getProxyCount(), Integer.valueOf(1));
         Assert.assertEquals(proxy.getAudiences().size(), 2);
-        Assert.assertEquals(proxy.getAudiences().get(0).getAudienceURI(), AUDIENCE1);
-        Assert.assertEquals(proxy.getAudiences().get(1).getAudienceURI(), AUDIENCE2);
+        Assert.assertEquals(proxy.getAudiences().get(0).getURI(), AUDIENCE1);
+        Assert.assertEquals(proxy.getAudiences().get(1).getURI(), AUDIENCE2);
     }
 
     /** Test that the condition is properly added if there are multiple assertions in the response. */
@@ -148,8 +148,8 @@ public class AddProxyRestrictionToAssertionsTest extends OpenSAMLInitBaseTestCas
             final ProxyRestriction proxy = assertion.getConditions().getProxyRestriction();
             Assert.assertEquals(proxy.getProxyCount(), Integer.valueOf(1));
             Assert.assertEquals(proxy.getAudiences().size(), 2);
-            Assert.assertEquals(proxy.getAudiences().get(0).getAudienceURI(), AUDIENCE1);
-            Assert.assertEquals(proxy.getAudiences().get(1).getAudienceURI(), AUDIENCE2);
+            Assert.assertEquals(proxy.getAudiences().get(0).getURI(), AUDIENCE1);
+            Assert.assertEquals(proxy.getAudiences().get(1).getURI(), AUDIENCE2);
         }
     }
 

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


More information about the commits mailing list