README.adoc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. = SAML 2.0 Login & Logout Sample using SAML Extension URLs
  2. 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.
  3. 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.
  4. == Run the Sample
  5. === Install Docker
  6. This sample requires Docker to run a local IdP.
  7. As an alternative, you can point the sample at your own IdP by changing the `application.yml` here:
  8. [source,java]
  9. ----
  10. spring:
  11. security:
  12. saml2:
  13. relyingparty:
  14. registration:
  15. one:
  16. assertingparty.metadata-uri: {your-idp-metadata-endpoint}
  17. ----
  18. === Start up the Sample Boot Application
  19. ```
  20. ./gradlew :servlet:spring-boot:java:saml2:saml-extension-urls:bootRun
  21. ```
  22. === Open a Browser
  23. http://localhost:8080/
  24. You will be redirected to the Okta SAML 2.0 IDP
  25. === Type in your credentials
  26. ```
  27. User: user1
  28. Password: user1pass
  29. ```
  30. == Key Changes
  31. There are two important differences in the way this sample is configured in order to support the Extension URIs:
  32. * A custom URL forwarding filter
  33. * Changes to `application.yml`
  34. === URL Forwarding Filter
  35. In this sample, you will see a forwarding `Filter` that maps SAML Extension URLs to Spring Security URLs.
  36. 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.
  37. The filter is called `SamlExtensionUrlForwardingFilter` and is an example of what you can create for yourself in your own project.
  38. It maps to Spring Security URLs in the following way:
  39. |===
  40. |SAML Extension URLs |Spring Security SAML 2.0 Support URLs |Description
  41. |`/saml/SSO`
  42. |`/login/saml2/sso`
  43. |The URL that processes a `<saml2:Response>` from the IdP
  44. |`/saml/login`
  45. |`/saml2/authenticate/one`
  46. |The URL that triggers a SAML 2.0 Login
  47. |`/saml/logout`
  48. |`/logout/saml2/slo`
  49. |The URL that trigger an SP's initiated SAML 2.0 Logout
  50. |`/saml/SingleLogout`
  51. |`/logout/saml2/slo`
  52. |The URL that processes a `<saml2:LogoutRequest>` from the IdP
  53. |`/saml/metadata`
  54. |`/saml2/metadata`
  55. |The URL that generates the SP metadata
  56. |===
  57. Note that the `SamlExtensionUrlForwardingFilter` has an order of `-101` so it's invoked before the `FilterChainProxy`:
  58. [source,java]
  59. ----
  60. @Component
  61. @Order(-101) // To run before FilterChainProxy
  62. public class SamlExtensionUrlForwardingFilter extends OncePerRequestFilter {
  63. // ...
  64. }
  65. ----
  66. === application.yml
  67. [source%linenums,yml]
  68. ----
  69. spring:
  70. security:
  71. filter:
  72. dispatcher-types: async, error, request, forward <1>
  73. saml2:
  74. relyingparty:
  75. registration:
  76. one:
  77. // ...
  78. singlelogout:
  79. binding: POST
  80. url: "{baseUrl}/saml/logout" <2>
  81. responseUrl: "{baseUrl}/saml/SingleLogout" <3>
  82. acs:
  83. location: "{baseUrl}/saml/SSO" <4>
  84. ----
  85. ==== `FilterChainProxy` Dispatcher Types
  86. In Spring Boot, by default, the `FilterChainProxy` is registered for the `REQUEST`, `ASYNC` and `ERROR` dispatcher types.
  87. Since we are forwarding from one URL to another, we should also register it for the `FORWARD` dispatcher type (see <1> above).
  88. ==== `RelyingPartyRegistration` properties
  89. The `RelyingPartyRegistration` properties should also be customized to match the values that were used by the SAML Extension (see <2>, <3> and <4> above).