Skip to content

Commit 2ccd921

Browse files
committed
Polish saml-extension-urls Sample
- Simplify URIs - Update README
1 parent 45793af commit 2ccd921

File tree

4 files changed

+58
-41
lines changed

4 files changed

+58
-41
lines changed

servlet/spring-boot/java/saml2/saml-extension-urls/README.adoc

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,66 @@
11
= SAML 2.0 Login & Logout Sample using SAML Extension URLs
22

3-
This guide provides instructions on setting up the new Spring Security SAML 2.0 support using the endpoint URLs from the EOLd Spring Security SAML Extension.
3+
This guide provides instructions on setting up the new Spring Security SAML 2.0 support using the endpoint URLs from the EOL'd Spring Security SAML Extension.
44

5-
See the https://github.com/spring-projects/spring-security/wiki/SAML-2.0-Migration-Guide[SAML 2.0 Migration Guide] for more details about the migration.
5+
See the https://github.com/spring-projects/spring-security/wiki/SAML-2.0-Migration-Guide[SAML 2.0 Migration Guide] for more details about migrating.
6+
7+
== Run the Sample
8+
9+
=== Install Docker
10+
11+
This sample requires Docker to run a local IdP.
12+
As an alternative, you can point the sample at your own IdP by changing the `application.yml` here:
13+
14+
[source,java]
15+
----
16+
spring:
17+
security:
18+
saml2:
19+
relyingparty:
20+
registration:
21+
one:
22+
assertingparty.metadata-uri: {your-idp-metadata-endpoint}
23+
----
24+
25+
=== Start up the Sample Boot Application
26+
```
27+
./gradlew :servlet:spring-boot:java:saml2:saml-extension-urls:bootRun
28+
```
29+
30+
=== Open a Browser
31+
32+
http://localhost:8080/
33+
34+
You will be redirected to the Okta SAML 2.0 IDP
35+
36+
=== Type in your credentials
37+
38+
```
39+
User: user1
40+
Password: user1pass
41+
```
642

743
== Key Changes
844

45+
There are two important differences in the way this sample is configured in order to support the Extension URIs:
46+
47+
* A custom URL forwarding filter
48+
* Changes to `application.yml`
49+
950
=== URL Forwarding Filter
1051

11-
Instead of customizing the default Spring Security configuration, a new `Filter` has been created named `SamlExtensionUrlForwardingFilter`.
12-
This new filter is responsible to forward from the SAML Extension URLs to the new https://docs.spring.io/spring-security/reference/servlet/saml2/login/overview.html[Spring Security SAML 2.0 support URLs].
13-
Below is a table with the URLs that the Filter listen to (column 1) and forwards to (column 2).
52+
In this sample, you will see a forwarding `Filter` that maps SAML Extension URLs to Spring Security URLs.
53+
This is a simple pattern you can follow to assist with migration so that as you transition from the Extension to Spring Security, you don't need to reconfigure the Identity Providers that you are connected to.
54+
55+
The filter is called `SamlExtensionUrlForwardingFilter` and is an example of what you can create for yourself in your own project.
56+
It maps to Spring Security URLs in the following way:
1457

1558

1659
|===
1760
|SAML Extension URLs |Spring Security SAML 2.0 Support URLs |Description
1861

1962
|`/saml/SSO`
20-
|`/login/saml2/sso/one`
63+
|`/login/saml2/sso`
2164
|The URL that processes a `<saml2:Response>` from the IdP
2265

2366
|`/saml/login`
@@ -33,11 +76,11 @@ Below is a table with the URLs that the Filter listen to (column 1) and forwards
3376
|The URL that processes a `<saml2:LogoutRequest>` from the IdP
3477

3578
|`/saml/metadata`
36-
|`/saml2/service-provider-metadata/one`
79+
|`/saml2/metadata`
3780
|The URL that generates the SP metadata
3881
|===
3982

