[java-opensaml] 14/14: JSPT-98 Integrate lifecycle checking methods in base classes

Rod Widdowson rdw at steadingsoftware.com
Mon Jul 11 15:47:44 UTC 2022


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

rdw pushed a commit to branch dev/JSPT-98
in repository java-opensaml.

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

commit 9b1cae3e2688be841827bb369fafe64f9add770a
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Mon Jun 13 20:41:42 2022 +0100

    JSPT-98 Integrate lifecycle checking methods in base classes
    
    https://shibboleth.atlassian.net/browse/JSPT-98
    
    Stop using ComponentSupport and use the appropriate methods instead: xmlsec-impl
---
 .../opensaml/xmlsec/agreement/impl/DigestMethod.java    |  5 ++---
 .../org/opensaml/xmlsec/agreement/impl/KANonce.java     |  9 ++++-----
 .../org/opensaml/xmlsec/derivation/impl/ConcatKDF.java  | 17 ++++++++---------
 .../org/opensaml/xmlsec/derivation/impl/PBKDF2.java     | 17 ++++++++---------
 .../PopulateSignatureValidationParametersHandler.java   |  7 +++----
 5 files changed, 25 insertions(+), 30 deletions(-)

diff --git a/opensaml-xmlsec-impl/src/main/java/org/opensaml/xmlsec/agreement/impl/DigestMethod.java b/opensaml-xmlsec-impl/src/main/java/org/opensaml/xmlsec/agreement/impl/DigestMethod.java
index a4335ffeb..08b3fa3c4 100644
--- a/opensaml-xmlsec-impl/src/main/java/org/opensaml/xmlsec/agreement/impl/DigestMethod.java
+++ b/opensaml-xmlsec-impl/src/main/java/org/opensaml/xmlsec/agreement/impl/DigestMethod.java
@@ -29,7 +29,6 @@ import org.opensaml.xmlsec.agreement.XMLExpressableKeyAgreementParameter;
 
 import net.shibboleth.utilities.java.support.component.AbstractInitializableComponent;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-import net.shibboleth.utilities.java.support.component.ComponentSupport;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.primitive.StringSupport;
 
@@ -64,13 +63,13 @@ public class DigestMethod extends AbstractInitializableComponent
      * @param newAlgorithm the algorithm URI
      */
     public void setAlgorithm(@Nullable final String newAlgorithm) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        throwSetterPreconditionExceptions();
         algorithm = StringSupport.trimOrNull(newAlgorithm);
     }
 
     /** {@inheritDoc} */
     public DigestMethod clone() {
-        ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
+        ifDestroyedThrowDestroyedComponentException();
         try {
             return (DigestMethod ) super.clone();
         } catch (final CloneNotSupportedException e) {
diff --git a/opensaml-xmlsec-impl/src/main/java/org/opensaml/xmlsec/agreement/impl/KANonce.java b/opensaml-xmlsec-impl/src/main/java/org/opensaml/xmlsec/agreement/impl/KANonce.java
index 3a7715dab..f9bcd0b3a 100644
--- a/opensaml-xmlsec-impl/src/main/java/org/opensaml/xmlsec/agreement/impl/KANonce.java
+++ b/opensaml-xmlsec-impl/src/main/java/org/opensaml/xmlsec/agreement/impl/KANonce.java
@@ -36,7 +36,6 @@ import net.shibboleth.utilities.java.support.codec.DecodingException;
 import net.shibboleth.utilities.java.support.codec.EncodingException;
 import net.shibboleth.utilities.java.support.component.AbstractInitializableComponent;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-import net.shibboleth.utilities.java.support.component.ComponentSupport;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.primitive.StringSupport;
 
@@ -76,7 +75,7 @@ public class KANonce extends AbstractInitializableComponent
      * @param newValue the nonce value
      */
     public void setValue(@Nullable final String newValue) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        throwSetterPreconditionExceptions();
         value = StringSupport.trimOrNull(newValue);
     }
     
@@ -95,7 +94,7 @@ public class KANonce extends AbstractInitializableComponent
      * @param length the generated length
      */
     public void setGeneratedLength(@Nullable final Integer length) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        throwSetterPreconditionExceptions();
         generatedLength = length;
     }
     
@@ -122,7 +121,7 @@ public class KANonce extends AbstractInitializableComponent
      * @param sr the secure random generator to set
      */
     public void setRandom(@Nullable final SecureRandom sr) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        throwSetterPreconditionExceptions();
         secureRandom = sr;
     }
 
