[java-identity-provider] 04/06: JSPT-98 Integrate lifecycle checking methods in base classes

Rod Widdowson rdw at steadingsoftware.com
Fri Jul 15 09:44:54 UTC 2022


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

rdw 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=a1fd5ad46eeafd90ba9569a5804bbb8a6b6cab1c

commit a1fd5ad46eeafd90ba9569a5804bbb8a6b6cab1c
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Thu Jul 14 16:47:59 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:
    
            idp-authn-impl (revisited)
---
 .../SubjectDerivedAttributeValuesFunction.java     | 23 +++++++++-------------
 .../impl/SubjectDerivedAttributesFunction.java     | 20 ++++++++-----------
 .../context/impl/SubjectScriptContextExtender.java |  9 ++-------
 3 files changed, 19 insertions(+), 33 deletions(-)

diff --git a/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/context/impl/SubjectDerivedAttributeValuesFunction.java b/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/context/impl/SubjectDerivedAttributeValuesFunction.java
index c43b25218..57dbbb893 100644
--- a/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/context/impl/SubjectDerivedAttributeValuesFunction.java
+++ b/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/context/impl/SubjectDerivedAttributeValuesFunction.java
@@ -28,6 +28,11 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.security.auth.Subject;
 
+import org.opensaml.messaging.context.navigate.ChildContextLookup;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import net.shibboleth.idp.attribute.IdPAttributeValue;
 import net.shibboleth.idp.authn.context.SubjectCanonicalizationContext;
 import net.shibboleth.idp.authn.context.SubjectContext;
@@ -35,14 +40,8 @@ import net.shibboleth.idp.authn.context.navigate.SubjectCanonicalizationContextS
 import net.shibboleth.utilities.java.support.annotation.constraint.NonnullAfterInit;
 import net.shibboleth.utilities.java.support.component.AbstractIdentifiableInitializableComponent;
 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 org.opensaml.messaging.context.navigate.ChildContextLookup;
-import org.opensaml.profile.context.ProfileRequestContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 /**
  * A Function which returns {@link IdPAttributeValue}s derived from the {@link java.security.Principal}s
  * associated with the request. The precise values are determined by an injected {@link Function}.
@@ -81,8 +80,7 @@ public class SubjectDerivedAttributeValuesFunction extends AbstractIdentifiableI
      * @param flag flag to set
      */
     public void setForCanonicalization(final boolean flag) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
-        
+        throwSetterPreconditionExceptions();
         forCanonicalization = flag;
     }
 
@@ -95,8 +93,7 @@ public class SubjectDerivedAttributeValuesFunction extends AbstractIdentifiableI
      */
     public void setSubjectContextLookupStrategy(
             @Nonnull final Function<ProfileRequestContext,SubjectContext> strategy) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
-
+        throwSetterPreconditionExceptions();
         scLookupStrategy = Constraint.isNotNull(strategy, "SubjectContext lookup strategy cannot be null");
     }
 
@@ -106,8 +103,7 @@ public class SubjectDerivedAttributeValuesFunction extends AbstractIdentifiableI
      * @param strategy strategy function
      */
     public void setAttributeValuesFunction(@Nonnull final Function<Principal,List<IdPAttributeValue>> strategy) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
-        
+        throwSetterPreconditionExceptions();
         attributeValuesFunction = Constraint.isNotNull(strategy, "Attribute value lookup strategy cannot be null");
     }
 
@@ -120,8 +116,7 @@ public class SubjectDerivedAttributeValuesFunction extends AbstractIdentifiableI
      */
     public void setSubjectLookupStrategy(
             @Nullable final Function<ProfileRequestContext,Subject> strategy) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
-
+        throwSetterPreconditionExceptions();
         subjectLookupStrategy = strategy;
     }
     
