|
16 | 16 |
|
17 | 17 | package org.springframework.security.saml2.provider.service.authentication;
|
18 | 18 |
|
| 19 | +import java.io.ByteArrayOutputStream; |
| 20 | +import java.io.IOException; |
| 21 | +import java.io.ObjectOutputStream; |
| 22 | + |
19 | 23 | import org.springframework.security.core.Authentication;
|
20 | 24 |
|
21 | 25 | import org.hamcrest.BaseMatcher;
|
@@ -346,6 +350,28 @@ public void authenticateWhenDecryptionKeysAreWrongThenThrowAuthenticationExcepti
|
346 | 350 | provider.authenticate(token);
|
347 | 351 | }
|
348 | 352 |
|
| 353 | + @Test |
| 354 | + public void writeObjectWhenTypeIsSaml2AuthenticationThenNoException() throws IOException { |
| 355 | + Response response = response(recipientUri, idpEntityId); |
| 356 | + Assertion assertion = defaultAssertion(); |
| 357 | + signXmlObject( |
| 358 | + assertion, |
| 359 | + assertingPartyCredentials(), |
| 360 | + recipientEntityId |
| 361 | + ); |
| 362 | + EncryptedAssertion encryptedAssertion = encryptAssertion(assertion, assertingPartyCredentials()); |
| 363 | + response.getEncryptedAssertions().add(encryptedAssertion); |
| 364 | + token = responseXml(response, idpEntityId); |
| 365 | + |
| 366 | + Saml2Authentication authentication = (Saml2Authentication) provider.authenticate(token); |
| 367 | + |
| 368 | + // the following code will throw an exception if authentication isn't serializable |
| 369 | + ByteArrayOutputStream byteStream = new ByteArrayOutputStream(1024); |
| 370 | + ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteStream); |
| 371 | + objectOutputStream.writeObject(authentication); |
| 372 | + objectOutputStream.flush(); |
| 373 | + } |
| 374 | + |
349 | 375 | private Assertion defaultAssertion() {
|
350 | 376 | return assertion(
|
351 | 377 | username,
|
|
0 commit comments