This repository has been archived by the owner on Nov 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug Fix: Support signature inheritance
- Loading branch information
Showing
3 changed files
with
125 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...ce-provider/src/test/java/org/springframework/security/samples/SimpleSamlPhpTestKeys.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2002-2018 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package org.springframework.security.samples;import org.springframework.security.saml.key.KeyType; | ||
import org.springframework.security.saml.key.SimpleKey; | ||
|
||
public class SimpleSamlPhpTestKeys { | ||
public static SimpleKey getSimpleSamlPhpKeyData() { | ||
return new SimpleKey( | ||
"simplesamlphp-key", | ||
"-----BEGIN RSA PRIVATE KEY-----\n" + | ||
"MIIEowIBAAKCAQEAuHJ+thNcS6qTd+D5m6ygW5DlxY81oCfW/qV7mkX7egN9/bri\n" + | ||
"EHqHh+ankikVU5d9i9IHc9mYry8GV1vnKr37VVtbbxB78yRcsXk1t3wlHgkLHmy5\n" + | ||
"wNqkWtO0ZMU6OjX9uOJllkQ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V9DQBy2zds9f1I3qxg0eX6JnGrXi/ZiCT+lJgVe3ZFXiejiLAiKB04sXW3ti0LW3\n" + | ||
"lx13Y1YlQ4/tlpgTgfIJxKV6nyPiLoK0nywbMd+vpAirDt2Oc+hk\n" + | ||
"-----END CERTIFICATE-----", | ||
"", | ||
KeyType.SIGNING | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,8 @@ | |
import org.springframework.security.saml.saml2.metadata.Metadata; | ||
import org.springframework.security.saml.saml2.metadata.NameId; | ||
import org.springframework.security.saml.saml2.metadata.ServiceProviderMetadata; | ||
import org.springframework.security.saml.saml2.signature.AlgorithmMethod; | ||
import org.springframework.security.saml.saml2.signature.DigestMethod; | ||
import org.springframework.security.saml.spi.DefaultSamlAuthentication; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
@@ -222,6 +224,36 @@ public void processResponse() throws Exception { | |
.andExpect(authenticated()); | ||
} | ||
|
||
@Test | ||
public void processResponseSignatureInheritance() throws Exception { | ||
ServiceProviderService provider = provisioning.getHostedProvider(); | ||
config.getServiceProvider().setWantAssertionsSigned(true); | ||
String idpEntityId = "http://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php"; | ||
AuthenticationRequest authn = getAuthenticationRequest(); | ||
IdentityProviderMetadata idp = provider.getRemoteProvider(idpEntityId); | ||
ServiceProviderMetadata sp = provider.getMetadata(); | ||
Assertion assertion = helper.assertion(sp, idp, authn, "[email protected]", NameId.PERSISTENT); | ||
Response response = helper.response( | ||
authn, | ||
assertion, | ||
sp, | ||
idp | ||
); | ||
response.setSigningKey( | ||
SimpleSamlPhpTestKeys.getSimpleSamlPhpKeyData(), | ||
AlgorithmMethod.RSA_SHA256, | ||
DigestMethod.SHA256 | ||
); | ||
|
||
String encoded = transformer.samlEncode(transformer.toXml(response), false); | ||
mockMvc.perform( | ||
post("/saml/sp/SSO/alias/boot-sample-sp") | ||
.param("SAMLResponse", encoded) | ||
) | ||
.andExpect(status().isFound()) | ||
.andExpect(authenticated()); | ||
} | ||
|
||
@Test | ||
public void invalidResponse() throws Exception { | ||
config.getServiceProvider().setWantAssertionsSigned(false); | ||
|