[java-identity-provider] branch master updated: Cosmetic changes to annotations, initialize checks.
Scott Cantor
cantor.2 at osu.edu
Mon May 20 14:51:15 EDT 2019
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch master
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=36c8289ccbd2a6985deed2ce86636a44e965d216
The following commit(s) were added to refs/heads/master by this push:
new 36c8289 Cosmetic changes to annotations, initialize checks.
36c8289 is described below
commit 36c8289ccbd2a6985deed2ce86636a44e965d216
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon May 20 14:51:12 2019 -0400
Cosmetic changes to annotations, initialize checks.
---
.../ad/impl/ContextDerivedAttributeDefinition.java | 26 ++++++-----
.../impl/IdPAttributePrincipalValuesFunction.java | 28 +++++++-----
.../SubjectDerivedAttributeValuesFunction.java | 52 ++++++++++++----------
3 files changed, 60 insertions(+), 46 deletions(-)
diff --git a/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/impl/ContextDerivedAttributeDefinition.java b/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/impl/ContextDerivedAttributeDefinition.java
index 192e765..0ad7b19 100644
--- a/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/impl/ContextDerivedAttributeDefinition.java
+++ b/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/impl/ContextDerivedAttributeDefinition.java
@@ -29,6 +29,7 @@ import net.shibboleth.idp.attribute.resolver.AbstractAttributeDefinition;
import net.shibboleth.idp.attribute.resolver.ResolutionException;
import net.shibboleth.idp.attribute.resolver.context.AttributeResolutionContext;
import net.shibboleth.idp.attribute.resolver.context.AttributeResolverWorkContext;
+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;
@@ -39,8 +40,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * An attribute definition which returns an attribute attributes derived from the {@link ProfileRequestContext}
- * associated with the request via a plugged in {@link Function}.
+ * An attribute definition which returns an attribute whose values are derived from the
+ * {@link ProfileRequestContext} associated with the request via a plugged in {@link Function}.
*/
public class ContextDerivedAttributeDefinition extends AbstractAttributeDefinition {
@@ -55,7 +56,7 @@ public class ContextDerivedAttributeDefinition extends AbstractAttributeDefiniti
*
* The function returns null or an empty list if the context isn't relevant.
*/
- @Nonnull private Function<ProfileRequestContext,List<IdPAttributeValue>> attributeValuesFunction;
+ @NonnullAfterInit private Function<ProfileRequestContext,List<IdPAttributeValue>> attributeValuesFunction;
/** Constructor. */
public ContextDerivedAttributeDefinition() {
@@ -87,6 +88,15 @@ public class ContextDerivedAttributeDefinition extends AbstractAttributeDefiniti
attributeValuesFunction = Constraint.isNotNull(function, "Attribute Function cannot be null");
}
+ /** {@inheritDoc} */
+ @Override protected void doInitialize() throws ComponentInitializationException {
+ super.doInitialize();
+
+ if (attributeValuesFunction == null) {
+ throw new ComponentInitializationException("Attribute value lookup strategy cannot be null");
+ }
+ }
+
@Override @Nullable protected IdPAttribute doAttributeDefinitionResolve(
@Nonnull final AttributeResolutionContext resolutionContext,
@Nonnull final AttributeResolverWorkContext workContext) throws ResolutionException {
@@ -105,12 +115,4 @@ public class ContextDerivedAttributeDefinition extends AbstractAttributeDefiniti
return attribute;
}
- /** {@inheritDoc} */
- @Override protected void doInitialize() throws ComponentInitializationException {
- Constraint.isNotNull(prcLookupStrategy, "ProfileRequestContext lookup strategy cannot be null");
- Constraint.isNotNull(attributeValuesFunction, "AttributeValue Function cannot be null");
-
- super.doInitialize();
- }
-
-}
+}
\ No newline at end of file
diff --git a/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/impl/IdPAttributePrincipalValuesFunction.java b/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/impl/IdPAttributePrincipalValuesFunction.java
index 66182cf..2068aae 100644
--- a/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/impl/IdPAttributePrincipalValuesFunction.java
+++ b/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/impl/IdPAttributePrincipalValuesFunction.java
@@ -24,9 +24,13 @@ import java.util.function.Function;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import com.google.common.base.Strings;
+
import net.shibboleth.idp.attribute.IdPAttribute;
import net.shibboleth.idp.attribute.IdPAttributeValue;
import net.shibboleth.idp.authn.principal.IdPAttributePrincipal;
+import net.shibboleth.utilities.java.support.annotation.constraint.NonnullAfterInit;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.component.AbstractInitializableComponent;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import net.shibboleth.utilities.java.support.logic.Constraint;
@@ -36,25 +40,26 @@ public class IdPAttributePrincipalValuesFunction extends AbstractInitializableCo
Function<Principal, List<IdPAttributeValue>> {
/** The Attribute Name to look for. */
- @Nonnull private String attributeName;
-
- /** Constructor. */
- public IdPAttributePrincipalValuesFunction() {
- }
+ @NonnullAfterInit @NotEmpty private String attributeName;
/**
* Set the attribute name.
*
- * @param attrName the name to filter on.
+ * @param attrName the attribute name to read values from
*/
- public void setAttributeName(@Nonnull final String attrName) {
- attributeName = Constraint.isNotNull(attrName, "Attribute Name should be non-null");
+ public void setAttributeName(@Nonnull @NotEmpty final String attrName) {
+ Constraint.isFalse(Strings.isNullOrEmpty(attrName), "Attribute Name cannot be null or empty");
+
+ attributeName = attrName;
}
/** {@inheritDoc} */
@Override protected void doInitialize() throws ComponentInitializationException {
- Constraint.isNotNull(attributeName, "Attribute Name should be non-null");
super.doInitialize();
+
+ if (attributeName == null) {
+ throw new ComponentInitializationException("Attribute name cannot be null or empty");
+ }
}
/** {@inheritDoc} */
@@ -63,10 +68,11 @@ public class IdPAttributePrincipalValuesFunction extends AbstractInitializableCo
if (null != principal && principal instanceof IdPAttributePrincipal) {
final IdPAttributePrincipal attributePrincipal = (IdPAttributePrincipal) principal;
final IdPAttribute attribute = attributePrincipal.getAttribute();
- if (null != attribute && attributeName.equals(attribute.getId())) {
+ if (attributeName.equals(attribute.getId())) {
return attribute.getValues();
}
}
return null;
}
-}
+
+}
\ No newline at end of file
diff --git a/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/impl/SubjectDerivedAttributeValuesFunction.java b/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/impl/SubjectDerivedAttributeValuesFunction.java
index 0db9f2b..96d9956 100644
--- a/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/impl/SubjectDerivedAttributeValuesFunction.java
+++ b/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/ad/impl/SubjectDerivedAttributeValuesFunction.java
@@ -28,6 +28,7 @@ import javax.security.auth.Subject;
import net.shibboleth.idp.attribute.IdPAttributeValue;
import net.shibboleth.idp.authn.context.SubjectContext;
+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;
@@ -56,71 +57,76 @@ public class SubjectDerivedAttributeValuesFunction extends AbstractIdentifiableI
*
* The {@link Function} returns null or an empty list if the {@link Principal} isn't relevant.
*/
- @Nonnull private Function<Principal,List<IdPAttributeValue>> attributesValueFunction;
+ @NonnullAfterInit private Function<Principal,List<IdPAttributeValue>> attributeValuesFunction;
/** Constructor. */
public SubjectDerivedAttributeValuesFunction() {
- scLookupStrategy = new ChildContextLookup<ProfileRequestContext,SubjectContext>(SubjectContext.class);
+ scLookupStrategy = new ChildContextLookup<>(SubjectContext.class);
}
/**
- * Set the strategy used to locate the {@link SubjectContext} associated with a given
+ * Sets the strategy used to locate the {@link SubjectContext} associated with a given
* {@link net.shibboleth.idp.attribute.resolver.context.AttributeResolutionContext}.
*
* @param strategy strategy used to locate the {@link SubjectContext} associated with a given
* {@link net.shibboleth.idp.attribute.resolver.context.AttributeResolutionContext}
*/
- public void
- setSubjectContextLookupStrategy(@Nonnull final Function<ProfileRequestContext,SubjectContext> strategy) {
+ public void setSubjectContextLookupStrategy(
+ @Nonnull final Function<ProfileRequestContext,SubjectContext> strategy) {
ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
scLookupStrategy = Constraint.isNotNull(strategy, "SubjectContext lookup strategy cannot be null");
}
/**
- * Sets the attribute value function.
+ * Sets the function to extract attribute values from a {@link Principal}.
*
- * @param engine what to set.
+ * @param strategy strategy function
*/
- public void setAttributeValuesFunction(@Nonnull final Function<Principal,List<IdPAttributeValue>> engine) {
+ public void setAttributeValuesFunction(@Nonnull final Function<Principal,List<IdPAttributeValue>> strategy) {
ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
- attributesValueFunction = Constraint.isNotNull(engine, "Attribute Engine cannot be null");
+
+ attributeValuesFunction = Constraint.isNotNull(strategy, "Attribute value lookup strategy cannot be null");
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void doInitialize() throws ComponentInitializationException {
+ super.doInitialize();
+
+ if (attributeValuesFunction == null) {
+ throw new ComponentInitializationException("Attribute value lookup strategy cannot be null");
+ }
}
/** {@inheritDoc} */
@Nullable public List<IdPAttributeValue> apply(@Nullable final ProfileRequestContext prc) {
final SubjectContext cs = scLookupStrategy.apply(prc);
- final List<IdPAttributeValue> results = new ArrayList<>(1);
+ final List<IdPAttributeValue> results = new ArrayList<>();
for (final Subject subject : cs.getSubjects()) {
for (final Principal principal : subject.getPrincipals()) {
- final List<IdPAttributeValue> values = attributesValueFunction.apply(principal);
+ final List<IdPAttributeValue> values = attributeValuesFunction.apply(principal);
if ((null != values) && !values.isEmpty()) {
results.addAll(values);
}
}
}
if (results.isEmpty()) {
- log.info("{} generated no values, attribute no resolved.", getLogPrefix());
+ log.info("{} Generated no values, no attribute resolved", getLogPrefix());
return null;
}
- log.debug("{} Generated {} values.", getLogPrefix(), results.size());
+ log.debug("{} Generated {} values", getLogPrefix(), results.size());
log.trace("{} Values:", getLogPrefix(), results);
return results;
}
- /** {@inheritDoc} */
- @Override protected void doInitialize() throws ComponentInitializationException {
- Constraint.isNotNull(scLookupStrategy, "SubjectContext lookup strategy cannot be null");
- Constraint.isNotNull(attributesValueFunction, "Attribute Engine cannot be null");
-
- super.doInitialize();
- }
-
- /** Produce a consistent log prefix.
+ /**
+ * Produce a consistent log prefix.
+ *
* @return a consistent log prefix
*/
private String getLogPrefix() {
return "SubjectDerivedAttributeDefinition" + getId();
}
-}
+
+}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list