metadata.adoc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. [[servlet-saml2login-metadata]]
  2. = Saml 2.0 Metadata
  3. Spring Security can <<parsing-asserting-party-metadata,parse asserting party metadata>> to produce an `AssertingPartyDetails` instance as well as <<publishing-relying-party-metadata,publish relying party metadata>> from a `RelyingPartyRegistration` instance.
  4. [[parsing-asserting-party-metadata]]
  5. == Parsing `<saml2:IDPSSODescriptor>` metadata
  6. You can parse an asserting party's metadata xref:servlet/saml2/login/overview.adoc#servlet-saml2login-relyingpartyregistrationrepository[using `RelyingPartyRegistrations`].
  7. When using the OpenSAML vendor support, the resulting `AssertingPartyDetails` will be of type `OpenSamlAssertingPartyDetails`.
  8. This means you'll be able to do get the underlying OpenSAML XMLObject by doing the following:
  9. ====
  10. .Java
  11. [source,java,role="primary"]
  12. ----
  13. OpenSamlAssertingPartyDetails details = (OpenSamlAssertingPartyDetails)
  14. registration.getAssertingPartyDetails();
  15. EntityDescriptor openSamlEntityDescriptor = details.getEntityDescriptor();
  16. ----
  17. .Kotlin
  18. [source,kotlin,role="secondary"]
  19. ----
  20. val details: OpenSamlAssertingPartyDetails =
  21. registration.getAssertingPartyDetails() as OpenSamlAssertingPartyDetails;
  22. val openSamlEntityDescriptor: EntityDescriptor = details.getEntityDescriptor();
  23. ----
  24. ====
  25. [[publishing-relying-party-metadata]]
  26. == Producing `<saml2:SPSSODescriptor>` Metadata
  27. You can publish a metadata endpoint using the `saml2Metadata` DSL method, as you'll see below:
  28. ====
  29. .Java
  30. [source,java,role="primary"]
  31. ----
  32. http
  33. // ...
  34. .saml2Login(withDefaults())
  35. .saml2Metadata(withDefaults());
  36. ----
  37. .Kotlin
  38. [source,kotlin,role="secondary"]
  39. ----
  40. http {
  41. //...
  42. saml2Login { }
  43. saml2Metadata { }
  44. }
  45. ----
  46. ====
  47. You can use this metadata endpoint to register your relying party with your asserting party.
  48. This is often as simple as finding the correct form field to supply the metadata endpoint.
  49. By default, the metadata endpoint is `+/saml2/metadata+`, though it also responds to `+/saml2/metadata/{registrationId}+` and `+/saml2/service-provider-metadata/{registrationId}+`.
  50. You can change this by calling the `metadataUrl` method in the DSL:
  51. ====
  52. .Java
  53. [source,java,role="primary"]
  54. ----
  55. .saml2Metadata((saml2) -> saml2.metadataUrl("/saml/metadata"))
  56. ----
  57. .Kotlin
  58. [source,kotlin,role="secondary"]
  59. ----
  60. saml2Metadata {
  61. metadataUrl = "/saml/metadata"
  62. }
  63. ----
  64. ====
  65. == Changing the Way a `RelyingPartyRegistration` Is Looked Up
  66. If you have a different strategy for identifying which `RelyingPartyRegistration` to use, you can configure your own `Saml2MetadataResponseResolver` like the one below:
  67. ====
  68. .Java
  69. [source,java,role="primary"]
  70. ----
  71. @Bean
  72. Saml2MetadataResponseResolver metadataResponseResolver(RelyingPartyRegistrationRepository registrations) {
  73. RequestMatcherMetadataResponseResolver metadata = new RequestMatcherMetadataResponseResolver(
  74. (id) -> registrations.findByRegistrationId("relying-party"));
  75. metadata.setMetadataFilename("metadata.xml");
  76. return metadata;
  77. }
  78. ----
  79. .Kotlin
  80. [source,kotlin,role="secondary"]
  81. ----
  82. @Bean
  83. fun metadataResponseResolver(val registrations: RelyingPartyRegistrationRepository): Saml2MetadataResponseResolver {
  84. val metadata = new RequestMatcherMetadataResponseResolver(
  85. id: String -> registrations.findByRegistrationId("relying-party"))
  86. metadata.setMetadataFilename("metadata.xml")
  87. return metadata
  88. }
  89. ----
  90. ====