metadata.adoc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. [[servlet-saml2login-metadata]]
  2. = Producing `<saml2:SPSSODescriptor>` Metadata
  3. You can publish a metadata endpoint by adding the `Saml2MetadataFilter` to the filter chain, as you'll see below:
  4. ====
  5. .Java
  6. [source,java,role="primary"]
  7. ----
  8. DefaultRelyingPartyRegistrationResolver relyingPartyRegistrationResolver =
  9. new DefaultRelyingPartyRegistrationResolver(this.relyingPartyRegistrationRepository);
  10. Saml2MetadataFilter filter = new Saml2MetadataFilter(
  11. relyingPartyRegistrationResolver,
  12. new OpenSamlMetadataResolver());
  13. http
  14. // ...
  15. .saml2Login(withDefaults())
  16. .addFilterBefore(filter, Saml2WebSsoAuthenticationFilter.class);
  17. ----
  18. .Kotlin
  19. [source,kotlin,role="secondary"]
  20. ----
  21. val relyingPartyRegistrationResolver: Converter<HttpServletRequest, RelyingPartyRegistration> =
  22. DefaultRelyingPartyRegistrationResolver(this.relyingPartyRegistrationRepository)
  23. val filter = Saml2MetadataFilter(
  24. relyingPartyRegistrationResolver,
  25. OpenSamlMetadataResolver()
  26. )
  27. http {
  28. //...
  29. saml2Login { }
  30. addFilterBefore<Saml2WebSsoAuthenticationFilter>(filter)
  31. }
  32. ----
  33. ====
  34. You can use this metadata endpoint to register your relying party with your asserting party.
  35. This is often as simple as finding the correct form field to supply the metadata endpoint.
  36. By default, the metadata endpoint is `+/saml2/service-provider-metadata/{registrationId}+`.
  37. You can change this by calling the `setRequestMatcher` method on the filter:
  38. ====
  39. .Java
  40. [source,java,role="primary"]
  41. ----
  42. filter.setRequestMatcher(new AntPathRequestMatcher("/saml2/metadata/{registrationId}", "GET"));
  43. ----
  44. .Kotlin
  45. [source,kotlin,role="secondary"]
  46. ----
  47. filter.setRequestMatcher(AntPathRequestMatcher("/saml2/metadata/{registrationId}", "GET"))
  48. ----
  49. ====
  50. Or, if you have registered a custom relying party registration resolver in the constructor, then you can specify a path without a `registrationId` hint, like so:
  51. ====
  52. .Java
  53. [source,java,role="primary"]
  54. ----
  55. filter.setRequestMatcher(new AntPathRequestMatcher("/saml2/metadata", "GET"));
  56. ----
  57. .Kotlin
  58. [source,kotlin,role="secondary"]
  59. ----
  60. filter.setRequestMatcher(AntPathRequestMatcher("/saml2/metadata", "GET"))
  61. ----
  62. ====
  63. == Changing the Way a `RelyingPartyRegistration` Is Looked Up
  64. To apply a custom `RelyingPartyRegistrationResolver` to the metadata endpoint, you can provide it directly in the filter constructor like so:
  65. ====
  66. .Java
  67. [source,java,role="primary"]
  68. ----
  69. RelyingPartyRegistrationResolver myRegistrationResolver = ...;
  70. Saml2MetadataFilter metadata = new Saml2MetadataFilter(myRegistrationResolver, new OpenSamlMetadataResolver());
  71. // ...
  72. http.addFilterBefore(metadata, BasicAuthenticationFilter.class);
  73. ----
  74. .Kotlin
  75. ----
  76. val myRegistrationResolver: RelyingPartyRegistrationResolver = ...;
  77. val metadata = new Saml2MetadataFilter(myRegistrationResolver, OpenSamlMetadataResolver());
  78. // ...
  79. http.addFilterBefore(metadata, BasicAuthenticationFilter::class.java);
  80. ----
  81. ====
  82. In the event that you are applying a `RelyingPartyRegistrationResolver` to remove the `registrationId` from the URI, you must also change the URI in the filter like so:
  83. ====
  84. .Java
  85. [source,java,role="primary"]
  86. ----
  87. metadata.setRequestMatcher("/saml2/metadata")
  88. ----
  89. .Kotlin
  90. ----
  91. metadata.setRequestMatcher("/saml2/metadata")
  92. ----
  93. ====