README.adoc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 EOLd 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 the migration.
  4. == Key Changes
  5. === URL Forwarding Filter
  6. Instead of customizing the default Spring Security configuration, a new `Filter` has been created named `SamlExtensionUrlForwardingFilter`.
  7. 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].
  8. Below is a table with the URLs that the Filter listen to (column 1) and forwards to (column 2).
  9. |===
  10. |SAML Extension URLs |Spring Security SAML 2.0 Support URLs |Description
  11. |`/saml/SSO`
  12. |`/login/saml2/sso/one`
  13. |The URL that processes a `<saml2:Response>` from the IdP
  14. |`/saml/login`
  15. |`/saml2/authenticate/one`
  16. |The URL that triggers a SAML 2.0 Login
  17. |`/saml/logout`
  18. |`/logout/saml2/slo`
  19. |The URL that trigger an SP's initiated SAML 2.0 Logout
  20. |`/saml/SingleLogout`
  21. |`/logout/saml2/slo`
  22. |The URL that processes a `<saml2:LogoutRequest>` from the IdP
  23. |`/saml/metadata`
  24. |`/saml2/service-provider-metadata/one`
  25. |The URL that generates the SP metadata
  26. |===
  27. Note that the `SamlExtensionUrlForwardingFilter` has an order of `-101`, this makes it be invoked before the `FilterChainProxy`.
  28. [source,java]
  29. ----
  30. @Component
  31. @Order(-101) // To run before FilterChainProxy
  32. public class SamlExtensionUrlForwardingFilter extends OncePerRequestFilter {
  33. // ...
  34. }
  35. ----
  36. === application.yml
  37. [source%linenums,yml]
  38. ----
  39. spring:
  40. security:
  41. filter:
  42. dispatcher-types: async, error, request, forward <1>
  43. saml2:
  44. relyingparty:
  45. registration:
  46. one:
  47. signing.credentials:
  48. - private-key-location: classpath:credentials/rp-private.key
  49. certificate-location: classpath:credentials/rp-certificate.crt
  50. assertingparty.metadata-uri: https://dev-05937739.okta.com/app/exk598vc9bHhwoTXM5d7/sso/saml/metadata
  51. singlelogout:
  52. binding: POST
  53. url: "{baseUrl}/saml/logout" <2>
  54. responseUrl: "{baseUrl}/saml/SingleLogout" <3>
  55. acs:
  56. location: "{baseUrl}/saml/SSO" <4>
  57. ----
  58. ==== `FilterChainProxy` Dispatcher Types
  59. In Spring Boot, by default, the `FilterChainProxy` is registered for the `REQUEST`, `ASYNC` and `ERROR` dispatcher types.
  60. Since we are forwarding from one URL to another, we should also register it for the `FORWARD` dispatcher type (see <1> above).
  61. ==== `RelyingPartyRegistration` properties
  62. The `RelyingPartyRegistration` properties should also be customized to match the values that were used by the SAML Extension (see <2>, <3> and <4> above).
  63. == Run the Sample
  64. === Start up the Sample Boot Application
  65. ```
  66. ./gradlew :servlet:spring-boot:java:saml2:custom-urls:bootRun
  67. ```
  68. === Open a Browser
  69. http://localhost:8080/
  70. You will be redirected to the Okta SAML 2.0 IDP
  71. === Type in your credentials
  72. ```
  73. User: testuser2@spring.security.saml
  74. Password: 12345678
  75. ```