[java-opensaml] branch main updated: IDP-2069 - Null Handling Task
Scott Cantor
cantor.2 at osu.edu
Thu Apr 13 12:15:48 UTC 2023
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-opensaml.
View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=c4d54f200a13526ba082a3cfc62035a66c2356f3
The following commit(s) were added to refs/heads/main by this push:
new c4d54f200 IDP-2069 - Null Handling Task
c4d54f200 is described below
commit c4d54f200a13526ba082a3cfc62035a66c2356f3
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Apr 13 08:15:42 2023 -0400
IDP-2069 - Null Handling Task
https://shibboleth.atlassian.net/browse/IDP-2069
Continued cleanup of saml-impl.
---
.../org/opensaml/core/xml/AbstractXMLObject.java | 5 +
.../main/java/org/opensaml/core/xml/XMLObject.java | 10 ++
.../opensaml/messaging/context/MessageContext.java | 18 +++-
.../impl/AddAudienceRestrictionToAssertions.java | 38 ++++---
.../profile/impl/AddInResponseToToResponse.java | 28 +++---
.../impl/AddNotBeforeConditionToAssertions.java | 33 +++---
.../impl/AddNotOnOrAfterConditionToAssertions.java | 54 ++++++----
.../impl/ChainingNameIdentifierGenerator.java | 6 +-
.../impl/PopulateSignatureSigningParameters.java | 6 +-
.../saml/common/profile/impl/SignAssertions.java | 35 +++----
.../common/profile/impl/VerifyChannelBindings.java | 22 ++--
.../impl/AbstractDynamicHTTPMetadataResolver.java | 9 +-
.../resolver/impl/AbstractMetadataResolver.java | 7 +-
.../impl/FileBackedHTTPMetadataResolver.java | 4 +-
.../resolver/impl/FilesystemMetadataResolver.java | 4 +-
.../resolver/impl/HTTPMetadataResolver.java | 6 +-
.../impl/ResourceBackedMetadataResolver.java | 4 +-
.../impl/AddInResponseToToResponseTest.java | 3 +-
.../AddNotBeforeConditionToAssertionsTest.java | 22 ++--
.../AddNotOnOrAfterConditionToAssertionsTest.java | 70 ++++++++-----
.../PopulateSignatureSigningParametersTest.java | 19 ++--
.../common/profile/impl/SignAssertionsTest.java | 15 +--
.../profile/impl/VerifyChannelBindingsTest.java | 23 +++--
.../ext/idpdisco/impl/DiscoveryResponseTest.java | 17 ++--
.../ext/reqattr/impl/RequestedAttributesTest.java | 3 +-
.../saml/ext/saml1md/impl/SourceIDTest.java | 8 +-
.../saml/ext/saml2alg/impl/DigestMethodTest.java | 12 +--
.../saml/ext/saml2alg/impl/SigningMethodTest.java | 18 ++--
.../saml/ext/saml2cb/impl/ChannelBindingsTest.java | 15 ++-
.../ext/saml2delrestrict/impl/DelegateTest.java | 18 ++--
.../impl/DelegationRestrictionTypeTest.java | 15 ++-
.../ext/saml2mdattr/impl/EntityAttributesTest.java | 9 +-
.../saml2mdreqinit/impl/RequestInitiatorTest.java | 5 +-
.../ext/saml2mdrpi/impl/PublicationInfoTest.java | 19 ++--
.../ext/saml2mdrpi/impl/PublicationPathTest.java | 11 +-
.../saml/ext/saml2mdrpi/impl/PublicationTest.java | 11 +-
.../ext/saml2mdrpi/impl/RegistrationInfoTest.java | 20 ++--
.../saml2mdrpi/impl/RegistrationPolicyTest.java | 10 +-
.../saml/ext/saml2mdrpi/impl/UsagePolicyTest.java | 7 +-
.../saml/ext/saml2mdui/impl/DescriptionTest.java | 5 +-
.../saml/ext/saml2mdui/impl/DiscoHintsTest.java | 10 +-
.../opensaml/saml/ext/samlec/impl/EncTypeTest.java | 9 +-
.../saml/ext/samlec/impl/GeneratedKeyTest.java | 9 +-
.../saml/ext/samlec/impl/SessionKeyTest.java | 20 ++--
.../SAML1ArtifactRequestIssuerHandlerTest.java | 4 +-
.../tests/BaseAssertionValidationTest.java | 25 ++++-
.../assertion/tests/MockAssertionValidator.java | 8 +-
.../tests/SAML20AssertionValidatorTest.java | 57 ++++++-----
.../binding/encoding/impl/HTTPPostEncoderTest.java | 55 +++++-----
.../impl/HTTPPostSimpleSignEncoderTest.java | 111 +++++++++++----------
.../saml/saml2/core/tests/AuthnRequestTest.java | 32 ++++--
.../core/tests/ResponseSuccessAuthnAttribTest.java | 56 ++++++++---
.../saml/saml2/core/tests/SignedAssertionTest.java | 33 +++---
.../saml/saml2/ecp/impl/RelayStateTest.java | 15 +--
.../saml2/ecp/impl/RequestAuthenticatedTest.java | 14 ++-
.../opensaml/saml/saml2/ecp/impl/RequestTest.java | 30 +++---
.../opensaml/saml/saml2/ecp/impl/ResponseTest.java | 18 ++--
.../saml2/ecp/impl/SubjectConfirmationTest.java | 7 +-
.../encryption/tests/ComplexEncryptionTest.java | 44 ++++----
.../tests/DecryptionPlusSigningTest.java | 17 ++--
.../saml/saml2/encryption/tests/ECDHTest.java | 57 +++++++----
...cryptedElementTypeEncryptedKeyResolverTest.java | 46 ++++++---
.../encryption/tests/SimpleDecryptionTest.java | 18 ++--
.../saml/saml2/metadata/tests/MetadataTest.java | 6 +-
64 files changed, 801 insertions(+), 544 deletions(-)
diff --git a/opensaml-core-api/src/main/java/org/opensaml/core/xml/AbstractXMLObject.java b/opensaml-core-api/src/main/java/org/opensaml/core/xml/AbstractXMLObject.java
index 1420d2693..8fa995479 100644
--- a/opensaml-core-api/src/main/java/org/opensaml/core/xml/AbstractXMLObject.java
+++ b/opensaml-core-api/src/main/java/org/opensaml/core/xml/AbstractXMLObject.java
@@ -109,6 +109,11 @@ public abstract class AbstractXMLObject implements XMLObject {
return dom;
}
+ /** {@inheritDoc} */
+ @Nonnull public Element ensureDOM() {
+ return Constraint.isNotNull(dom, "DOM was null");
+ }
+
/** {@inheritDoc} */
@Nonnull public QName getElementQName() {
return elementQname;
diff --git a/opensaml-core-api/src/main/java/org/opensaml/core/xml/XMLObject.java b/opensaml-core-api/src/main/java/org/opensaml/core/xml/XMLObject.java
index 901ee623c..666ade984 100644
--- a/opensaml-core-api/src/main/java/org/opensaml/core/xml/XMLObject.java
+++ b/opensaml-core-api/src/main/java/org/opensaml/core/xml/XMLObject.java
@@ -31,6 +31,7 @@ import org.w3c.dom.Element;
import net.shibboleth.shared.annotation.constraint.NotLive;
import net.shibboleth.shared.annotation.constraint.Unmodifiable;
import net.shibboleth.shared.collection.LockableClassToInstanceMultiMap;
+import net.shibboleth.shared.logic.ConstraintViolationException;
/**
* A object that represents an XML element, usually of a specific schema type, that has been unmarshalled into this Java
@@ -53,6 +54,15 @@ public interface XMLObject {
*/
@Nullable public Element getDOM();
+ /**
+ * Gets the DOM representation of this XMLObject, if one exists, or raises a {@link ConstraintViolationException}.
+ *
+ * @return the DOM representation of this XMLObject
+ *
+ * @since 5.0.0
+ */
+ @Nonnull public Element ensureDOM();
+
/**
* Gets the QName for this element. This QName <strong>MUST</strong> contain the namespace URI, namespace prefix,
* and local element name.
diff --git a/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/MessageContext.java b/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/MessageContext.java
index e2b4f0d13..ad5a5ba73 100644
--- a/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/MessageContext.java
+++ b/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/MessageContext.java
@@ -17,8 +17,12 @@
package org.opensaml.messaging.context;
+import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.logic.ConstraintViolationException;
+
/**
* A context component which holds the state related to the processing of a single message.
*
@@ -38,11 +42,23 @@ public final class MessageContext extends BaseContext {
/**
* Get the message represented by the message context.
*
- * @return the message
+ * @return the message or null
*/
@Nullable public Object getMessage() {
return msg;
}
+
+ /**
+ * Get the message represented by the message context, raising a {@link ConstraintViolationException}
+ * if null.
+ *
+ * @return the message
+ *
+ * @since 5.0.0
+ */
+ @Nonnull public Object ensureMessage() {
+ return Constraint.isNotNull(msg, "Message was null");
+ }
/**
* Set the message represented by the message context.
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/AddAudienceRestrictionToAssertions.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/AddAudienceRestrictionToAssertions.java
index f046ed96a..1fc528dc9 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/AddAudienceRestrictionToAssertions.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/AddAudienceRestrictionToAssertions.java
@@ -21,7 +21,6 @@ import java.util.Collection;
import java.util.function.Function;
import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
import org.opensaml.messaging.context.navigate.MessageLookup;
@@ -37,10 +36,12 @@ import org.opensaml.saml.saml1.profile.SAML1ActionSupport;
import org.opensaml.saml.saml2.core.AudienceRestriction;
import org.opensaml.saml.saml2.profile.SAML2ActionSupport;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
/**
* Action adds an audience restriction condition to every assertion contained in a SAML 1/2
@@ -65,13 +66,13 @@ public class AddAudienceRestrictionToAssertions extends AbstractConditionalProfi
@Nonnull private Function<ProfileRequestContext,SAMLObject> responseLookupStrategy;
/** Strategy used to obtain the audiences to add. */
- @Nullable private Function<ProfileRequestContext,Collection<String>> audienceRestrictionsLookupStrategy;
+ @NonnullAfterInit private Function<ProfileRequestContext,Collection<String>> audienceRestrictionsLookupStrategy;
/** Response to modify. */
- @Nullable private SAMLObject response;
+ @NonnullBeforeExec private SAMLObject response;
/** Audiences to add. */
- @Nullable private Collection<String> audiences;
+ @NonnullBeforeExec private Collection<String> audiences;
/**
* Constructor.
@@ -79,7 +80,8 @@ public class AddAudienceRestrictionToAssertions extends AbstractConditionalProfi
public AddAudienceRestrictionToAssertions() {
addingAudiencesToExistingRestriction = true;
- responseLookupStrategy = new MessageLookup<>(SAMLObject.class).compose(new OutboundMessageContextLookup());
+ responseLookupStrategy = new MessageLookup<>(SAMLObject.class).compose(
+ new OutboundMessageContextLookup());
}
/**
@@ -130,6 +132,10 @@ public class AddAudienceRestrictionToAssertions extends AbstractConditionalProfi
@Override
protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+ if (!super.doPreExecute(profileRequestContext)) {
+ return false;
+ }
+
audiences = audienceRestrictionsLookupStrategy.apply(profileRequestContext);
if (audiences == null || audiences.isEmpty()) {
log.debug("{} No audiences to add, nothing to do", getLogPrefix());
@@ -162,23 +168,23 @@ public class AddAudienceRestrictionToAssertions extends AbstractConditionalProfi
return false;
}
- return super.doPreExecute(profileRequestContext);
+ return true;
}
/** {@inheritDoc} */
@Override
protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
- if (response instanceof org.opensaml.saml.saml1.core.Response) {
- for (final org.opensaml.saml.saml1.core.Assertion assertion :
- ((org.opensaml.saml.saml1.core.Response) response).getAssertions()) {
+ if (response instanceof org.opensaml.saml.saml1.core.Response saml1) {
+ for (final var assertion : saml1.getAssertions()) {
+ assert assertion != null;
addAudienceRestriction(profileRequestContext,
SAML1ActionSupport.addConditionsToAssertion(this, assertion));
log.debug("{} Added AudienceRestrictionCondition to Assertion {}", getLogPrefix(), assertion.getID());
}
- } else if (response instanceof org.opensaml.saml.saml2.core.Response) {
- for (final org.opensaml.saml.saml2.core.Assertion assertion :
- ((org.opensaml.saml.saml2.core.Response) response).getAssertions()) {
+ } else if (response instanceof org.opensaml.saml.saml2.core.Response saml2) {
+ for (final var assertion : saml2.getAssertions()) {
+ assert assertion != null;
addAudienceRestriction(profileRequestContext,
SAML2ActionSupport.addConditionsToAssertion(this, assertion));
log.debug("{} Added AudienceRestrictionCondition to Assertion {}", getLogPrefix(), assertion.getID());
@@ -204,7 +210,7 @@ public class AddAudienceRestrictionToAssertions extends AbstractConditionalProfi
org.opensaml.saml.saml1.core.Audience.DEFAULT_ELEMENT_NAME);
for (final String audienceId : audiences) {
log.debug("{} Adding {} as an Audience of the AudienceRestrictionCondition", getLogPrefix(), audienceId);
- final org.opensaml.saml.saml1.core.Audience audience = audienceBuilder.buildObject();
+ final var audience = audienceBuilder.buildObject();
audience.setURI(audienceId);
condition.getAudiences().add(audience);
}
@@ -228,7 +234,7 @@ public class AddAudienceRestrictionToAssertions extends AbstractConditionalProfi
org.opensaml.saml.saml2.core.Audience.DEFAULT_ELEMENT_NAME);
for (final String audienceId : audiences) {
log.debug("{} Adding {} as an Audience of the AudienceRestriction", getLogPrefix(), audienceId);
- final org.opensaml.saml.saml2.core.Audience audience = audienceBuilder.buildObject();
+ final var audience = audienceBuilder.buildObject();
audience.setURI(audienceId);
condition.getAudiences().add(audience);
}
@@ -259,6 +265,7 @@ public class AddAudienceRestrictionToAssertions extends AbstractConditionalProfi
condition = conditions.getAudienceRestrictionConditions().get(0);
}
+ assert condition != null;
return condition;
}
@@ -287,6 +294,7 @@ public class AddAudienceRestrictionToAssertions extends AbstractConditionalProfi
condition = conditions.getAudienceRestrictions().get(0);
}
+ assert condition != null;
return condition;
}
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/AddInResponseToToResponse.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/AddInResponseToToResponse.java
index 07963c81b..a987deb9c 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/AddInResponseToToResponse.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/AddInResponseToToResponse.java
@@ -18,7 +18,6 @@
package org.opensaml.saml.common.profile.impl;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Function;
@@ -39,10 +38,12 @@ import org.opensaml.saml.common.messaging.context.SAMLMessageInfoContext;
import org.opensaml.saml.saml1.core.ResponseAbstractType;
import org.opensaml.saml.saml2.core.StatusResponseType;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
import net.shibboleth.shared.annotation.constraint.NonnullElements;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.shared.primitive.StringSupport;
/**
@@ -66,14 +67,15 @@ public class AddInResponseToToResponse extends AbstractConditionalProfileAction
@Nonnull private Function<ProfileRequestContext,String> requestIdLookupStrategy;
/** Message to modify. */
- @Nullable private SAMLObject response;
+ @NonnullBeforeExec private SAMLObject response;
/** Request ID to populate from. */
- @Nullable private String requestId;
+ @NonnullBeforeExec private String requestId;
/** Constructor. */
public AddInResponseToToResponse() {
- responseLookupStrategy = new MessageLookup<>(SAMLObject.class).compose(new OutboundMessageContextLookup());
+ responseLookupStrategy = new MessageLookup<>(SAMLObject.class).compose(
+ new OutboundMessageContextLookup());
requestIdLookupStrategy = new DefaultRequestIdLookupStrategy();
}
@@ -100,6 +102,11 @@ public class AddInResponseToToResponse extends AbstractConditionalProfileAction
/** {@inheritDoc} */
@Override
protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+
+ if (!super.doPreExecute(profileRequestContext) ) {
+ return false;
+ }
+
log.debug("{} Attempting to add InResponseTo to outgoing Response", getLogPrefix());
response = responseLookupStrategy.apply(profileRequestContext);
@@ -115,7 +122,7 @@ public class AddInResponseToToResponse extends AbstractConditionalProfileAction
return false;
}
- return super.doPreExecute(profileRequestContext);
+ return true;
}
/** {@inheritDoc} */
@@ -146,7 +153,7 @@ public class AddInResponseToToResponse extends AbstractConditionalProfileAction
/** Constructor. */
public DefaultRequestIdLookupStrategy() {
- suppressForBindings = Collections.emptySet();
+ suppressForBindings = CollectionSupport.emptySet();
}
/**
@@ -169,7 +176,7 @@ public class AddInResponseToToResponse extends AbstractConditionalProfileAction
/** {@inheritDoc} */
@Override
@Nullable public String apply(@Nullable final ProfileRequestContext input) {
- final MessageContext inMsgCtx = input.getInboundMessageContext();
+ final MessageContext inMsgCtx = input != null ? input.getInboundMessageContext() : null;
if (inMsgCtx == null) {
log.debug("No inbound message context available");
return null;
@@ -186,11 +193,6 @@ public class AddInResponseToToResponse extends AbstractConditionalProfileAction
}
final SAMLMessageInfoContext infoCtx = inMsgCtx.ensureSubcontext(SAMLMessageInfoContext.class);
- if (infoCtx == null) {
- log.debug("No inbound SAMLMessageInfoContext available");
- return null;
- }
-
return infoCtx.getMessageId();
}
}
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/AddNotBeforeConditionToAssertions.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/AddNotBeforeConditionToAssertions.java
index bd4b588e1..3d0dd2e8c 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/AddNotBeforeConditionToAssertions.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/AddNotBeforeConditionToAssertions.java
@@ -20,7 +20,6 @@ package org.opensaml.saml.common.profile.impl;
import java.util.function.Function;
import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import org.opensaml.messaging.context.navigate.MessageLookup;
import org.opensaml.profile.action.AbstractConditionalProfileAction;
@@ -32,9 +31,10 @@ import org.opensaml.saml.common.SAMLObject;
import org.opensaml.saml.saml1.profile.SAML1ActionSupport;
import org.opensaml.saml.saml2.profile.SAML2ActionSupport;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
/**
* Action that adds the <code>NotBefore</code> attribute to every assertion in a SAML 1/2
@@ -52,11 +52,12 @@ public class AddNotBeforeConditionToAssertions extends AbstractConditionalProfil
@Nonnull private Function<ProfileRequestContext,SAMLObject> responseLookupStrategy;
/** Response to modify. */
- @Nullable private SAMLObject response;
+ @NonnullBeforeExec private SAMLObject response;
/** Constructor. */
public AddNotBeforeConditionToAssertions() {
- responseLookupStrategy = new MessageLookup<>(SAMLObject.class).compose(new OutboundMessageContextLookup());
+ responseLookupStrategy = new MessageLookup<>(SAMLObject.class).compose(
+ new OutboundMessageContextLookup());
}
/**
@@ -81,13 +82,13 @@ public class AddNotBeforeConditionToAssertions extends AbstractConditionalProfil
return false;
}
- if (response instanceof org.opensaml.saml.saml1.core.Response) {
- if (((org.opensaml.saml.saml1.core.Response) response).getAssertions().isEmpty()) {
+ if (response instanceof org.opensaml.saml.saml1.core.Response saml1) {
+ if (saml1.getAssertions().isEmpty()) {
log.debug("{} No assertions available, nothing to do", getLogPrefix());
return false;
}
- } else if (response instanceof org.opensaml.saml.saml2.core.Response) {
- if (((org.opensaml.saml.saml2.core.Response) response).getAssertions().isEmpty()) {
+ } else if (response instanceof org.opensaml.saml.saml2.core.Response saml2) {
+ if (saml2.getAssertions().isEmpty()) {
log.debug("{} No assertions available, nothing to do", getLogPrefix());
return false;
}
@@ -104,19 +105,15 @@ public class AddNotBeforeConditionToAssertions extends AbstractConditionalProfil
@Override
protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
- if (response instanceof org.opensaml.saml.saml1.core.Response) {
- for (final org.opensaml.saml.saml1.core.Assertion assertion :
- ((org.opensaml.saml.saml1.core.Response) response).getAssertions()) {
+ if (response instanceof org.opensaml.saml.saml1.core.Response saml1) {
+ for (final var assertion : saml1.getAssertions()) {
log.debug("{} Added NotBefore condition to Assertion {}", getLogPrefix(), assertion.getID());
- SAML1ActionSupport.addConditionsToAssertion(this, assertion).setNotBefore(
- ((org.opensaml.saml.saml1.core.Response) response).getIssueInstant());
+ SAML1ActionSupport.addConditionsToAssertion(this, assertion).setNotBefore(saml1.getIssueInstant());
}
- } else if (response instanceof org.opensaml.saml.saml2.core.Response) {
- for (final org.opensaml.saml.saml2.core.Assertion assertion :
- ((org.opensaml.saml.saml2.core.Response) response).getAssertions()) {
+ } else if (response instanceof org.opensaml.saml.saml2.core.Response saml2) {
+ for (final var assertion : saml2.getAssertions()) {
log.debug("{} Added NotBefore condition to Assertion {}", getLogPrefix(), assertion.getID());
- SAML2ActionSupport.addConditionsToAssertion(this, assertion).setNotBefore(
- ((org.opensaml.saml.saml2.core.Response) response).getIssueInstant());
+ SAML2ActionSupport.addConditionsToAssertion(this, assertion).setNotBefore(saml2.getIssueInstant());
}
}
}
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/AddNotOnOrAfterConditionToAssertions.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/AddNotOnOrAfterConditionToAssertions.java
index 1f3489e96..3db36af2c 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/AddNotOnOrAfterConditionToAssertions.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/AddNotOnOrAfterConditionToAssertions.java
@@ -34,9 +34,10 @@ import org.opensaml.saml.common.SAMLObject;
import org.opensaml.saml.saml1.profile.SAML1ActionSupport;
import org.opensaml.saml.saml2.profile.SAML2ActionSupport;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
/**
* Action that adds the <code>NotBefore</code> attribute to every assertion in a SAML 1/2
@@ -60,11 +61,12 @@ public class AddNotOnOrAfterConditionToAssertions extends AbstractConditionalPro
@Nonnull private Duration defaultAssertionLifetime;
/** Response to modify. */
- @Nullable private SAMLObject response;
+ @NonnullBeforeExec private SAMLObject response;
/** Constructor. */
public AddNotOnOrAfterConditionToAssertions() {
- responseLookupStrategy = new MessageLookup<>(SAMLObject.class).compose(new OutboundMessageContextLookup());
+ responseLookupStrategy = new MessageLookup<>(SAMLObject.class).compose(
+ new OutboundMessageContextLookup());
defaultAssertionLifetime = Duration.ofMinutes(5);
}
@@ -105,6 +107,11 @@ public class AddNotOnOrAfterConditionToAssertions extends AbstractConditionalPro
/** {@inheritDoc} */
@Override
protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+
+ if (!super.doPreExecute(profileRequestContext)) {
+ return false;
+ }
+
log.debug("{} Attempting to add NotOnOrAfter condition to every Assertion in outgoing Response",
getLogPrefix());
@@ -115,13 +122,13 @@ public class AddNotOnOrAfterConditionToAssertions extends AbstractConditionalPro
return false;
}
- if (response instanceof org.opensaml.saml.saml1.core.Response) {
- if (((org.opensaml.saml.saml1.core.Response) response).getAssertions().isEmpty()) {
+ if (response instanceof org.opensaml.saml.saml1.core.Response saml1) {
+ if (saml1.getAssertions().isEmpty()) {
log.debug("{} No assertions available, nothing to do", getLogPrefix());
return false;
}
- } else if (response instanceof org.opensaml.saml.saml2.core.Response) {
- if (((org.opensaml.saml.saml2.core.Response) response).getAssertions().isEmpty()) {
+ } else if (response instanceof org.opensaml.saml.saml2.core.Response saml2) {
+ if (saml2.getAssertions().isEmpty()) {
log.debug("{} No assertions available, nothing to do", getLogPrefix());
return false;
}
@@ -131,35 +138,38 @@ public class AddNotOnOrAfterConditionToAssertions extends AbstractConditionalPro
return false;
}
- return super.doPreExecute(profileRequestContext);
+ return true;
}
/** {@inheritDoc} */
@Override
protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
- final Duration lifetime = assertionLifetimeStrategy != null ?
- assertionLifetimeStrategy.apply(profileRequestContext) : null;
+ Duration lifetime = assertionLifetimeStrategy != null
+ ? assertionLifetimeStrategy.apply(profileRequestContext) : null;
if (lifetime == null) {
log.debug("{} No assertion lifetime supplied, using default", getLogPrefix());
+ lifetime = defaultAssertionLifetime;
}
- if (response instanceof org.opensaml.saml.saml1.core.Response) {
- for (final org.opensaml.saml.saml1.core.Assertion assertion :
- ((org.opensaml.saml.saml1.core.Response) response).getAssertions()) {
-
- final Instant expiration =
- assertion.getIssueInstant().plus(lifetime != null ? lifetime : defaultAssertionLifetime);
+ if (response instanceof org.opensaml.saml.saml1.core.Response saml1) {
+ for (final var assertion : saml1.getAssertions()) {
+ Instant issueInstant = assertion.getIssueInstant();
+ if (issueInstant == null) {
+ issueInstant = Instant.now();
+ }
+ final Instant expiration = issueInstant.plus(lifetime);
log.debug("{} Added NotOnOrAfter condition, indicating an expiration of {}, to Assertion {}",
new Object[] {getLogPrefix(), expiration, assertion.getID()});
SAML1ActionSupport.addConditionsToAssertion(this, assertion).setNotOnOrAfter(expiration);
}
- } else if (response instanceof org.opensaml.saml.saml2.core.Response) {
- for (final org.opensaml.saml.saml2.core.Assertion assertion :
- ((org.opensaml.saml.saml2.core.Response) response).getAssertions()) {
-
- final Instant expiration =
- assertion.getIssueInstant().plus(lifetime != null ? lifetime : defaultAssertionLifetime);
+ } else if (response instanceof org.opensaml.saml.saml2.core.Response saml2) {
+ for (final var assertion : saml2.getAssertions()) {
+ Instant issueInstant = assertion.getIssueInstant();
+ if (issueInstant == null) {
+ issueInstant = Instant.now();
+ }
+ final Instant expiration = issueInstant.plus(lifetime);
log.debug("{} Added NotOnOrAfter condition, indicating an expiration of {}, to Assertion {}",
new Object[] {getLogPrefix(), expiration, assertion.getID()});
SAML2ActionSupport.addConditionsToAssertion(this, assertion).setNotOnOrAfter(expiration);
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/ChainingNameIdentifierGenerator.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/ChainingNameIdentifierGenerator.java
index 9b779e324..34430775f 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/ChainingNameIdentifierGenerator.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/ChainingNameIdentifierGenerator.java
@@ -23,10 +23,10 @@ import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import net.shibboleth.shared.annotation.constraint.NonnullElements;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
import net.shibboleth.shared.annotation.constraint.NullableElements;
import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
import org.opensaml.profile.context.ProfileRequestContext;
import org.opensaml.saml.common.SAMLException;
@@ -34,7 +34,6 @@ import org.opensaml.saml.common.SAMLObject;
import org.opensaml.saml.common.profile.FormatSpecificNameIdentifierGenerator;
import org.opensaml.saml.common.profile.NameIdentifierGenerator;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
@@ -52,7 +51,7 @@ public class ChainingNameIdentifierGenerator<NameIdType extends SAMLObject>
@Nonnull private final Logger log = LoggerFactory.getLogger(ChainingNameIdentifierGenerator.class);
/** Map of formats to generators. */
- @Nonnull @NonnullElements private ListMultimap<String,NameIdentifierGenerator<NameIdType>> nameIdGeneratorMap;
+ @Nonnull private ListMultimap<String,NameIdentifierGenerator<NameIdType>> nameIdGeneratorMap;
/** Fallback generator, generally for legacy support. */
@Nullable private NameIdentifierGenerator<NameIdType> defaultNameIdGenerator;
@@ -96,7 +95,6 @@ public class ChainingNameIdentifierGenerator<NameIdType extends SAMLObject>
}
/** {@inheritDoc} */
- @Override
@Nullable public NameIdType generate(@Nonnull final ProfileRequestContext profileRequestContext,
@Nonnull @NotEmpty final String format) throws SAMLException {
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/PopulateSignatureSigningParameters.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/PopulateSignatureSigningParameters.java
index 5f2e1b923..c49cf9cd1 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/PopulateSignatureSigningParameters.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/PopulateSignatureSigningParameters.java
@@ -38,11 +38,11 @@ import org.opensaml.xmlsec.SignatureSigningParameters;
import org.opensaml.xmlsec.SignatureSigningParametersResolver;
import org.opensaml.xmlsec.context.SecurityParametersContext;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
/**
* Action that resolves and populates {@link SignatureSigningParameters} on a {@link SecurityParametersContext}
@@ -188,8 +188,8 @@ public class PopulateSignatureSigningParameters
final PopulateSignatureSigningParametersHandler delegate = getDelegate();
delegate.setNoResultIsError(noResultIsError);
delegate.setSignatureSigningParametersResolver(resolver);
- delegate.setConfigurationLookupStrategy(adapt(configurationLookupStrategy));
- delegate.setSecurityParametersContextLookupStrategy(adapt(securityParametersContextLookupStrategy));
+ delegate.setConfigurationLookupStrategy(adaptRequired(configurationLookupStrategy));
+ delegate.setSecurityParametersContextLookupStrategy(adaptRequired(securityParametersContextLookupStrategy));
delegate.setExistingParametersContextLookupStrategy(adapt(existingParametersContextLookupStrategy));
delegate.setMetadataContextLookupStrategy(adapt(metadataContextLookupStrategy));
delegate.initialize();
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/SignAssertions.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/SignAssertions.java
index 3157edbab..5f23461d1 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/SignAssertions.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/SignAssertions.java
@@ -20,7 +20,6 @@ package org.opensaml.saml.common.profile.impl;
import java.util.function.Function;
import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import org.opensaml.core.xml.io.MarshallingException;
import org.opensaml.core.xml.util.XMLObjectSupport;
@@ -39,10 +38,11 @@ import org.opensaml.xmlsec.context.SecurityParametersContext;
import org.opensaml.xmlsec.signature.support.SignatureException;
import org.opensaml.xmlsec.signature.support.SignatureSupport;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.shared.xml.SerializeSupport;
/**
@@ -67,14 +67,15 @@ public class SignAssertions extends AbstractProfileAction {
@Nonnull private Function<ProfileRequestContext,SecurityParametersContext> securityParametersLookupStrategy;
/** The signature signing parameters. */
- @Nullable private SignatureSigningParameters signatureSigningParameters;
+ @NonnullBeforeExec private SignatureSigningParameters signatureSigningParameters;
/** The response containing the assertions to be signed. */
- @Nullable private SAMLObject response;
+ @NonnullBeforeExec private SAMLObject response;
/** Constructor. */
public SignAssertions() {
- responseLookupStrategy = new MessageLookup<>(SAMLObject.class).compose(new OutboundMessageContextLookup());
+ responseLookupStrategy = new MessageLookup<>(SAMLObject.class).compose(
+ new OutboundMessageContextLookup());
securityParametersLookupStrategy = new ChildContextLookup<>(SecurityParametersContext.class);
}
@@ -116,18 +117,18 @@ public class SignAssertions extends AbstractProfileAction {
}
// Step down into ArtifactResponses.
- if (response instanceof ArtifactResponse) {
+ if (response instanceof ArtifactResponse resp) {
log.debug("{} Found ArtifactResponse, stepping down into enclosed message", getLogPrefix());
- response = ((ArtifactResponse) response).getMessage();
+ response = resp.getMessage();
}
- if (response instanceof org.opensaml.saml.saml1.core.Response) {
- if (((org.opensaml.saml.saml1.core.Response) response).getAssertions().isEmpty()) {
+ if (response instanceof org.opensaml.saml.saml1.core.Response saml1) {
+ if (saml1.getAssertions().isEmpty()) {
log.debug("{} No assertions available, nothing to do", getLogPrefix());
return false;
}
- } else if (response instanceof org.opensaml.saml.saml2.core.Response) {
- if (((org.opensaml.saml.saml2.core.Response) response).getAssertions().isEmpty()) {
+ } else if (response instanceof org.opensaml.saml.saml2.core.Response saml2) {
+ if (saml2.getAssertions().isEmpty()) {
log.debug("{} No assertions available, nothing to do", getLogPrefix());
return false;
}
@@ -161,14 +162,14 @@ public class SignAssertions extends AbstractProfileAction {
logResponse("Response before signing:");
}
- if (response instanceof org.opensaml.saml.saml1.core.Response) {
- for (final org.opensaml.saml.saml1.core.Assertion assertion :
- ((org.opensaml.saml.saml1.core.Response) response).getAssertions()) {
+ if (response instanceof org.opensaml.saml.saml1.core.Response saml1) {
+ for (final var assertion : saml1.getAssertions()) {
+ assert assertion != null;
SignatureSupport.signObject(assertion, signatureSigningParameters);
}
- } else if (response instanceof org.opensaml.saml.saml2.core.Response) {
- for (final org.opensaml.saml.saml2.core.Assertion assertion :
- ((org.opensaml.saml.saml2.core.Response) response).getAssertions()) {
+ } else if (response instanceof org.opensaml.saml.saml2.core.Response saml2) {
+ for (final var assertion : saml2.getAssertions()) {
+ assert assertion != null;
SignatureSupport.signObject(assertion, signatureSigningParameters);
}
}
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/VerifyChannelBindings.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/VerifyChannelBindings.java
index ebb194ff3..0eb3c949f 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/VerifyChannelBindings.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/common/profile/impl/VerifyChannelBindings.java
@@ -21,7 +21,6 @@ import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import org.opensaml.messaging.context.navigate.ChildContextLookup;
import org.opensaml.profile.action.AbstractProfileAction;
@@ -34,9 +33,10 @@ import org.opensaml.saml.common.profile.SAMLEventIds;
import org.opensaml.saml.ext.saml2cb.ChannelBindings;
import org.opensaml.soap.messaging.context.SOAP11Context;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.shared.primitive.StringSupport;
/**
@@ -72,10 +72,10 @@ public class VerifyChannelBindings extends AbstractProfileAction {
@Nonnull private Function<ProfileRequestContext,ChannelBindingsContext> channelBindingsCreationStrategy;
/** The first set of bindings. */
- @Nullable private ChannelBindingsContext channelBindingsContext1;
+ @NonnullBeforeExec private ChannelBindingsContext channelBindingsContext1;
/** The second set of bindings. */
- @Nullable private ChannelBindingsContext channelBindingsContext2;
+ @NonnullBeforeExec private ChannelBindingsContext channelBindingsContext2;
/** Constructor. */
public VerifyChannelBindings() {
@@ -152,7 +152,13 @@ public class VerifyChannelBindings extends AbstractProfileAction {
log.debug("{} No channel bindings found to verify, nothing to do", getLogPrefix());
return false;
}
-
+
+ if (channelBindingsContext1 == null || channelBindingsContext2 == null) {
+ log.warn("{} Unable to verify channel bindings sent for comparison", getLogPrefix());
+ ActionSupport.buildEvent(profileRequestContext, SAMLEventIds.CHANNEL_BINDINGS_ERROR);
+ return false;
+ }
+
return true;
}
@@ -161,12 +167,6 @@ public class VerifyChannelBindings extends AbstractProfileAction {
@Override
protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
- if (channelBindingsContext1 == null || channelBindingsContext2 == null) {
- log.warn("{} Unable to verify channel bindings sent for comparison", getLogPrefix());
- ActionSupport.buildEvent(profileRequestContext, SAMLEventIds.CHANNEL_BINDINGS_ERROR);
- return;
- }
-
ChannelBindings matched = null;
for (final ChannelBindings cb1 : channelBindingsContext1.getChannelBindings()) {
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicHTTPMetadataResolver.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicHTTPMetadataResolver.java
index a3b330eff..93ddbf0a6 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicHTTPMetadataResolver.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicHTTPMetadataResolver.java
@@ -80,7 +80,7 @@ public abstract class AbstractDynamicHTTPMetadataResolver extends AbstractDynami
@Nonnull private final Logger log = LoggerFactory.getLogger(AbstractDynamicHTTPMetadataResolver.class);
/** HTTP Client used to pull the metadata. */
- @Nonnull private HttpClient httpClient;
+ @NonnullAfterInit private HttpClient httpClient;
/** List of supported MIME types for use in Accept request header and validation of
* response Content-Type header.*/
@@ -226,7 +226,7 @@ public abstract class AbstractDynamicHTTPMetadataResolver extends AbstractDynami
setSupportedContentTypes(Arrays.asList(DEFAULT_CONTENT_TYPES));
}
- if (! getSupportedContentTypes().isEmpty()) {
+ if (!getSupportedContentTypes().isEmpty()) {
supportedContentTypesValue = StringSupport.listToStringValue(getSupportedContentTypes(), ", ");
supportedMediaTypes = new LazySet<>();
for (final String contentType : getSupportedContentTypes()) {
@@ -242,6 +242,7 @@ public abstract class AbstractDynamicHTTPMetadataResolver extends AbstractDynami
/** {@inheritDoc} */
@Override
protected void doDestroy() {
+ // TODO: if we pull this, httpClient should be Nonnull.
httpClient = null;
httpClientSecurityParameters = null;
@@ -332,7 +333,6 @@ public abstract class AbstractDynamicHTTPMetadataResolver extends AbstractDynami
public class BasicMetadataResponseHandler implements HttpClientResponseHandler<XMLObject> {
/** {@inheritDoc} */
- @Override
public XMLObject handleResponse(final ClassicHttpResponse response) throws IOException {
final int httpStatusCode = response.getCode();
@@ -363,6 +363,7 @@ public abstract class AbstractDynamicHTTPMetadataResolver extends AbstractDynami
try {
final InputStream ins = response.getEntity().getContent();
final byte[] source = ByteStreams.toByteArray(ins);
+ assert source != null;
try (final ByteArrayInputStream bais = new ByteArrayInputStream(source)) {
final XMLObject xmlObject = unmarshallMetadata(bais);
xmlObject.getObjectMetadata().put(new XMLObjectSource(source));
@@ -381,7 +382,7 @@ public abstract class AbstractDynamicHTTPMetadataResolver extends AbstractDynami
* @param response the received response
* @throws ResolverException if the response was not valid, or if there is a fatal error validating the response
*/
- protected void validateHttpResponse(final ClassicHttpResponse response) throws ResolverException {
+ protected void validateHttpResponse(@Nonnull final ClassicHttpResponse response) throws ResolverException {
if (!getSupportedMediaTypes().isEmpty()) {
final String contentType = StringSupport.trimOrNull(response.getEntity().getContentType());
log.debug("{} Saw raw Content-Type from response header '{}'", getLogPrefix(), contentType);
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractMetadataResolver.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractMetadataResolver.java
index 69bc22b47..41a52a8bc 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractMetadataResolver.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractMetadataResolver.java
@@ -79,7 +79,7 @@ public abstract class AbstractMetadataResolver extends AbstractIdentifiableIniti
@Nonnull private final Logger log = LoggerFactory.getLogger(AbstractMetadataResolver.class);
/** Unmarshaller factory used to get an unmarshaller for the metadata DOM. */
- @Nonnull private UnmarshallerFactory unmarshallerFactory;
+ @NonnullAfterInit private UnmarshallerFactory unmarshallerFactory;
/** Whether metadata is required to be valid. */
private boolean requireValidMetadata;
@@ -320,7 +320,7 @@ public abstract class AbstractMetadataResolver extends AbstractIdentifiableIniti
*
* @return the unmarshaller factory instance to use
*/
- @Nonnull protected UnmarshallerFactory getUnmarshallerFactory() {
+ @NonnullAfterInit protected UnmarshallerFactory getUnmarshallerFactory() {
return unmarshallerFactory;
}
@@ -343,6 +343,7 @@ public abstract class AbstractMetadataResolver extends AbstractIdentifiableIniti
/** {@inheritDoc} */
@Override protected void doDestroy() {
+ // TODO: if we pull this, unmarshallerFactory should be Nonnull.
unmarshallerFactory = null;
mdFilter = null;
entityBackingStore = null;
@@ -631,7 +632,7 @@ public abstract class AbstractMetadataResolver extends AbstractIdentifiableIniti
* @param backingStore the backing store instance to update
*/
protected void preProcessEntitiesDescriptor(@Nonnull final EntitiesDescriptor entitiesDescriptor,
- final EntityBackingStore backingStore) {
+ @Nonnull final EntityBackingStore backingStore) {
// TODO: If order doesn't matter here, we should change to use the non-null getters of the specific child types.
final List<XMLObject> children = entitiesDescriptor.getOrderedChildren();
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/FileBackedHTTPMetadataResolver.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/FileBackedHTTPMetadataResolver.java
index 4a9948d2e..4b8fdf439 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/FileBackedHTTPMetadataResolver.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/FileBackedHTTPMetadataResolver.java
@@ -37,6 +37,7 @@ import org.w3c.dom.Document;
import com.google.common.io.Files;
+import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.LoggerFactory;
@@ -66,7 +67,7 @@ public class FileBackedHTTPMetadataResolver extends HTTPMetadataResolver {
@Nonnull private final Logger log = LoggerFactory.getLogger(FileBackedHTTPMetadataResolver.class);
/** File containing the backup of the metadata. */
- @Nonnull private File metadataBackupFile;
+ @NonnullAfterInit private File metadataBackupFile;
/** Flag used to track state of whether currently initializing or not. */
private boolean initializing;
@@ -181,6 +182,7 @@ public class FileBackedHTTPMetadataResolver extends HTTPMetadataResolver {
/** {@inheritDoc} */
@Override
protected void doDestroy() {
+ // TODO: if we pull this, becomes Nonnull.
metadataBackupFile = null;
super.doDestroy();
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/FilesystemMetadataResolver.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/FilesystemMetadataResolver.java
index 12a3c878a..f0ac617a1 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/FilesystemMetadataResolver.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/FilesystemMetadataResolver.java
@@ -28,6 +28,7 @@ import javax.annotation.Nullable;
import org.slf4j.Logger;
+import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.shared.resolver.ResolverException;
@@ -53,7 +54,7 @@ public class FilesystemMetadataResolver extends AbstractReloadingMetadataResolve
@Nonnull private final Logger log = LoggerFactory.getLogger(FilesystemMetadataResolver.class);
/** The metadata file. */
- @Nonnull private File metadataFile;
+ @NonnullAfterInit private File metadataFile;
/**
* Constructor.
@@ -96,6 +97,7 @@ public class FilesystemMetadataResolver extends AbstractReloadingMetadataResolve
/** {@inheritDoc} */
@Override
protected void doDestroy() {
+ // TODO: if we pull this, becomes Nonnull.
metadataFile = null;
super.doDestroy();
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/HTTPMetadataResolver.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/HTTPMetadataResolver.java
index 1e425f6a4..9960d2dd4 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/HTTPMetadataResolver.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/HTTPMetadataResolver.java
@@ -39,6 +39,7 @@ import org.opensaml.security.httpclient.HttpClientSecurityParameters;
import org.opensaml.security.httpclient.HttpClientSecuritySupport;
import org.slf4j.Logger;
+import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.shared.resolver.ResolverException;
@@ -63,10 +64,10 @@ public class HTTPMetadataResolver extends AbstractReloadingMetadataResolver {
@Nonnull private final Logger log = LoggerFactory.getLogger(HTTPMetadataResolver.class);
/** HTTP Client used to pull the metadata. */
- @Nonnull private HttpClient httpClient;
+ @NonnullAfterInit private HttpClient httpClient;
/** URL to the Metadata. */
- @Nonnull private URI metadataURI;
+ @NonnullAfterInit private URI metadataURI;
/** The ETag provided when the currently cached metadata was fetched. */
@Nullable private String cachedMetadataETag;
@@ -174,6 +175,7 @@ public class HTTPMetadataResolver extends AbstractReloadingMetadataResolver {
/** {@inheritDoc} */
@Override
protected void doDestroy() {
+ // TODO: if we pull this, httpClient and metadataURI become Nonnull.
httpClient = null;
httpClientSecurityParameters = null;
metadataURI = null;
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/ResourceBackedMetadataResolver.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/ResourceBackedMetadataResolver.java
index 94298edcd..62e7867a1 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/ResourceBackedMetadataResolver.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/ResourceBackedMetadataResolver.java
@@ -27,6 +27,7 @@ import javax.annotation.Nullable;
import org.slf4j.Logger;
import net.shibboleth.shared.annotation.ParameterName;
+import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
import net.shibboleth.shared.primitive.LoggerFactory;
import net.shibboleth.shared.resolver.ResolverException;
import net.shibboleth.shared.resource.Resource;
@@ -42,7 +43,7 @@ public class ResourceBackedMetadataResolver extends AbstractReloadingMetadataRes
@Nonnull private final Logger log = LoggerFactory.getLogger(ResourceBackedMetadataResolver.class);
/** Resource from which metadata is read. */
- @Nonnull private Resource metadataResource;
+ @NonnullAfterInit private Resource metadataResource;
/**
* Constructor.
@@ -81,6 +82,7 @@ public class ResourceBackedMetadataResolver extends AbstractReloadingMetadataRes
/** {@inheritDoc} */
@Override
protected void doDestroy() {
+ // If we pull this, becomes Nonnull.
metadataResource = null;
super.doDestroy();
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/AddInResponseToToResponseTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/AddInResponseToToResponseTest.java
index 034468ada..6889a7ee3 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/AddInResponseToToResponseTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/AddInResponseToToResponseTest.java
@@ -34,7 +34,8 @@ import org.testng.annotations.Test;
import net.shibboleth.shared.component.ComponentInitializationException;
/** {@link AddInResponseToToResponse} unit test. */
-public class AddInResponseToToResponseTest extends OpenSAMLInitBaseTestCase {
+ at SuppressWarnings("javadoc")
+public class AddInResponseToToResponseTest extends OpenSAMLInitBaseTestCase {
private ProfileRequestContext prc;
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/AddNotBeforeConditionToAssertionsTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/AddNotBeforeConditionToAssertionsTest.java
index 6ff4ee49f..c24ea8d86 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/AddNotBeforeConditionToAssertionsTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/AddNotBeforeConditionToAssertionsTest.java
@@ -90,8 +90,9 @@ public class AddNotBeforeConditionToAssertionsTest extends OpenSAMLInitBaseTest
Assert.assertNotNull(response.getAssertions());
Assert.assertEquals(response.getAssertions().size(), 1);
- Assert.assertNotNull(assertion.getConditions());
- Assert.assertNotNull(assertion.getConditions().getNotBefore());
+ final Conditions c = assertion.getConditions();
+ assert c != null;
+ Assert.assertNotNull(c.getNotBefore());
}
/**
@@ -115,9 +116,10 @@ public class AddNotBeforeConditionToAssertionsTest extends OpenSAMLInitBaseTest
action.execute(prc);
ActionTestingSupport.assertProceedEvent(prc);
- Assert.assertNotNull(assertion.getConditions());
- Assert.assertSame(assertion.getConditions(), conditions);
- Assert.assertNotNull(assertion.getConditions().getNotBefore());
+ final Conditions c = assertion.getConditions();
+ assert c != null;
+ Assert.assertSame(c, conditions);
+ Assert.assertNotNull(c.getNotBefore());
}
/** Test that the condition is properly added if there are multiple assertions in the response. */
@@ -136,8 +138,9 @@ public class AddNotBeforeConditionToAssertionsTest extends OpenSAMLInitBaseTest
Assert.assertEquals(response.getAssertions().size(), 3);
for (final Assertion assertion : response.getAssertions()) {
- Assert.assertNotNull(assertion.getConditions());
- Assert.assertNotNull(assertion.getConditions().getNotBefore());
+ final Conditions c = assertion.getConditions();
+ assert c != null;
+ Assert.assertNotNull(c.getNotBefore());
}
}
@@ -159,8 +162,9 @@ public class AddNotBeforeConditionToAssertionsTest extends OpenSAMLInitBaseTest
Assert.assertNotNull(response.getAssertions());
Assert.assertEquals(response.getAssertions().size(), 1);
- Assert.assertNotNull(assertion.getConditions());
- Assert.assertNotNull(assertion.getConditions().getNotBefore());
+ final var c = response.getAssertions().get(0).getConditions();
+ assert c != null;
+ Assert.assertNotNull(c.getNotBefore());
}
}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/AddNotOnOrAfterConditionToAssertionsTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/AddNotOnOrAfterConditionToAssertionsTest.java
index 6b8c09358..02cbb10eb 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/AddNotOnOrAfterConditionToAssertionsTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/AddNotOnOrAfterConditionToAssertionsTest.java
@@ -21,6 +21,7 @@ import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.FunctionSupport;
import java.time.Duration;
+import java.time.Instant;
import org.opensaml.core.testing.OpenSAMLInitBaseTestCase;
import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
@@ -45,6 +46,11 @@ public class AddNotOnOrAfterConditionToAssertionsTest extends OpenSAMLInitBaseT
private AddNotOnOrAfterConditionToAssertions action;
+ /**
+ * Test set up.
+ *
+ * @throws ComponentInitializationException
+ */
@BeforeMethod
public void setUp() throws ComponentInitializationException {
prc = new RequestContextBuilder().setOutboundMessage(
@@ -79,7 +85,8 @@ public class AddNotOnOrAfterConditionToAssertionsTest extends OpenSAMLInitBaseT
public void testSingleAssertion() {
final Assertion assertion = SAML1ActionTestingSupport.buildAssertion();
- final Response response = (Response) prc.getOutboundMessageContext().getMessage();
+ final Response response = (Response) prc.ensureOutboundMessageContext().getMessage();
+ assert response != null;
response.getAssertions().add(assertion);
action.execute(prc);
@@ -88,11 +95,14 @@ public class AddNotOnOrAfterConditionToAssertionsTest extends OpenSAMLInitBaseT
Assert.assertNotNull(response.getAssertions());
Assert.assertEquals(response.getAssertions().size(), 1);
- Assert.assertNotNull(assertion.getConditions());
- Assert.assertNotNull(assertion.getConditions().getNotOnOrAfter());
- Assert.assertEquals(
- assertion.getConditions().getNotOnOrAfter().minusMillis(response.getIssueInstant().toEpochMilli()).toEpochMilli(),
- 5 * 60 * 1000);
+ final Conditions c = response.getAssertions().get(0).getConditions();
+ assert c != null;
+
+ final Instant i1 = c.getNotOnOrAfter();
+ final Instant i2 = response.getIssueInstant();
+ assert i1 != null;
+ assert i2 != null;
+ Assert.assertEquals(i1.minusMillis(i2.toEpochMilli()).toEpochMilli(), 5 * 60 * 1000);
}
/**
@@ -111,7 +121,8 @@ public class AddNotOnOrAfterConditionToAssertionsTest extends OpenSAMLInitBaseT
final Assertion assertion = SAML1ActionTestingSupport.buildAssertion();
assertion.setConditions(conditions);
- final Response response = (Response) prc.getOutboundMessageContext().getMessage();
+ final Response response = (Response) prc.ensureOutboundMessageContext().getMessage();
+ assert response != null;
response.getAssertions().add(assertion);
final AddNotOnOrAfterConditionToAssertions action = new AddNotOnOrAfterConditionToAssertions();
@@ -121,12 +132,14 @@ public class AddNotOnOrAfterConditionToAssertionsTest extends OpenSAMLInitBaseT
action.execute(prc);
ActionTestingSupport.assertProceedEvent(prc);
- Assert.assertNotNull(assertion.getConditions());
- Assert.assertSame(assertion.getConditions(), conditions);
- Assert.assertNotNull(assertion.getConditions().getNotOnOrAfter());
- Assert.assertEquals(
- assertion.getConditions().getNotOnOrAfter().minusMillis(response.getIssueInstant().toEpochMilli()).toEpochMilli(),
- 10 * 60 * 1000);
+ final Conditions c = response.getAssertions().get(0).getConditions();
+ assert c != null;
+ Assert.assertSame(c, conditions);
+ final Instant i1 = c.getNotOnOrAfter();
+ final Instant i2 = response.getIssueInstant();
+ assert i1 != null;
+ assert i2 != null;
+ Assert.assertEquals(i1.minusMillis(i2.toEpochMilli()).toEpochMilli(), 10 * 60 * 1000);
}
/**
@@ -136,7 +149,8 @@ public class AddNotOnOrAfterConditionToAssertionsTest extends OpenSAMLInitBaseT
*/
@Test
public void testMultipleAssertion() throws ComponentInitializationException {
- final Response response = (Response) prc.getOutboundMessageContext().getMessage();
+ final Response response = (Response) prc.ensureOutboundMessageContext().getMessage();
+ assert response != null;
response.getAssertions().add(SAML1ActionTestingSupport.buildAssertion());
response.getAssertions().add(SAML1ActionTestingSupport.buildAssertion());
response.getAssertions().add(SAML1ActionTestingSupport.buildAssertion());
@@ -152,11 +166,13 @@ public class AddNotOnOrAfterConditionToAssertionsTest extends OpenSAMLInitBaseT
Assert.assertEquals(response.getAssertions().size(), 3);
for (final Assertion assertion : response.getAssertions()) {
- Assert.assertNotNull(assertion.getConditions());
- Assert.assertNotNull(assertion.getConditions().getNotOnOrAfter());
- Assert.assertEquals(
- assertion.getConditions().getNotOnOrAfter().minusMillis(response.getIssueInstant().toEpochMilli()).toEpochMilli(),
- 3 * 60 * 1000);
+ final Conditions c = assertion.getConditions();
+ assert c != null;
+ final Instant i1 = c.getNotOnOrAfter();
+ final Instant i2 = response.getIssueInstant();
+ assert i1 != null;
+ assert i2 != null;
+ Assert.assertEquals(i1.minusMillis(i2.toEpochMilli()).toEpochMilli(), 3 * 60 * 1000);
}
}
@@ -169,7 +185,7 @@ public class AddNotOnOrAfterConditionToAssertionsTest extends OpenSAMLInitBaseT
final org.opensaml.saml.saml2.core.Assertion assertion = SAML2ActionTestingSupport.buildAssertion();
final org.opensaml.saml.saml2.core.Response response = SAML2ActionTestingSupport.buildResponse();
response.getAssertions().add(assertion);
- prc.getOutboundMessageContext().setMessage(response);
+ prc.ensureOutboundMessageContext().setMessage(response);
action.execute(prc);
ActionTestingSupport.assertProceedEvent(prc);
@@ -177,11 +193,13 @@ public class AddNotOnOrAfterConditionToAssertionsTest extends OpenSAMLInitBaseT
Assert.assertNotNull(response.getAssertions());
Assert.assertEquals(response.getAssertions().size(), 1);
- Assert.assertNotNull(assertion.getConditions());
- Assert.assertNotNull(assertion.getConditions().getNotOnOrAfter());
- Assert.assertEquals(
- assertion.getConditions().getNotOnOrAfter().minusMillis(response.getIssueInstant().toEpochMilli()).toEpochMilli(),
- 5 * 60 * 1000);
+ final var c = response.getAssertions().get(0).getConditions();
+ assert c != null;
+ final Instant i1 = c.getNotOnOrAfter();
+ final Instant i2 = response.getIssueInstant();
+ assert i1 != null;
+ assert i2 != null;
+ Assert.assertEquals(i1.minusMillis(i2.toEpochMilli()).toEpochMilli(), 5 * 60 * 1000);
}
-}
+}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/PopulateSignatureSigningParametersTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/PopulateSignatureSigningParametersTest.java
index bfb41b128..9a25fc3ef 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/PopulateSignatureSigningParametersTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/PopulateSignatureSigningParametersTest.java
@@ -17,8 +17,10 @@
package org.opensaml.saml.common.profile.impl;
-import java.util.Collections;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.component.ComponentInitializationException;
import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.resolver.CriteriaSet;
@@ -81,7 +83,7 @@ public class PopulateSignatureSigningParametersTest extends OpenSAMLInitBaseTest
action.execute(prc);
ActionTestingSupport.assertProceedEvent(prc);
- Assert.assertNotNull(prc.getOutboundMessageContext().getSubcontext(
+ Assert.assertNotNull(prc.ensureOutboundMessageContext().ensureSubcontext(
SecurityParametersContext.class).getSignatureSigningParameters());
}
@@ -98,8 +100,8 @@ public class PopulateSignatureSigningParametersTest extends OpenSAMLInitBaseTest
action.execute(prc);
ActionTestingSupport.assertProceedEvent(prc);
- Assert.assertSame(prc.getSubcontext(SecurityParametersContext.class).getSignatureSigningParameters(),
- prc.getOutboundMessageContext().getSubcontext(SecurityParametersContext.class).getSignatureSigningParameters());
+ Assert.assertSame(prc.ensureSubcontext(SecurityParametersContext.class).getSignatureSigningParameters(),
+ prc.ensureOutboundMessageContext().ensureSubcontext(SecurityParametersContext.class).getSignatureSigningParameters());
}
private class MockResolver implements SignatureSigningParametersResolver {
@@ -111,18 +113,17 @@ public class PopulateSignatureSigningParametersTest extends OpenSAMLInitBaseTest
}
/** {@inheritDoc} */
- @Override
- public Iterable<SignatureSigningParameters> resolve(CriteriaSet criteria) throws ResolverException {
- return Collections.singletonList(resolveSingle(criteria));
+ @Nonnull public Iterable<SignatureSigningParameters> resolve(@Nullable CriteriaSet criteria) throws ResolverException {
+ return CollectionSupport.singletonList(Constraint.isNotNull(resolveSingle(criteria), "Resolver was null"));
}
/** {@inheritDoc} */
- @Override
- public SignatureSigningParameters resolveSingle(CriteriaSet criteria) throws ResolverException {
+ @Nullable public SignatureSigningParameters resolveSingle(@Nullable CriteriaSet criteria) throws ResolverException {
if (throwException) {
throw new ResolverException();
}
+ assert criteria != null;
Constraint.isNotNull(criteria.get(SignatureSigningConfigurationCriterion.class), "Criterion was null");
return new SignatureSigningParameters();
}
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/SignAssertionsTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/SignAssertionsTest.java
index 0c7fefb12..71ae59871 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/SignAssertionsTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/SignAssertionsTest.java
@@ -37,6 +37,7 @@ import org.testng.annotations.Test;
import net.shibboleth.shared.component.ComponentInitializationException;
/** {@link SignAssertions} unit test. */
+ at SuppressWarnings("javadoc")
public class SignAssertionsTest extends OpenSAMLInitBaseTestCase {
private SignAssertions action;
@@ -60,14 +61,14 @@ public class SignAssertionsTest extends OpenSAMLInitBaseTestCase {
}
@Test public void testNoMessage() throws Exception {
- prc.getOutboundMessageContext().setMessage(null);
+ prc.ensureOutboundMessageContext().setMessage(null);
action.execute(prc);
ActionTestingSupport.assertEvent(prc, EventIds.INVALID_MSG_CTX);
}
@Test public void testBadMessage() throws Exception {
- prc.getOutboundMessageContext().setMessage(SAML1ActionTestingSupport.buildAttributeQueryRequest(null));
+ prc.ensureOutboundMessageContext().setMessage(SAML1ActionTestingSupport.buildAttributeQueryRequest(null));
action.execute(prc);
ActionTestingSupport.assertProceedEvent(prc);
@@ -95,9 +96,9 @@ public class SignAssertionsTest extends OpenSAMLInitBaseTestCase {
}
@Test public void testSignSAML1Assertions() throws Exception {
- prc.getOutboundMessageContext().setMessage(SAML1ActionTestingSupport.buildResponse());
- final org.opensaml.saml.saml1.core.Assertion assertion = SAML1ActionTestingSupport.buildAssertion();
- ((org.opensaml.saml.saml1.core.Response) prc.getOutboundMessageContext().getMessage()).getAssertions().add(assertion);
+ prc.ensureOutboundMessageContext().setMessage(SAML1ActionTestingSupport.buildResponse());
+ final var assertion = SAML1ActionTestingSupport.buildAssertion();
+ ((org.opensaml.saml.saml1.core.Response) prc.ensureOutboundMessageContext().ensureMessage()).getAssertions().add(assertion);
final SignatureSigningParameters signingParameters = new SignatureSigningParameters();
final KeyPair kp = KeySupport.generateKeyPair("RSA", 1024, null);
@@ -115,8 +116,8 @@ public class SignAssertionsTest extends OpenSAMLInitBaseTestCase {
}
@Test public void testSignSAML2Assertions() throws Exception {
- final org.opensaml.saml.saml2.core.Assertion assertion = SAML2ActionTestingSupport.buildAssertion();
- ((org.opensaml.saml.saml2.core.Response) prc.getOutboundMessageContext().getMessage()).getAssertions().add(assertion);
+ final var assertion = SAML2ActionTestingSupport.buildAssertion();
+ ((org.opensaml.saml.saml2.core.Response) prc.ensureOutboundMessageContext().ensureMessage()).getAssertions().add(assertion);
final SignatureSigningParameters signingParameters = new SignatureSigningParameters();
final KeyPair kp = KeySupport.generateKeyPair("RSA", 1024, null);
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/VerifyChannelBindingsTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/VerifyChannelBindingsTest.java
index 71a3680a0..32cd95999 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/VerifyChannelBindingsTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/VerifyChannelBindingsTest.java
@@ -34,6 +34,7 @@ import org.testng.annotations.Test;
import net.shibboleth.shared.component.ComponentInitializationException;
/** {@link VerifyChannelBindings} unit test. */
+ at SuppressWarnings("javadoc")
public class VerifyChannelBindingsTest extends OpenSAMLInitBaseTestCase {
private ProfileRequestContext prc;
@@ -62,15 +63,15 @@ public class VerifyChannelBindingsTest extends OpenSAMLInitBaseTestCase {
cb.setType("foo");
cb.setValue("foo");
- prc.getInboundMessageContext().getSubcontext(ChannelBindingsContext.class, true).getChannelBindings().add(cb);
- prc.getInboundMessageContext().getSubcontext(SOAP11Context.class, true).getSubcontext(
- ChannelBindingsContext.class, true).getChannelBindings().add(cb);
+ prc.ensureInboundMessageContext().ensureSubcontext(ChannelBindingsContext.class).getChannelBindings().add(cb);
+ prc.ensureInboundMessageContext().ensureSubcontext(SOAP11Context.class).ensureSubcontext(
+ ChannelBindingsContext.class).getChannelBindings().add(cb);
action.execute(prc);
ActionTestingSupport.assertProceedEvent(prc);
- final ChannelBindingsContext cbCtx = prc.getOutboundMessageContext().getSubcontext(ChannelBindingsContext.class);
- Assert.assertNotNull(cbCtx);
+ final ChannelBindingsContext cbCtx = prc.ensureOutboundMessageContext().getSubcontext(ChannelBindingsContext.class);
+ assert cbCtx != null;
Assert.assertEquals(cbCtx.getChannelBindings().size(), 1);
final ChannelBindings[] array = cbCtx.getChannelBindings().toArray(new ChannelBindings[1]);
@@ -89,13 +90,13 @@ public class VerifyChannelBindingsTest extends OpenSAMLInitBaseTestCase {
cb.setType("bar");
cb.setValue("foo");
- prc.getInboundMessageContext().getSubcontext(ChannelBindingsContext.class, true).getChannelBindings().add(cb);
- prc.getInboundMessageContext().getSubcontext(SOAP11Context.class, true).getSubcontext(
- ChannelBindingsContext.class, true).getChannelBindings().add(cb2);
+ prc.ensureInboundMessageContext().ensureSubcontext(ChannelBindingsContext.class).getChannelBindings().add(cb);
+ prc.ensureInboundMessageContext().ensureSubcontext(SOAP11Context.class).ensureSubcontext(
+ ChannelBindingsContext.class).getChannelBindings().add(cb2);
action.execute(prc);
ActionTestingSupport.assertEvent(prc, SAMLEventIds.CHANNEL_BINDINGS_ERROR);
- Assert.assertNull(prc.getOutboundMessageContext().getSubcontext(ChannelBindingsContext.class));
+ Assert.assertNull(prc.ensureOutboundMessageContext().getSubcontext(ChannelBindingsContext.class));
}
@Test public void testNoMatch2() throws MessageHandlerException {
@@ -105,11 +106,11 @@ public class VerifyChannelBindingsTest extends OpenSAMLInitBaseTestCase {
cb.setType("foo");
cb.setValue("foo");
- prc.getInboundMessageContext().getSubcontext(ChannelBindingsContext.class, true).getChannelBindings().add(cb);
+ prc.ensureInboundMessageContext().ensureSubcontext(ChannelBindingsContext.class).getChannelBindings().add(cb);
action.execute(prc);
ActionTestingSupport.assertEvent(prc, SAMLEventIds.CHANNEL_BINDINGS_ERROR);
- Assert.assertNull(prc.getOutboundMessageContext().getSubcontext(ChannelBindingsContext.class));
+ Assert.assertNull(prc.ensureOutboundMessageContext().getSubcontext(ChannelBindingsContext.class));
}
}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/idpdisco/impl/DiscoveryResponseTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/idpdisco/impl/DiscoveryResponseTest.java
index 532a6b334..8070381a1 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/idpdisco/impl/DiscoveryResponseTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/idpdisco/impl/DiscoveryResponseTest.java
@@ -114,20 +114,21 @@ public class DiscoveryResponseTest extends XMLObjectProviderBaseTestCase {
// isDefault attribute
acs.setIsDefault(Boolean.TRUE);
Assert.assertEquals(acs.isDefault(), Boolean.TRUE, "Unexpected value for boolean attribute found");
- Assert.assertNotNull(acs.isDefaultXSBoolean(), "XSBooleanValue was null");
- Assert.assertEquals(acs
- .isDefaultXSBoolean(), new XSBooleanValue(Boolean.TRUE, false), "XSBooleanValue was unexpected value");
- Assert.assertEquals(acs.isDefaultXSBoolean().toString(), "true", "XSBooleanValue string was unexpected value");
+ XSBooleanValue xsbool = acs.isDefaultXSBoolean();
+ assert xsbool != null;
+ Assert.assertEquals(xsbool, new XSBooleanValue(Boolean.TRUE, false), "XSBooleanValue was unexpected value");
+ Assert.assertEquals(xsbool.toString(), "true", "XSBooleanValue string was unexpected value");
acs.setIsDefault(Boolean.FALSE);
Assert.assertEquals(acs.isDefault(), Boolean.FALSE, "Unexpected value for boolean attribute found");
- Assert.assertNotNull(acs.isDefaultXSBoolean(), "XSBooleanValue was null");
- Assert.assertEquals(acs
- .isDefaultXSBoolean(), new XSBooleanValue(Boolean.FALSE, false), "XSBooleanValue was unexpected value");
- Assert.assertEquals(acs.isDefaultXSBoolean().toString(), "false", "XSBooleanValue string was unexpected value");
+ xsbool = acs.isDefaultXSBoolean();
+ assert xsbool != null;
+ Assert.assertEquals(xsbool, new XSBooleanValue(Boolean.FALSE, false), "XSBooleanValue was unexpected value");
+ Assert.assertEquals(xsbool.toString(), "false", "XSBooleanValue string was unexpected value");
acs.setIsDefault((Boolean) null);
Assert.assertEquals(acs.isDefault(), Boolean.FALSE, "Unexpected default value for boolean attribute found");
Assert.assertNull(acs.isDefaultXSBoolean(), "XSBooleanValue was not null");
}
+
}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesTest.java
index 61895ccf3..8dfa4f545 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/reqattr/impl/RequestedAttributesTest.java
@@ -59,7 +59,8 @@ public class RequestedAttributesTest extends XMLObjectProviderBaseTestCase {
@Test
public void testChildElementsUnmarshall() {
final RequestedAttributes requestedAttributes = (RequestedAttributes) unmarshallElement(childElementsFile);
-
+ assert requestedAttributes != null;
+
Assert.assertEquals(requestedAttributes.getRequestedAttributes().size(), expectedNames.length);
for (int i = 0; i < expectedNames.length; i++) {
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml1md/impl/SourceIDTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml1md/impl/SourceIDTest.java
index 514c097b5..20a4af70f 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml1md/impl/SourceIDTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml1md/impl/SourceIDTest.java
@@ -45,10 +45,10 @@ public class SourceIDTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementMarshall() {
- SAMLObjectBuilder<SourceID> builder = (SAMLObjectBuilder<SourceID>)
+ final SAMLObjectBuilder<SourceID> builder = (SAMLObjectBuilder<SourceID>)
builderFactory.<SourceID>ensureBuilder(SourceID.DEFAULT_ELEMENT_NAME);
- SourceID sourceID = builder.buildObject();
+ final SourceID sourceID = builder.buildObject();
sourceID.setValue(expectedValue);
assertXMLEquals(expectedDOM, sourceID);
@@ -57,9 +57,9 @@ public class SourceIDTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementUnmarshall() {
- SourceID sourceID = (SourceID) unmarshallElement(singleElementFile);
+ final SourceID sourceID = (SourceID) unmarshallElement(singleElementFile);
- Assert.assertNotNull(sourceID);
+ assert sourceID != null;
Assert.assertEquals(sourceID.getValue(), expectedValue);
}
}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2alg/impl/DigestMethodTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2alg/impl/DigestMethodTest.java
index bacb9108a..5150237c9 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2alg/impl/DigestMethodTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2alg/impl/DigestMethodTest.java
@@ -36,16 +36,16 @@ public class DigestMethodTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementUnmarshall() {
- DigestMethod digestMethod = (DigestMethod) unmarshallElement(singleElementFile);
- Assert.assertNotNull(digestMethod);
+ final DigestMethod digestMethod = (DigestMethod) unmarshallElement(singleElementFile);
+ assert digestMethod != null;
Assert.assertEquals(digestMethod.getAlgorithm(), SignatureConstants.ALGO_ID_DIGEST_SHA256);
}
/** {@inheritDoc} */
@Test
public void testChildElementsUnmarshall() {
- DigestMethod digestMethod = (DigestMethod) unmarshallElement(childElementsFile);
- Assert.assertNotNull(digestMethod);
+ final DigestMethod digestMethod = (DigestMethod) unmarshallElement(childElementsFile);
+ assert digestMethod != null;
Assert.assertEquals(digestMethod.getAlgorithm(), SignatureConstants.ALGO_ID_DIGEST_SHA256);
Assert.assertEquals(digestMethod.getUnknownXMLObjects().size(), 3);
}
@@ -53,7 +53,7 @@ public class DigestMethodTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementMarshall() {
- DigestMethod digestMethod = (DigestMethod) buildXMLObject(DigestMethod.DEFAULT_ELEMENT_NAME);
+ final DigestMethod digestMethod = (DigestMethod) buildXMLObject(DigestMethod.DEFAULT_ELEMENT_NAME);
digestMethod.setAlgorithm(SignatureConstants.ALGO_ID_DIGEST_SHA256);
assertXMLEquals(expectedDOM, digestMethod);
@@ -62,7 +62,7 @@ public class DigestMethodTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testChildElementsMarshall() {
- DigestMethod digestMethod = (DigestMethod) buildXMLObject(DigestMethod.DEFAULT_ELEMENT_NAME);
+ final DigestMethod digestMethod = (DigestMethod) buildXMLObject(DigestMethod.DEFAULT_ELEMENT_NAME);
digestMethod.setAlgorithm(SignatureConstants.ALGO_ID_DIGEST_SHA256);
digestMethod.getUnknownXMLObjects().add(buildXMLObject(SimpleXMLObject.ELEMENT_NAME));
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2alg/impl/SigningMethodTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2alg/impl/SigningMethodTest.java
index 9f5f2870e..4a2b2236a 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2alg/impl/SigningMethodTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2alg/impl/SigningMethodTest.java
@@ -37,8 +37,8 @@ public class SigningMethodTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementUnmarshall() {
- SigningMethod signingMethod = (SigningMethod) unmarshallElement(singleElementFile);
- Assert.assertNotNull(signingMethod);
+ final SigningMethod signingMethod = (SigningMethod) unmarshallElement(singleElementFile);
+ assert signingMethod != null;
Assert.assertEquals(signingMethod.getAlgorithm(), SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA256);
}
@@ -46,8 +46,8 @@ public class SigningMethodTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test public void testSingleElementOptionalAttributesUnmarshall() {
- SigningMethod signingMethod = (SigningMethod) unmarshallElement(singleElementOptionalAttributesFile);
- Assert.assertNotNull(signingMethod);
+ final SigningMethod signingMethod = (SigningMethod) unmarshallElement(singleElementOptionalAttributesFile);
+ assert signingMethod != null;
Assert.assertEquals(signingMethod.getAlgorithm(), SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA256);
Assert.assertEquals(signingMethod.getMinKeySize(), Integer.valueOf(2048));
Assert.assertEquals(signingMethod.getMaxKeySize(), Integer.valueOf(4096));
@@ -56,8 +56,8 @@ public class SigningMethodTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testChildElementsUnmarshall() {
- SigningMethod signingMethod = (SigningMethod) unmarshallElement(childElementsFile);
- Assert.assertNotNull(signingMethod);
+ final SigningMethod signingMethod = (SigningMethod) unmarshallElement(childElementsFile);
+ assert signingMethod != null;
Assert.assertEquals(signingMethod.getAlgorithm(), SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA256);
Assert.assertEquals(signingMethod.getUnknownXMLObjects().size(), 3);
}
@@ -65,7 +65,7 @@ public class SigningMethodTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementMarshall() {
- SigningMethod signingMethod = (SigningMethod) buildXMLObject(SigningMethod.DEFAULT_ELEMENT_NAME);
+ final SigningMethod signingMethod = (SigningMethod) buildXMLObject(SigningMethod.DEFAULT_ELEMENT_NAME);
signingMethod.setAlgorithm(SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA256);
assertXMLEquals(expectedDOM, signingMethod);
@@ -74,7 +74,7 @@ public class SigningMethodTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test public void testSingleElementOptionalAttributesMarshall() {
- SigningMethod signingMethod = (SigningMethod) buildXMLObject(SigningMethod.DEFAULT_ELEMENT_NAME);
+ final SigningMethod signingMethod = (SigningMethod) buildXMLObject(SigningMethod.DEFAULT_ELEMENT_NAME);
signingMethod.setAlgorithm(SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA256);
signingMethod.setMinKeySize(2048);
signingMethod.setMaxKeySize(4096);
@@ -85,7 +85,7 @@ public class SigningMethodTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testChildElementsMarshall() {
- SigningMethod signingMethod = (SigningMethod) buildXMLObject(SigningMethod.DEFAULT_ELEMENT_NAME);
+ final SigningMethod signingMethod = (SigningMethod) buildXMLObject(SigningMethod.DEFAULT_ELEMENT_NAME);
signingMethod.setAlgorithm(SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA256);
signingMethod.getUnknownXMLObjects().add(buildXMLObject(SimpleXMLObject.ELEMENT_NAME));
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2cb/impl/ChannelBindingsTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2cb/impl/ChannelBindingsTest.java
index b219663f0..1c0709232 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2cb/impl/ChannelBindingsTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2cb/impl/ChannelBindingsTest.java
@@ -34,10 +34,18 @@ public class ChannelBindingsTest extends XMLObjectProviderBaseTestCase {
private Boolean expectedSOAP11MustUnderstand;
+ /**
+ * Constructor.
+ */
public ChannelBindingsTest() {
singleElementFile = "/org/opensaml/saml/ext/saml2cb/impl/ChannelBindings.xml";
}
+ /**
+ * Test set up.
+ *
+ * @throws Exception
+ */
@BeforeMethod
protected void setUp() throws Exception {
expectedContent = "YourChannelIsBound";
@@ -48,9 +56,8 @@ public class ChannelBindingsTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementUnmarshall() {
- ChannelBindings cb = (ChannelBindings) unmarshallElement(singleElementFile);
-
- Assert.assertNotNull(cb);
+ final ChannelBindings cb = (ChannelBindings) unmarshallElement(singleElementFile);
+ assert cb != null;
Assert.assertEquals(expectedSOAP11MustUnderstand, cb.isSOAP11MustUnderstand(),
"SOAP mustUnderstand had unxpected value");
@@ -61,7 +68,7 @@ public class ChannelBindingsTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementMarshall() {
- ChannelBindings cb = (ChannelBindings) buildXMLObject(ChannelBindings.DEFAULT_ELEMENT_NAME);
+ final ChannelBindings cb = (ChannelBindings) buildXMLObject(ChannelBindings.DEFAULT_ELEMENT_NAME);
cb.setSOAP11Actor(expectedSOAP11Actor);
cb.setSOAP11MustUnderstand(expectedSOAP11MustUnderstand);
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2delrestrict/impl/DelegateTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2delrestrict/impl/DelegateTest.java
index 1a1dc15b6..86f642759 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2delrestrict/impl/DelegateTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2delrestrict/impl/DelegateTest.java
@@ -53,7 +53,7 @@ public class DelegateTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementUnmarshall() {
- Delegate delegate = (Delegate) unmarshallElement(singleElementFile);
+ final Delegate delegate = (Delegate) unmarshallElement(singleElementFile);
Assert.assertNotNull(delegate);
}
@@ -61,9 +61,8 @@ public class DelegateTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementOptionalAttributesUnmarshall() {
- Delegate delegate = (Delegate) unmarshallElement(singleElementOptionalAttributesFile);
-
- Assert.assertNotNull(delegate);
+ final Delegate delegate = (Delegate) unmarshallElement(singleElementOptionalAttributesFile);
+ assert delegate != null;
Instant instant = delegate.getDelegationInstant();
Assert.assertEquals(instant, expectedDelegationInstant, "DelegationInstant was unexpected value");
@@ -75,9 +74,8 @@ public class DelegateTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testChildElementsUnmarshall() {
- Delegate delegate = (Delegate) unmarshallElement(childElementsFile);
-
- Assert.assertNotNull(delegate);
+ final Delegate delegate = (Delegate) unmarshallElement(childElementsFile);
+ assert delegate != null;
Assert.assertNotNull(delegate.getNameID(), "NameID was null");
Assert.assertNull(delegate.getBaseID(), "BaseID was non-null");
@@ -87,7 +85,7 @@ public class DelegateTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementMarshall() {
- Delegate delegate = (Delegate) buildXMLObject(Delegate.DEFAULT_ELEMENT_NAME);
+ final Delegate delegate = (Delegate) buildXMLObject(Delegate.DEFAULT_ELEMENT_NAME);
assertXMLEquals(expectedDOM, delegate);
}
@@ -95,7 +93,7 @@ public class DelegateTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementOptionalAttributesMarshall() {
- Delegate delegate = (Delegate) buildXMLObject(Delegate.DEFAULT_ELEMENT_NAME);
+ final Delegate delegate = (Delegate) buildXMLObject(Delegate.DEFAULT_ELEMENT_NAME);
delegate.setConfirmationMethod(expectedConfirmationMethod);
delegate.setDelegationInstant(expectedDelegationInstant);
@@ -108,7 +106,7 @@ public class DelegateTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testChildElementsMarshall() {
- Delegate delegate = (Delegate) buildXMLObject(Delegate.DEFAULT_ELEMENT_NAME);
+ final Delegate delegate = (Delegate) buildXMLObject(Delegate.DEFAULT_ELEMENT_NAME);
delegate.setNameID((NameID) buildXMLObject(NameID.DEFAULT_ELEMENT_NAME));
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2delrestrict/impl/DelegationRestrictionTypeTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2delrestrict/impl/DelegationRestrictionTypeTest.java
index 108ffd681..bfe1925e9 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2delrestrict/impl/DelegationRestrictionTypeTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2delrestrict/impl/DelegationRestrictionTypeTest.java
@@ -48,7 +48,7 @@ public class DelegationRestrictionTypeTest extends XMLObjectProviderBaseTestCase
/** {@inheritDoc} */
@Test
public void testSingleElementUnmarshall() {
- DelegationRestrictionType drt = (DelegationRestrictionType) unmarshallElement(singleElementFile);
+ final DelegationRestrictionType drt = (DelegationRestrictionType) unmarshallElement(singleElementFile);
Assert.assertNotNull(drt);
}
@@ -56,9 +56,8 @@ public class DelegationRestrictionTypeTest extends XMLObjectProviderBaseTestCase
/** {@inheritDoc} */
@Test
public void testChildElementsUnmarshall() {
- DelegationRestrictionType drt = (DelegationRestrictionType) unmarshallElement(childElementsFile);
-
- Assert.assertNotNull(drt);
+ final DelegationRestrictionType drt = (DelegationRestrictionType) unmarshallElement(childElementsFile);
+ assert drt != null;
Assert.assertEquals(drt.getDelegates().size(), expectedDelegateChildren, "Incorrect # of Delegate Children");
}
@@ -66,11 +65,11 @@ public class DelegationRestrictionTypeTest extends XMLObjectProviderBaseTestCase
/** {@inheritDoc} */
@Test
public void testSingleElementMarshall() {
- SAMLObjectBuilder<DelegationRestrictionType> builder = (SAMLObjectBuilder<DelegationRestrictionType>)
+ final SAMLObjectBuilder<DelegationRestrictionType> builder = (SAMLObjectBuilder<DelegationRestrictionType>)
XMLObjectProviderRegistrySupport.getBuilderFactory().<DelegationRestrictionType>ensureBuilder(
DelegationRestrictionType.TYPE_NAME);
- DelegationRestrictionType drt = builder.buildObject();
+ final DelegationRestrictionType drt = builder.buildObject();
assertXMLEquals(expectedDOM, drt);
}
@@ -79,11 +78,11 @@ public class DelegationRestrictionTypeTest extends XMLObjectProviderBaseTestCase
/** {@inheritDoc} */
@Test
public void testChildElementsMarshall() {
- SAMLObjectBuilder<DelegationRestrictionType> builder = (SAMLObjectBuilder<DelegationRestrictionType>)
+ final SAMLObjectBuilder<DelegationRestrictionType> builder = (SAMLObjectBuilder<DelegationRestrictionType>)
XMLObjectProviderRegistrySupport.getBuilderFactory().<DelegationRestrictionType>ensureBuilder(
DelegationRestrictionType.TYPE_NAME);
- DelegationRestrictionType drt = builder.buildObject();
+ final DelegationRestrictionType drt = builder.buildObject();
drt.getDelegates().add((Delegate) buildXMLObject(Delegate.DEFAULT_ELEMENT_NAME));
drt.getDelegates().add((Delegate) buildXMLObject(Delegate.DEFAULT_ELEMENT_NAME));
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdattr/impl/EntityAttributesTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdattr/impl/EntityAttributesTest.java
index eb086faaa..f0addd1d4 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdattr/impl/EntityAttributesTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdattr/impl/EntityAttributesTest.java
@@ -41,7 +41,7 @@ public class EntityAttributesTest extends XMLObjectProviderBaseTestCase {
@Test
public void testSingleElementUnmarshall() {
EntityAttributes attributes = (EntityAttributes) unmarshallElement(singleElementFile);
- Assert.assertNotNull(attributes);
+ assert attributes != null;
Assert.assertTrue(attributes.getAssertions().isEmpty());
Assert.assertTrue(attributes.getAttributes().isEmpty());
}
@@ -50,7 +50,7 @@ public class EntityAttributesTest extends XMLObjectProviderBaseTestCase {
@Test
public void testChildElementsUnmarshall() {
EntityAttributes attributes = (EntityAttributes) unmarshallElement(childElementsFile);
- Assert.assertNotNull(attributes);
+ assert attributes != null;
Assert.assertEquals(attributes.getAssertions().size(), 2);
Assert.assertEquals(attributes.getAttributes().size(), 3);
@@ -90,7 +90,10 @@ public class EntityAttributesTest extends XMLObjectProviderBaseTestCase {
attributes.getAttributes().add(attrib2);
attributes.getAttributes().add(attrib3);
- Assert.assertEquals(attributes.getOrderedChildren().size(), 5);
+ final var children = attributes.getOrderedChildren();
+ assert children != null;
+ Assert.assertEquals(children.size(), 5);
assertXMLEquals(expectedChildElementsDOM, attributes);
}
+
}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdreqinit/impl/RequestInitiatorTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdreqinit/impl/RequestInitiatorTest.java
index 8b004b6d9..dc12e5151 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdreqinit/impl/RequestInitiatorTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdreqinit/impl/RequestInitiatorTest.java
@@ -52,7 +52,8 @@ public class RequestInitiatorTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test public void testSingleElementUnmarshall() {
- RequestInitiator reqinit = (RequestInitiator) unmarshallElement(singleElementFile);
+ final RequestInitiator reqinit = (RequestInitiator) unmarshallElement(singleElementFile);
+ assert reqinit != null;
Assert.assertEquals(reqinit.getBinding(), expectedBinding, "Binding URI was not expected value");
Assert.assertEquals(reqinit.getLocation(), expectedLocation, "Location was not expected value");
@@ -60,7 +61,7 @@ public class RequestInitiatorTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test public void testSingleElementMarshall() {
- RequestInitiator reqinit = (new RequestInitiatorBuilder()).buildObject();
+ final RequestInitiator reqinit = (new RequestInitiatorBuilder()).buildObject();
reqinit.setBinding(expectedBinding);
reqinit.setLocation(expectedLocation);
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/PublicationInfoTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/PublicationInfoTest.java
index 7fb543345..7a8b4a45a 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/PublicationInfoTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/PublicationInfoTest.java
@@ -25,6 +25,7 @@ import org.opensaml.saml.ext.saml2mdrpi.UsagePolicy;
import org.testng.Assert;
import org.testng.annotations.Test;
+ at SuppressWarnings("javadoc")
public class PublicationInfoTest extends XMLObjectProviderBaseTestCase {
private static String expectedPublisher = "publisher";
@@ -44,14 +45,16 @@ public class PublicationInfoTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementUnmarshall() {
- PublicationInfo info = (PublicationInfo) unmarshallElement(singleElementFile);
+ final PublicationInfo info = (PublicationInfo) unmarshallElement(singleElementFile);
+ assert info != null;
Assert.assertEquals(info.getPublisher(), expectedPublisher);
}
/** {@inheritDoc} */
@Test
public void testSingleElementOptionalAttributesUnmarshall() {
- PublicationInfo info = (PublicationInfo) unmarshallElement(singleElementOptionalAttributesFile);
+ final PublicationInfo info = (PublicationInfo) unmarshallElement(singleElementOptionalAttributesFile);
+ assert info != null;
Assert.assertEquals(info.getPublisher(), expectedPublisher);
Assert.assertEquals(info.getPublicationId(), expectedPublicationId);
Assert.assertEquals(info.getCreationInstant(), expectedCreationInstant);
@@ -60,7 +63,7 @@ public class PublicationInfoTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementMarshall() {
- PublicationInfo info = (PublicationInfo) buildXMLObject(PublicationInfo.DEFAULT_ELEMENT_NAME);
+ final PublicationInfo info = (PublicationInfo) buildXMLObject(PublicationInfo.DEFAULT_ELEMENT_NAME);
info.setPublisher(expectedPublisher);
@@ -70,7 +73,7 @@ public class PublicationInfoTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementOptionalAttributesMarshall() {
- PublicationInfo info = (PublicationInfo) buildXMLObject(PublicationInfo.DEFAULT_ELEMENT_NAME);
+ final PublicationInfo info = (PublicationInfo) buildXMLObject(PublicationInfo.DEFAULT_ELEMENT_NAME);
info.setPublisher(expectedPublisher);
info.setCreationInstant(expectedCreationInstant);
@@ -81,7 +84,8 @@ public class PublicationInfoTest extends XMLObjectProviderBaseTestCase {
@Test
public void testChildElementsUnmarshall() {
- PublicationInfo info = (PublicationInfo) unmarshallElement(childElementsFile);
+ final PublicationInfo info = (PublicationInfo) unmarshallElement(childElementsFile);
+ assert info != null;
Assert.assertEquals(info.getPublisher(), expectedPublisher);
UsagePolicy policy = info.getUsagePolicies().get(0);
Assert.assertEquals(policy.getXMLLang(), langs[0]);
@@ -93,12 +97,11 @@ public class PublicationInfoTest extends XMLObjectProviderBaseTestCase {
@Test
public void testChildElementsMarshall() {
- PublicationInfo info = (PublicationInfo) buildXMLObject(PublicationInfo.DEFAULT_ELEMENT_NAME);
+ final PublicationInfo info = (PublicationInfo) buildXMLObject(PublicationInfo.DEFAULT_ELEMENT_NAME);
info.setPublisher(expectedPublisher);
for (int i = 0; i < 2; i++) {
-
- UsagePolicy policy = (UsagePolicy) buildXMLObject(UsagePolicy.DEFAULT_ELEMENT_NAME);
+ final UsagePolicy policy = (UsagePolicy) buildXMLObject(UsagePolicy.DEFAULT_ELEMENT_NAME);
policy.setURI(uris[i]);
policy.setXMLLang(langs[i]);
info.getUsagePolicies().add(policy);
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/PublicationPathTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/PublicationPathTest.java
index 2f1c7cb50..101008427 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/PublicationPathTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/PublicationPathTest.java
@@ -23,6 +23,7 @@ import org.opensaml.saml.ext.saml2mdrpi.PublicationPath;
import org.testng.Assert;
+ at SuppressWarnings("javadoc")
public class PublicationPathTest extends XMLObjectProviderBaseTestCase {
private static String[] publishers = {"pub1", "pub2",};
@@ -38,7 +39,8 @@ public class PublicationPathTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
public void testSingleElementUnmarshall() {
- PublicationPath pPath = (PublicationPath) unmarshallElement(singleElementFile);
+ final PublicationPath pPath = (PublicationPath) unmarshallElement(singleElementFile);
+ assert pPath != null;
Assert.assertEquals(pPath.getPublications().size(), 0);
}
@@ -50,7 +52,8 @@ public class PublicationPathTest extends XMLObjectProviderBaseTestCase {
}
public void testChildElementsUnmarshall() {
- PublicationPath pPath = (PublicationPath) unmarshallElement(childElementsFile);
+ final PublicationPath pPath = (PublicationPath) unmarshallElement(childElementsFile);
+ assert pPath != null;
Assert.assertEquals(pPath.getPublications().size(), 2);
Publication pub = pPath.getPublications().get(0);
Assert.assertEquals(pub.getPublisher(), publishers[0]);
@@ -59,10 +62,10 @@ public class PublicationPathTest extends XMLObjectProviderBaseTestCase {
}
public void testChildElementsMarshall() {
- PublicationPath pPath = (PublicationPath) buildXMLObject(PublicationPath.DEFAULT_ELEMENT_NAME);
+ final PublicationPath pPath = (PublicationPath) buildXMLObject(PublicationPath.DEFAULT_ELEMENT_NAME);
for (int i = 0; i < 2; i++) {
- Publication pub = (Publication) buildXMLObject(Publication.DEFAULT_ELEMENT_NAME);
+ final Publication pub = (Publication) buildXMLObject(Publication.DEFAULT_ELEMENT_NAME);
pub.setPublisher(publishers[i]);
pPath.getPublications().add(pub);
}
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/PublicationTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/PublicationTest.java
index 83d188267..a6e93bd63 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/PublicationTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/PublicationTest.java
@@ -23,6 +23,7 @@ import org.opensaml.core.testing.XMLObjectProviderBaseTestCase;
import org.opensaml.saml.ext.saml2mdrpi.Publication;
import org.testng.Assert;
+ at SuppressWarnings("javadoc")
public class PublicationTest extends XMLObjectProviderBaseTestCase {
private static String expectedPublisher = "publisher";
@@ -40,13 +41,15 @@ public class PublicationTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
public void testSingleElementUnmarshall() {
- Publication info = (Publication) unmarshallElement(singleElementFile);
+ final Publication info = (Publication) unmarshallElement(singleElementFile);
+ assert info != null;
Assert.assertEquals(info.getPublisher(), expectedPublisher);
}
/** {@inheritDoc} */
public void testSingleElementOptionalAttributesUnmarshall() {
- Publication info = (Publication) unmarshallElement(singleElementOptionalAttributesFile);
+ final Publication info = (Publication) unmarshallElement(singleElementOptionalAttributesFile);
+ assert info != null;
Assert.assertEquals(info.getPublisher(), expectedPublisher);
Assert.assertEquals(info.getPublicationId(), expectedPublicationId);
Assert.assertEquals(info.getCreationInstant(), expectedCreationInstant);
@@ -54,7 +57,7 @@ public class PublicationTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
public void testSingleElementMarshall() {
- Publication info = (Publication) buildXMLObject(Publication.DEFAULT_ELEMENT_NAME);
+ final Publication info = (Publication) buildXMLObject(Publication.DEFAULT_ELEMENT_NAME);
info.setPublisher(expectedPublisher);
@@ -63,7 +66,7 @@ public class PublicationTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
public void testSingleElementOptionalAttributesMarshall() {
- Publication info = (Publication) buildXMLObject(Publication.DEFAULT_ELEMENT_NAME);
+ final Publication info = (Publication) buildXMLObject(Publication.DEFAULT_ELEMENT_NAME);
info.setPublisher(expectedPublisher);
info.setCreationInstant(expectedCreationInstant);
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/RegistrationInfoTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/RegistrationInfoTest.java
index 0e0f45462..c5a951f6c 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/RegistrationInfoTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/RegistrationInfoTest.java
@@ -25,7 +25,7 @@ import org.opensaml.saml.ext.saml2mdrpi.RegistrationPolicy;
import org.testng.Assert;
-
+ at SuppressWarnings("javadoc")
public class RegistrationInfoTest extends XMLObjectProviderBaseTestCase {
private static String expectedAuthority = "https://www.aai.dfn.de";
@@ -47,20 +47,22 @@ public class RegistrationInfoTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
public void testSingleElementUnmarshall() {
- RegistrationInfo info = (RegistrationInfo) unmarshallElement(singleElementFile);
+ final RegistrationInfo info = (RegistrationInfo) unmarshallElement(singleElementFile);
+ assert info != null;
Assert.assertEquals(info.getRegistrationAuthority(), expectedAuthority);
}
/** {@inheritDoc} */
public void testSingleElementOptionalAttributesUnmarshall() {
- RegistrationInfo info = (RegistrationInfo) unmarshallElement(singleElementOptionalAttributesFile);
+ final RegistrationInfo info = (RegistrationInfo) unmarshallElement(singleElementOptionalAttributesFile);
+ assert info != null;
Assert.assertEquals(info.getRegistrationAuthority(), expectedAuthority);
Assert.assertEquals(info.getRegistrationInstant(), expectedRegistrationInstant);
}
/** {@inheritDoc} */
public void testSingleElementMarshall() {
- RegistrationInfo info = (RegistrationInfo) buildXMLObject(RegistrationInfo.DEFAULT_ELEMENT_NAME);
+ final RegistrationInfo info = (RegistrationInfo) buildXMLObject(RegistrationInfo.DEFAULT_ELEMENT_NAME);
info.setRegistrationAuthority(expectedAuthority);
@@ -69,7 +71,7 @@ public class RegistrationInfoTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
public void testSingleElementOptionalAttributesMarshall() {
- RegistrationInfo info = (RegistrationInfo) buildXMLObject(RegistrationInfo.DEFAULT_ELEMENT_NAME);
+ final RegistrationInfo info = (RegistrationInfo) buildXMLObject(RegistrationInfo.DEFAULT_ELEMENT_NAME);
info.setRegistrationAuthority(expectedAuthority);
info.setRegistrationInstant(expectedRegistrationInstant);
@@ -77,7 +79,8 @@ public class RegistrationInfoTest extends XMLObjectProviderBaseTestCase {
assertXMLEquals(expectedOptionalAttributesDOM, info);
}
public void testChildElementsUnmarshall() {
- RegistrationInfo info = (RegistrationInfo) unmarshallElement(childElementsFile);
+ final RegistrationInfo info = (RegistrationInfo) unmarshallElement(childElementsFile);
+ assert info != null;
Assert.assertEquals(info.getRegistrationAuthority(), expectedAuthority);
Assert.assertEquals(info.getRegistrationInstant(), expectedRegistrationInstant);
RegistrationPolicy policy = info.getRegistrationPolicies().get(0);
@@ -89,13 +92,12 @@ public class RegistrationInfoTest extends XMLObjectProviderBaseTestCase {
}
public void testChildElementsMarshall() {
- RegistrationInfo info = (RegistrationInfo) buildXMLObject(RegistrationInfo.DEFAULT_ELEMENT_NAME);
+ final RegistrationInfo info = (RegistrationInfo) buildXMLObject(RegistrationInfo.DEFAULT_ELEMENT_NAME);
info.setRegistrationAuthority(expectedAuthority);
info.setRegistrationInstant(expectedRegistrationInstant);
for (int i = 0; i < 2; i++) {
-
- RegistrationPolicy policy = (RegistrationPolicy) buildXMLObject(RegistrationPolicy.DEFAULT_ELEMENT_NAME);
+ final RegistrationPolicy policy = (RegistrationPolicy) buildXMLObject(RegistrationPolicy.DEFAULT_ELEMENT_NAME);
policy.setURI(uris[i]);
policy.setXMLLang(langs[i]);
info.getRegistrationPolicies().add(policy);
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/RegistrationPolicyTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/RegistrationPolicyTest.java
index a6d6d2ea8..a36a46200 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/RegistrationPolicyTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/RegistrationPolicyTest.java
@@ -21,29 +21,27 @@ import org.testng.Assert;
import org.opensaml.core.testing.XMLObjectProviderBaseTestCase;
import org.opensaml.saml.ext.saml2mdrpi.RegistrationPolicy;
-/**
- *
- */
+ at SuppressWarnings("javadoc")
public class RegistrationPolicyTest extends XMLObjectProviderBaseTestCase {
/**
* Constructor.
*/
public RegistrationPolicyTest() {
- super();
singleElementFile = "/org/opensaml/saml/ext/saml2mdrpi/RegistrationPolicy.xml";
}
/** {@inheritDoc} */
public void testSingleElementUnmarshall() {
- RegistrationPolicy policy = (RegistrationPolicy) unmarshallElement(singleElementFile);
+ final RegistrationPolicy policy = (RegistrationPolicy) unmarshallElement(singleElementFile);
+ assert policy != null;
Assert.assertEquals(policy.getXMLLang(), "en");
Assert.assertEquals(policy.getURI(), "https://www.aai.dfn.de/en/join/");
}
/** {@inheritDoc} */
public void testSingleElementMarshall() {
- RegistrationPolicy policy = (RegistrationPolicy) buildXMLObject(RegistrationPolicy.DEFAULT_ELEMENT_NAME);
+ final RegistrationPolicy policy = (RegistrationPolicy) buildXMLObject(RegistrationPolicy.DEFAULT_ELEMENT_NAME);
policy.setURI("https://www.aai.dfn.de/en/join/");
policy.setXMLLang("en");
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/UsagePolicyTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/UsagePolicyTest.java
index f8a637826..3c7f11ad1 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/UsagePolicyTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdrpi/impl/UsagePolicyTest.java
@@ -21,26 +21,27 @@ import org.testng.Assert;
import org.opensaml.core.testing.XMLObjectProviderBaseTestCase;
import org.opensaml.saml.ext.saml2mdrpi.UsagePolicy;
+ at SuppressWarnings("javadoc")
public class UsagePolicyTest extends XMLObjectProviderBaseTestCase {
/**
* Constructor.
*/
public UsagePolicyTest() {
- super();
singleElementFile = "/org/opensaml/saml/ext/saml2mdrpi/UsagePolicy.xml";
}
/** {@inheritDoc} */
public void testSingleElementUnmarshall() {
- UsagePolicy policy = (UsagePolicy) unmarshallElement(singleElementFile);
+ final UsagePolicy policy = (UsagePolicy) unmarshallElement(singleElementFile);
+ assert policy != null;
Assert.assertEquals(policy.getXMLLang(), "en");
Assert.assertEquals(policy.getURI(), "https://www.aai.dfn.de/en/join/");
}
/** {@inheritDoc} */
public void testSingleElementMarshall() {
- UsagePolicy policy = (UsagePolicy) buildXMLObject(UsagePolicy.DEFAULT_ELEMENT_NAME);
+ final UsagePolicy policy = (UsagePolicy) buildXMLObject(UsagePolicy.DEFAULT_ELEMENT_NAME);
policy.setURI("https://www.aai.dfn.de/en/join/");
policy.setXMLLang("en");
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdui/impl/DescriptionTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdui/impl/DescriptionTest.java
index 477b1df36..8ce0730c5 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdui/impl/DescriptionTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdui/impl/DescriptionTest.java
@@ -47,7 +47,8 @@ public class DescriptionTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementUnmarshall() {
- Description name = (Description) unmarshallElement(singleElementFile);
+ final Description name = (Description) unmarshallElement(singleElementFile);
+ assert name != null;
Assert.assertEquals(name.getValue(), expectValue, "Name was not expected value");
Assert.assertEquals(name.getXMLLang(), expectLang, "xml:lang was not expected value");
@@ -56,7 +57,7 @@ public class DescriptionTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementMarshall() {
- Description name = (Description) buildXMLObject(Description.DEFAULT_ELEMENT_NAME);
+ final Description name = (Description) buildXMLObject(Description.DEFAULT_ELEMENT_NAME);
name.setValue(expectValue);
name.setXMLLang(expectLang);
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdui/impl/DiscoHintsTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdui/impl/DiscoHintsTest.java
index ad58379eb..3dcbe14aa 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdui/impl/DiscoHintsTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/saml2mdui/impl/DiscoHintsTest.java
@@ -58,7 +58,8 @@ public class DiscoHintsTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementUnmarshall() {
- DiscoHints hints = (DiscoHints) unmarshallElement(singleElementFile);
+ final DiscoHints hints = (DiscoHints) unmarshallElement(singleElementFile);
+ assert hints != null;
//
// Shut up warning
//
@@ -68,7 +69,7 @@ public class DiscoHintsTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementMarshall() {
- DiscoHints hints = (DiscoHints) buildXMLObject(DiscoHints.DEFAULT_ELEMENT_NAME);
+ final DiscoHints hints = (DiscoHints) buildXMLObject(DiscoHints.DEFAULT_ELEMENT_NAME);
assertXMLEquals(expectedDOM, hints);
}
@@ -76,7 +77,8 @@ public class DiscoHintsTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testChildElementsUnmarshall(){
- DiscoHints hints = (DiscoHints) unmarshallElement(childElementsFile);
+ final DiscoHints hints = (DiscoHints) unmarshallElement(childElementsFile);
+ assert hints != null;
Assert.assertEquals(hints.getIPHints().size(), expectedIPHintCount, "<IPHint> count");
Assert.assertEquals(hints.getDomainHints().size(), expectedDomainHintsCount, "<DomainHint> count");
@@ -87,7 +89,7 @@ public class DiscoHintsTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testChildElementsMarshall(){
- DiscoHints hints = (DiscoHints) buildXMLObject(DiscoHints.DEFAULT_ELEMENT_NAME);
+ final DiscoHints hints = (DiscoHints) buildXMLObject(DiscoHints.DEFAULT_ELEMENT_NAME);
hints.getDomainHints().add((DomainHint) buildXMLObject(DomainHint.DEFAULT_ELEMENT_NAME));
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/samlec/impl/EncTypeTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/samlec/impl/EncTypeTest.java
index 99fb30b93..9fa2ccb42 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/samlec/impl/EncTypeTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/samlec/impl/EncTypeTest.java
@@ -45,9 +45,9 @@ public class EncTypeTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementMarshall() {
- EncTypeBuilder builder = (EncTypeBuilder) builderFactory.getBuilder(EncType.DEFAULT_ELEMENT_NAME);
+ final EncTypeBuilder builder = (EncTypeBuilder) builderFactory.<EncType>ensureBuilder(EncType.DEFAULT_ELEMENT_NAME);
- EncType et = builder.buildObject();
+ final EncType et = builder.buildObject();
et.setValue(expectedValue);
assertXMLEquals(expectedDOM, et);
@@ -56,8 +56,9 @@ public class EncTypeTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementUnmarshall() {
- EncType et = (EncType) unmarshallElement(singleElementFile);
-
+ final EncType et = (EncType) unmarshallElement(singleElementFile);
+ assert et != null;
Assert.assertEquals(expectedValue, et.getValue());
}
+
}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/samlec/impl/GeneratedKeyTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/samlec/impl/GeneratedKeyTest.java
index e54030a2e..cef7f6b4b 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/samlec/impl/GeneratedKeyTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/samlec/impl/GeneratedKeyTest.java
@@ -50,9 +50,9 @@ public class GeneratedKeyTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementMarshall() {
- GeneratedKeyBuilder builder = (GeneratedKeyBuilder) builderFactory.getBuilder(GeneratedKey.DEFAULT_ELEMENT_NAME);
+ final GeneratedKeyBuilder builder = (GeneratedKeyBuilder) builderFactory.<GeneratedKey>ensureBuilder(GeneratedKey.DEFAULT_ELEMENT_NAME);
- GeneratedKey key = builder.buildObject();
+ final GeneratedKey key = builder.buildObject();
key.setSOAP11Actor(expectedSOAP11Actor);
key.setSOAP11MustUnderstand(expectedSOAP11MustUnderstand);
key.setValue(expectedValue);
@@ -63,13 +63,14 @@ public class GeneratedKeyTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementUnmarshall() {
- GeneratedKey key = (GeneratedKey) unmarshallElement(singleElementFile);
+ final GeneratedKey key = (GeneratedKey) unmarshallElement(singleElementFile);
- Assert.assertNotNull(key);
+ assert key != null;
Assert.assertEquals(expectedValue, key.getValue());
Assert.assertEquals(expectedSOAP11MustUnderstand, key.isSOAP11MustUnderstand(),
"SOAP mustUnderstand had unxpected value");
Assert.assertEquals(expectedSOAP11Actor, key.getSOAP11Actor(),
"SOAP actor had unxpected value");
}
+
}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/samlec/impl/SessionKeyTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/samlec/impl/SessionKeyTest.java
index aaf0e10af..afbbe6250 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/samlec/impl/SessionKeyTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/ext/samlec/impl/SessionKeyTest.java
@@ -36,11 +36,17 @@ public class SessionKeyTest extends XMLObjectProviderBaseTestCase {
private Boolean expectedSOAP11MustUnderstand;
+ /** Constructor. */
public SessionKeyTest() {
singleElementFile = "/org/opensaml/saml/ext/samlec/impl/SessionKey.xml";
childElementsFile = "/org/opensaml/saml/ext/samlec/impl/SessionKeyChildElements.xml";
}
+ /**
+ * Test set up.
+ *
+ * @throws Exception
+ */
@BeforeMethod
protected void setUp() throws Exception {
expectedAlg = "http://myalgorithm.example.com";
@@ -51,9 +57,8 @@ public class SessionKeyTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementUnmarshall() {
- SessionKey key = (SessionKey) unmarshallElement(singleElementFile);
-
- Assert.assertNotNull(key);
+ final SessionKey key = (SessionKey) unmarshallElement(singleElementFile);
+ assert key != null;
Assert.assertEquals(expectedSOAP11MustUnderstand, key.isSOAP11MustUnderstand(),
"SOAP mustUnderstand had unxpected value");
@@ -64,9 +69,8 @@ public class SessionKeyTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testChildElementsUnmarshall() {
- SessionKey key = (SessionKey) unmarshallElement(childElementsFile);
-
- Assert.assertNotNull(key);
+ final SessionKey key = (SessionKey) unmarshallElement(childElementsFile);
+ assert key != null;
Assert.assertEquals(expectedSOAP11MustUnderstand, key.isSOAP11MustUnderstand(),
"SOAP mustUnderstand had unxpected value");
@@ -77,7 +81,7 @@ public class SessionKeyTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementMarshall() {
- SessionKey key = (SessionKey) buildXMLObject(SessionKey.DEFAULT_ELEMENT_NAME);
+ final SessionKey key = (SessionKey) buildXMLObject(SessionKey.DEFAULT_ELEMENT_NAME);
key.setSOAP11Actor(expectedSOAP11Actor);
key.setSOAP11MustUnderstand(expectedSOAP11MustUnderstand);
@@ -89,7 +93,7 @@ public class SessionKeyTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testChildElementsMarshall() {
- SessionKey key = (SessionKey) buildXMLObject(SessionKey.DEFAULT_ELEMENT_NAME);
+ final SessionKey key = (SessionKey) buildXMLObject(SessionKey.DEFAULT_ELEMENT_NAME);
key.setSOAP11Actor(expectedSOAP11Actor);
key.setSOAP11MustUnderstand(expectedSOAP11MustUnderstand);
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml1/binding/impl/SAML1ArtifactRequestIssuerHandlerTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml1/binding/impl/SAML1ArtifactRequestIssuerHandlerTest.java
index 72da4d583..7107a81b2 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml1/binding/impl/SAML1ArtifactRequestIssuerHandlerTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml1/binding/impl/SAML1ArtifactRequestIssuerHandlerTest.java
@@ -32,6 +32,7 @@ import org.testng.annotations.Test;
import net.shibboleth.shared.component.ComponentInitializationException;
/** {@link SAML1ArtifactRequestIssuerHandler} unit test. */
+ at SuppressWarnings("javadoc")
public class SAML1ArtifactRequestIssuerHandlerTest extends OpenSAMLInitBaseTestCase {
private BasicSAMLArtifactMap artifactMap;
@@ -82,8 +83,7 @@ public class SAML1ArtifactRequestIssuerHandlerTest extends OpenSAMLInitBaseTestC
handler.invoke(mc);
- final SAMLPeerEntityContext peerCtx = mc.getSubcontext(SAMLPeerEntityContext.class);
- Assert.assertNotNull(peerCtx);
+ final SAMLPeerEntityContext peerCtx = mc.ensureSubcontext(SAMLPeerEntityContext.class);
Assert.assertEquals(peerCtx.getEntityId(), "https://sp.example.org");
}
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/assertion/tests/BaseAssertionValidationTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/assertion/tests/BaseAssertionValidationTest.java
index cb0c3c792..fd734a165 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/assertion/tests/BaseAssertionValidationTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/assertion/tests/BaseAssertionValidationTest.java
@@ -46,6 +46,8 @@ import org.opensaml.saml.saml2.core.AuthnContext;
import org.opensaml.saml.saml2.core.AuthnContextClassRef;
import org.opensaml.saml.saml2.core.AuthnStatement;
import org.opensaml.saml.saml2.core.Conditions;
+import org.opensaml.saml.saml2.core.Issuer;
+import org.opensaml.saml.saml2.core.Subject;
import org.opensaml.saml.saml2.core.SubjectConfirmation;
import org.opensaml.saml.saml2.core.SubjectConfirmationData;
import org.opensaml.saml.saml2.core.SubjectLocality;
@@ -65,7 +67,9 @@ import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
+import net.shibboleth.shared.logic.Constraint;
+ at SuppressWarnings("javadoc")
public class BaseAssertionValidationTest extends XMLObjectBaseTestCase {
@Nonnull public static final Duration CLOCK_SKEW = Duration.ofMinutes(5);
@@ -85,23 +89,36 @@ public class BaseAssertionValidationTest extends XMLObjectBaseTestCase {
private Assertion assertion;
- protected Assertion getAssertion() {
- return assertion;
+ @Nonnull Assertion getAssertion() {
+ return Constraint.isNotNull(assertion, "Assertion was null");
}
+ @Nonnull protected Conditions getConditions() {
+ return Constraint.isNotNull(assertion.getConditions(), "Conditions was null");
+ }
+
+ @Nonnull protected Subject getSubject() {
+ return Constraint.isNotNull(assertion.getSubject(), "Subject was null");
+ }
+
+ @Nonnull protected Issuer getIssuer() {
+ return Constraint.isNotNull(assertion.getIssuer(), "Issuer was null");
+ }
+
@BeforeMethod
protected void setUpBasicAssertion() {
assertion = SAML2ActionTestingSupport.buildAssertion();
assertion.setIssueInstant(Instant.now());
assertion.setIssuer(SAML2ActionTestingSupport.buildIssuer(ISSUER));
- assertion.setSubject(SAML2ActionTestingSupport.buildSubject(PRINCIPAL_NAME));
+ final Subject subject = SAML2ActionTestingSupport.buildSubject(PRINCIPAL_NAME);
+ assertion.setSubject(subject);
assertion.setConditions(buildBasicConditions());
SubjectConfirmation subjectConfirmation = buildXMLObject(SubjectConfirmation.DEFAULT_ELEMENT_NAME);
// Default to bearer with basic valid confirmation data, but the test can change as appropriate
subjectConfirmation.setMethod(SubjectConfirmation.METHOD_BEARER);
subjectConfirmation.setSubjectConfirmationData(buildBasicSubjectConfirmationData());
- assertion.getSubject().getSubjectConfirmations().add(subjectConfirmation);
+ subject.getSubjectConfirmations().add(subjectConfirmation);
}
protected Conditions buildBasicConditions() {
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/assertion/tests/MockAssertionValidator.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/assertion/tests/MockAssertionValidator.java
index 7615025c9..440c97606 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/assertion/tests/MockAssertionValidator.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/assertion/tests/MockAssertionValidator.java
@@ -20,6 +20,8 @@ package org.opensaml.saml.saml2.assertion.tests;
import java.util.Collections;
import java.util.Map;
+import javax.annotation.Nonnull;
+
import org.opensaml.saml.common.assertion.AssertionValidationException;
import org.opensaml.saml.common.assertion.ValidationContext;
import org.opensaml.saml.common.assertion.ValidationResult;
@@ -29,6 +31,7 @@ import org.opensaml.saml.saml2.core.Assertion;
import net.shibboleth.shared.collection.Pair;
import net.shibboleth.shared.logic.Constraint;
+ at SuppressWarnings("javadoc")
public class MockAssertionValidator extends SAML20AssertionValidator {
private Map<Assertion, Object> resultsMap;
@@ -39,7 +42,8 @@ public class MockAssertionValidator extends SAML20AssertionValidator {
}
/** {@inheritDoc} */
- public ValidationResult validate(Assertion assertion, ValidationContext context) throws AssertionValidationException {
+ @Nonnull public ValidationResult validate(@Nonnull final Assertion assertion,
+ @Nonnull final ValidationContext context) throws AssertionValidationException {
Object result = resultsMap.get(assertion);
if (Throwable.class.isInstance(result)) {
@@ -73,7 +77,7 @@ public class MockAssertionValidator extends SAML20AssertionValidator {
if (!ValidationResult.VALID.equals(pair.getFirst())) {
context.setValidationFailureMessage(pair.getSecond());
}
- return pair.getFirst();
+ return Constraint.isNotNull(pair.getFirst(), "ValidationResult was null");
}
throw new IllegalArgumentException(String.format("Invalid result type supplied in mock results map for Assertion '%s': %s",
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/assertion/tests/SAML20AssertionValidatorTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/assertion/tests/SAML20AssertionValidatorTest.java
index 49581f76f..ba8fd12a8 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/assertion/tests/SAML20AssertionValidatorTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/assertion/tests/SAML20AssertionValidatorTest.java
@@ -168,7 +168,7 @@ public class SAML20AssertionValidatorTest extends BaseAssertionValidationTest {
@Test
public void testNoSubjectConfirmations() throws AssertionValidationException {
- getAssertion().getSubject().getSubjectConfirmations().clear();
+ getSubject().getSubjectConfirmations().clear();
validator = getCurrentValidator();
@@ -199,7 +199,7 @@ public class SAML20AssertionValidatorTest extends BaseAssertionValidationTest {
Assert.assertEquals(validator.validate(assertion, validationContext), ValidationResult.VALID);
Assert.assertSame(validationContext.getDynamicParameters().get(SAML2AssertionValidationParameters.CONFIRMED_SUBJECT_CONFIRMATION),
- assertion.getSubject().getSubjectConfirmations().get(0));
+ getSubject().getSubjectConfirmations().get(0));
}
@Test
@@ -233,7 +233,7 @@ public class SAML20AssertionValidatorTest extends BaseAssertionValidationTest {
Assert.assertEquals(validator.validate(assertion, validationContext), ValidationResult.VALID);
Assert.assertSame(validationContext.getDynamicParameters().get(SAML2AssertionValidationParameters.CONFIRMED_SUBJECT_CONFIRMATION),
- assertion.getSubject().getSubjectConfirmations().get(0));
+ getSubject().getSubjectConfirmations().get(0));
}
@Test
@@ -254,7 +254,7 @@ public class SAML20AssertionValidatorTest extends BaseAssertionValidationTest {
Assert.assertEquals(validator.validate(assertion, validationContext), ValidationResult.VALID);
Assert.assertSame(validationContext.getDynamicParameters().get(SAML2AssertionValidationParameters.CONFIRMED_SUBJECT_CONFIRMATION),
- assertion.getSubject().getSubjectConfirmations().get(0));
+ getSubject().getSubjectConfirmations().get(0));
}
@Test
@@ -275,7 +275,7 @@ public class SAML20AssertionValidatorTest extends BaseAssertionValidationTest {
Assert.assertEquals(validator.validate(assertion, validationContext), ValidationResult.VALID);
Assert.assertSame(validationContext.getDynamicParameters().get(SAML2AssertionValidationParameters.CONFIRMED_SUBJECT_CONFIRMATION),
- assertion.getSubject().getSubjectConfirmations().get(0));
+ getSubject().getSubjectConfirmations().get(0));
}
@Test
@@ -340,7 +340,7 @@ public class SAML20AssertionValidatorTest extends BaseAssertionValidationTest {
signAssertion(getAssertion(), cred1);
SignatureTrustEngine failingEngine = new SignatureTrustEngine() {
- public boolean validate(Signature token, CriteriaSet trustBasisCriteria) throws SecurityException {
+ public boolean validate(@Nonnull final Signature token, @Nullable final CriteriaSet trustBasisCriteria) throws SecurityException {
throw new SecurityException();
}
@Nullable public KeyInfoCredentialResolver getKeyInfoResolver() {
@@ -381,7 +381,7 @@ public class SAML20AssertionValidatorTest extends BaseAssertionValidationTest {
Assert.assertEquals(validator.validate(assertion, validationContext), ValidationResult.VALID);
Assert.assertSame(validationContext.getDynamicParameters().get(SAML2AssertionValidationParameters.CONFIRMED_SUBJECT_CONFIRMATION),
- assertion.getSubject().getSubjectConfirmations().get(0));
+ getSubject().getSubjectConfirmations().get(0));
}
@Test
@@ -404,8 +404,8 @@ public class SAML20AssertionValidatorTest extends BaseAssertionValidationTest {
@Test
public void testConditionsWithRequiredPresent() throws AssertionValidationException {
- getAssertion().getConditions().getConditions().add(new MockCondition());
- getAssertion().getConditions().getConditions().add(new MockCondition2());
+ getConditions().getConditions().add(new MockCondition());
+ getConditions().getConditions().add(new MockCondition2());
conditionValidators.add(new MockConditionValidator());
conditionValidators.add(new MockCondition2Validator());
@@ -426,7 +426,7 @@ public class SAML20AssertionValidatorTest extends BaseAssertionValidationTest {
@Test
public void testConditionsWithRequiredMissing() throws AssertionValidationException {
- getAssertion().getConditions().getConditions().add(new MockCondition2());
+ getConditions().getConditions().add(new MockCondition2());
conditionValidators.add(new MockConditionValidator());
conditionValidators.add(new MockCondition2Validator());
@@ -447,8 +447,8 @@ public class SAML20AssertionValidatorTest extends BaseAssertionValidationTest {
@Test
public void testInvalidConditionsNotBefore() throws AssertionValidationException {
- getAssertion().getConditions().setNotBefore(Instant.now().plus(30, ChronoUnit.MINUTES));
- getAssertion().getConditions().setNotOnOrAfter(Instant.now().plus(60, ChronoUnit.MINUTES));
+ getConditions().setNotBefore(Instant.now().plus(30, ChronoUnit.MINUTES));
+ getConditions().setNotOnOrAfter(Instant.now().plus(60, ChronoUnit.MINUTES));
validator = getCurrentValidator();
@@ -464,8 +464,8 @@ public class SAML20AssertionValidatorTest extends BaseAssertionValidationTest {
@Test
public void testInvalidConditionsNotOnOrAfter() throws AssertionValidationException {
- getAssertion().getConditions().setNotBefore(Instant.now().minus(60, ChronoUnit.MINUTES));
- getAssertion().getConditions().setNotOnOrAfter(Instant.now().minus(30, ChronoUnit.MINUTES));
+ getConditions().setNotBefore(Instant.now().minus(60, ChronoUnit.MINUTES));
+ getConditions().setNotOnOrAfter(Instant.now().minus(30, ChronoUnit.MINUTES));
validator = getCurrentValidator();
@@ -491,7 +491,7 @@ public class SAML20AssertionValidatorTest extends BaseAssertionValidationTest {
}
};
conditionValidators.add(failingValidator);
- getAssertion().getConditions().getConditions().add((Condition) buildXMLObject(OneTimeUse.DEFAULT_ELEMENT_NAME));
+ getConditions().getConditions().add((Condition) buildXMLObject(OneTimeUse.DEFAULT_ELEMENT_NAME));
validator = getCurrentValidator();
@@ -507,7 +507,7 @@ public class SAML20AssertionValidatorTest extends BaseAssertionValidationTest {
@Test
public void testUnknownCondition() throws AssertionValidationException {
- getAssertion().getConditions().getConditions().add((Condition) buildXMLObject(OneTimeUse.DEFAULT_ELEMENT_NAME));
+ getConditions().getConditions().add((Condition) buildXMLObject(OneTimeUse.DEFAULT_ELEMENT_NAME));
validator = getCurrentValidator();
@@ -565,7 +565,7 @@ public class SAML20AssertionValidatorTest extends BaseAssertionValidationTest {
@Test
public void testInvalidIssuer() throws AssertionValidationException {
- getAssertion().getIssuer().setValue("invalid");
+ getIssuer().setValue("invalid");
validator = getCurrentValidator();
@@ -725,7 +725,8 @@ public class SAML20AssertionValidatorTest extends BaseAssertionValidationTest {
this(ELEMENT_NAME.getNamespaceURI(), ELEMENT_NAME.getLocalPart(), ELEMENT_NAME.getPrefix());
}
- protected MockCondition(String namespaceURI, String elementLocalName, String namespacePrefix) {
+ protected MockCondition(@Nullable final String namespaceURI, @Nonnull final String elementLocalName,
+ @Nonnull final String namespacePrefix) {
super(namespaceURI, elementLocalName, namespacePrefix);
}
@@ -744,7 +745,8 @@ public class SAML20AssertionValidatorTest extends BaseAssertionValidationTest {
this(ELEMENT_NAME.getNamespaceURI(), ELEMENT_NAME.getLocalPart(), ELEMENT_NAME.getPrefix());
}
- protected MockCondition2(String namespaceURI, String elementLocalName, String namespacePrefix) {
+ protected MockCondition2(@Nullable final String namespaceURI, @Nonnull final String elementLocalName,
+ @Nonnull final String namespacePrefix) {
super(namespaceURI, elementLocalName, namespacePrefix);
}
@@ -758,13 +760,14 @@ public class SAML20AssertionValidatorTest extends BaseAssertionValidationTest {
public static class MockConditionValidator implements ConditionValidator {
/** {@inheritDoc} */
- public QName getServicedCondition() {
+ @Nonnull public QName getServicedCondition() {
return MockCondition.ELEMENT_NAME;
}
/** {@inheritDoc} */
- public ValidationResult validate(Condition condition, Assertion assertion, ValidationContext context)
- throws AssertionValidationException {
+ @Nonnull public ValidationResult validate(@Nonnull final Condition condition,
+ @Nonnull final Assertion assertion, @Nonnull final ValidationContext context)
+ throws AssertionValidationException {
return ValidationResult.VALID;
}
@@ -773,16 +776,16 @@ public class SAML20AssertionValidatorTest extends BaseAssertionValidationTest {
public static class MockCondition2Validator implements ConditionValidator {
/** {@inheritDoc} */
- public QName getServicedCondition() {
+ @Nonnull public QName getServicedCondition() {
return MockCondition2.ELEMENT_NAME;
}
/** {@inheritDoc} */
- public ValidationResult validate(Condition condition, Assertion assertion, ValidationContext context)
- throws AssertionValidationException {
+ @Nonnull public ValidationResult validate(@Nonnull final Condition condition,
+ @Nonnull final Assertion assertion, @Nonnull final ValidationContext context)
+ throws AssertionValidationException {
return ValidationResult.VALID;
}
-
}
-}
+}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostEncoderTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostEncoderTest.java
index 7ca844110..fe97c65db 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostEncoderTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostEncoderTest.java
@@ -55,6 +55,7 @@ import net.shibboleth.shared.testing.ConstantSupplier;
/**
* Test case for {@link HTTPPostEncoder}.
*/
+ at SuppressWarnings("javadoc")
public class HTTPPostEncoderTest extends XMLObjectBaseTestCase {
/** Velocity template engine. */
@@ -105,8 +106,8 @@ public class HTTPPostEncoderTest extends XMLObjectBaseTestCase {
MessageContext messageContext = new MessageContext();
messageContext.setMessage(samlMessage);
SAMLBindingSupport.setRelayState(messageContext, "relay");
- messageContext.getSubcontext(SAMLPeerEntityContext.class, true)
- .getSubcontext(SAMLEndpointContext.class, true).setEndpoint(samlEndpoint);
+ messageContext.ensureSubcontext(SAMLPeerEntityContext.class)
+ .ensureSubcontext(SAMLEndpointContext.class).setEndpoint(samlEndpoint);
SAMLOutboundDestinationHandler handler = new SAMLOutboundDestinationHandler();
handler.invoke(messageContext);
@@ -143,39 +144,39 @@ public class HTTPPostEncoderTest extends XMLObjectBaseTestCase {
Assert.assertTrue(sawDocType);
Element head = webDoc.selectFirst("html > head");
- Assert.assertNotNull(head);
+ assert head != null;
Element metaCharSet = head.selectFirst("meta[charset]");
- Assert.assertNotNull(metaCharSet);
+ assert metaCharSet != null;
Assert.assertEquals(metaCharSet.attr("charset").toLowerCase(), "utf-8");
Element body = webDoc.selectFirst("html > body");
- Assert.assertNotNull(body);
+ assert body != null;
Assert.assertEquals(body.attr("onload"), "document.forms[0].submit()");
Element form = body.selectFirst("form");
- Assert.assertNotNull(form);
+ assert form != null;
Assert.assertEquals(form.attr("method").toLowerCase(), "post");
Assert.assertEquals(form.attr("action"), "http://example.org/response");
Element relayState = form.selectFirst("input[name=RelayState]");
- Assert.assertNotNull(relayState);
+ assert relayState != null;
Assert.assertEquals(relayState.val(), "relay");
Element noscriptMsg = body.selectFirst("noscript > p");
- Assert.assertNotNull(noscriptMsg);
+ assert noscriptMsg != null;
Assert.assertTrue(noscriptMsg.text().contains("Since your browser does not support JavaScript"));
Element samlResponse = form.selectFirst("input[name=SAMLResponse]");
- Assert.assertNotNull(samlResponse);
+ assert samlResponse != null;
Assert.assertNotNull(samlResponse.val());
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Support.decode(samlResponse.val()))) {
XMLObject xmlObject = XMLObjectSupport.unmarshallFromInputStream(parserPool, inputStream);
Assert.assertTrue(xmlObject instanceof Response);
- assertXMLEquals(xmlObject.getDOM().getOwnerDocument(), samlMessage);
+ assertXMLEquals(xmlObject.ensureDOM().getOwnerDocument(), samlMessage);
}
Element submit = body.selectFirst("noscript > div > input[type=submit]");
- Assert.assertNotNull(submit);
+ assert submit != null;
Assert.assertEquals(submit.val(), "Continue");
}
@@ -183,15 +184,15 @@ public class HTTPPostEncoderTest extends XMLObjectBaseTestCase {
@Test
@SuppressWarnings("unchecked")
public void testRequestEncoding() throws Exception {
- SAMLObjectBuilder<AuthnRequest> responseBuilder = (SAMLObjectBuilder<AuthnRequest>) builderFactory
- .getBuilder(AuthnRequest.DEFAULT_ELEMENT_NAME);
- AuthnRequest samlMessage = responseBuilder.buildObject();
+ SAMLObjectBuilder<AuthnRequest> requestBuilder =
+ (SAMLObjectBuilder<AuthnRequest>) builderFactory.<AuthnRequest>ensureBuilder(AuthnRequest.DEFAULT_ELEMENT_NAME);
+ AuthnRequest samlMessage = requestBuilder.buildObject();
samlMessage.setID("foo");
samlMessage.setVersion(SAMLVersion.VERSION_20);
samlMessage.setIssueInstant(Instant.ofEpochMilli(0));
- SAMLObjectBuilder<Endpoint> endpointBuilder = (SAMLObjectBuilder<Endpoint>) builderFactory
- .getBuilder(AssertionConsumerService.DEFAULT_ELEMENT_NAME);
+ SAMLObjectBuilder<Endpoint> endpointBuilder =
+ (SAMLObjectBuilder<Endpoint>) builderFactory.<Endpoint>ensureBuilder(AssertionConsumerService.DEFAULT_ELEMENT_NAME);
Endpoint samlEndpoint = endpointBuilder.buildObject();
samlEndpoint.setLocation("http://example.org");
samlEndpoint.setResponseLocation("http://example.org/response");
@@ -199,8 +200,8 @@ public class HTTPPostEncoderTest extends XMLObjectBaseTestCase {
MessageContext messageContext = new MessageContext();
messageContext.setMessage(samlMessage);
SAMLBindingSupport.setRelayState(messageContext, "relay");
- messageContext.getSubcontext(SAMLPeerEntityContext.class, true)
- .getSubcontext(SAMLEndpointContext.class, true).setEndpoint(samlEndpoint);
+ messageContext.ensureSubcontext(SAMLPeerEntityContext.class)
+ .ensureSubcontext(SAMLEndpointContext.class).setEndpoint(samlEndpoint);
SAMLOutboundDestinationHandler handler = new SAMLOutboundDestinationHandler();
handler.invoke(messageContext);
@@ -237,39 +238,39 @@ public class HTTPPostEncoderTest extends XMLObjectBaseTestCase {
Assert.assertTrue(sawDocType);
Element head = webDoc.selectFirst("html > head");
- Assert.assertNotNull(head);
+ assert head != null;
Element metaCharSet = head.selectFirst("meta[charset]");
- Assert.assertNotNull(metaCharSet);
+ assert metaCharSet != null;
Assert.assertEquals(metaCharSet.attr("charset").toLowerCase(), "utf-8");
Element body = webDoc.selectFirst("html > body");
- Assert.assertNotNull(body);
+ assert body != null;
Assert.assertEquals(body.attr("onload"), "document.forms[0].submit()");
Element form = body.selectFirst("form");
- Assert.assertNotNull(form);
+ assert form != null;
Assert.assertEquals(form.attr("method").toLowerCase(), "post");
Assert.assertEquals(form.attr("action"), "http://example.org");
Element relayState = form.selectFirst("input[name=RelayState]");
- Assert.assertNotNull(relayState);
+ assert relayState != null;
Assert.assertEquals(relayState.val(), "relay");
Element noscriptMsg = body.selectFirst("noscript > p");
- Assert.assertNotNull(noscriptMsg);
+ assert noscriptMsg != null;
Assert.assertTrue(noscriptMsg.text().contains("Since your browser does not support JavaScript"));
Element samlResponse = form.selectFirst("input[name=SAMLRequest]");
- Assert.assertNotNull(samlResponse);
+ assert samlResponse != null;
Assert.assertNotNull(samlResponse.val());
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Support.decode(samlResponse.val()))) {
XMLObject xmlObject = XMLObjectSupport.unmarshallFromInputStream(parserPool, inputStream);
Assert.assertTrue(xmlObject instanceof AuthnRequest);
- assertXMLEquals(xmlObject.getDOM().getOwnerDocument(), samlMessage);
+ assertXMLEquals(xmlObject.ensureDOM().getOwnerDocument(), samlMessage);
}
Element submit = body.selectFirst("noscript > div > input[type=submit]");
- Assert.assertNotNull(submit);
+ assert submit != null;
Assert.assertEquals(submit.val(), "Continue");
}
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostSimpleSignEncoderTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostSimpleSignEncoderTest.java
index e42c2cdc0..cbf31cb46 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostSimpleSignEncoderTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/binding/encoding/impl/HTTPPostSimpleSignEncoderTest.java
@@ -45,11 +45,13 @@ import org.opensaml.saml.saml2.core.Status;
import org.opensaml.saml.saml2.core.StatusCode;
import org.opensaml.saml.saml2.metadata.AssertionConsumerService;
import org.opensaml.saml.saml2.metadata.Endpoint;
+import org.opensaml.security.credential.Credential;
import org.opensaml.security.credential.CredentialSupport;
import org.opensaml.security.crypto.KeySupport;
import org.opensaml.xmlsec.SignatureSigningParameters;
import org.opensaml.xmlsec.config.impl.DefaultSecurityConfigurationBootstrap;
import org.opensaml.xmlsec.context.SecurityParametersContext;
+import org.opensaml.xmlsec.keyinfo.KeyInfoGenerator;
import org.opensaml.xmlsec.keyinfo.KeyInfoSupport;
import org.opensaml.xmlsec.keyinfo.NamedKeyInfoGeneratorManager;
import org.opensaml.xmlsec.signature.KeyInfo;
@@ -116,8 +118,8 @@ public class HTTPPostSimpleSignEncoderTest extends XMLObjectBaseTestCase {
MessageContext messageContext = new MessageContext();
messageContext.setMessage(samlMessage);
SAMLBindingSupport.setRelayState(messageContext, "relay");
- messageContext.getSubcontext(SAMLPeerEntityContext.class, true)
- .getSubcontext(SAMLEndpointContext.class, true).setEndpoint(samlEndpoint);
+ messageContext.ensureSubcontext(SAMLPeerEntityContext.class)
+ .ensureSubcontext(SAMLEndpointContext.class).setEndpoint(samlEndpoint);
SAMLOutboundDestinationHandler handler = new SAMLOutboundDestinationHandler();
handler.invoke(messageContext);
@@ -154,35 +156,35 @@ public class HTTPPostSimpleSignEncoderTest extends XMLObjectBaseTestCase {
Assert.assertTrue(sawDocType);
Element head = webDoc.selectFirst("html > head");
- Assert.assertNotNull(head);
+ assert head != null;
Element metaCharSet = head.selectFirst("meta[charset]");
- Assert.assertNotNull(metaCharSet);
+ assert metaCharSet != null;
Assert.assertEquals(metaCharSet.attr("charset").toLowerCase(), "utf-8");
Element body = webDoc.selectFirst("html > body");
- Assert.assertNotNull(body);
+ assert body != null;
Assert.assertEquals(body.attr("onload"), "document.forms[0].submit()");
Element form = body.selectFirst("form");
- Assert.assertNotNull(form);
+ assert form != null;
Assert.assertEquals(form.attr("method").toLowerCase(), "post");
Assert.assertEquals(form.attr("action"), "http://example.org/response");
Element relayState = form.selectFirst("input[name=RelayState]");
- Assert.assertNotNull(relayState);
+ assert relayState != null;
Assert.assertEquals(relayState.val(), "relay");
Element noscriptMsg = body.selectFirst("noscript > p");
- Assert.assertNotNull(noscriptMsg);
+ assert noscriptMsg != null;
Assert.assertTrue(noscriptMsg.text().contains("Since your browser does not support JavaScript"));
Element samlResponse = form.selectFirst("input[name=SAMLResponse]");
- Assert.assertNotNull(samlResponse);
+ assert samlResponse != null;
Assert.assertNotNull(samlResponse.val());
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Support.decode(samlResponse.val()))) {
XMLObject xmlObject = XMLObjectSupport.unmarshallFromInputStream(parserPool, inputStream);
Assert.assertTrue(xmlObject instanceof Response);
- assertXMLEquals(xmlObject.getDOM().getOwnerDocument(), samlMessage);
+ assertXMLEquals(xmlObject.ensureDOM().getOwnerDocument(), samlMessage);
}
Assert.assertNull(form.selectFirst("input[name=SigAlg]"));
@@ -190,22 +192,22 @@ public class HTTPPostSimpleSignEncoderTest extends XMLObjectBaseTestCase {
Assert.assertNull(form.selectFirst("input[name=KeyInfo]"));
Element submit = body.selectFirst("noscript > div > input[type=submit]");
- Assert.assertNotNull(submit);
+ assert submit != null;
Assert.assertEquals(submit.val(), "Continue");
}
@Test
@SuppressWarnings("unchecked")
public void testRequestEncoding() throws Exception {
- SAMLObjectBuilder<AuthnRequest> responseBuilder = (SAMLObjectBuilder<AuthnRequest>) builderFactory
- .getBuilder(AuthnRequest.DEFAULT_ELEMENT_NAME);
+ SAMLObjectBuilder<AuthnRequest> responseBuilder =
+ (SAMLObjectBuilder<AuthnRequest>) builderFactory.<AuthnRequest>ensureBuilder(AuthnRequest.DEFAULT_ELEMENT_NAME);
AuthnRequest samlMessage = responseBuilder.buildObject();
samlMessage.setID("foo");
samlMessage.setVersion(SAMLVersion.VERSION_20);
samlMessage.setIssueInstant(Instant.ofEpochMilli(0));
- SAMLObjectBuilder<Endpoint> endpointBuilder = (SAMLObjectBuilder<Endpoint>) builderFactory
- .getBuilder(AssertionConsumerService.DEFAULT_ELEMENT_NAME);
+ SAMLObjectBuilder<Endpoint> endpointBuilder =
+ (SAMLObjectBuilder<Endpoint>) builderFactory.<Endpoint>ensureBuilder(AssertionConsumerService.DEFAULT_ELEMENT_NAME);
Endpoint samlEndpoint = endpointBuilder.buildObject();
samlEndpoint.setLocation("http://example.org");
samlEndpoint.setResponseLocation("http://example.org/response");
@@ -213,8 +215,8 @@ public class HTTPPostSimpleSignEncoderTest extends XMLObjectBaseTestCase {
MessageContext messageContext = new MessageContext();
messageContext.setMessage(samlMessage);
SAMLBindingSupport.setRelayState(messageContext, "relay");
- messageContext.getSubcontext(SAMLPeerEntityContext.class, true)
- .getSubcontext(SAMLEndpointContext.class, true).setEndpoint(samlEndpoint);
+ messageContext.ensureSubcontext(SAMLPeerEntityContext.class)
+ .ensureSubcontext(SAMLEndpointContext.class).setEndpoint(samlEndpoint);
MockHttpServletResponse response = new MockHttpServletResponse();
@@ -248,35 +250,35 @@ public class HTTPPostSimpleSignEncoderTest extends XMLObjectBaseTestCase {
Assert.assertTrue(sawDocType);
Element head = webDoc.selectFirst("html > head");
- Assert.assertNotNull(head);
+ assert head != null;
Element metaCharSet = head.selectFirst("meta[charset]");
- Assert.assertNotNull(metaCharSet);
+ assert metaCharSet != null;
Assert.assertEquals(metaCharSet.attr("charset").toLowerCase(), "utf-8");
Element body = webDoc.selectFirst("html > body");
- Assert.assertNotNull(body);
+ assert body != null;
Assert.assertEquals(body.attr("onload"), "document.forms[0].submit()");
Element form = body.selectFirst("form");
- Assert.assertNotNull(form);
+ assert form != null;
Assert.assertEquals(form.attr("method").toLowerCase(), "post");
Assert.assertEquals(form.attr("action"), "http://example.org");
Element relayState = form.selectFirst("input[name=RelayState]");
- Assert.assertNotNull(relayState);
+ assert relayState != null;
Assert.assertEquals(relayState.val(), "relay");
Element noscriptMsg = body.selectFirst("noscript > p");
- Assert.assertNotNull(noscriptMsg);
+ assert noscriptMsg != null;
Assert.assertTrue(noscriptMsg.text().contains("Since your browser does not support JavaScript"));
Element samlResponse = form.selectFirst("input[name=SAMLRequest]");
- Assert.assertNotNull(samlResponse);
+ assert samlResponse != null;
Assert.assertNotNull(samlResponse.val());
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Support.decode(samlResponse.val()))) {
XMLObject xmlObject = XMLObjectSupport.unmarshallFromInputStream(parserPool, inputStream);
Assert.assertTrue(xmlObject instanceof AuthnRequest);
- assertXMLEquals(xmlObject.getDOM().getOwnerDocument(), samlMessage);
+ assertXMLEquals(xmlObject.ensureDOM().getOwnerDocument(), samlMessage);
}
Assert.assertNull(form.selectFirst("input[name=SigAlg]"));
@@ -284,22 +286,22 @@ public class HTTPPostSimpleSignEncoderTest extends XMLObjectBaseTestCase {
Assert.assertNull(form.selectFirst("input[name=KeyInfo]"));
Element submit = body.selectFirst("noscript > div > input[type=submit]");
- Assert.assertNotNull(submit);
+ assert submit != null;
Assert.assertEquals(submit.val(), "Continue");
}
@Test
@SuppressWarnings("unchecked")
public void testRequestEncodingWithSimpleSign() throws Exception {
- SAMLObjectBuilder<AuthnRequest> responseBuilder = (SAMLObjectBuilder<AuthnRequest>) builderFactory
- .getBuilder(AuthnRequest.DEFAULT_ELEMENT_NAME);
+ SAMLObjectBuilder<AuthnRequest> responseBuilder =
+ (SAMLObjectBuilder<AuthnRequest>) builderFactory.<AuthnRequest>ensureBuilder(AuthnRequest.DEFAULT_ELEMENT_NAME);
AuthnRequest samlMessage = responseBuilder.buildObject();
samlMessage.setID("foo");
samlMessage.setVersion(SAMLVersion.VERSION_20);
samlMessage.setIssueInstant(Instant.ofEpochMilli(0));
- SAMLObjectBuilder<Endpoint> endpointBuilder = (SAMLObjectBuilder<Endpoint>) builderFactory
- .getBuilder(AssertionConsumerService.DEFAULT_ELEMENT_NAME);
+ SAMLObjectBuilder<Endpoint> endpointBuilder =
+ (SAMLObjectBuilder<Endpoint>) builderFactory.<Endpoint>ensureBuilder(AssertionConsumerService.DEFAULT_ELEMENT_NAME);
Endpoint samlEndpoint = endpointBuilder.buildObject();
samlEndpoint.setLocation("http://example.org");
samlEndpoint.setResponseLocation("http://example.org/response");
@@ -307,16 +309,17 @@ public class HTTPPostSimpleSignEncoderTest extends XMLObjectBaseTestCase {
MessageContext messageContext = new MessageContext();
messageContext.setMessage(samlMessage);
SAMLBindingSupport.setRelayState(messageContext, "relay");
- messageContext.getSubcontext(SAMLPeerEntityContext.class, true)
- .getSubcontext(SAMLEndpointContext.class, true).setEndpoint(samlEndpoint);
+ messageContext.ensureSubcontext(SAMLPeerEntityContext.class)
+ .ensureSubcontext(SAMLEndpointContext.class).setEndpoint(samlEndpoint);
KeyPair kp = KeySupport.generateKeyPair("RSA", 1024, null);
SignatureSigningParameters signingParameters = new SignatureSigningParameters();
- signingParameters.setSigningCredential(CredentialSupport.getSimpleCredential(kp.getPublic(), kp.getPrivate()));
+ final Credential signingCredential = CredentialSupport.getSimpleCredential(kp.getPublic(), kp.getPrivate());
+ signingParameters.setSigningCredential(signingCredential);
signingParameters.setSignatureAlgorithm(SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA256);
NamedKeyInfoGeneratorManager kiManager = DefaultSecurityConfigurationBootstrap.buildBasicKeyInfoGeneratorManager();
- signingParameters.setKeyInfoGenerator(KeyInfoSupport.getKeyInfoGenerator(signingParameters.getSigningCredential(), kiManager, null));
- messageContext.getSubcontext(SecurityParametersContext.class, true).setSignatureSigningParameters(signingParameters);
+ signingParameters.setKeyInfoGenerator(KeyInfoSupport.getKeyInfoGenerator(signingCredential, kiManager, null));
+ messageContext.ensureSubcontext(SecurityParametersContext.class).setSignatureSigningParameters(signingParameters);
MockHttpServletResponse response = new MockHttpServletResponse();
@@ -346,51 +349,55 @@ public class HTTPPostSimpleSignEncoderTest extends XMLObjectBaseTestCase {
Assert.assertTrue(sawDocType);
Element head = webDoc.selectFirst("html > head");
- Assert.assertNotNull(head);
+ assert head != null;
Element metaCharSet = head.selectFirst("meta[charset]");
- Assert.assertNotNull(metaCharSet);
+ assert metaCharSet != null;
Assert.assertEquals(metaCharSet.attr("charset").toLowerCase(), "utf-8");
Element body = webDoc.selectFirst("html > body");
- Assert.assertNotNull(body);
+ assert body != null;
Assert.assertEquals(body.attr("onload"), "document.forms[0].submit()");
Element form = body.selectFirst("form");
- Assert.assertNotNull(form);
+ assert form != null;
Assert.assertEquals(form.attr("method").toLowerCase(), "post");
Assert.assertEquals(form.attr("action"), "http://example.org");
Element relayState = form.selectFirst("input[name=RelayState]");
- Assert.assertNotNull(relayState);
+ assert relayState != null;
Assert.assertEquals(relayState.val(), "relay");
Element noscriptMsg = body.selectFirst("noscript > p");
- Assert.assertNotNull(noscriptMsg);
+ assert noscriptMsg != null;
Assert.assertTrue(noscriptMsg.text().contains("Since your browser does not support JavaScript"));
Element samlResponse = form.selectFirst("input[name=SAMLRequest]");
- Assert.assertNotNull(samlResponse);
+ assert samlResponse != null;
Assert.assertNotNull(samlResponse.val());
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Support.decode(samlResponse.val()))) {
XMLObject xmlObject = XMLObjectSupport.unmarshallFromInputStream(parserPool, inputStream);
Assert.assertTrue(xmlObject instanceof AuthnRequest);
- assertXMLEquals(xmlObject.getDOM().getOwnerDocument(), samlMessage);
+ assertXMLEquals(xmlObject.ensureDOM().getOwnerDocument(), samlMessage);
}
- Assert.assertNotNull(form.selectFirst("input[name=SigAlg]"));
- Assert.assertEquals(form.selectFirst("input[name=SigAlg]").val(), SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA256);
- Assert.assertNotNull(form.selectFirst("input[name=Signature]"));
- Assert.assertNotNull(form.selectFirst("input[name=Signature]").val());
- Assert.assertNotNull(form.selectFirst("input[name=KeyInfo]"));
- try (ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Support.decode(form.selectFirst("input[name=KeyInfo]").val()))) {
+ var formElement = form.selectFirst("input[name=SigAlg]");
+ assert formElement != null;
+ Assert.assertEquals(formElement.val(), SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA256);
+ formElement = form.selectFirst("input[name=Signature]");
+ assert formElement != null;
+ Assert.assertNotNull(formElement.val());
+ formElement = form.selectFirst("input[name=KeyInfo]");
+ assert formElement != null;
+ try (ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Support.decode(formElement.val()))) {
XMLObject xmlObject = XMLObjectSupport.unmarshallFromInputStream(parserPool, inputStream);
Assert.assertTrue(xmlObject instanceof KeyInfo);
- assertXMLEquals(xmlObject.getDOM().getOwnerDocument(),
- signingParameters.getKeyInfoGenerator().generate(signingParameters.getSigningCredential()));
+ final KeyInfoGenerator generator = signingParameters.getKeyInfoGenerator();
+ assert generator != null;
+ assertXMLEquals(xmlObject.ensureDOM().getOwnerDocument(), generator.generate(signingParameters.getSigningCredential()));
}
Element submit = body.selectFirst("noscript > div > input[type=submit]");
- Assert.assertNotNull(submit);
+ assert submit != null;
Assert.assertEquals(submit.val(), "Continue");
// Note: to test that actual signature is cryptographically correct, really need a known good test vector.
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/core/tests/AuthnRequestTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/core/tests/AuthnRequestTest.java
index ddc0e275c..829e6819a 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/core/tests/AuthnRequestTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/core/tests/AuthnRequestTest.java
@@ -53,23 +53,34 @@ public class AuthnRequestTest extends BaseComplexSAMLObjectTestCase {
/** {@inheritDoc} */
@Test
public void testUnmarshall() {
- AuthnRequest request = (AuthnRequest) unmarshallElement(elementFile);
+ final AuthnRequest request = (AuthnRequest) unmarshallElement(elementFile);
+ assert request != null;
- Assert.assertNotNull(request, "AuthnRequest was null");
- Assert.assertEquals(request.isForceAuthn().booleanValue(), true, "ForceAuthn");
+ Assert.assertEquals(request.isForceAuthn(), Boolean.TRUE, "ForceAuthn");
Assert.assertEquals(request.getAssertionConsumerServiceURL(), "http://www.example.com/", "AssertionConsumerServiceURL");
- Assert.assertEquals(request.getAttributeConsumingServiceIndex().intValue(), 0, "AttributeConsumingServiceIndex");
+ Assert.assertEquals(request.getAttributeConsumingServiceIndex(), 0, "AttributeConsumingServiceIndex");
Assert.assertEquals(request.getProviderName(), "SomeProvider", "ProviderName");
Assert.assertEquals(request.getID(), "abe567de6", "ID");
- Assert.assertEquals(request.getVersion().toString(), SAMLVersion.VERSION_20.toString(), "Version");
+ Assert.assertEquals(request.getVersion(), SAMLVersion.VERSION_20, "Version");
Assert.assertEquals(request.getIssueInstant(), Instant.parse("2005-01-31T12:00:00.000Z"), "IssueInstant");
Assert.assertEquals(request.getDestination(), "http://www.example.com/", "Destination");
Assert.assertEquals(request.getConsent(), RequestAbstractType.OBTAINED_CONSENT, "Consent");
- Assert.assertEquals(request.getSubject().getNameID().getFormat(), NameIDType.EMAIL, "Subject/NameID/@NameIdFormat");
- Assert.assertEquals(request.getSubject().getNameID().getValue(), "j.doe at company.com", "Subject/NameID contents");
- Audience audience = request.getConditions().getAudienceRestrictions().get(0).getAudiences().get(0);
+
+ final Subject subject = request.getSubject();
+ assert subject != null;
+ final NameID nameID = subject.getNameID();
+ assert nameID != null;
+ Assert.assertEquals(nameID.getFormat(), NameIDType.EMAIL, "Subject/NameID/@NameIdFormat");
+ Assert.assertEquals(nameID.getValue(), "j.doe at company.com", "Subject/NameID contents");
+
+ final Conditions cond = request.getConditions();
+ assert cond != null;
+ final Audience audience = cond.getAudienceRestrictions().get(0).getAudiences().get(0);
Assert.assertEquals(audience.getURI(), "urn:foo:sp.example.org", "Conditions/AudienceRestriction[1]/Audience[1] contents");
- AuthnContextClassRef classRef = request.getRequestedAuthnContext().getAuthnContextClassRefs().get(0);
+
+ final RequestedAuthnContext rac = request.getRequestedAuthnContext();
+ assert rac != null;
+ final AuthnContextClassRef classRef = rac.getAuthnContextClassRefs().get(0);
Assert.assertEquals(classRef.getURI(), AuthnContext.PPT_AUTHN_CTX, "RequestedAuthnContext/AuthnContextClassRef[1] contents");
}
@@ -114,7 +125,6 @@ public class AuthnRequestTest extends BaseComplexSAMLObjectTestCase {
request.setConsent(RequestAbstractType.OBTAINED_CONSENT);
assertXMLEquals("Marshalled AuthnRequest", expectedDOM, request);
-
-
}
+
}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/core/tests/ResponseSuccessAuthnAttribTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/core/tests/ResponseSuccessAuthnAttribTest.java
index 4357fec0e..9fbf54c74 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/core/tests/ResponseSuccessAuthnAttribTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/core/tests/ResponseSuccessAuthnAttribTest.java
@@ -60,34 +60,58 @@ public class ResponseSuccessAuthnAttribTest extends BaseComplexSAMLObjectTestCas
/** {@inheritDoc} */
@Test
public void testUnmarshall() {
- Response response = (Response) unmarshallElement(elementFile);
+ final Response response = (Response) unmarshallElement(elementFile);
+ assert response != null;
- Assert.assertNotNull(response, "Response was null");
Assert.assertEquals(response.getID(), "_c7055387-af61-4fce-8b98-e2927324b306", "Response ID");
Assert.assertEquals(response.getInResponseTo(), "_abcdef123456", "InResponseTo");
- Assert.assertEquals(response.getVersion().toString(), SAMLVersion.VERSION_20.toString(), "Version");
+ Assert.assertEquals(response.getVersion(), SAMLVersion.VERSION_20, "Version");
Assert.assertEquals(response.getIssueInstant(), Instant.parse("2006-01-26T13:35:05.000Z"), "IssueInstant");
- Assert.assertEquals(response.getIssuer().getFormat(), NameIDType.ENTITY, "Issuer/@Format");
- Assert.assertEquals(response.getStatus().getStatusCode().getValue(), StatusCode.SUCCESS, "Status/Statuscode/@Value");
- Assertion assertion = response.getAssertions().get(0);
+ final Issuer issuer = response.getIssuer();
+ assert issuer != null;
+ Assert.assertEquals(issuer.getFormat(), NameIDType.ENTITY, "Issuer/@Format");
+
+ final Status status = response.getStatus();
+ assert status != null;
+ final StatusCode code = status.getStatusCode();
+ assert code != null;
+ Assert.assertEquals(code.getValue(), StatusCode.SUCCESS, "Status/Statuscode/@Value");
+
+ final Assertion assertion = response.getAssertions().get(0);
Assert.assertNotNull(assertion, "Assertion[0] was null");
Assert.assertEquals(assertion.getID(), "_a75adf55-01d7-40cc-929f-dbd8372ebdfc", "Assertion ID");
Assert.assertEquals(assertion.getIssueInstant(), Instant.parse("2006-01-26T13:35:05.000Z"), "Assertion/@IssueInstant");
- Assert.assertEquals(assertion.getVersion().toString(), SAMLVersion.VERSION_20.toString(), "Assertion/@Version");
- Assert.assertEquals(assertion.getIssuer().getFormat(), NameIDType.ENTITY, "Assertion/Issuer/@Format");
- Assert.assertEquals(assertion.getSubject().getNameID().getFormat(), NameIDType.TRANSIENT, "Assertion/Subject/NameID/@Format");
- Assert.assertEquals(assertion.getSubject().getNameID().getValue(), "_820d2843-2342-8236-ad28-8ac94fb3e6a1", "Assertion/Subject/NameID contents");
- SubjectConfirmation sc = assertion.getSubject().getSubjectConfirmations().get(0);
+ Assert.assertEquals(assertion.getVersion(), SAMLVersion.VERSION_20, "Assertion/@Version");
+
+ final Issuer aissuer = assertion.getIssuer();
+ assert aissuer != null;
+ Assert.assertEquals(aissuer.getFormat(), NameIDType.ENTITY, "Assertion/Issuer/@Format");
+
+ final Subject subject = assertion.getSubject();
+ assert subject != null;
+ final NameID nameID = subject.getNameID();
+ assert nameID != null;
+ Assert.assertEquals(nameID.getFormat(), NameIDType.TRANSIENT, "Assertion/Subject/NameID/@Format");
+ Assert.assertEquals(nameID.getValue(), "_820d2843-2342-8236-ad28-8ac94fb3e6a1", "Assertion/Subject/NameID contents");
+
+ final SubjectConfirmation sc = subject.getSubjectConfirmations().get(0);
Assert.assertEquals(sc.getMethod(), SubjectConfirmation.METHOD_BEARER, "Assertion/Subject/SubjectConfirmation/@Method");
- Assert.assertEquals(assertion.getConditions().getNotBefore(), Instant.parse("2006-01-26T13:35:05.000Z"), "Assertion/Condition/@NotBefore");
- Assert.assertEquals(assertion.getConditions().getNotOnOrAfter(), Instant.parse("2006-01-26T13:45:05.000Z"), "Assertion/Condition/@NotOnOrAfter");
- Audience audience = assertion.getConditions().getAudienceRestrictions().get(0).getAudiences().get(0);
+
+ final Conditions cond = assertion.getConditions();
+ assert cond != null;
+ Assert.assertEquals(cond.getNotBefore(), Instant.parse("2006-01-26T13:35:05.000Z"), "Assertion/Condition/@NotBefore");
+ Assert.assertEquals(cond.getNotOnOrAfter(), Instant.parse("2006-01-26T13:45:05.000Z"), "Assertion/Condition/@NotOnOrAfter");
+ Audience audience = cond.getAudienceRestrictions().get(0).getAudiences().get(0);
Assert.assertEquals(audience.getURI(), "https://sp.example.org", "Assertion/Conditions/AudienceRestriction/Audience contents");
- AuthnStatement authnStatement = assertion.getAuthnStatements().get(0);
+ final AuthnStatement authnStatement = assertion.getAuthnStatements().get(0);
Assert.assertEquals(authnStatement.getAuthnInstant(), Instant.parse("2006-01-26T13:35:05.000Z"), "Assertion/AuthnStatement/@AuthnInstant");
- Assert.assertEquals(authnStatement.getAuthnContext().getAuthnContextClassRef().getURI(), AuthnContext.PPT_AUTHN_CTX, "Assertion/AuthnStatement/AuthnContext/AuthnContextClassRef contents");
+ final AuthnContext ac = authnStatement.getAuthnContext();
+ assert ac != null;
+ final AuthnContextClassRef acref = ac.getAuthnContextClassRef();
+ assert acref != null;
+ Assert.assertEquals(acref.getURI(), AuthnContext.PPT_AUTHN_CTX, "Assertion/AuthnStatement/AuthnContext/AuthnContextClassRef contents");
AttributeStatement attribStatement = assertion.getAttributeStatements().get(0);
Attribute attrib = null;
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/core/tests/SignedAssertionTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/core/tests/SignedAssertionTest.java
index 71b70583a..450ebb282 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/core/tests/SignedAssertionTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/core/tests/SignedAssertionTest.java
@@ -54,6 +54,7 @@ import org.opensaml.xmlsec.signature.support.impl.ExplicitKeySignatureTrustEngin
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+ at SuppressWarnings("javadoc")
public class SignedAssertionTest extends XMLObjectBaseTestCase {
/** Class logger. */
@@ -105,45 +106,47 @@ public class SignedAssertionTest extends XMLObjectBaseTestCase {
@Test
public void testAssertionSignature()
throws MarshallingException, SignatureException, UnmarshallingException, SecurityException {
- Instant now = Instant.now();
+ final Instant now = Instant.now();
- Assertion assertion = assertionBuilder.buildObject();
+ final Assertion assertion = assertionBuilder.buildObject();
assertion.setVersion(SAMLVersion.VERSION_20);
assertion.setID(idGenerator.generateIdentifier());
assertion.setIssueInstant(now);
- Issuer issuer = issuerBuilder.buildObject();
+ final Issuer issuer = issuerBuilder.buildObject();
issuer.setValue("urn:example.org:issuer");
assertion.setIssuer(issuer);
- AuthnStatement authnStmt = authnStatementBuilder.buildObject();
+ final AuthnStatement authnStmt = authnStatementBuilder.buildObject();
authnStmt.setAuthnInstant(now);
assertion.getAuthnStatements().add(authnStmt);
- Signature signature = signatureBuilder.buildObject(Signature.DEFAULT_ELEMENT_NAME);
+ final Signature signature = signatureBuilder.buildObject(Signature.DEFAULT_ELEMENT_NAME);
signature.setSigningCredential(goodCredential);
signature.setCanonicalizationAlgorithm(SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS);
signature.setSignatureAlgorithm(SignatureConstants.ALGO_ID_SIGNATURE_RSA);
assertion.setSignature(signature);
- Marshaller marshaller = marshallerFactory.getMarshaller(assertion);
+ final Marshaller marshaller = marshallerFactory.ensureMarshaller(assertion);
marshaller.marshall(assertion);
Signer.signObject(signature);
if (log.isDebugEnabled()) {
- log.debug("Marshalled signed assertion: \n" + SerializeSupport.nodeToString(assertion.getDOM()));
+ log.debug("Marshalled signed assertion: \n" + SerializeSupport.nodeToString(assertion.ensureDOM()));
}
// Unmarshall new tree around DOM to avoid side effects and Apache xmlsec bug.
- Assertion signedAssertion =
- (Assertion) unmarshallerFactory.getUnmarshaller(assertion.getDOM()).unmarshall(assertion.getDOM());
+ final Assertion signedAssertion =
+ (Assertion) unmarshallerFactory.ensureUnmarshaller(assertion.ensureDOM()).unmarshall(assertion.ensureDOM());
- StaticCredentialResolver credResolver = new StaticCredentialResolver(goodCredential);
- KeyInfoCredentialResolver kiResolver = SAMLTestSupport.buildBasicInlineKeyInfoResolver();
- ExplicitKeySignatureTrustEngine trustEngine = new ExplicitKeySignatureTrustEngine(credResolver, kiResolver);
+ final StaticCredentialResolver credResolver = new StaticCredentialResolver(goodCredential);
+ final KeyInfoCredentialResolver kiResolver = SAMLTestSupport.buildBasicInlineKeyInfoResolver();
+ final ExplicitKeySignatureTrustEngine trustEngine = new ExplicitKeySignatureTrustEngine(credResolver, kiResolver);
- CriteriaSet criteriaSet = new CriteriaSet( new EntityIdCriterion("urn:example.org:issuer") );
- Assert.assertTrue(trustEngine.validate(signedAssertion.getSignature(), criteriaSet),
- "Assertion signature was not valid");
+ final CriteriaSet criteriaSet = new CriteriaSet( new EntityIdCriterion("urn:example.org:issuer") );
+ final Signature sig = signedAssertion.getSignature();
+ assert sig != null;
+ Assert.assertTrue(trustEngine.validate(sig, criteriaSet), "Assertion signature was not valid");
}
+
}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/ecp/impl/RelayStateTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/ecp/impl/RelayStateTest.java
index 7559f4e4a..6d1ec00b8 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/ecp/impl/RelayStateTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/ecp/impl/RelayStateTest.java
@@ -34,12 +34,16 @@ public class RelayStateTest extends XMLObjectProviderBaseTestCase {
private Boolean expectedSOAP11MustUnderstand;
+ /**
+ * Constructor.
+ */
public RelayStateTest() {
singleElementFile = "/org/opensaml/saml/saml2/ecp/impl/RelayState.xml";
}
-
+
+ /** Test set up. */
@BeforeMethod
- protected void setUp() throws Exception {
+ protected void setUp() {
expectedContent = "ThisIsSomeRelayState";
expectedSOAP11Actor = "https://soap11actor.example.org";
expectedSOAP11MustUnderstand = true;
@@ -50,9 +54,8 @@ public class RelayStateTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementUnmarshall() {
- RelayState relayState = (RelayState) unmarshallElement(singleElementFile);
-
- Assert.assertNotNull(relayState);
+ final RelayState relayState = (RelayState) unmarshallElement(singleElementFile);
+ assert relayState != null;
Assert.assertEquals(relayState.isSOAP11MustUnderstand(), expectedSOAP11MustUnderstand, "SOAP mustUnderstand had unxpected value");
Assert.assertEquals(relayState.getSOAP11Actor(), expectedSOAP11Actor, "SOAP actor had unxpected value");
@@ -62,7 +65,7 @@ public class RelayStateTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementMarshall() {
- RelayState relayState = (RelayState) buildXMLObject(RelayState.DEFAULT_ELEMENT_NAME);
+ final RelayState relayState = (RelayState) buildXMLObject(RelayState.DEFAULT_ELEMENT_NAME);
relayState.setSOAP11Actor(expectedSOAP11Actor);
relayState.setSOAP11MustUnderstand(expectedSOAP11MustUnderstand);
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/ecp/impl/RequestAuthenticatedTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/ecp/impl/RequestAuthenticatedTest.java
index 83040451f..de6a5d786 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/ecp/impl/RequestAuthenticatedTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/ecp/impl/RequestAuthenticatedTest.java
@@ -33,13 +33,19 @@ public class RequestAuthenticatedTest extends XMLObjectProviderBaseTestCase {
private Boolean expectedSOAP11MustUnderstand;
+ /**
+ * Constructor.
+ */
public RequestAuthenticatedTest() {
super();
singleElementFile = "/org/opensaml/saml/saml2/ecp/impl/RequestAuthenticated.xml";
}
+ /**
+ * Test set up.
+ */
@BeforeMethod
- protected void setUp() throws Exception {
+ protected void setUp() {
expectedSOAP11Actor = "https://soap11actor.example.org";
expectedSOAP11MustUnderstand = true;
}
@@ -47,9 +53,9 @@ public class RequestAuthenticatedTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementUnmarshall() {
- RequestAuthenticated ra = (RequestAuthenticated) unmarshallElement(singleElementFile);
+ final RequestAuthenticated ra = (RequestAuthenticated) unmarshallElement(singleElementFile);
- Assert.assertNotNull(ra);
+ assert ra != null;
Assert.assertEquals(expectedSOAP11MustUnderstand, ra.isSOAP11MustUnderstand(),
"SOAP mustUnderstand had unxpected value");
@@ -59,7 +65,7 @@ public class RequestAuthenticatedTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementMarshall() {
- RequestAuthenticated ra = (RequestAuthenticated) buildXMLObject(RequestAuthenticated.DEFAULT_ELEMENT_NAME);
+ final RequestAuthenticated ra = (RequestAuthenticated) buildXMLObject(RequestAuthenticated.DEFAULT_ELEMENT_NAME);
ra.setSOAP11Actor(expectedSOAP11Actor);
ra.setSOAP11MustUnderstand(expectedSOAP11MustUnderstand);
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/ecp/impl/RequestTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/ecp/impl/RequestTest.java
index 9d9c2e2ba..f7758d65b 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/ecp/impl/RequestTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/ecp/impl/RequestTest.java
@@ -38,14 +38,20 @@ public class RequestTest extends XMLObjectProviderBaseTestCase {
private Boolean expectedSOAP11MustUnderstand;
+ /**
+ * Constructor.
+ */
public RequestTest() {
singleElementFile = "/org/opensaml/saml/saml2/ecp/impl/Request.xml";
singleElementOptionalAttributesFile = "/org/opensaml/saml/saml2/ecp/impl/RequestOptionalAttributes.xml";
childElementsFile = "/org/opensaml/saml/saml2/ecp/impl/RequestChildElements.xml";
}
-
+
+ /**
+ * Test set up.
+ */
@BeforeMethod
- protected void setUp() throws Exception {
+ protected void setUp() {
expectedProviderName = "https://provider.example.org";
expectedSOAP11Actor = "https://soap11actor.example.org";
expectedSOAP11MustUnderstand = true;
@@ -57,9 +63,9 @@ public class RequestTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementUnmarshall() {
- Request request = (Request) unmarshallElement(singleElementFile);
+ final Request request = (Request) unmarshallElement(singleElementFile);
- Assert.assertNotNull(request);
+ assert request != null;
Assert.assertEquals(request.isSOAP11MustUnderstand(), expectedSOAP11MustUnderstand, "SOAP mustUnderstand had unxpected value");
Assert.assertEquals(request.getSOAP11Actor(), expectedSOAP11Actor, "SOAP actor had unxpected value");
@@ -68,9 +74,9 @@ public class RequestTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementOptionalAttributesUnmarshall() {
- Request request = (Request) unmarshallElement(singleElementOptionalAttributesFile);
+ final Request request = (Request) unmarshallElement(singleElementOptionalAttributesFile);
- Assert.assertNotNull(request);
+ assert request != null;
Assert.assertEquals(request.isSOAP11MustUnderstand(), expectedSOAP11MustUnderstand, "SOAP mustUnderstand had unxpected value");
Assert.assertEquals(request.getSOAP11Actor(), expectedSOAP11Actor, "SOAP actor had unxpected value");
@@ -82,9 +88,9 @@ public class RequestTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testChildElementsUnmarshall() {
- Request request = (Request) unmarshallElement(childElementsFile);
+ final Request request = (Request) unmarshallElement(childElementsFile);
- Assert.assertNotNull(request);
+ assert request != null;
Assert.assertEquals(request.isSOAP11MustUnderstand(), expectedSOAP11MustUnderstand, "SOAP mustUnderstand had unxpected value");
Assert.assertEquals(request.getSOAP11Actor(), expectedSOAP11Actor, "SOAP actor had unxpected value");
@@ -96,7 +102,7 @@ public class RequestTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementMarshall() {
- Request request = (Request) buildXMLObject(Request.DEFAULT_ELEMENT_NAME);
+ final Request request = (Request) buildXMLObject(Request.DEFAULT_ELEMENT_NAME);
request.setSOAP11Actor(expectedSOAP11Actor);
request.setSOAP11MustUnderstand(expectedSOAP11MustUnderstand);
@@ -107,7 +113,7 @@ public class RequestTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementOptionalAttributesMarshall() {
- Request request = (Request) buildXMLObject(Request.DEFAULT_ELEMENT_NAME);
+ final Request request = (Request) buildXMLObject(Request.DEFAULT_ELEMENT_NAME);
request.setSOAP11Actor(expectedSOAP11Actor);
request.setSOAP11MustUnderstand(expectedSOAP11MustUnderstand);
@@ -120,7 +126,7 @@ public class RequestTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testChildElementsMarshall() {
- Request request = (Request) buildXMLObject(Request.DEFAULT_ELEMENT_NAME);
+ final Request request = (Request) buildXMLObject(Request.DEFAULT_ELEMENT_NAME);
request.setSOAP11Actor(expectedSOAP11Actor);
request.setSOAP11MustUnderstand(expectedSOAP11MustUnderstand);
@@ -131,4 +137,4 @@ public class RequestTest extends XMLObjectProviderBaseTestCase {
assertXMLEquals(expectedChildElementsDOM, request);
}
-}
+}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/ecp/impl/ResponseTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/ecp/impl/ResponseTest.java
index 41c460f84..841617ef2 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/ecp/impl/ResponseTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/ecp/impl/ResponseTest.java
@@ -34,12 +34,18 @@ public class ResponseTest extends XMLObjectProviderBaseTestCase {
private Boolean expectedSOAP11MustUnderstand;
+ /**
+ * Constructor.
+ */
public ResponseTest() {
singleElementFile = "/org/opensaml/saml/saml2/ecp/impl/Response.xml";
}
-
+
+ /**
+ * Test set up.
+ */
@BeforeMethod
- protected void setUp() throws Exception {
+ protected void setUp() {
expectedACSURL = "https://sp.example.org/acs";
expectedSOAP11Actor = "https://soap11actor.example.org";
expectedSOAP11MustUnderstand = true;
@@ -50,9 +56,9 @@ public class ResponseTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementUnmarshall() {
- Response response = (Response) unmarshallElement(singleElementFile);
+ final Response response = (Response) unmarshallElement(singleElementFile);
- Assert.assertNotNull(response);
+ assert response != null;
Assert.assertEquals(response.isSOAP11MustUnderstand(), expectedSOAP11MustUnderstand, "SOAP mustUnderstand had unxpected value");
Assert.assertEquals(response.getSOAP11Actor(), expectedSOAP11Actor, "SOAP actor had unxpected value");
@@ -62,7 +68,7 @@ public class ResponseTest extends XMLObjectProviderBaseTestCase {
/** {@inheritDoc} */
@Test
public void testSingleElementMarshall() {
- Response response = (Response) buildXMLObject(Response.DEFAULT_ELEMENT_NAME);
+ final Response response = (Response) buildXMLObject(Response.DEFAULT_ELEMENT_NAME);
response.setSOAP11Actor(expectedSOAP11Actor);
response.setSOAP11MustUnderstand(expectedSOAP11MustUnderstand);
@@ -71,4 +77,4 @@ public class ResponseTest extends XMLObjectProviderBaseTestCase {
assertXMLEquals(expectedDOM, response);
}
-}
+}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/ecp/impl/SubjectConfirmationTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/ecp/impl/SubjectConfirmationTest.java
index f1910e729..9d61c6200 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/ecp/impl/SubjectConfirmationTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/ecp/impl/SubjectConfirmationTest.java
@@ -41,8 +41,11 @@ public class SubjectConfirmationTest extends XMLObjectProviderBaseTestCase {
childElementsFile = "/org/opensaml/saml/saml2/ecp/impl/SubjectConfirmationChildElements.xml";
}
+ /**
+ * Test set up.
+ */
@BeforeMethod
- protected void setUp() throws Exception {
+ protected void setUp() {
expectedMethod = "conf method";
expectedSOAP11Actor = "https://soap11actor.example.org";
expectedSOAP11MustUnderstand = true;
@@ -52,6 +55,7 @@ public class SubjectConfirmationTest extends XMLObjectProviderBaseTestCase {
@Test
public void testSingleElementUnmarshall() {
SubjectConfirmation subjectConfirmation = (SubjectConfirmation) unmarshallElement(singleElementFile);
+ assert subjectConfirmation != null;
String method = subjectConfirmation.getMethod();
Assert.assertEquals(expectedMethod, method, "Method not as expected");
@@ -77,6 +81,7 @@ public class SubjectConfirmationTest extends XMLObjectProviderBaseTestCase {
@Test
public void testChildElementsUnmarshall() {
SubjectConfirmation subjectConfirmation = (SubjectConfirmation) unmarshallElement(childElementsFile);
+ assert subjectConfirmation != null;
Assert.assertNotNull(subjectConfirmation.getSubjectConfirmationData(), "SubjectConfirmationData element not present");
}
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/encryption/tests/ComplexEncryptionTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/encryption/tests/ComplexEncryptionTest.java
index bf979c1e5..249e0053d 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/encryption/tests/ComplexEncryptionTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/encryption/tests/ComplexEncryptionTest.java
@@ -36,6 +36,7 @@ import org.opensaml.xmlsec.algorithm.AlgorithmSupport;
import org.opensaml.xmlsec.encryption.DataReference;
import org.opensaml.xmlsec.encryption.EncryptedData;
import org.opensaml.xmlsec.encryption.EncryptedKey;
+import org.opensaml.xmlsec.encryption.EncryptionMethod;
import org.opensaml.xmlsec.encryption.support.EncryptionConstants;
import org.opensaml.xmlsec.encryption.support.EncryptionException;
import org.opensaml.xmlsec.encryption.support.DataEncryptionParameters;
@@ -106,7 +107,8 @@ public class ComplexEncryptionTest extends XMLObjectBaseTestCase {
*/
@Test
public void testSingleKEKInline() {
- Assertion target = (Assertion) unmarshallElement("/org/opensaml/saml/saml2/encryption/Assertion.xml");
+ final Assertion target = (Assertion) unmarshallElement("/org/opensaml/saml/saml2/encryption/Assertion.xml");
+ assert target != null;
KeyName keyName = (KeyName) buildXMLObject(KeyName.DEFAULT_ELEMENT_NAME);
keyName.setValue(expectedKeyNameRSA);
@@ -129,30 +131,35 @@ public class ComplexEncryptionTest extends XMLObjectBaseTestCase {
Assert.assertTrue(encObject instanceof EncryptedAssertion,
"Encrypted object was not an instance of the expected type");
encTarget = (EncryptedAssertion) encObject;
+ assert encTarget != null;
- Assert.assertEquals(encTarget.getEncryptedData().getKeyInfo().getEncryptedKeys().size(), 1,
+ final EncryptedData encData = encTarget.getEncryptedData();
+ assert encData != null;
+ KeyInfo keyInfo = encData.getKeyInfo();
+ assert keyInfo != null;
+
+ Assert.assertEquals(keyInfo.getEncryptedKeys().size(), 1,
"Number of inline EncryptedKeys");
Assert.assertEquals(encTarget.getEncryptedKeys().size(), 0,
"Number of peer EncryptedKeys");
+ Assert.assertEquals(keyInfo.getRetrievalMethods().size(), 0,
+ "EncryptedData improperly contained a RetrievalMethod");
- EncryptedKey encKey = encTarget.getEncryptedData().getKeyInfo().getEncryptedKeys().get(0);
+ final EncryptedKey encKey = keyInfo.getEncryptedKeys().get(0);
Assert.assertNotNull(encKey, "EncryptedKey was null");
- Assert.assertEquals(encKey.getEncryptionMethod().getAlgorithm(), kekURIRSA,
- "Algorithm attribute");
- Assert.assertNotNull(encKey.getKeyInfo(), "KeyInfo");
- Assert.assertEquals(encKey.getKeyInfo().getKeyNames().get(0).getValue(), expectedKeyNameRSA,
+ final EncryptionMethod method = encKey.getEncryptionMethod();
+ assert method != null;
+ Assert.assertEquals(method.getAlgorithm(), kekURIRSA, "Algorithm attribute");
+ keyInfo = encKey.getKeyInfo();
+ assert keyInfo != null;
+ Assert.assertEquals(keyInfo.getKeyNames().get(0).getValue(), expectedKeyNameRSA,
"KeyName");
Assert.assertFalse(Strings.isNullOrEmpty(encKey.getID()),
"EncryptedKey ID attribute was empty");
- EncryptedData encData = encTarget.getEncryptedData();
- Assert.assertNotNull(encData.getKeyInfo(), "EncryptedData KeyInfo wasn't null");
- Assert.assertEquals(encData.getKeyInfo().getRetrievalMethods().size(), 0,
- "EncryptedData improperly contained a RetrievalMethod");
-
Assert.assertNull(encKey.getReferenceList(), "EncryptedKey ReferenceList wasn't null");
Assert.assertNull(encKey.getCarriedKeyName(), "EncryptedKey CarriedKeyName wasn't null");
}
@@ -162,8 +169,9 @@ public class ComplexEncryptionTest extends XMLObjectBaseTestCase {
*/
@Test
public void testSingleKEKPeer() {
- Assertion target = (Assertion) unmarshallElement("/org/opensaml/saml/saml2/encryption/Assertion.xml");
-
+ final Assertion target = (Assertion) unmarshallElement("/org/opensaml/saml/saml2/encryption/Assertion.xml");
+ assert target != null;
+
KeyName keyName = (KeyName) buildXMLObject(KeyName.DEFAULT_ELEMENT_NAME);
keyName.setValue(expectedKeyNameRSA);
kekKeyInfoRSA.getKeyNames().add(keyName);
@@ -226,7 +234,8 @@ public class ComplexEncryptionTest extends XMLObjectBaseTestCase {
/** Test encryption with multicast key encryption keys with key placement as peer. */
@Test
public void testMulticastKEKPeer() {
- Assertion target = (Assertion) unmarshallElement("/org/opensaml/saml/saml2/encryption/Assertion.xml");
+ final Assertion target = (Assertion) unmarshallElement("/org/opensaml/saml/saml2/encryption/Assertion.xml");
+ assert target != null;
String multicastKeyNameValue = "MulticastDataEncryptionKeyName";
KeyName keyName = (KeyName) buildXMLObject(KeyName.DEFAULT_ELEMENT_NAME);
@@ -315,7 +324,8 @@ public class ComplexEncryptionTest extends XMLObjectBaseTestCase {
/** Test that reuse is allowed with same key encryption parameters. */
@Test
public void testReuse() {
- Assertion assertion = (Assertion) unmarshallElement("/org/opensaml/saml/saml2/encryption/Assertion.xml");
+ final Assertion assertion = (Assertion) unmarshallElement("/org/opensaml/saml/saml2/encryption/Assertion.xml");
+ assert assertion != null;
Attribute target = assertion.getAttributeStatements().get(0).getAttributes().get(0);
Attribute target2 = assertion.getAttributeStatements().get(0).getAttributes().get(1);
@@ -353,4 +363,4 @@ public class ComplexEncryptionTest extends XMLObjectBaseTestCase {
"Encrypted object was not an instance of the expected type");
}
-}
+}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/encryption/tests/DecryptionPlusSigningTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/encryption/tests/DecryptionPlusSigningTest.java
index 414907251..bb85e18c3 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/encryption/tests/DecryptionPlusSigningTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/encryption/tests/DecryptionPlusSigningTest.java
@@ -120,7 +120,8 @@ public class DecryptionPlusSigningTest extends XMLObjectBaseTestCase {
String filename = "/org/opensaml/saml/saml2/encryption/Assertion.xml";
Document targetDOM = getDOM(filename);
- Assertion assertion = (Assertion) unmarshallElement(filename);
+ final Assertion assertion = (Assertion) unmarshallElement(filename);
+ assert assertion != null;
EncryptedAssertion encryptedAssertion = encrypter.encrypt(assertion);
// Build Response container
@@ -145,12 +146,12 @@ public class DecryptionPlusSigningTest extends XMLObjectBaseTestCase {
SignatureSupport.prepareSignatureParams(responseSignature, signingParams);
- marshallerFactory.getMarshaller(response).marshall(response);
+ marshallerFactory.ensureMarshaller(response).marshall(response);
Signer.signObject(responseSignature);
// Marshall Response and re-parse, for good measure
- Element marshalledResponse = marshallerFactory.getMarshaller(response).marshall(response);
+ Element marshalledResponse = marshallerFactory.ensureMarshaller(response).marshall(response);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
SerializeSupport.writeNode(marshalledResponse, baos);
@@ -161,11 +162,13 @@ public class DecryptionPlusSigningTest extends XMLObjectBaseTestCase {
Element parsedResponse = parsedDoc.getDocumentElement();
Response newResponse =
- (Response) unmarshallerFactory.getUnmarshaller(parsedResponse).unmarshall(parsedResponse);
+ (Response) unmarshallerFactory.ensureUnmarshaller(parsedResponse).unmarshall(parsedResponse);
// Validate Response signature first time
try {
- SignatureValidator.validate(newResponse.getSignature(), signingCred);
+ final Signature sig = newResponse.getSignature();
+ assert sig != null;
+ SignatureValidator.validate(sig, signingCred);
} catch (SignatureException e1) {
Assert.fail("First Response signature validation failed");
}
@@ -189,7 +192,9 @@ public class DecryptionPlusSigningTest extends XMLObjectBaseTestCase {
// Validate Response signature second time
try {
- SignatureValidator.validate(newResponse.getSignature(), signingCred);
+ final Signature sig = newResponse.getSignature();
+ assert sig != null;
+ SignatureValidator.validate(sig, signingCred);
} catch (SignatureException e1) {
Assert.fail("Second Response signature validation failed");
}
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/encryption/tests/ECDHTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/encryption/tests/ECDHTest.java
index 9291d8aa6..b72631e7a 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/encryption/tests/ECDHTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/encryption/tests/ECDHTest.java
@@ -30,6 +30,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.annotation.Nonnull;
+
import org.opensaml.core.config.ConfigurationService;
import org.opensaml.core.testing.XMLObjectBaseTestCase;
import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
@@ -64,6 +66,7 @@ import org.opensaml.xmlsec.EncryptionParametersResolver;
import org.opensaml.xmlsec.criterion.DecryptionConfigurationCriterion;
import org.opensaml.xmlsec.criterion.EncryptionConfigurationCriterion;
import org.opensaml.xmlsec.derivation.impl.PBKDF2;
+import org.opensaml.xmlsec.encryption.EncryptedData;
import org.opensaml.xmlsec.encryption.EncryptedKey;
import org.opensaml.xmlsec.encryption.KeyDerivationMethod;
import org.opensaml.xmlsec.encryption.support.DataEncryptionParameters;
@@ -84,12 +87,11 @@ import org.testng.annotations.Test;
import org.w3c.dom.Element;
import net.shibboleth.shared.codec.EncodingException;
+import net.shibboleth.shared.logic.Constraint;
import net.shibboleth.shared.resolver.CriteriaSet;
import net.shibboleth.shared.xml.SerializeSupport;
-/**
- *
- */
+ at SuppressWarnings("javadoc")
public class ECDHTest extends XMLObjectBaseTestCase {
private String targetFile;
@@ -190,7 +192,7 @@ public class ECDHTest extends XMLObjectBaseTestCase {
@Test
public void roundtripWithKeyWrapAndEncryptionMethods() throws Exception {
- KeyDescriptor kd = buildKeyDescriptor(recipientCredKeyName, UsageType.ENCRYPTION, recipientCredPublic.getPublicKey());
+ final KeyDescriptor kd = buildKeyDescriptor(recipientCredKeyName, UsageType.ENCRYPTION, recipientCredPublic.getPublicKey());
kd.getEncryptionMethods().add(buildEncryptionMethod(EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES128_GCM));
kd.getEncryptionMethods().add(buildEncryptionMethod(EncryptionConstants.ALGO_ID_KEYWRAP_AES256));
roleDesc.getKeyDescriptors().add(kd);
@@ -242,10 +244,11 @@ public class ECDHTest extends XMLObjectBaseTestCase {
private void testRoundtrip(String expectedDataAlgo, String expectedKEKAlgo, String expectedKDFAlgo, Encrypter.KeyPlacement keyPlacement) throws Exception {
// Encrypt
- Assertion assertionOrig = (Assertion) unmarshallElement(targetFile);
+ final Assertion assertionOrig = (Assertion) unmarshallElement(targetFile);
+ assert assertionOrig != null;
- EncryptionParameters encParams = encParamsResolver.resolveSingle(encCriteria);
- Assert.assertNotNull(encParams);
+ final EncryptionParameters encParams = encParamsResolver.resolveSingle(encCriteria);
+ assert encParams != null;
DataEncryptionParameters dataEncParams = new DataEncryptionParameters(encParams);
List<KeyEncryptionParameters> kekParams = encParams.getKeyTransportEncryptionCredential() != null ?
@@ -254,19 +257,25 @@ public class ECDHTest extends XMLObjectBaseTestCase {
encrypter = new Encrypter(dataEncParams, kekParams);
encrypter.setKeyPlacement(keyPlacement);
- EncryptedAssertion encryptedAssertionOrig = encrypter.encrypt(assertionOrig);
- Assert.assertNotNull(encryptedAssertionOrig);
- Assert.assertNotNull(encryptedAssertionOrig.getEncryptedData().getKeyInfo());
+ final EncryptedAssertion encryptedAssertionOrig = encrypter.encrypt(assertionOrig);
+ assert encryptedAssertionOrig != null;
+ final EncryptedData encData = encryptedAssertionOrig.getEncryptedData();
+ assert encData != null;
+ Assert.assertNotNull(encData.getKeyInfo());
if (expectedDataAlgo != null) {
- Assert.assertEquals(encryptedAssertionOrig.getEncryptedData().getEncryptionMethod().getAlgorithm(), expectedDataAlgo);
+ final var method = encData.getEncryptionMethod();
+ assert method != null;
+ Assert.assertEquals(method.getAlgorithm(), expectedDataAlgo);
}
EncryptedKey encryptedKey = null;
+ final KeyInfo dataKeyInfo = encData.getKeyInfo();
+ assert dataKeyInfo != null;
switch(keyPlacement) {
case INLINE:
- encryptedKey = !encryptedAssertionOrig.getEncryptedData().getKeyInfo().getEncryptedKeys().isEmpty()
- ? encryptedAssertionOrig.getEncryptedData().getKeyInfo().getEncryptedKeys().get(0) : null;
+ encryptedKey = !dataKeyInfo.getEncryptedKeys().isEmpty()
+ ? dataKeyInfo.getEncryptedKeys().get(0) : null;
break;
case PEER:
encryptedKey = !encryptedAssertionOrig.getEncryptedKeys().isEmpty()
@@ -275,16 +284,20 @@ public class ECDHTest extends XMLObjectBaseTestCase {
};
if (expectedKEKAlgo != null) {
- Assert.assertNotNull(encryptedKey);
- Assert.assertEquals(encryptedKey.getEncryptionMethod().getAlgorithm(), expectedKEKAlgo);
+ assert encryptedKey != null;
+ final var method = encryptedKey.getEncryptionMethod();
+ assert method != null;
+ Assert.assertEquals(method.getAlgorithm(), expectedKEKAlgo);
}
if (expectedKDFAlgo != null) {
KeyDerivationMethod kdm = null;
if (encryptedKey != null) {
- kdm = (KeyDerivationMethod) encryptedKey.getKeyInfo().getAgreementMethods().get(0).getUnknownXMLObjects(KeyDerivationMethod.DEFAULT_ELEMENT_NAME).get(0);
+ final KeyInfo ki = encryptedKey.getKeyInfo();
+ assert ki != null;
+ kdm = (KeyDerivationMethod) ki.getAgreementMethods().get(0).getUnknownXMLObjects(KeyDerivationMethod.DEFAULT_ELEMENT_NAME).get(0);
} else {
- kdm = (KeyDerivationMethod) encryptedAssertionOrig.getEncryptedData().getKeyInfo().getAgreementMethods().get(0).getUnknownXMLObjects(KeyDerivationMethod.DEFAULT_ELEMENT_NAME).get(0);
+ kdm = (KeyDerivationMethod) dataKeyInfo.getAgreementMethods().get(0).getUnknownXMLObjects(KeyDerivationMethod.DEFAULT_ELEMENT_NAME).get(0);
}
Assert.assertNotNull(kdm);
Assert.assertEquals(kdm.getAlgorithm(), expectedKDFAlgo);
@@ -300,7 +313,7 @@ public class ECDHTest extends XMLObjectBaseTestCase {
ByteArrayInputStream bais = new ByteArrayInputStream(bytesEncrypted);
EncryptedAssertion encryptedAssertion = (EncryptedAssertion) XMLObjectSupport.unmarshallFromInputStream(
- XMLObjectProviderRegistrySupport.getParserPool(), bais);
+ Constraint.isNotNull(XMLObjectProviderRegistrySupport.getParserPool(), "ParserPool null"), bais);
Assert.assertNotNull(encryptedAssertion);
// Decrypt
@@ -311,10 +324,10 @@ public class ECDHTest extends XMLObjectBaseTestCase {
Assertion decryptedAssertion = decrypter.decrypt(encryptedAssertion);
Assert.assertNotNull(decryptedAssertion);
- assertXMLEquals(assertionOrig.getDOM().getOwnerDocument(), decryptedAssertion);
+ assertXMLEquals(assertionOrig.ensureDOM().getOwnerDocument(), decryptedAssertion);
}
- private RoleDescriptor buildRoleDescriptorSkeleton() {
+ @Nonnull private RoleDescriptor buildRoleDescriptorSkeleton() {
EntityDescriptor entityDesc = buildXMLObject(EntityDescriptor.DEFAULT_ELEMENT_NAME);
entityDesc.setEntityID(targetEntityID);
@@ -324,7 +337,7 @@ public class ECDHTest extends XMLObjectBaseTestCase {
return spSSODesc;
}
- private KeyDescriptor buildKeyDescriptor(String keyName, UsageType use, Object ... contentItems) {
+ @Nonnull private KeyDescriptor buildKeyDescriptor(String keyName, UsageType use, Object ... contentItems) {
KeyDescriptor keyDesc = buildXMLObject(KeyDescriptor.DEFAULT_ELEMENT_NAME);
KeyInfo keyInfo = buildXMLObject(KeyInfo.DEFAULT_ELEMENT_NAME);
@@ -359,7 +372,7 @@ public class ECDHTest extends XMLObjectBaseTestCase {
return keyDesc;
}
- private EncryptionMethod buildEncryptionMethod(String algorithm) {
+ @Nonnull private EncryptionMethod buildEncryptionMethod(String algorithm) {
EncryptionMethod encMethod = buildXMLObject(EncryptionMethod.DEFAULT_ELEMENT_NAME);
encMethod.setAlgorithm(algorithm);
return encMethod;
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/encryption/tests/EncryptedElementTypeEncryptedKeyResolverTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/encryption/tests/EncryptedElementTypeEncryptedKeyResolverTest.java
index 51941c4fa..90e343fed 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/encryption/tests/EncryptedElementTypeEncryptedKeyResolverTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/encryption/tests/EncryptedElementTypeEncryptedKeyResolverTest.java
@@ -26,6 +26,8 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.List;
+import javax.annotation.Nonnull;
+
import org.opensaml.core.testing.XMLObjectBaseTestCase;
import org.opensaml.saml.saml2.core.EncryptedAssertion;
import org.opensaml.saml.saml2.encryption.EncryptedElementTypeEncryptedKeyResolver;
@@ -46,10 +48,12 @@ public class EncryptedElementTypeEncryptedKeyResolverTest extends XMLObjectBaseT
public void testSingleEKNoRecipients() {
String filename =
"/org/opensaml/saml/saml2/encryption/EncryptedElementTypeEncryptedKeyResolverSingleNoRecipient.xml";
- EncryptedAssertion encAssertion = (EncryptedAssertion) unmarshallElement(filename);
+ final EncryptedAssertion encAssertion = (EncryptedAssertion) unmarshallElement(filename);
+ assert encAssertion != null;
Assert.assertNotNull(encAssertion.getEncryptedData());
- EncryptedData encData = encAssertion.getEncryptedData();
+ final EncryptedData encData = encAssertion.getEncryptedData();
+ assert encData != null;
List<EncryptedKey> allKeys = encAssertion.getEncryptedKeys();
Assert.assertFalse(allKeys.isEmpty());
@@ -67,10 +71,12 @@ public class EncryptedElementTypeEncryptedKeyResolverTest extends XMLObjectBaseT
public void testSingleEKMultiRecipientWithImplicitMatch() {
String filename =
"/org/opensaml/saml/saml2/encryption/EncryptedElementTypeEncryptedKeyResolverSingleNoRecipient.xml";
- EncryptedAssertion encAssertion = (EncryptedAssertion) unmarshallElement(filename);
+ final EncryptedAssertion encAssertion = (EncryptedAssertion) unmarshallElement(filename);
+ assert encAssertion != null;
Assert.assertNotNull(encAssertion.getEncryptedData());
- EncryptedData encData = encAssertion.getEncryptedData();
+ final EncryptedData encData = encAssertion.getEncryptedData();
+ assert encData != null;
List<EncryptedKey> allKeys = encAssertion.getEncryptedKeys();
Assert.assertFalse(allKeys.isEmpty());
@@ -88,10 +94,12 @@ public class EncryptedElementTypeEncryptedKeyResolverTest extends XMLObjectBaseT
public void testSingleEKOneRecipientWithMatch() {
String filename =
"/org/opensaml/saml/saml2/encryption/EncryptedElementTypeEncryptedKeyResolverSingleWithRecipient.xml";
- EncryptedAssertion encAssertion = (EncryptedAssertion) unmarshallElement(filename);
+ final EncryptedAssertion encAssertion = (EncryptedAssertion) unmarshallElement(filename);
+ assert encAssertion != null;
Assert.assertNotNull(encAssertion.getEncryptedData());
- EncryptedData encData = encAssertion.getEncryptedData();
+ final EncryptedData encData = encAssertion.getEncryptedData();
+ assert encData != null;
List<EncryptedKey> allKeys = encAssertion.getEncryptedKeys();
Assert.assertFalse(allKeys.isEmpty());
@@ -109,10 +117,12 @@ public class EncryptedElementTypeEncryptedKeyResolverTest extends XMLObjectBaseT
public void testSingleEKOneRecipientNoMatch() {
String filename =
"/org/opensaml/saml/saml2/encryption/EncryptedElementTypeEncryptedKeyResolverSingleWithRecipient.xml";
- EncryptedAssertion encAssertion = (EncryptedAssertion) unmarshallElement(filename);
+ final EncryptedAssertion encAssertion = (EncryptedAssertion) unmarshallElement(filename);
+ assert encAssertion != null;
Assert.assertNotNull(encAssertion.getEncryptedData());
- EncryptedData encData = encAssertion.getEncryptedData();
+ final EncryptedData encData = encAssertion.getEncryptedData();
+ assert encData != null;
List<EncryptedKey> allKeys = encAssertion.getEncryptedKeys();
Assert.assertFalse(allKeys.isEmpty());
@@ -127,10 +137,12 @@ public class EncryptedElementTypeEncryptedKeyResolverTest extends XMLObjectBaseT
@Test
public void testMultiEKNoRecipients() {
String filename = "/org/opensaml/saml/saml2/encryption/EncryptedElementTypeEncryptedKeyResolverMultiple.xml";
- EncryptedAssertion encAssertion = (EncryptedAssertion) unmarshallElement(filename);
+ final EncryptedAssertion encAssertion = (EncryptedAssertion) unmarshallElement(filename);
+ assert encAssertion != null;
Assert.assertNotNull(encAssertion.getEncryptedData());
- EncryptedData encData = encAssertion.getEncryptedData();
+ final EncryptedData encData = encAssertion.getEncryptedData();
+ assert encData != null;
List<EncryptedKey> allKeys = encAssertion.getEncryptedKeys();
Assert.assertFalse(allKeys.isEmpty());
@@ -151,10 +163,12 @@ public class EncryptedElementTypeEncryptedKeyResolverTest extends XMLObjectBaseT
@Test
public void testMultiEKOneRecipientWithMatch() {
String filename = "/org/opensaml/saml/saml2/encryption/EncryptedElementTypeEncryptedKeyResolverMultiple.xml";
- EncryptedAssertion encAssertion = (EncryptedAssertion) unmarshallElement(filename);
+ final EncryptedAssertion encAssertion = (EncryptedAssertion) unmarshallElement(filename);
+ assert encAssertion != null;
Assert.assertNotNull(encAssertion.getEncryptedData());
- EncryptedData encData = encAssertion.getEncryptedData();
+ final EncryptedData encData = encAssertion.getEncryptedData();
+ assert encData != null;
List<EncryptedKey> allKeys = encAssertion.getEncryptedKeys();
Assert.assertFalse(allKeys.isEmpty());
@@ -172,10 +186,12 @@ public class EncryptedElementTypeEncryptedKeyResolverTest extends XMLObjectBaseT
@Test
public void testMultiEKOneRecipientWithMatches() {
String filename = "/org/opensaml/saml/saml2/encryption/EncryptedElementTypeEncryptedKeyResolverMultiple.xml";
- EncryptedAssertion encAssertion = (EncryptedAssertion) unmarshallElement(filename);
+ final EncryptedAssertion encAssertion = (EncryptedAssertion) unmarshallElement(filename);
+ assert encAssertion != null;
Assert.assertNotNull(encAssertion.getEncryptedData());
- EncryptedData encData = encAssertion.getEncryptedData();
+ final EncryptedData encData = encAssertion.getEncryptedData();
+ assert encData != null;
List<EncryptedKey> allKeys = encAssertion.getEncryptedKeys();
Assert.assertFalse(allKeys.isEmpty());
@@ -197,7 +213,7 @@ public class EncryptedElementTypeEncryptedKeyResolverTest extends XMLObjectBaseT
* @param ekResolver the resolver to test
* @return list of resolved EncryptedKeys
*/
- private List<EncryptedKey> generateList(EncryptedData encData, EncryptedKeyResolver ekResolver) {
+ @Nonnull private List<EncryptedKey> generateList(@Nonnull final EncryptedData encData, @Nonnull final EncryptedKeyResolver ekResolver) {
List<EncryptedKey> resolved = new ArrayList<>();
for (EncryptedKey encKey : ekResolver.resolve(encData)) {
resolved.add(encKey);
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/encryption/tests/SimpleDecryptionTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/encryption/tests/SimpleDecryptionTest.java
index 0cd6e8052..ba13a7963 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/encryption/tests/SimpleDecryptionTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/encryption/tests/SimpleDecryptionTest.java
@@ -97,7 +97,8 @@ public class SimpleDecryptionTest extends XMLObjectBaseTestCase {
String filename = "/org/opensaml/saml/saml2/encryption/Assertion.xml";
Document targetDOM = getDOM(filename);
- Assertion target = (Assertion) unmarshallElement(filename);
+ final Assertion target = (Assertion) unmarshallElement(filename);
+ assert target != null;
EncryptedAssertion encryptedTarget = encrypter.encrypt(target);
Decrypter decrypter = new Decrypter(keyResolver, null, null);
@@ -126,7 +127,8 @@ public class SimpleDecryptionTest extends XMLObjectBaseTestCase {
String filename = "/org/opensaml/saml/saml2/encryption/Assertion.xml";
Document targetDOM = getDOM(filename);
- Assertion target = (Assertion) unmarshallElement(filename);
+ final Assertion target = (Assertion) unmarshallElement(filename);
+ assert target != null;
EncryptedID encryptedTarget = encrypter.encryptAsID(target);
Decrypter decrypter = new Decrypter(keyResolver, null, null);
@@ -155,7 +157,8 @@ public class SimpleDecryptionTest extends XMLObjectBaseTestCase {
String filename = "/org/opensaml/saml/saml2/encryption/NameID.xml";
Document targetDOM = getDOM(filename);
- NameID target = (NameID) unmarshallElement(filename);
+ final NameID target = (NameID) unmarshallElement(filename);
+ assert target != null;
EncryptedID encryptedTarget = encrypter.encrypt(target);
Decrypter decrypter = new Decrypter(keyResolver, null, null);
@@ -184,7 +187,8 @@ public class SimpleDecryptionTest extends XMLObjectBaseTestCase {
String filename = "/org/opensaml/saml/saml2/encryption/NewID.xml";
Document targetDOM = getDOM(filename);
- NewID target = (NewID) unmarshallElement(filename);
+ final NewID target = (NewID) unmarshallElement(filename);
+ assert target != null;
NewEncryptedID encryptedTarget = encrypter.encrypt(target);
Decrypter decrypter = new Decrypter(keyResolver, null, null);
@@ -213,7 +217,8 @@ public class SimpleDecryptionTest extends XMLObjectBaseTestCase {
String filename = "/org/opensaml/saml/saml2/encryption/Attribute.xml";
Document targetDOM = getDOM(filename);
- Attribute target = (Attribute) unmarshallElement(filename);
+ final Attribute target = (Attribute) unmarshallElement(filename);
+ assert target != null;
EncryptedAttribute encryptedTarget = encrypter.encrypt(target);
Decrypter decrypter = new Decrypter(keyResolver, null, null);
@@ -249,7 +254,8 @@ public class SimpleDecryptionTest extends XMLObjectBaseTestCase {
String filename = "/org/opensaml/saml/saml2/encryption/Assertion.xml";
- Assertion target = (Assertion) unmarshallElement(filename);
+ final Assertion target = (Assertion) unmarshallElement(filename);
+ assert target != null;
EncryptedAssertion encryptedTarget = encrypter.encrypt(target);
Decrypter decrypter = new Decrypter(badEncResolver, null, null);
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/metadata/tests/MetadataTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/metadata/tests/MetadataTest.java
index 3b0173719..4e854ae91 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/metadata/tests/MetadataTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/metadata/tests/MetadataTest.java
@@ -56,7 +56,7 @@ public class MetadataTest extends XMLObjectBaseTestCase {
try {
InputStream in = MetadataTest.class.getResourceAsStream(inCommonMDFile);
Document inCommonMDDoc = parserPool.parse(in);
- Unmarshaller unmarshaller = XMLObjectProviderRegistrySupport.getUnmarshallerFactory().getUnmarshaller(
+ Unmarshaller unmarshaller = XMLObjectProviderRegistrySupport.getUnmarshallerFactory().ensureUnmarshaller(
inCommonMDDoc.getDocumentElement());
XMLObject inCommonMD = unmarshaller.unmarshall(inCommonMDDoc.getDocumentElement());
@@ -80,7 +80,7 @@ public class MetadataTest extends XMLObjectBaseTestCase {
try {
InputStream in = MetadataTest.class.getResourceAsStream(switchMDFile);
Document switchMDDoc = parserPool.parse(in);
- Unmarshaller unmarshaller = XMLObjectProviderRegistrySupport.getUnmarshallerFactory().getUnmarshaller(
+ Unmarshaller unmarshaller = XMLObjectProviderRegistrySupport.getUnmarshallerFactory().ensureUnmarshaller(
switchMDDoc.getDocumentElement());
XMLObject switchMD = unmarshaller.unmarshall(switchMDDoc.getDocumentElement());
@@ -104,7 +104,7 @@ public class MetadataTest extends XMLObjectBaseTestCase {
try {
InputStream in = MetadataTest.class.getResourceAsStream(switchMDFile);
Document ukFedDoc = parserPool.parse(in);
- Unmarshaller unmarshaller = XMLObjectProviderRegistrySupport.getUnmarshallerFactory().getUnmarshaller(
+ Unmarshaller unmarshaller = XMLObjectProviderRegistrySupport.getUnmarshallerFactory().ensureUnmarshaller(
ukFedDoc.getDocumentElement());
XMLObject ukFedMD = unmarshaller.unmarshall(ukFedDoc.getDocumentElement());
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list