|
@@ -19,17 +19,16 @@ package org.springframework.security.saml2.provider.service.authentication;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.ObjectOutputStream;
|
|
|
+import java.util.Arrays;
|
|
|
|
|
|
import org.hamcrest.BaseMatcher;
|
|
|
import org.hamcrest.Description;
|
|
|
import org.hamcrest.Matcher;
|
|
|
import org.joda.time.DateTime;
|
|
|
import org.joda.time.Duration;
|
|
|
-import org.junit.Before;
|
|
|
import org.junit.Rule;
|
|
|
import org.junit.Test;
|
|
|
import org.junit.rules.ExpectedException;
|
|
|
-import org.opensaml.core.xml.XMLObject;
|
|
|
import org.opensaml.saml.saml2.core.Assertion;
|
|
|
import org.opensaml.saml.saml2.core.EncryptedAssertion;
|
|
|
import org.opensaml.saml.saml2.core.EncryptedID;
|
|
@@ -37,15 +36,17 @@ import org.opensaml.saml.saml2.core.NameID;
|
|
|
import org.opensaml.saml.saml2.core.Response;
|
|
|
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
-
|
|
|
-import static java.util.Collections.emptyList;
|
|
|
-import static org.springframework.security.saml2.provider.service.authentication.Saml2CryptoTestSupport.encryptAssertion;
|
|
|
-import static org.springframework.security.saml2.provider.service.authentication.Saml2CryptoTestSupport.encryptNameId;
|
|
|
-import static org.springframework.security.saml2.provider.service.authentication.Saml2CryptoTestSupport.signXmlObject;
|
|
|
-import static org.springframework.security.saml2.provider.service.authentication.TestSaml2AuthenticationObjects.assertion;
|
|
|
-import static org.springframework.security.saml2.provider.service.authentication.TestSaml2AuthenticationObjects.response;
|
|
|
-import static org.springframework.security.saml2.provider.service.authentication.TestSaml2X509Credentials.assertingPartyCredentials;
|
|
|
-import static org.springframework.security.saml2.provider.service.authentication.TestSaml2X509Credentials.relyingPartyCredentials;
|
|
|
+import org.springframework.security.saml2.credentials.Saml2X509Credential;
|
|
|
+
|
|
|
+import static org.springframework.security.saml2.provider.service.authentication.TestOpenSamlObjects.assertion;
|
|
|
+import static org.springframework.security.saml2.provider.service.authentication.TestOpenSamlObjects.encrypted;
|
|
|
+import static org.springframework.security.saml2.provider.service.authentication.TestOpenSamlObjects.response;
|
|
|
+import static org.springframework.security.saml2.provider.service.authentication.TestOpenSamlObjects.signed;
|
|
|
+import static org.springframework.security.saml2.provider.service.authentication.TestSaml2X509Credentials.assertingPartyEncryptingCredential;
|
|
|
+import static org.springframework.security.saml2.provider.service.authentication.TestSaml2X509Credentials.assertingPartyPrivateCredential;
|
|
|
+import static org.springframework.security.saml2.provider.service.authentication.TestSaml2X509Credentials.assertingPartySigningCredential;
|
|
|
+import static org.springframework.security.saml2.provider.service.authentication.TestSaml2X509Credentials.relyingPartyDecryptingCredential;
|
|
|
+import static org.springframework.security.saml2.provider.service.authentication.TestSaml2X509Credentials.relyingPartyVerifyingCredential;
|
|
|
import static org.springframework.test.util.AssertionErrors.assertTrue;
|
|
|
import static org.springframework.util.StringUtils.hasText;
|
|
|
|
|
@@ -57,37 +58,23 @@ import static org.springframework.util.StringUtils.hasText;
|
|
|
*/
|
|
|
public class OpenSamlAuthenticationProviderTests {
|
|
|
|
|
|
- private static String username = "test@saml.user";
|
|
|
- private static String recipientUri = "https://localhost/login/saml2/sso/idp-alias";
|
|
|
- private static String recipientEntityId = "https://localhost/saml2/service-provider-metadata/idp-alias";
|
|
|
- private static String idpEntityId = "https://some.idp.test/saml2/idp";
|
|
|
+ private static String DESTINATION = "https://localhost/login/saml2/sso/idp-alias";
|
|
|
+ private static String RELYING_PARTY_ENTITY_ID = "https://localhost/saml2/service-provider-metadata/idp-alias";
|
|
|
+ private static String ASSERTING_PARTY_ENTITY_ID = "https://some.idp.test/saml2/idp";
|
|
|
+
|
|
|
+ private OpenSamlAuthenticationProvider provider = new OpenSamlAuthenticationProvider();
|
|
|
+ private OpenSamlImplementation saml = OpenSamlImplementation.getInstance();
|
|
|
|
|
|
- private OpenSamlAuthenticationProvider provider;
|
|
|
- private OpenSamlImplementation saml;
|
|
|
- private Saml2AuthenticationToken token;
|
|
|
|
|
|
@Rule
|
|
|
public ExpectedException exception = ExpectedException.none();
|
|
|
|
|
|
- @Before
|
|
|
- public void setup() {
|
|
|
- this.saml = OpenSamlImplementation.getInstance();
|
|
|
- this.provider = new OpenSamlAuthenticationProvider();
|
|
|
- this.token = new Saml2AuthenticationToken(
|
|
|
- "responseXml",
|
|
|
- recipientUri,
|
|
|
- idpEntityId,
|
|
|
- recipientEntityId,
|
|
|
- relyingPartyCredentials()
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
@Test
|
|
|
public void supportsWhenSaml2AuthenticationTokenThenReturnTrue() {
|
|
|
|
|
|
assertTrue(
|
|
|
- OpenSamlAuthenticationProvider.class + "should support " + this.token.getClass(),
|
|
|
- this.provider.supports(this.token.getClass())
|
|
|
+ OpenSamlAuthenticationProvider.class + "should support " + Saml2AuthenticationToken.class,
|
|
|
+ this.provider.supports(Saml2AuthenticationToken.class)
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -101,247 +88,191 @@ public class OpenSamlAuthenticationProviderTests {
|
|
|
|
|
|
@Test
|
|
|
public void authenticateWhenUnknownDataClassThenThrowAuthenticationException() {
|
|
|
- Assertion assertion = defaultAssertion();
|
|
|
- this.token = responseXml(assertion);
|
|
|
this.exception.expect(authenticationMatcher(Saml2ErrorCodes.UNKNOWN_RESPONSE_CLASS));
|
|
|
- this.provider.authenticate(this.token);
|
|
|
+
|
|
|
+ Assertion assertion = this.saml.buildSamlObject(Assertion.DEFAULT_ELEMENT_NAME);
|
|
|
+ this.provider.authenticate(token(this.saml.serialize(assertion)));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void authenticateWhenXmlErrorThenThrowAuthenticationException() {
|
|
|
- this.token = new Saml2AuthenticationToken(
|
|
|
- "invalid xml string",
|
|
|
- recipientUri,
|
|
|
- idpEntityId,
|
|
|
- recipientEntityId,
|
|
|
- relyingPartyCredentials()
|
|
|
- );
|
|
|
this.exception.expect(authenticationMatcher(Saml2ErrorCodes.MALFORMED_RESPONSE_DATA));
|
|
|
- this.provider.authenticate(this.token);
|
|
|
+
|
|
|
+ Saml2AuthenticationToken token = token("invalid xml");
|
|
|
+ this.provider.authenticate(token);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void authenticateWhenInvalidDestinationThenThrowAuthenticationException() {
|
|
|
- Response response = response(recipientUri + "invalid", idpEntityId);
|
|
|
- this.token = responseXml(response);
|
|
|
this.exception.expect(authenticationMatcher(Saml2ErrorCodes.INVALID_DESTINATION));
|
|
|
- this.provider.authenticate(this.token);
|
|
|
+
|
|
|
+ Response response = response(DESTINATION + "invalid", ASSERTING_PARTY_ENTITY_ID);
|
|
|
+ response.getAssertions().add(assertion());
|
|
|
+ signed(response, assertingPartySigningCredential(), RELYING_PARTY_ENTITY_ID);
|
|
|
+ Saml2AuthenticationToken token = token(response, relyingPartyVerifyingCredential());
|
|
|
+ this.provider.authenticate(token);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void authenticateWhenNoAssertionsPresentThenThrowAuthenticationException() {
|
|
|
- Response response = response(recipientUri, idpEntityId);
|
|
|
- this.token = responseXml(response);
|
|
|
this.exception.expect(
|
|
|
authenticationMatcher(Saml2ErrorCodes.MALFORMED_RESPONSE_DATA, "No assertions found in response.")
|
|
|
);
|
|
|
- this.provider.authenticate(this.token);
|
|
|
+
|
|
|
+ Saml2AuthenticationToken token = token(response(), assertingPartySigningCredential());
|
|
|
+ this.provider.authenticate(token);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void authenticateWhenInvalidSignatureOnAssertionThenThrowAuthenticationException() {
|
|
|
- Response response = response(recipientUri, idpEntityId);
|
|
|
- Assertion assertion = defaultAssertion();
|
|
|
- response.getAssertions().add(assertion);
|
|
|
- this.token = responseXml(response);
|
|
|
this.exception.expect(authenticationMatcher(Saml2ErrorCodes.INVALID_SIGNATURE));
|
|
|
- this.provider.authenticate(this.token);
|
|
|
+
|
|
|
+ Response response = response();
|
|
|
+ response.getAssertions().add(assertion());
|
|
|
+ Saml2AuthenticationToken token = token(response);
|
|
|
+ this.provider.authenticate(token);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void authenticateWhenOpenSAMLValidationErrorThenThrowAuthenticationException() throws Exception {
|
|
|
- Response response = response(recipientUri, idpEntityId);
|
|
|
- Assertion assertion = defaultAssertion();
|
|
|
+ this.exception.expect(authenticationMatcher(Saml2ErrorCodes.INVALID_ASSERTION));
|
|
|
+
|
|
|
+ Response response = response();
|
|
|
+ Assertion assertion = assertion();
|
|
|
assertion
|
|
|
.getSubject()
|
|
|
.getSubjectConfirmations()
|
|
|
.get(0)
|
|
|
.getSubjectConfirmationData()
|
|
|
.setNotOnOrAfter(DateTime.now().minus(Duration.standardDays(3)));
|
|
|
- signXmlObject(
|
|
|
- assertion,
|
|
|
- assertingPartyCredentials(),
|
|
|
- recipientEntityId
|
|
|
- );
|
|
|
+ signed(assertion, assertingPartySigningCredential(), RELYING_PARTY_ENTITY_ID);
|
|
|
response.getAssertions().add(assertion);
|
|
|
- this.token = responseXml(response);
|
|
|
-
|
|
|
- this.exception.expect(authenticationMatcher(Saml2ErrorCodes.INVALID_ASSERTION));
|
|
|
- this.provider.authenticate(this.token);
|
|
|
+ Saml2AuthenticationToken token = token(response, relyingPartyVerifyingCredential());
|
|
|
+ this.provider.authenticate(token);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void authenticateWhenMissingSubjectThenThrowAuthenticationException() {
|
|
|
- Response response = response(recipientUri, idpEntityId);
|
|
|
- Assertion assertion = defaultAssertion();
|
|
|
+ this.exception.expect(authenticationMatcher(Saml2ErrorCodes.SUBJECT_NOT_FOUND));
|
|
|
+
|
|
|
+ Response response = response();
|
|
|
+ Assertion assertion = assertion();
|
|
|
assertion.setSubject(null);
|
|
|
- signXmlObject(
|
|
|
- assertion,
|
|
|
- assertingPartyCredentials(),
|
|
|
- recipientEntityId
|
|
|
- );
|
|
|
+ signed(assertion, assertingPartySigningCredential(), RELYING_PARTY_ENTITY_ID);
|
|
|
response.getAssertions().add(assertion);
|
|
|
- this.token = responseXml(response);
|
|
|
-
|
|
|
- this.exception.expect(authenticationMatcher(Saml2ErrorCodes.SUBJECT_NOT_FOUND));
|
|
|
+ Saml2AuthenticationToken token = token(response, relyingPartyVerifyingCredential());
|
|
|
this.provider.authenticate(token);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void authenticateWhenUsernameMissingThenThrowAuthenticationException() throws Exception {
|
|
|
- Response response = response(recipientUri, idpEntityId);
|
|
|
- Assertion assertion = defaultAssertion();
|
|
|
+ this.exception.expect(authenticationMatcher(Saml2ErrorCodes.USERNAME_NOT_FOUND));
|
|
|
+
|
|
|
+ Response response = response();
|
|
|
+ Assertion assertion = assertion();
|
|
|
assertion
|
|
|
.getSubject()
|
|
|
.getNameID()
|
|
|
.setValue(null);
|
|
|
- signXmlObject(
|
|
|
- assertion,
|
|
|
- assertingPartyCredentials(),
|
|
|
- recipientEntityId
|
|
|
- );
|
|
|
+ signed(assertion, assertingPartySigningCredential(), RELYING_PARTY_ENTITY_ID);
|
|
|
response.getAssertions().add(assertion);
|
|
|
- this.token = responseXml(response);
|
|
|
-
|
|
|
- this.exception.expect(authenticationMatcher(Saml2ErrorCodes.USERNAME_NOT_FOUND));
|
|
|
- this.provider.authenticate(this.token);
|
|
|
+ Saml2AuthenticationToken token = token(response, relyingPartyVerifyingCredential());
|
|
|
+ this.provider.authenticate(token);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void authenticateWhenAssertionContainsValidationAddressThenItSucceeds() throws Exception {
|
|
|
- Response response = response(recipientUri, idpEntityId);
|
|
|
- Assertion assertion = defaultAssertion();
|
|
|
+ Response response = response();
|
|
|
+ Assertion assertion = assertion();
|
|
|
assertion.getSubject().getSubjectConfirmations().forEach(
|
|
|
sc -> sc.getSubjectConfirmationData().setAddress("10.10.10.10")
|
|
|
);
|
|
|
- signXmlObject(
|
|
|
- assertion,
|
|
|
- assertingPartyCredentials(),
|
|
|
- recipientEntityId
|
|
|
- );
|
|
|
+ signed(assertion, assertingPartySigningCredential(), RELYING_PARTY_ENTITY_ID);
|
|
|
response.getAssertions().add(assertion);
|
|
|
- this.token = responseXml(response);
|
|
|
- this.provider.authenticate(this.token);
|
|
|
+ Saml2AuthenticationToken token = token(response, relyingPartyVerifyingCredential());
|
|
|
+ this.provider.authenticate(token);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void authenticateWhenEncryptedAssertionWithoutSignatureThenItFails() throws Exception {
|
|
|
- Response response = response(recipientUri, idpEntityId);
|
|
|
- Assertion assertion = defaultAssertion();
|
|
|
- EncryptedAssertion encryptedAssertion = encryptAssertion(assertion, assertingPartyCredentials());
|
|
|
- response.getEncryptedAssertions().add(encryptedAssertion);
|
|
|
- this.token = responseXml(response);
|
|
|
this.exception.expect(authenticationMatcher(Saml2ErrorCodes.INVALID_SIGNATURE));
|
|
|
- this.provider.authenticate(this.token);
|
|
|
+
|
|
|
+ Response response = response();
|
|
|
+ EncryptedAssertion encryptedAssertion = encrypted(assertion(), assertingPartyEncryptingCredential());
|
|
|
+ response.getEncryptedAssertions().add(encryptedAssertion);
|
|
|
+ Saml2AuthenticationToken token = token(response, relyingPartyDecryptingCredential());
|
|
|
+ this.provider.authenticate(token);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void authenticateWhenEncryptedAssertionWithSignatureThenItSucceeds() throws Exception {
|
|
|
- Response response = response(recipientUri, idpEntityId);
|
|
|
- Assertion assertion = defaultAssertion();
|
|
|
- signXmlObject(
|
|
|
- assertion,
|
|
|
- assertingPartyCredentials(),
|
|
|
- recipientEntityId
|
|
|
- );
|
|
|
- EncryptedAssertion encryptedAssertion = encryptAssertion(assertion, assertingPartyCredentials());
|
|
|
+ Response response = response();
|
|
|
+ Assertion assertion = signed(assertion(), assertingPartySigningCredential(), RELYING_PARTY_ENTITY_ID);
|
|
|
+ EncryptedAssertion encryptedAssertion = encrypted(assertion, assertingPartyEncryptingCredential());
|
|
|
response.getEncryptedAssertions().add(encryptedAssertion);
|
|
|
- this.token = responseXml(response);
|
|
|
- this.provider.authenticate(this.token);
|
|
|
+ Saml2AuthenticationToken token = token(response, relyingPartyVerifyingCredential(), relyingPartyDecryptingCredential());
|
|
|
+ this.provider.authenticate(token);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void authenticateWhenEncryptedAssertionWithResponseSignatureThenItSucceeds() throws Exception {
|
|
|
- Response response = response(recipientUri, idpEntityId);
|
|
|
- Assertion assertion = defaultAssertion();
|
|
|
- EncryptedAssertion encryptedAssertion = encryptAssertion(assertion, assertingPartyCredentials());
|
|
|
+ Response response = response();
|
|
|
+ EncryptedAssertion encryptedAssertion = encrypted(assertion(), assertingPartyEncryptingCredential());
|
|
|
response.getEncryptedAssertions().add(encryptedAssertion);
|
|
|
- signXmlObject(
|
|
|
- response,
|
|
|
- assertingPartyCredentials(),
|
|
|
- recipientEntityId
|
|
|
- );
|
|
|
- this.token = responseXml(response);
|
|
|
- provider.authenticate(this.token);
|
|
|
+ signed(response, assertingPartySigningCredential(), RELYING_PARTY_ENTITY_ID);
|
|
|
+ Saml2AuthenticationToken token = token(response, relyingPartyVerifyingCredential(), relyingPartyDecryptingCredential());
|
|
|
+ this.provider.authenticate(token);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void authenticateWhenEncryptedNameIdWithSignatureThenItSucceeds() throws Exception {
|
|
|
- Response response = response(recipientUri, idpEntityId);
|
|
|
- Assertion assertion = defaultAssertion();
|
|
|
+ Response response = response();
|
|
|
+ Assertion assertion = assertion();
|
|
|
NameID nameId = assertion.getSubject().getNameID();
|
|
|
- EncryptedID encryptedID = encryptNameId(nameId, assertingPartyCredentials());
|
|
|
+ EncryptedID encryptedID = encrypted(nameId, assertingPartyEncryptingCredential());
|
|
|
assertion.getSubject().setNameID(null);
|
|
|
assertion.getSubject().setEncryptedID(encryptedID);
|
|
|
- signXmlObject(
|
|
|
- assertion,
|
|
|
- assertingPartyCredentials(),
|
|
|
- recipientEntityId
|
|
|
- );
|
|
|
response.getAssertions().add(assertion);
|
|
|
- this.token = responseXml(response);
|
|
|
- this.provider.authenticate(this.token);
|
|
|
+ signed(assertion, assertingPartySigningCredential(), RELYING_PARTY_ENTITY_ID);
|
|
|
+ Saml2AuthenticationToken token = token(response, relyingPartyVerifyingCredential(), relyingPartyDecryptingCredential());
|
|
|
+ this.provider.authenticate(token);
|
|
|
}
|
|
|
|
|
|
|
|
|
@Test
|
|
|
public void authenticateWhenDecryptionKeysAreMissingThenThrowAuthenticationException() throws Exception {
|
|
|
- Response response = response(recipientUri, idpEntityId);
|
|
|
- Assertion assertion = defaultAssertion();
|
|
|
- EncryptedAssertion encryptedAssertion = encryptAssertion(assertion, assertingPartyCredentials());
|
|
|
- response.getEncryptedAssertions().add(encryptedAssertion);
|
|
|
- this.token = responseXml(response);
|
|
|
-
|
|
|
- this.token = new Saml2AuthenticationToken(
|
|
|
- this.token.getSaml2Response(),
|
|
|
- recipientUri,
|
|
|
- idpEntityId,
|
|
|
- recipientEntityId,
|
|
|
- emptyList()
|
|
|
- );
|
|
|
-
|
|
|
this.exception.expect(
|
|
|
authenticationMatcher(Saml2ErrorCodes.DECRYPTION_ERROR, "No valid decryption credentials found.")
|
|
|
);
|
|
|
- this.provider.authenticate(this.token);
|
|
|
+
|
|
|
+ Response response = response();
|
|
|
+ EncryptedAssertion encryptedAssertion = encrypted(assertion(), assertingPartyEncryptingCredential());
|
|
|
+ response.getEncryptedAssertions().add(encryptedAssertion);
|
|
|
+ Saml2AuthenticationToken token = token(this.saml.serialize(response));
|
|
|
+ this.provider.authenticate(token);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void authenticateWhenDecryptionKeysAreWrongThenThrowAuthenticationException() throws Exception {
|
|
|
- Response response = response(recipientUri, idpEntityId);
|
|
|
- Assertion assertion = defaultAssertion();
|
|
|
- EncryptedAssertion encryptedAssertion = encryptAssertion(assertion, assertingPartyCredentials());
|
|
|
- response.getEncryptedAssertions().add(encryptedAssertion);
|
|
|
- this.token = responseXml(response);
|
|
|
-
|
|
|
- this.token = new Saml2AuthenticationToken(
|
|
|
- this.token.getSaml2Response(),
|
|
|
- recipientUri,
|
|
|
- idpEntityId,
|
|
|
- recipientEntityId,
|
|
|
- assertingPartyCredentials()
|
|
|
- );
|
|
|
-
|
|
|
this.exception.expect(
|
|
|
authenticationMatcher(Saml2ErrorCodes.DECRYPTION_ERROR, "Failed to decrypt EncryptedData")
|
|
|
);
|
|
|
- this.provider.authenticate(this.token);
|
|
|
+
|
|
|
+ Response response = response();
|
|
|
+ EncryptedAssertion encryptedAssertion = encrypted(assertion(), assertingPartyEncryptingCredential());
|
|
|
+ response.getEncryptedAssertions().add(encryptedAssertion);
|
|
|
+ Saml2AuthenticationToken token = token(this.saml.serialize(response), assertingPartyPrivateCredential());
|
|
|
+ this.provider.authenticate(token);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void writeObjectWhenTypeIsSaml2AuthenticationThenNoException() throws IOException {
|
|
|
- Response response = response(recipientUri, idpEntityId);
|
|
|
- Assertion assertion = defaultAssertion();
|
|
|
- signXmlObject(
|
|
|
- assertion,
|
|
|
- assertingPartyCredentials(),
|
|
|
- recipientEntityId
|
|
|
- );
|
|
|
- EncryptedAssertion encryptedAssertion = encryptAssertion(assertion, assertingPartyCredentials());
|
|
|
+ Response response = response();
|
|
|
+ Assertion assertion = signed(assertion(), assertingPartySigningCredential(), RELYING_PARTY_ENTITY_ID);
|
|
|
+ EncryptedAssertion encryptedAssertion = encrypted(assertion, assertingPartyEncryptingCredential());
|
|
|
response.getEncryptedAssertions().add(encryptedAssertion);
|
|
|
- this.token = responseXml(response);
|
|
|
-
|
|
|
- Saml2Authentication authentication = (Saml2Authentication) this.provider.authenticate(this.token);
|
|
|
+ Saml2AuthenticationToken token = token(response, relyingPartyVerifyingCredential(), relyingPartyDecryptingCredential());
|
|
|
+ Saml2Authentication authentication = (Saml2Authentication) this.provider.authenticate(token);
|
|
|
|
|
|
// the following code will throw an exception if authentication isn't serializable
|
|
|
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(1024);
|
|
@@ -350,27 +281,6 @@ public class OpenSamlAuthenticationProviderTests {
|
|
|
objectOutputStream.flush();
|
|
|
}
|
|
|
|
|
|
- private Assertion defaultAssertion() {
|
|
|
- return assertion(
|
|
|
- username,
|
|
|
- idpEntityId,
|
|
|
- recipientEntityId,
|
|
|
- recipientUri
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- private Saml2AuthenticationToken responseXml(XMLObject assertion) {
|
|
|
- String xml = this.saml.serialize(assertion);
|
|
|
- return new Saml2AuthenticationToken(
|
|
|
- xml,
|
|
|
- recipientUri,
|
|
|
- idpEntityId,
|
|
|
- recipientEntityId,
|
|
|
- relyingPartyCredentials()
|
|
|
- );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
private Matcher<Saml2AuthenticationException> authenticationMatcher(String code) {
|
|
|
return authenticationMatcher(code, null);
|
|
|
}
|
|
@@ -402,4 +312,14 @@ public class OpenSamlAuthenticationProviderTests {
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
+
|
|
|
+ private Saml2AuthenticationToken token(Response response, Saml2X509Credential... credentials) {
|
|
|
+ String payload = this.saml.serialize(response);
|
|
|
+ return token(payload, credentials);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Saml2AuthenticationToken token(String payload, Saml2X509Credential... credentials) {
|
|
|
+ return new Saml2AuthenticationToken(payload,
|
|
|
+ DESTINATION, ASSERTING_PARTY_ENTITY_ID, RELYING_PARTY_ENTITY_ID, Arrays.asList(credentials));
|
|
|
+ }
|
|
|
}
|