40-
Note that the `SamlExtensionUrlForwardingFilter` has an order of `-101`, this makes it be invoked before the `FilterChainProxy`.
83+
Note that the `SamlExtensionUrlForwardingFilter` has an order of `-101` so it's invoked before the `FilterChainProxy`:
4184

4285
[source,java]
4386
----
@@ -60,10 +103,7 @@ spring:
60103
relyingparty:
61104
registration:
62105
one:
63-
signing.credentials:
64-
- private-key-location: classpath:credentials/rp-private.key
65-
certificate-location: classpath:credentials/rp-certificate.crt
66-
assertingparty.metadata-uri: https://dev-05937739.okta.com/app/exk598vc9bHhwoTXM5d7/sso/saml/metadata
106+
// ...
67107
singlelogout:
68108
binding: POST
69109
url: "{baseUrl}/saml/logout" <2>
@@ -80,24 +120,3 @@ Since we are forwarding from one URL to another, we should also register it for
80120
==== `RelyingPartyRegistration` properties
81121

82122
The `RelyingPartyRegistration` properties should also be customized to match the values that were used by the SAML Extension (see <2>, <3> and <4> above).
83-
84-
== Run the Sample
85-
86-
=== Start up the Sample Boot Application
87-
```
88-
./gradlew :servlet:spring-boot:java:saml2:custom-urls:bootRun
89-
```
90-
91-
=== Open a Browser
92-
93-
http://localhost:8080/
94-
95-
You will be redirected to the Okta SAML 2.0 IDP
96-
97-
=== Type in your credentials
98-
99-
```
100-
101-
Password: 12345678
102-
```
103-
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
4545
@AutoConfigureMockMvc
46-
public class CustomUrlsApplicationITests {
46+
public class SamlExtensionUrlsApplicationITests {
4747

4848
@LocalServerPort
4949
int port;
@@ -81,9 +81,7 @@ void logoutWhenRelyingPartyInitiatedLogoutThenLoginPageWithLogoutParam() throws
8181

8282
@Test
8383
void metadataWhenGetThenForwardToUrl() throws Exception {
84-
this.mvc.perform(get("/saml/metadata"))
85-
.andExpect(status().isOk())
86-
.andExpect(forwardedUrl("/saml2/service-provider-metadata/one"));
84+
this.mvc.perform(get("/saml/metadata")).andExpect(status().isOk()).andExpect(forwardedUrl("/saml2/metadata"));
8785
}
8886

8987
private void performLogin() throws Exception {

servlet/spring-boot/java/saml2/saml-extension-urls/src/main/java/example/SamlExtensionUrlForwardingFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
public class SamlExtensionUrlForwardingFilter extends OncePerRequestFilter {
4141

4242
// @formatter:off
43-
private static final Map<String, String> urlMapping = Map.of("/saml/SSO", "/login/saml2/sso/one",
43+
private static final Map<String, String> urlMapping = Map.of("/saml/SSO", "/login/saml2/sso",
4444
"/saml/login", "/saml2/authenticate/one",
4545
"/saml/logout", "/logout/saml2/slo",
4646
"/saml/SingleLogout", "/logout/saml2/slo",
47-
"/saml/metadata", "/saml2/service-provider-metadata/one");
47+
"/saml/metadata", "/saml2/metadata");
4848
// @formatter:on
4949

5050
private final RequestMatcher matcher = createRequestMatcher();

servlet/spring-boot/java/saml2/saml-extension-urls/src/main/java/example/CustomUrlsApplication.java renamed to servlet/spring-boot/java/saml2/saml-extension-urls/src/main/java/example/SamlExtensionUrlsApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
import org.springframework.boot.autoconfigure.SpringBootApplication;
2121

2222
@SpringBootApplication
23-
public class CustomUrlsApplication {
23+
public class SamlExtensionUrlsApplication {
2424

2525
public static void main(String[] args) {
26-
SpringApplication.run(CustomUrlsApplication.class, args);
26+
SpringApplication.run(SamlExtensionUrlsApplication.class, args);
2727
}
2828

2929
}

0 commit comments

Comments
 (0)