diff --git a/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/context/impl/SubjectDerivedAttributesFunction.java b/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/context/impl/SubjectDerivedAttributesFunction.java
index 5254b9495..588c5ca16 100644
--- a/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/context/impl/SubjectDerivedAttributesFunction.java
+++ b/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/context/impl/SubjectDerivedAttributesFunction.java
@@ -28,6 +28,11 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.security.auth.Subject;
 
+import org.opensaml.messaging.context.navigate.ChildContextLookup;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import net.shibboleth.idp.attribute.IdPAttribute;
 import net.shibboleth.idp.authn.context.SubjectCanonicalizationContext;
 import net.shibboleth.idp.authn.context.SubjectContext;
@@ -35,14 +40,8 @@ import net.shibboleth.idp.authn.context.navigate.SubjectCanonicalizationContextS
 import net.shibboleth.idp.authn.principal.IdPAttributePrincipal;
 import net.shibboleth.utilities.java.support.component.AbstractIdentifiableInitializableComponent;
 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 org.opensaml.messaging.context.navigate.ChildContextLookup;
-import org.opensaml.profile.context.ProfileRequestContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 /**
  * A Function which returns {@link IdPAttribute}s derived from the {@link java.security.Principal}s
  * associated with the request.
@@ -84,8 +83,7 @@ public class SubjectDerivedAttributesFunction extends AbstractIdentifiableInitia
      * @param flag flag to set
      */
     public void setForCanonicalization(final boolean flag) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
-        
+        throwSetterPreconditionExceptions();
         forCanonicalization = flag;
     }
 
@@ -98,8 +96,7 @@ public class SubjectDerivedAttributesFunction extends AbstractIdentifiableInitia
      */
     public void setSubjectContextLookupStrategy(
             @Nonnull final Function<ProfileRequestContext,SubjectContext> strategy) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
-
+        throwSetterPreconditionExceptions();
         scLookupStrategy = Constraint.isNotNull(strategy, "SubjectContext lookup strategy cannot be null");
     }
 
@@ -111,8 +108,7 @@ public class SubjectDerivedAttributesFunction extends AbstractIdentifiableInitia
      *            {@link net.shibboleth.idp.attribute.resolver.context.AttributeResolutionContext}
      */
     public void setSubjectLookupStrategy(@Nullable final Function<ProfileRequestContext,Subject> strategy) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
-
+        throwSetterPreconditionExceptions();
         subjectLookupStrategy = strategy;
     }
     
diff --git a/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/context/impl/SubjectScriptContextExtender.java b/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/context/impl/SubjectScriptContextExtender.java
index 6cf812790..fd250d2cd 100644
--- a/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/context/impl/SubjectScriptContextExtender.java
+++ b/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/context/impl/SubjectScriptContextExtender.java
@@ -33,7 +33,6 @@ import net.shibboleth.idp.attribute.filter.FilterScriptContextExtender;
 import net.shibboleth.idp.attribute.resolver.scripted.ResolverScriptContextExtender;
 import net.shibboleth.idp.authn.context.SubjectContext;
 import net.shibboleth.utilities.java.support.component.AbstractInitializableComponent;
-import net.shibboleth.utilities.java.support.component.ComponentSupport;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 
 /**
@@ -62,17 +61,13 @@ public class SubjectScriptContextExtender extends AbstractInitializableComponent
      */
     public void setSubjectContextLookupStrategy(
             @Nonnull final Function<ProfileRequestContext,SubjectContext> strategy) {
-        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
-        ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
-    
+        throwSetterPreconditionExceptions();
         subjectContextLookupStrategy = Constraint.isNotNull(strategy, "SubjectContext lookup strategy cannot be null");
     }
     
     /** {@inheritDoc} */
     public void extendContext(@Nonnull final ScriptContext scriptContext) {
-        ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this);
-        ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
-
+        throwSetterPreconditionExceptions();
         final ProfileRequestContext prc = (ProfileRequestContext) scriptContext.getAttribute("profileContext");
         
         final SubjectContext sc = subjectContextLookupStrategy.apply(prc);

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


More information about the commits mailing list