Search in sources :

Example 1 with SamlMetadataDocument

use of org.apereo.cas.support.saml.services.idp.metadata.SamlMetadataDocument in project cas by apereo.

the class RestSamlRegisteredServiceMetadataResolverTests method setup.

@Before
@SneakyThrows
public void setup() {
    final SamlMetadataDocument doc = new SamlMetadataDocument();
    doc.setId(1);
    doc.setName("SAML Document");
    doc.setSignature(null);
    doc.setValue(IOUtils.toString(new ClassPathResource("sp-metadata.xml").getInputStream(), StandardCharsets.UTF_8));
    final String data = MAPPER.writeValueAsString(doc);
    this.webServer = new MockWebServer(8078, new ByteArrayResource(data.getBytes(StandardCharsets.UTF_8), "REST Output"), MediaType.APPLICATION_XML_VALUE);
    this.webServer.start();
}
Also used : MockWebServer(org.apereo.cas.util.MockWebServer) SamlMetadataDocument(org.apereo.cas.support.saml.services.idp.metadata.SamlMetadataDocument) ByteArrayResource(org.springframework.core.io.ByteArrayResource) ClassPathResource(org.springframework.core.io.ClassPathResource) Before(org.junit.Before) SneakyThrows(lombok.SneakyThrows)

Example 2 with SamlMetadataDocument

use of org.apereo.cas.support.saml.services.idp.metadata.SamlMetadataDocument in project cas by apereo.

the class JpaSamlRegisteredServiceMetadataResolverTests method verifyResolver.

@Test
public void verifyResolver() throws Exception {
    final ClassPathResource res = new ClassPathResource("samlsp-metadata.xml");
    final SamlMetadataDocument md = new SamlMetadataDocument();
    md.setName("SP");
    md.setValue(IOUtils.toString(res.getInputStream(), StandardCharsets.UTF_8));
    resolver.saveOrUpdate(md);
    final SamlRegisteredService service = new SamlRegisteredService();
    service.setName("SAML Service");
    service.setServiceId("https://carmenwiki.osu.edu/shibboleth");
    service.setDescription("Testing");
    service.setMetadataLocation("jdbc://");
    assertTrue(resolver.supports(service));
    final Collection<MetadataResolver> resolvers = resolver.resolve(service);
    assertTrue(resolvers.size() == 1);
}
Also used : SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) SamlMetadataDocument(org.apereo.cas.support.saml.services.idp.metadata.SamlMetadataDocument) SamlRegisteredServiceMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.resolver.SamlRegisteredServiceMetadataResolver) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) ClassPathResource(org.springframework.core.io.ClassPathResource) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 3 with SamlMetadataDocument

use of org.apereo.cas.support.saml.services.idp.metadata.SamlMetadataDocument in project cas by apereo.

the class MongoDbSamlRegisteredServiceMetadataResolverTests method setup.

@Before
public void setup() throws Exception {
    final MongoDbSamlMetadataProperties mongo = casProperties.getAuthn().getSamlIdp().getMetadata().getMongo();
    final ClassPathResource res = new ClassPathResource("sp-metadata.xml");
    final SamlMetadataDocument md = new SamlMetadataDocument();
    md.setName("SP");
    md.setValue(IOUtils.toString(res.getInputStream(), StandardCharsets.UTF_8));
    mongoDbSamlMetadataResolverTemplate.save(md, mongo.getCollection());
}
Also used : MongoDbSamlMetadataProperties(org.apereo.cas.configuration.model.support.saml.idp.metadata.MongoDbSamlMetadataProperties) SamlMetadataDocument(org.apereo.cas.support.saml.services.idp.metadata.SamlMetadataDocument) ClassPathResource(org.springframework.core.io.ClassPathResource) Before(org.junit.Before)

Example 4 with SamlMetadataDocument

use of org.apereo.cas.support.saml.services.idp.metadata.SamlMetadataDocument in project cas by apereo.

the class RestSamlRegisteredServiceMetadataResolver method resolve.

@Override
public Collection<MetadataResolver> resolve(final SamlRegisteredService service) {
    try {
        final RestSamlMetadataProperties rest = samlIdPProperties.getMetadata().getRest();
        final HttpResponse response = HttpUtils.execute(rest.getUrl(), rest.getMethod(), rest.getBasicAuthUsername(), rest.getBasicAuthPassword(), CollectionUtils.wrap("entityId", service.getServiceId()), CollectionUtils.wrap("Content-Type", MediaType.APPLICATION_XML_VALUE));
        if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            final SamlMetadataDocument doc = MAPPER.readValue(response.getEntity().getContent(), SamlMetadataDocument.class);
            final MetadataResolver resolver = buildMetadataResolverFrom(service, doc);
            return CollectionUtils.wrapList(resolver);
        }
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return null;
}
Also used : RestSamlMetadataProperties(org.apereo.cas.configuration.model.support.saml.idp.metadata.RestSamlMetadataProperties) HttpResponse(org.apache.http.HttpResponse) SamlMetadataDocument(org.apereo.cas.support.saml.services.idp.metadata.SamlMetadataDocument) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) BaseSamlRegisteredServiceMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.resolver.BaseSamlRegisteredServiceMetadataResolver)

Aggregations

SamlMetadataDocument (org.apereo.cas.support.saml.services.idp.metadata.SamlMetadataDocument)4 ClassPathResource (org.springframework.core.io.ClassPathResource)3 Before (org.junit.Before)2 MetadataResolver (org.opensaml.saml.metadata.resolver.MetadataResolver)2 SneakyThrows (lombok.SneakyThrows)1 HttpResponse (org.apache.http.HttpResponse)1 MongoDbSamlMetadataProperties (org.apereo.cas.configuration.model.support.saml.idp.metadata.MongoDbSamlMetadataProperties)1 RestSamlMetadataProperties (org.apereo.cas.configuration.model.support.saml.idp.metadata.RestSamlMetadataProperties)1 SamlRegisteredService (org.apereo.cas.support.saml.services.SamlRegisteredService)1 BaseSamlRegisteredServiceMetadataResolver (org.apereo.cas.support.saml.services.idp.metadata.cache.resolver.BaseSamlRegisteredServiceMetadataResolver)1 SamlRegisteredServiceMetadataResolver (org.apereo.cas.support.saml.services.idp.metadata.cache.resolver.SamlRegisteredServiceMetadataResolver)1 MockWebServer (org.apereo.cas.util.MockWebServer)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 ByteArrayResource (org.springframework.core.io.ByteArrayResource)1