[java-identity-provider] branch main updated: IDP-2069 Null handling
Rod Widdowson
rdw at steadingsoftware.com
Fri Feb 24 14:53:19 UTC 2023
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=1de5f62f49a0eefa628477d5a5fc7ab97b5b7ae5
The following commit(s) were added to refs/heads/main by this push:
new 1de5f62f4 IDP-2069 Null handling
1de5f62f4 is described below
commit 1de5f62f49a0eefa628477d5a5fc7ab97b5b7ae5
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Feb 24 14:53:35 2023 +0000
IDP-2069 Null handling
https://shibboleth.atlassian.net/browse/IDP-2069
Cleanup idp-testing
---
.../MockAuthenticationProfileConfiguration.java | 29 +++++-----
.../idp/saml/impl/testing/TestSources.java | 67 ++++++++++++----------
.../profile/testing/ActionTestSupportAction.java | 4 +-
3 files changed, 53 insertions(+), 47 deletions(-)
diff --git a/idp-testing/src/main/java/net/shibboleth/idp/authn/testing/MockAuthenticationProfileConfiguration.java b/idp-testing/src/main/java/net/shibboleth/idp/authn/testing/MockAuthenticationProfileConfiguration.java
index 5b8d0bcd5..8d67e5594 100644
--- a/idp-testing/src/main/java/net/shibboleth/idp/authn/testing/MockAuthenticationProfileConfiguration.java
+++ b/idp-testing/src/main/java/net/shibboleth/idp/authn/testing/MockAuthenticationProfileConfiguration.java
@@ -19,7 +19,6 @@ package net.shibboleth.idp.authn.testing;
import java.security.Principal;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
@@ -30,8 +29,6 @@ import javax.annotation.Nullable;
import org.opensaml.profile.context.ProfileRequestContext;
import org.opensaml.xmlsec.config.BasicXMLSecurityConfiguration;
-import com.google.common.base.Predicates;
-
import net.shibboleth.idp.authn.config.AuthenticationProfileConfiguration;
import net.shibboleth.idp.profile.config.AbstractInterceptorAwareProfileConfiguration;
import net.shibboleth.shared.annotation.constraint.NonNegative;
@@ -39,7 +36,9 @@ import net.shibboleth.shared.annotation.constraint.NonnullElements;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
import net.shibboleth.shared.annotation.constraint.NotLive;
import net.shibboleth.shared.annotation.constraint.Unmodifiable;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.logic.PredicateSupport;
import net.shibboleth.shared.primitive.StringSupport;
/** Mock implementation of {@link AuthenticationProfileConfiguration}. */
@@ -47,22 +46,22 @@ public class MockAuthenticationProfileConfiguration extends AbstractInterceptorA
implements AuthenticationProfileConfiguration {
/** Selects, and limits, the authentication methods to use for requests. */
- @Nonnull @NonnullElements private List<Principal> defaultAuthenticationMethods;
+ @Nonnull @NonnullElements private List<Principal> defaultAuthenticationMethods = CollectionSupport.emptyList();
/** Filters the usable authentication flows. */
- @Nonnull @NonnullElements private Set<String> authenticationFlows;
+ @Nonnull @NonnullElements private Set<String> authenticationFlows = CollectionSupport.emptySet();
/** Enables post-authentication interceptor flows. */
- @Nonnull @NonnullElements private List<String> postAuthenticationFlows;
+ @Nonnull @NonnullElements private List<String> postAuthenticationFlows = CollectionSupport.emptyList();
/** Precedence of name identifier formats to use for requests. */
- @Nonnull @NonnullElements private List<String> nameIDFormatPrecedence;
+ @Nonnull @NonnullElements private List<String> nameIDFormatPrecedence = CollectionSupport.emptyList();
/** ForceAuthn predicate. */
@Nonnull private Predicate<ProfileRequestContext> forceAuthnPredicate;
/** Proxy count. */
- @Nonnull private Integer proxyCount;
+ private Integer proxyCount;
/**
* Constructor.
@@ -72,7 +71,7 @@ public class MockAuthenticationProfileConfiguration extends AbstractInterceptorA
*/
public MockAuthenticationProfileConfiguration(@Nonnull @NotEmpty final String id,
@Nonnull @NonnullElements final List<Principal> methods) {
- this(id, methods, Collections.emptySet(), Collections.emptyList());
+ this(id, methods, CollectionSupport.emptySet(), CollectionSupport.emptyList());
}
/**
@@ -92,7 +91,7 @@ public class MockAuthenticationProfileConfiguration extends AbstractInterceptorA
setDefaultAuthenticationMethods(methods);
setAuthenticationFlows(flows);
setNameIDFormatPrecedence(formats);
- forceAuthnPredicate = Predicates.alwaysFalse();
+ forceAuthnPredicate = PredicateSupport.alwaysFalse();
}
/** {@inheritDoc} */
@@ -107,7 +106,7 @@ public class MockAuthenticationProfileConfiguration extends AbstractInterceptorA
* @param methods default authentication methods to use
*/
public void setDefaultAuthenticationMethods(@Nonnull @NonnullElements final List<Principal> methods) {
- defaultAuthenticationMethods = List.copyOf(Constraint.isNotNull(methods, "List of methods cannot be null"));
+ defaultAuthenticationMethods = CollectionSupport.copyToList(Constraint.isNotNull(methods, "List of methods cannot be null"));
}
/**
@@ -129,7 +128,7 @@ public class MockAuthenticationProfileConfiguration extends AbstractInterceptorA
public void setNameIDFormatPrecedence(@Nonnull @NonnullElements final List<String> formats) {
Constraint.isNotNull(formats, "List of formats cannot be null");
- nameIDFormatPrecedence = List.copyOf(StringSupport.normalizeStringCollection(formats));
+ nameIDFormatPrecedence = CollectionSupport.copyToList(StringSupport.normalizeStringCollection(formats));
}
/** {@inheritDoc} */
@@ -146,7 +145,7 @@ public class MockAuthenticationProfileConfiguration extends AbstractInterceptorA
public void setAuthenticationFlows(@Nonnull @NonnullElements final Collection<String> flows) {
Constraint.isNotNull(flows, "Collection of flows cannot be null");
- authenticationFlows = Set.copyOf(StringSupport.normalizeStringCollection(flows));
+ authenticationFlows = CollectionSupport.copyToSet(StringSupport.normalizeStringCollection(flows));
}
/** {@inheritDoc} */
@@ -163,11 +162,11 @@ public class MockAuthenticationProfileConfiguration extends AbstractInterceptorA
public void setPostAuthenticationFlows(@Nonnull @NonnullElements final Collection<String> flows) {
Constraint.isNotNull(flows, "Collection of flows cannot be null");
- postAuthenticationFlows = List.copyOf(StringSupport.normalizeStringCollection(flows));
+ postAuthenticationFlows = CollectionSupport.copyToList(StringSupport.normalizeStringCollection(flows));
}
/** {@inheritDoc} */
- public boolean isForceAuthn(ProfileRequestContext profileRequestContext) {
+ public boolean isForceAuthn(@Nullable ProfileRequestContext profileRequestContext) {
return forceAuthnPredicate.test(profileRequestContext);
}
diff --git a/idp-testing/src/main/java/net/shibboleth/idp/saml/impl/testing/TestSources.java b/idp-testing/src/main/java/net/shibboleth/idp/saml/impl/testing/TestSources.java
index b214c3df3..49f5fbede 100644
--- a/idp-testing/src/main/java/net/shibboleth/idp/saml/impl/testing/TestSources.java
+++ b/idp-testing/src/main/java/net/shibboleth/idp/saml/impl/testing/TestSources.java
@@ -19,7 +19,6 @@ package net.shibboleth.idp.saml.impl.testing;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -46,72 +45,75 @@ import net.shibboleth.idp.saml.attribute.resolver.impl.SAML2NameIDAttributeDefin
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.annotation.constraint.NonnullElements;
import net.shibboleth.shared.annotation.constraint.NullableElements;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.ComponentInitializationException;
/** Basic data sources for testing the attribute generators. */
@SuppressWarnings({"javadoc", "removal"})
public final class TestSources {
/** The name we use in this test for the static connector. */
- public static final String STATIC_CONNECTOR_NAME = "staticCon";
+ @Nonnull public static final String STATIC_CONNECTOR_NAME = "staticCon";
/** The name of the attribute we use as source. */
- public static final String DEPENDS_ON_ATTRIBUTE_NAME_ATTR = "at1";
+ @Nonnull public static final String DEPENDS_ON_ATTRIBUTE_NAME_ATTR = "at1";
- public static final String DEPENDS_ON_ATTRIBUTE_NAME_CONNECTOR = "ac1";
+ @Nonnull public static final String DEPENDS_ON_ATTRIBUTE_NAME_CONNECTOR = "ac1";
/** The name of another attribute we use as source. */
- public static final String DEPENDS_ON_SECOND_ATTRIBUTE_NAME = "at2";
+ @Nonnull public static final String DEPENDS_ON_SECOND_ATTRIBUTE_NAME = "at2";
/** Another attributes values. */
- public static final String[] SECOND_ATTRIBUTE_VALUE_STRINGS = {"at2-Val1", "at2-Val2"};
+ @Nonnull public static final String[] SECOND_ATTRIBUTE_VALUE_STRINGS = {"at2-Val1", "at2-Val2"};
- public static final StringAttributeValue[] SECOND_ATTRIBUTE_VALUE_RESULTS = {
+ @SuppressWarnings("null")
+ @Nonnull public static final StringAttributeValue[] SECOND_ATTRIBUTE_VALUE_RESULTS = {
new StringAttributeValue(SECOND_ATTRIBUTE_VALUE_STRINGS[0]),
new StringAttributeValue(SECOND_ATTRIBUTE_VALUE_STRINGS[0]),};
/** A value from both providers. */
- public static final String COMMON_ATTRIBUTE_VALUE_STRING = "at1-Data";
+ @Nonnull public static final String COMMON_ATTRIBUTE_VALUE_STRING = "at1-Data";
- public static final StringAttributeValue COMMON_ATTRIBUTE_VALUE_RESULT = new StringAttributeValue(
+ @Nonnull public static final StringAttributeValue COMMON_ATTRIBUTE_VALUE_RESULT = new StringAttributeValue(
COMMON_ATTRIBUTE_VALUE_STRING);
/** A value from the connector. */
- public static final String CONNECTOR_ATTRIBUTE_VALUE_STRING = "at1-Connector";
+ @Nonnull public static final String CONNECTOR_ATTRIBUTE_VALUE_STRING = "at1-Connector";
- public static final StringAttributeValue CONNECTOR_ATTRIBUTE_VALUE_RESULT = new StringAttributeValue(
+ @Nonnull public static final StringAttributeValue CONNECTOR_ATTRIBUTE_VALUE_RESULT = new StringAttributeValue(
CONNECTOR_ATTRIBUTE_VALUE_STRING);
/** A value from the attribute. */
- public static final String ATTRIBUTE_ATTRIBUTE_VALUE_STRING = "at1-Attribute";
+ @Nonnull public static final String ATTRIBUTE_ATTRIBUTE_VALUE_STRING = "at1-Attribute";
- public static final StringAttributeValue ATTRIBUTE_ATTRIBUTE_VALUE_RESULT = new StringAttributeValue(
+ @Nonnull public static final StringAttributeValue ATTRIBUTE_ATTRIBUTE_VALUE_RESULT = new StringAttributeValue(
ATTRIBUTE_ATTRIBUTE_VALUE_STRING);
/** Regexp. for CONNECTOR_ATTRIBUTE_VALUE (for map and regexp testing). */
- public static final String CONNECTOR_ATTRIBUTE_VALUE_REGEXP = "at1-(.+)or";
+ @Nonnull public static final String CONNECTOR_ATTRIBUTE_VALUE_REGEXP = "at1-(.+)or";
- public static final Pattern CONNECTOR_ATTRIBUTE_VALUE_REGEXP_PATTERN = Pattern
+ @SuppressWarnings("null")
+ @Nonnull public static final Pattern CONNECTOR_ATTRIBUTE_VALUE_REGEXP_PATTERN = Pattern
.compile(CONNECTOR_ATTRIBUTE_VALUE_REGEXP);
- public static final StringAttributeValue CONNECTOR_ATTRIBUTE_VALUE_REGEXP_RESULT = new StringAttributeValue(
+ @Nonnull public static final StringAttributeValue CONNECTOR_ATTRIBUTE_VALUE_REGEXP_RESULT = new StringAttributeValue(
"Connect");
/** Principal name for Principal method tests */
- public static final String TEST_PRINCIPAL = "PrincipalName";
+ @Nonnull public static final String TEST_PRINCIPAL = "PrincipalName";
/** Relying party name for Principal method tests */
- public static final String TEST_RELYING_PARTY = "RP1";
+ @Nonnull public static final String TEST_RELYING_PARTY = "RP1";
/** Authentication method for Principal method tests */
- public static final String TEST_AUTHN_METHOD = "AuthNmEthod";
+ @Nonnull public static final String TEST_AUTHN_METHOD = "AuthNmEthod";
- public static final String IDP_ENTITY_ID = "https://idp.example.org/idp";
+ @Nonnull public static final String IDP_ENTITY_ID = "https://idp.example.org/idp";
- public static final String PRINCIPAL_ID = "PETER_THE_PRINCIPAL";
+ @Nonnull public static final String PRINCIPAL_ID = "PETER_THE_PRINCIPAL";
- public static final String SP_ENTITY_ID = "https://sp.example.org/sp";
+ @Nonnull public static final String SP_ENTITY_ID = "https://sp.example.org/sp";
/** Constructor. */
private TestSources() {
@@ -141,6 +143,7 @@ public final class TestSources {
* @return The connector
* @throws ComponentInitializationException if we cannot initialized (unlikely)
*/
+ @SuppressWarnings("null")
public static DataConnector populatedStaticConnector() throws ComponentInitializationException {
List<IdPAttribute> attributeSet = new ArrayList<>(2);
@@ -167,7 +170,7 @@ public final class TestSources {
return populatedStaticAttribute(DEPENDS_ON_ATTRIBUTE_NAME_ATTR, 2);
}
- public static AttributeDefinition populatedStaticAttribute(String attributeName,
+ public static AttributeDefinition populatedStaticAttribute(@Nonnull String attributeName,
int attributeValuesCount) throws ComponentInitializationException {
final List<IdPAttributeValue> valuesList = new ArrayList<>();
@@ -204,21 +207,21 @@ public final class TestSources {
return definition;
}
- public static AttributeDefinition nonStringAttributeDefiniton(String name) throws ComponentInitializationException {
+ public static AttributeDefinition nonStringAttributeDefiniton(@Nonnull String name) throws ComponentInitializationException {
final SAML2NameIDAttributeDefinition defn = new SAML2NameIDAttributeDefinition();
defn.setId(name);
// Set the dependency on the data connector
ResolverAttributeDefinitionDependency depend = new ResolverAttributeDefinitionDependency(TestSources.DEPENDS_ON_ATTRIBUTE_NAME_ATTR);
- defn.setAttributeDependencies(Collections.singleton(depend));
+ defn.setAttributeDependencies(CollectionSupport.singleton(depend));
defn.initialize();
return defn;
}
- public static AttributeResolutionContext createResolutionContext(String principal, String issuerID,
- String recipientId) {
+ public static AttributeResolutionContext createResolutionContext(@Nonnull String principal, @Nonnull String issuerID,
+ @Nonnull String recipientId) {
ProfileRequestContext parent = new ProfileRequestContext();
- AttributeResolutionContext retVal = parent.getSubcontext(AttributeResolutionContext.class, true);
+ AttributeResolutionContext retVal = parent.getOrCreateSubcontext(AttributeResolutionContext.class);
retVal.setAttributeIssuerID(issuerID);
retVal.setAttributeRecipientID(recipientId);
@@ -228,7 +231,7 @@ public final class TestSources {
return retVal;
}
- public static ResolverAttributeDefinitionDependency makeAttributeDefinitionDependency(String attributeId) {
+ public static ResolverAttributeDefinitionDependency makeAttributeDefinitionDependency(@Nonnull String attributeId) {
ResolverAttributeDefinitionDependency retVal = new ResolverAttributeDefinitionDependency(attributeId);
return retVal;
}
@@ -238,7 +241,7 @@ public final class TestSources {
if (null == attributeId) {
retVal.setAllAttributes(true);
} else {
- retVal.setAttributeNames(Collections.singleton(attributeId));
+ retVal.setAttributeNames(CollectionSupport.singleton(attributeId));
}
return retVal;
}
@@ -269,8 +272,9 @@ public final class TestSources {
/** {@inheritDoc} */
@Override @Nonnull protected IdPAttribute doAttributeDefinitionResolve(
- final AttributeResolutionContext resolutionContext,
+ final @Nonnull AttributeResolutionContext resolutionContext,
@Nonnull final AttributeResolverWorkContext workContext) throws ResolutionException {
+ assert value != null;
return value;
}
@@ -325,6 +329,7 @@ public final class TestSources {
@Override @Nonnull protected Map<String, IdPAttribute> doDataConnectorResolve(
@Nonnull final AttributeResolutionContext resolutionContext,
@Nonnull final AttributeResolverWorkContext workContext) throws ResolutionException {
+ assert attributes != null;
return attributes;
}
diff --git a/idp-testing/src/main/java/net/shibboleth/idp/saml/profile/testing/ActionTestSupportAction.java b/idp-testing/src/main/java/net/shibboleth/idp/saml/profile/testing/ActionTestSupportAction.java
index 51bc2b613..fda25e605 100644
--- a/idp-testing/src/main/java/net/shibboleth/idp/saml/profile/testing/ActionTestSupportAction.java
+++ b/idp-testing/src/main/java/net/shibboleth/idp/saml/profile/testing/ActionTestSupportAction.java
@@ -20,6 +20,8 @@ package net.shibboleth.idp.saml.profile.testing;
import net.shibboleth.idp.profile.AbstractProfileAction;
import net.shibboleth.shared.component.ComponentInitializationException;
+import javax.annotation.Nonnull;
+
import org.opensaml.profile.context.ProfileRequestContext;
public class ActionTestSupportAction extends AbstractProfileAction {
@@ -30,7 +32,7 @@ public class ActionTestSupportAction extends AbstractProfileAction {
/** {@inheritDoc} */
@Override
- protected void doExecute(ProfileRequestContext profileRequestContext) {
+ protected void doExecute(@Nonnull ProfileRequestContext profileRequestContext) {
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list