[java-oidc-common] branch main updated: Null cleanup, guard against possible null objects in nonnull getters

Phil Smart philip.smart at jisc.ac.uk
Thu Nov 2 14:11:05 UTC 2023


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

philsmart pushed a commit to branch main
in repository java-oidc-common.

View the commit online:
http://git.shibboleth.net/view/?p=java-oidc-common.git;a=commit;h=6997d5ef43144e40cadc5e3e3473502f9eb686ad

The following commit(s) were added to refs/heads/main by this push:
     new 6997d5e  Null cleanup, guard against possible null objects in nonnull getters
6997d5e is described below

commit 6997d5ef43144e40cadc5e3e3473502f9eb686ad
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Thu Nov 2 14:10:58 2023 +0000

    Null cleanup, guard against possible null objects in nonnull getters
    
     - Add deprecations to nullable constructors and setters.
     - Look to make classes immutable in the next major version
---
 .../security/credential/BasicJWKReferenceCredential.java  | 15 +++++++++++++--
 .../security/credential/BasicNimbusSecretCredential.java  | 15 +++++++++++++--
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/oidc-common-crypto-api/src/main/java/net/shibboleth/oidc/security/credential/BasicJWKReferenceCredential.java b/oidc-common-crypto-api/src/main/java/net/shibboleth/oidc/security/credential/BasicJWKReferenceCredential.java
index 9b35a39..46e59d2 100644
--- a/oidc-common-crypto-api/src/main/java/net/shibboleth/oidc/security/credential/BasicJWKReferenceCredential.java
+++ b/oidc-common-crypto-api/src/main/java/net/shibboleth/oidc/security/credential/BasicJWKReferenceCredential.java
@@ -22,9 +22,14 @@ import javax.annotation.Nullable;
 import org.opensaml.security.credential.AbstractCredential;
 import org.opensaml.security.credential.Credential;
 
+import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.DeprecationSupport;
+import net.shibboleth.shared.primitive.DeprecationSupport.ObjectType;
+
 /**
  * A basic implementation of {@link JWKReferenceCredential}.
  */
+//TODO Make immutable in next major release (remove default constructor and setter).
 public class BasicJWKReferenceCredential extends AbstractCredential implements JWKReferenceCredential {
 
     /** A reference to a JWK. */
@@ -33,6 +38,7 @@ public class BasicJWKReferenceCredential extends AbstractCredential implements J
     /**
      * Constructor.
      */
+    @Deprecated(since = "3.1.0", forRemoval=true)
     public BasicJWKReferenceCredential() {
 
     }
@@ -43,6 +49,10 @@ public class BasicJWKReferenceCredential extends AbstractCredential implements J
      * @param uri A reference to a JWK.
      */
     public BasicJWKReferenceCredential(@Nullable final URI uri) {
+        if (uri == null) {
+            DeprecationSupport.warn(ObjectType.METHOD, "Nullable BasicJWKReferenceCredential Constructor", 
+                    null, "Nonnull BasicJWKReferenceCredential Constructor");
+        }
         referenceUri = uri;
     }
     
@@ -51,14 +61,15 @@ public class BasicJWKReferenceCredential extends AbstractCredential implements J
      * 
      * @param uri What to set.
      */
+    @Deprecated(since = "3.1.0", forRemoval=true)
     public void setReferenceURI(@Nullable final URI uri) {
+        DeprecationSupport.warn(ObjectType.METHOD, "setReferenceURI", null, null);
         referenceUri = uri;
     }
     
     /** {@inheritDoc} */
     @Nonnull public URI getReferenceURI() {
-        // TODO: this is nullable, so needs a guard, not sure what to do if null.
-        return referenceUri;
+        return Constraint.isNotNull(referenceUri, "Reference URI cannot be null");
     }
 
     /** {@inheritDoc} */
diff --git a/oidc-common-crypto-api/src/main/java/net/shibboleth/oidc/security/credential/BasicNimbusSecretCredential.java b/oidc-common-crypto-api/src/main/java/net/shibboleth/oidc/security/credential/BasicNimbusSecretCredential.java
index ff6f259..ca5bdbe 100644
--- a/oidc-common-crypto-api/src/main/java/net/shibboleth/oidc/security/credential/BasicNimbusSecretCredential.java
+++ b/oidc-common-crypto-api/src/main/java/net/shibboleth/oidc/security/credential/BasicNimbusSecretCredential.java
@@ -22,11 +22,16 @@ import org.opensaml.security.credential.Credential;
 
 import com.nimbusds.oauth2.sdk.auth.Secret;
 
+import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.DeprecationSupport;
+import net.shibboleth.shared.primitive.DeprecationSupport.ObjectType;
+
 /**
  * A basic implementation of {@link NimbusSecretCredential}.
  * 
  * @deprecated use {@link ClientSecretCredential}
  */
+// TODO If we can not remove usage of this class easily, make immutable (remove default constructor and setter).
 @Deprecated(since = "2.2.0", forRemoval=true)
 public class BasicNimbusSecretCredential extends AbstractCredential implements NimbusSecretCredential {
 
@@ -36,6 +41,7 @@ public class BasicNimbusSecretCredential extends AbstractCredential implements N
     /**
      * Constructor.
      */
+    @Deprecated(since = "3.1.0", forRemoval=true)
     public BasicNimbusSecretCredential() {
         
     }
@@ -46,6 +52,10 @@ public class BasicNimbusSecretCredential extends AbstractCredential implements N
      * @param secret The client secret.
      */
     public BasicNimbusSecretCredential(@Nullable final Secret secret) {
+        if (secret == null) {
+            DeprecationSupport.warn(ObjectType.METHOD, "Nullable BasicNimbusSecretCredential Constructor", 
+                    null, "Nonnull BasicNimbusSecretCredential Constructor");
+        }
         clientSecret = secret;
     }
     
@@ -54,14 +64,15 @@ public class BasicNimbusSecretCredential extends AbstractCredential implements N
      * 
      * @param secret What to set.
      */
+    @Deprecated(since = "3.1.0", forRemoval=true)
     public void setSecret(@Nullable final Secret secret) {
+        DeprecationSupport.warn(ObjectType.METHOD, "setSecret", null, null);
         clientSecret = secret;
     }
     
     /** {@inheritDoc} */
     @Nonnull public Secret getSecret() {
-        // TODO: this is nullable, so needs a guard, not sure what to do if null.
-        return clientSecret;
+        return Constraint.isNotNull(clientSecret, "Client secret cannot be null");
     }
 
     /** {@inheritDoc} */

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


More information about the commits mailing list