@@ -163,7 +162,7 @@ public class KANonce extends AbstractInitializableComponent
 
     /** {@inheritDoc} */
     public KANonce clone() {
-        ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
+        ifDestroyedThrowDestroyedComponentException();
         try {
             return (KANonce ) super.clone();
         } catch (final CloneNotSupportedException e) {
diff --git a/opensaml-xmlsec-impl/src/main/java/org/opensaml/xmlsec/derivation/impl/ConcatKDF.java b/opensaml-xmlsec-impl/src/main/java/org/opensaml/xmlsec/derivation/impl/ConcatKDF.java
index 25e98faca..54d71c167 100644
--- a/opensaml-xmlsec-impl/src/main/java/org/opensaml/xmlsec/derivation/impl/ConcatKDF.java
+++ b/opensaml-xmlsec-impl/src/main/java/org/opensaml/xmlsec/derivation/impl/ConcatKDF.java
@@ -57,7 +57,6 @@ import com.google.common.primitives.Bytes;
 import net.shibboleth.utilities.java.support.annotation.constraint.NonnullAfterInit;
 import net.shibboleth.utilities.java.support.component.AbstractInitializableComponent;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-import net.shibboleth.utilities.java.support.component.ComponentSupport;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.primitive.StringSupport;
 
@@ -132,7 +131,7 @@ public class ConcatKDF extends AbstractInitializableComponent
      * @param newDigestMethod the algorithm URI
      */
     public void setDigestMethod(@Nullable final String newDigestMethod) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        throwSetterPreconditionExceptions();
         digestMethod = StringSupport.trimOrNull(newDigestMethod);
     }
 
@@ -151,7 +150,7 @@ public class ConcatKDF extends AbstractInitializableComponent
      * @param newAlgorithmID the AlgorithmID
      */
     public void setAlgorithmID(@Nullable final String newAlgorithmID) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        throwSetterPreconditionExceptions();
         algorithmID = StringSupport.trimOrNull(newAlgorithmID);
     }
 
@@ -170,7 +169,7 @@ public class ConcatKDF extends AbstractInitializableComponent
      * @param newPartyUInfo the PartyUInfo
      */
     public void setPartyUInfo(@Nullable final String newPartyUInfo) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        throwSetterPreconditionExceptions();
         partyUInfo = StringSupport.trimOrNull(newPartyUInfo);
     }
 
@@ -189,7 +188,7 @@ public class ConcatKDF extends AbstractInitializableComponent
      * @param newPartyVInfo the PartyVInfo
      */
     public void setPartyVInfo(@Nullable final String newPartyVInfo) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        throwSetterPreconditionExceptions();
         partyVInfo = StringSupport.trimOrNull(newPartyVInfo);
     }
 
@@ -208,7 +207,7 @@ public class ConcatKDF extends AbstractInitializableComponent
      * @param newSuppPubInfo the SuppPubInfo
      */
     public void setSuppPubInfo(@Nullable final String newSuppPubInfo) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        throwSetterPreconditionExceptions();
         suppPubInfo = StringSupport.trimOrNull(newSuppPubInfo);
     }
 
@@ -227,7 +226,7 @@ public class ConcatKDF extends AbstractInitializableComponent
      * @param newSuppPrivInfo the SuppPrivInfo
      */
     public void setSuppPrivInfo(@Nullable final String newSuppPrivInfo) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        throwSetterPreconditionExceptions();
         suppPrivInfo = StringSupport.trimOrNull(newSuppPrivInfo);
     }
 
@@ -269,7 +268,7 @@ public class ConcatKDF extends AbstractInitializableComponent
             @Nullable final Integer keyLength) throws KeyDerivationException {
         Constraint.isNotNull(secret, "Secret byte[] was null");
         Constraint.isNotNull(keyAlgorithm, "Key algorithm was null");
-        ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this);
+        throwComponentStateExceptions();
         
         final String jcaKeyAlgorithm = KeyDerivationSupport.getJCAKeyAlgorithm(keyAlgorithm);
         
@@ -458,7 +457,7 @@ public class ConcatKDF extends AbstractInitializableComponent
     
     /** {@inheritDoc} */
     public XMLObject buildXMLObject() {
-        ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this);
+        throwComponentStateExceptions();
         
         final KeyDerivationMethod method =
                 (KeyDerivationMethod) XMLObjectSupport.buildXMLObject(KeyDerivationMethod.DEFAULT_ELEMENT_NAME);
diff --git a/opensaml-xmlsec-impl/src/main/java/org/opensaml/xmlsec/derivation/impl/PBKDF2.java b/opensaml-xmlsec-impl/src/main/java/org/opensaml/xmlsec/derivation/impl/PBKDF2.java
index bc5f9b7d1..ac5205f08 100644
--- a/opensaml-xmlsec-impl/src/main/java/org/opensaml/xmlsec/derivation/impl/PBKDF2.java
+++ b/opensaml-xmlsec-impl/src/main/java/org/opensaml/xmlsec/derivation/impl/PBKDF2.java
@@ -59,7 +59,6 @@ import net.shibboleth.utilities.java.support.codec.DecodingException;
 import net.shibboleth.utilities.java.support.codec.EncodingException;
 import net.shibboleth.utilities.java.support.component.AbstractInitializableComponent;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-import net.shibboleth.utilities.java.support.component.ComponentSupport;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.primitive.StringSupport;
 
