Skip to content

Commit

Permalink
[SHIBUI-451]
Browse files Browse the repository at this point in the history
Stub out service endpoint
  • Loading branch information
Jj! committed Apr 27, 2018
1 parent 85e508b commit 5765f49
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public MetadataResolver metadataResolver() throws ResolverException, ComponentIn
List<MetadataResolver> resolvers = new ArrayList<>();

// TODO: remove this later when we allow for creation of arbitrary metadata resolvers
FileBackedHTTPMetadataResolver incommonMR = new FileBackedHTTPMetadataResolver(HttpClients.createMinimal(), "http://md.incommon.org/InCommon/InCommon-metadata.xml", "/tmp/incommon.xml"){
FileBackedHTTPMetadataResolver incommonMR = new FileBackedHTTPMetadataResolver(HttpClients.createMinimal(), "http://md.incommon.org/InCommon/InCommon-metadata.xml", "/tmp/incommonmd.xml"){
@Override
protected void initMetadataResolver() throws ComponentInitializationException {
super.initMetadataResolver();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.w3c.dom.Document;

import java.util.*;

Expand Down Expand Up @@ -68,4 +69,10 @@ public void reloadFilters(String metadataResolverName) {
}
}
}

@Override
public Document generateConfiguration() {
//TODO: implement
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package edu.internet2.tier.shibboleth.admin.ui.service;

import org.w3c.dom.Document;

public interface MetadataResolverService {
public void reloadFilters(String metadataResolverName);

public Document generateConfiguration();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.web.servlet.result.MockMvcResultHandlers
import org.springframework.test.web.servlet.setup.MockMvcBuilders
import org.w3c.dom.Document
import spock.lang.Specification

import static org.hamcrest.CoreMatchers.containsString
Expand Down Expand Up @@ -66,6 +67,11 @@ class FilterControllerTests extends Specification {
void reloadFilters(String metadataResolverName) {
// we do nothing 'cause we're lazy
}

@Override
Document generateConfiguration() {
return null
}
}
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package edu.internet2.tier.shibboleth.admin.ui.service

import edu.internet2.tier.shibboleth.admin.ui.configuration.CoreShibUiConfiguration
import edu.internet2.tier.shibboleth.admin.ui.configuration.SearchConfiguration
import edu.internet2.tier.shibboleth.admin.ui.opensaml.OpenSamlObjects
import edu.internet2.tier.shibboleth.admin.ui.repository.MetadataResolverRepository
import org.apache.http.impl.client.HttpClients
import org.opensaml.saml.metadata.resolver.ChainingMetadataResolver
import org.opensaml.saml.metadata.resolver.MetadataResolver
import org.opensaml.saml.metadata.resolver.impl.FileBackedHTTPMetadataResolver
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.domain.EntityScan
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.context.TestConfiguration
import org.springframework.context.annotation.Bean
import org.springframework.data.jpa.repository.config.EnableJpaRepositories
import org.springframework.test.context.ContextConfiguration
import org.xmlunit.builder.DiffBuilder
import org.xmlunit.builder.Input
import spock.lang.Specification

@SpringBootTest
@DataJpaTest
@ContextConfiguration(classes = [CoreShibUiConfiguration, SearchConfiguration])
@EnableJpaRepositories(basePackages = ["edu.internet2.tier.shibboleth.admin.ui"])
@EntityScan("edu.internet2.tier.shibboleth.admin.ui")
class IncommonJPAMetadataResolverServiceImplTests extends Specification {
@Autowired
MetadataResolverService metadataResolverService

def 'test generation of metadata-providers.xml'() {
when:
def output = metadataResolverService.generateConfiguration()

then:
assert !DiffBuilder.compare(Input.fromStream(this.class.getResourceAsStream('/conf/278.xml'))).withTest(Input.fromDocument(output)).ignoreComments().ignoreWhitespace().build().hasDifferences()
}

//TODO: check that this configuration is sufficient
@TestConfiguration
static class Config {
@Autowired
OpenSamlObjects openSamlObjects

@Autowired
MetadataResolverRepository metadataResolverRepository

@Bean
MetadataResolver metadataResolver() {
def resolver = new ChainingMetadataResolver().with {
it.id = 'chain'

resolvers = [
[
'id': { 'incommonmd' }
] as MetadataResolver
]
it.initialize()
it
}

if (!metadataResolverRepository.findAll().iterator().hasNext()) {
edu.internet2.tier.shibboleth.admin.ui.domain.MetadataResolver mr = new edu.internet2.tier.shibboleth.admin.ui.domain.MetadataResolver()
mr.setName("incommonmd")
metadataResolverRepository.save(mr)
}

return resolver
}
}
}
19 changes: 19 additions & 0 deletions backend/src/test/resources/conf/278.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- This file is an EXAMPLE metadata configuration file. -->
<MetadataProvider id="ShibbolethMetadata" xsi:type="ChainingMetadataProvider"
xmlns="urn:mace:shibboleth:2.0:metadata"
xmlns:resource="urn:mace:shibboleth:2.0:resource"
xmlns:security="urn:mace:shibboleth:2.0:security"
xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:mace:shibboleth:2.0:metadata http://shibboleth.net/schema/idp/shibboleth-metadata.xsd
urn:mace:shibboleth:2.0:resource http://shibboleth.net/schema/idp/shibboleth-resource.xsd
urn:mace:shibboleth:2.0:security http://shibboleth.net/schema/idp/shibboleth-security.xsd
urn:oasis:names:tc:SAML:2.0:metadata http://docs.oasis-open.org/security/saml/v2.0/saml-schema-metadata-2.0.xsd">
<MetadataProvider id="HTTPMetadata"
xsi:type="FileBackedHTTPMetadataProvider"
backingFile="%{idp.home}/metadata/incommonmd.xml"
metadataURL="http://md.incommon.org/InCommon/InCommon-metadata.xml">
</MetadataProvider>

</MetadataProvider>

0 comments on commit 5765f49

Please sign in to comment.