SAML2ServiceProviderMetadataResolver implements SAML2MetadataResolver { @Override public final MetadataResolver resolve() { return this.metadataResolver; } SAML2ServiceProviderMetadataResolver(final SAML2Configuration configuration); void destroy(); @Override final MetadataResolver resolve(); @Override final String getEntityId(); @Override String getMetadata(); @Override XMLObject getEntityDescriptorElement();  }
@Test public void resolveServiceProviderMetadataViaFile() { final SAML2Configuration configuration = initializeConfiguration(new FileSystemResource("target/out.xml"), "target/keystore.jks"); final SAML2MetadataResolver metadataResolver = new SAML2ServiceProviderMetadataResolver(configuration); assertNotNull(metadataResolver.resolve()); }
@Test public void resolveServiceProviderMetadataViaUrl() throws Exception { final String restBody = IOUtils.toString( new ClassPathResource("sample-sp-metadata.xml").getInputStream(), StandardCharsets.UTF_8); final WireMockServer wireMockServer = new WireMockServer(8081); wireMockServer.stubFor( get(urlPathEqualTo("/saml")) .willReturn(aResponse() .withStatus(200) .withHeader("Content-Type", ContentType.APPLICATION_XML.getMimeType()) .withBody(restBody))); wireMockServer.stubFor( post(urlPathEqualTo("/saml")) .willReturn(aResponse().withStatus(200))); final String keystore = IOUtils.toString( new ClassPathResource("dummy-keystore.txt").getInputStream(), StandardCharsets.UTF_8); wireMockServer.stubFor( get(urlPathEqualTo("/keystore")) .willReturn(aResponse().withStatus(200).withBody(keystore))); wireMockServer.stubFor( post(urlPathEqualTo("/keystore")) .willReturn(aResponse().withStatus(200))); try { wireMockServer.start(); final SAML2Configuration configuration = initializeConfiguration(new FileUrlResource(new URL("http: "http: final SAML2MetadataResolver metadataResolver = new SAML2ServiceProviderMetadataResolver(configuration); assertNotNull(metadataResolver.resolve()); } finally { wireMockServer.stop(); } }