@@ -119,7 +118,7 @@ public class PBKDF2 extends AbstractInitializableComponent
      * @param value the salt
      */
     public void setSalt(@Nullable final String value) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        throwSetterPreconditionExceptions();
         salt = StringSupport.trimOrNull(value);
     }
     
@@ -138,7 +137,7 @@ public class PBKDF2 extends AbstractInitializableComponent
      * @param length the generated salt length
      */
     public void setGeneratedSaltLength(@Nullable final Integer length) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        throwSetterPreconditionExceptions();
         generatedSaltLength = length;
     }
     
@@ -165,7 +164,7 @@ public class PBKDF2 extends AbstractInitializableComponent
      * @param sr the secure random generator to set
      */
     public void setRandom(@Nullable final SecureRandom sr) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        throwSetterPreconditionExceptions();
         
         secureRandom = sr;
     }
@@ -185,7 +184,7 @@ public class PBKDF2 extends AbstractInitializableComponent
      * @param count the iteration count
      */
     public void setIterationCount(@Nullable final Integer count) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        throwSetterPreconditionExceptions();
         iterationCount = count;
     }
     
@@ -212,7 +211,7 @@ public class PBKDF2 extends AbstractInitializableComponent
      * @param length the key length
      */
     public void setKeyLength(@Nullable final Integer length) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        throwSetterPreconditionExceptions();
         keyLength = length;
     }
     
@@ -231,7 +230,7 @@ public class PBKDF2 extends AbstractInitializableComponent
      * @param uri the PRF URI
      */
     public void setPRF(@Nullable final String uri) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        throwSetterPreconditionExceptions();
         prf = StringSupport.trimOrNull(uri);
     }
 
@@ -281,7 +280,7 @@ public class PBKDF2 extends AbstractInitializableComponent
             @Nullable final Integer specifiedKeyLength) throws KeyDerivationException {
         Constraint.isNotNull(secret, "Secret byte[] was null");
         Constraint.isNotNull(keyAlgorithm, "Key algorithm was null");
-        ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this);
+        throwComponentStateExceptions();
         
         final String jcaKeyAlgorithm = KeyDerivationSupport.getJCAKeyAlgorithm(keyAlgorithm);
         
@@ -374,7 +373,7 @@ public class PBKDF2 extends AbstractInitializableComponent
 
     /** {@inheritDoc} */
     public XMLObject buildXMLObject() {
-        ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this);
+        throwComponentStateExceptions();
         
         // If initialized, iterationCount and PRF are guaranteed to be non-null.
         // These 2 would happen if initialized but derive(...) hasn't been called.
diff --git a/opensaml-xmlsec-impl/src/main/java/org/opensaml/xmlsec/messaging/impl/PopulateSignatureValidationParametersHandler.java b/opensaml-xmlsec-impl/src/main/java/org/opensaml/xmlsec/messaging/impl/PopulateSignatureValidationParametersHandler.java
index 4dd65887a..708fef2f4 100644
--- a/opensaml-xmlsec-impl/src/main/java/org/opensaml/xmlsec/messaging/impl/PopulateSignatureValidationParametersHandler.java
+++ b/opensaml-xmlsec-impl/src/main/java/org/opensaml/xmlsec/messaging/impl/PopulateSignatureValidationParametersHandler.java
@@ -38,7 +38,6 @@ import org.slf4j.LoggerFactory;
 
 import net.shibboleth.utilities.java.support.annotation.constraint.NonnullAfterInit;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-import net.shibboleth.utilities.java.support.component.ComponentSupport;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
 import net.shibboleth.utilities.java.support.resolver.ResolverException;
@@ -78,7 +77,7 @@ public class PopulateSignatureValidationParametersHandler extends AbstractMessag
      */
     public void setSecurityParametersContextLookupStrategy(
             @Nonnull final Function<MessageContext,SecurityParametersContext> strategy) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        throwSetterPreconditionExceptions();
 
         securityParametersContextLookupStrategy = Constraint.isNotNull(strategy,
                 "SecurityParametersContext lookup strategy cannot be null");
@@ -91,7 +90,7 @@ public class PopulateSignatureValidationParametersHandler extends AbstractMessag
      */
     public void setConfigurationLookupStrategy(
             @Nonnull final Function<MessageContext,List<SignatureValidationConfiguration>> strategy) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        throwSetterPreconditionExceptions();
         
         configurationLookupStrategy = Constraint.isNotNull(strategy,
                 "SignatureValidationConfiguration lookup strategy cannot be null");
@@ -104,7 +103,7 @@ public class PopulateSignatureValidationParametersHandler extends AbstractMessag
      */
     public void setSignatureValidationParametersResolver(
             @Nonnull final SignatureValidationParametersResolver newResolver) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        throwSetterPreconditionExceptions();
         
         resolver = Constraint.isNotNull(newResolver, "SignatureValidationParametersResolver cannot be null");
     }

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


More information about the commits mailing list