Skip to content

Commit

Permalink
[SHIBUI-1263]
Browse files Browse the repository at this point in the history
remove Filter versioning since it is rolling up into the resolver
  • Loading branch information
jj committed Jul 5, 2019
1 parent df3abf7 commit 7c74fe8
Show file tree
Hide file tree
Showing 10 changed files with 372 additions and 11 deletions.
6 changes: 6 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ task generateSources {
xmlSecBuilders.ObjectProviders.ObjectProvider.BuilderClass.each {
processLine(it['@className'].toString(), 'src/main/templates/XMLSecBuilderTemplate.java')
}

new XmlSlurper().parse(file('src/main/resources/jpa-saml2-metadata-algorithm-config.xml')).with { builders ->
builders.ObjectProviders.ObjectProvider.BuilderClass.each {
processLine(it['@className'].toString(), 'src/main/templates/AlgorithmBuilderTemplate.java')
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
import org.opensaml.core.xml.util.AttributeMap;

import javax.annotation.Nonnull;
import javax.persistence.ElementCollection;
import javax.persistence.MappedSuperclass;
import javax.persistence.PostLoad;
import javax.persistence.PrePersist;
import javax.persistence.Transient;
import javax.xml.namespace.QName;
import java.util.HashMap;
import java.util.Map;

@MappedSuperclass
@EqualsAndHashCode(callSuper = true, exclude={"unknownAttributes"})
@EqualsAndHashCode(callSuper = true, exclude={"storageAttributeMap"})
public abstract class AbstractAttributeExtensibleXMLObject extends AbstractXMLObject implements AttributeExtensibleXMLObject {

private transient final AttributeMap unknownAttributes;
private transient final AttributeMap unknownAttributes = new AttributeMap(this);

AbstractAttributeExtensibleXMLObject() {
unknownAttributes = new AttributeMap(this);
}

@Nonnull
Expand All @@ -24,4 +28,17 @@ public abstract class AbstractAttributeExtensibleXMLObject extends AbstractXMLOb
public AttributeMap getUnknownAttributes() {
return this.unknownAttributes;
}

@ElementCollection
private Map<QName,String> storageAttributeMap = new HashMap<>();

@PrePersist
void prePersist() {
this.storageAttributeMap = this.unknownAttributes;
}

@PostLoad
void postLoad() {
this.unknownAttributes.putAll(this.storageAttributeMap);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package edu.internet2.tier.shibboleth.admin.ui.domain;

import lombok.EqualsAndHashCode;

import javax.annotation.Nullable;
import javax.persistence.Entity;

@Entity
@EqualsAndHashCode(callSuper = true)
public class DigestMethod extends AbstractElementExtensibleXMLObject implements org.opensaml.saml.ext.saml2alg.DigestMethod {
private String algorithm;

public DigestMethod() {}

public DigestMethod(String algorithm) {
this.algorithm = algorithm;
}

@Nullable
@Override
public String getAlgorithm() {
return null;
}

@Override
public void setAlgorithm(@Nullable String value) {

}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
package edu.internet2.tier.shibboleth.admin.ui.domain;

import lombok.EqualsAndHashCode;
import org.opensaml.core.xml.util.AttributeMap;

import javax.annotation.Nonnull;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.PostLoad;
import javax.persistence.PrePersist;
import javax.persistence.Transient;
import javax.xml.namespace.QName;
import java.util.HashMap;
import java.util.Map;

@Entity
@EqualsAndHashCode(callSuper = true, exclude = {"storageAttributeMap"})
public class RequestInitiator extends AbstractElementExtensibleXMLObject implements org.opensaml.saml.ext.saml2mdreqinit.RequestInitiator {
private String binding;
@Override
Expand Down Expand Up @@ -40,10 +51,25 @@ public void setResponseLocation(String location) {
this.responseLocation = location;
}

@ElementCollection
private Map<QName,String> storageAttributeMap = new HashMap<>();

@Transient
private AttributeMap attributeMap = new AttributeMap(this);

@PrePersist
void prePersist() {
this.storageAttributeMap = this.attributeMap;
}

@PostLoad
void postLoad() {
this.attributeMap.putAll(this.storageAttributeMap);
}

@Nonnull
@Override
@Transient
public AttributeMap getUnknownAttributes() {
return this.attributeMap;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package edu.internet2.tier.shibboleth.admin.ui.domain;

import lombok.EqualsAndHashCode;

import javax.annotation.Nullable;
import javax.persistence.Entity;

@Entity
@EqualsAndHashCode(callSuper = true)
public class SigningMethod extends AbstractElementExtensibleXMLObject implements org.opensaml.saml.ext.saml2alg.SigningMethod {
private String algorithm;
private Integer minKeySize;
private Integer maxKeySize;

public SigningMethod() {}

public SigningMethod(String algorithm, Integer minKeySize, Integer maxKeySize) {
this.algorithm = algorithm;
this.minKeySize = minKeySize;
this.maxKeySize = maxKeySize;
}

@Nullable
@Override
public String getAlgorithm() {
return this.algorithm;
}

@Override
public void setAlgorithm(@Nullable String value) {
this.algorithm = value;
}

@Nullable
@Override
public Integer getMinKeySize() {
return this.minKeySize;
}

@Override
public void setMinKeySize(@Nullable Integer value) {
this.minKeySize = value;
}

@Nullable
@Override
public Integer getMaxKeySize() {
return this.maxKeySize;
}

@Override
public void setMaxKeySize(@Nullable Integer value) {
this.maxKeySize = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ protected String[] getConfigResources() {
"/jpa-schema-config.xml",
"/jpa-saml2-metadata-ui-config.xml",
"/jpa-signature-config.xml",
"/jpa-saml2-metadata-algorithm-config.xml",
"/encryption-config.xml",
"/saml2-metadata-algorithm-config.xml",
"/jpa-saml2-metadata-reqinit-config.xml",
"/saml2-protocol-config.xml",
"/modified-saml2-assertion-config.xml"
Expand Down
34 changes: 34 additions & 0 deletions backend/src/main/resources/jpa-saml2-metadata-algorithm-config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<XMLTooling xmlns="http://www.opensaml.org/xmltooling-config" xmlns:alg="urn:oasis:names:tc:SAML:metadata:algsupport" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opensaml.org/xmltooling-config ../../src/schema/xmltooling-config.xsd">

<!-- SAML v2.0 Metadata Profile for Algorithm Support Version 1.0 XMLObject providers -->
<ObjectProviders>

<!-- DigestMethod provider -->
<ObjectProvider qualifiedName="alg:DigestMethod">
<BuilderClass className="edu.internet2.tier.shibboleth.admin.ui.domain.DigestMethodBuilder"/>
<MarshallingClass className="org.opensaml.saml.ext.saml2alg.impl.DigestMethodMarshaller"/>
<UnmarshallingClass className="org.opensaml.saml.ext.saml2alg.impl.DigestMethodUnmarshaller"/>
</ObjectProvider>

<ObjectProvider qualifiedName="alg:DigestMethodType">
<BuilderClass className="edu.internet2.tier.shibboleth.admin.ui.domain.DigestMethodBuilder"/>
<MarshallingClass className="org.opensaml.saml.ext.saml2alg.impl.DigestMethodMarshaller"/>
<UnmarshallingClass className="org.opensaml.saml.ext.saml2alg.impl.DigestMethodUnmarshaller"/>
</ObjectProvider>

<!-- SigningMethod provider -->
<ObjectProvider qualifiedName="alg:SigningMethod">
<BuilderClass className="edu.internet2.tier.shibboleth.admin.ui.domain.SigningMethodBuilder"/>
<MarshallingClass className="org.opensaml.saml.ext.saml2alg.impl.SigningMethodMarshaller"/>
<UnmarshallingClass className="org.opensaml.saml.ext.saml2alg.impl.SigningMethodUnmarshaller"/>
</ObjectProvider>

<ObjectProvider qualifiedName="alg:SigningMethodType">
<BuilderClass className="edu.internet2.tier.shibboleth.admin.ui.domain.SigningMethodBuilder"/>
<MarshallingClass className="org.opensaml.saml.ext.saml2alg.impl.SigningMethodMarshaller"/>
<UnmarshallingClass className="org.opensaml.saml.ext.saml2alg.impl.SigningMethodUnmarshaller"/>
</ObjectProvider>

</ObjectProviders>
</XMLTooling>
22 changes: 22 additions & 0 deletions backend/src/main/templates/AlgorithmBuilderTemplate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package edu.internet2.tier.shibboleth.admin.ui.domain;

import edu.internet2.tier.shibboleth.admin.ui.opensaml.xml.AbstractSAMLObjectBuilder;
import org.opensaml.saml.common.xml.SAMLConstants;

public class {{TOKEN}}Builder extends AbstractSAMLObjectBuilder<{{TOKEN}}> {
public {{TOKEN}}Builder() {
}

public {{TOKEN}} buildObject() {
return buildObject(SAMLConstants.SAML20ALG_NS, {{TOKEN}}.DEFAULT_ELEMENT_LOCAL_NAME,
SAMLConstants.SAML20ALG_PREFIX);
}

public {{TOKEN}} buildObject(final String namespaceURI, final String localName, final String namespacePrefix) {
{{TOKEN}} o = new {{TOKEN}}();
o.setNamespaceURI(namespaceURI);
o.setElementLocalName(localName);
o.setNamespacePrefix(namespacePrefix);
return o;
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package edu.internet2.tier.shibboleth.admin.ui.repository

import edu.internet2.tier.shibboleth.admin.ui.configuration.InternationalizationConfiguration
import edu.internet2.tier.shibboleth.admin.ui.configuration.TestConfiguration
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.configuration.InternationalizationConfiguration
import edu.internet2.tier.shibboleth.admin.ui.domain.EntityDescriptor
import edu.internet2.tier.shibboleth.admin.ui.domain.resolvers.opensaml.OpenSamlChainingMetadataResolver
import edu.internet2.tier.shibboleth.admin.ui.opensaml.OpenSamlObjects
import edu.internet2.tier.shibboleth.admin.ui.security.repository.RoleRepository
import edu.internet2.tier.shibboleth.admin.ui.security.repository.UserRepository
import edu.internet2.tier.shibboleth.admin.ui.security.service.UserService
import edu.internet2.tier.shibboleth.admin.ui.service.JPAEntityDescriptorServiceImpl
import edu.internet2.tier.shibboleth.admin.ui.service.JPAEntityServiceImpl
import org.apache.lucene.analysis.Analyzer
import org.apache.lucene.analysis.en.EnglishAnalyzer
import org.opensaml.saml.metadata.resolver.MetadataResolver
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.TestConfiguration
import org.springframework.context.annotation.Bean
import org.springframework.data.jpa.repository.config.EnableJpaRepositories

import org.springframework.test.annotation.DirtiesContext
import org.springframework.test.context.ContextConfiguration
import spock.lang.Specification

Expand All @@ -25,9 +29,10 @@ import javax.persistence.EntityManager
* A highly unnecessary test so that I can check to make sure that persistence is correct for the model
*/
@DataJpaTest
@ContextConfiguration(classes=[CoreShibUiConfiguration, SearchConfiguration, TestConfiguration, InternationalizationConfiguration])
@ContextConfiguration(classes=[CoreShibUiConfiguration, InternationalizationConfiguration])
@EnableJpaRepositories(basePackages = ["edu.internet2.tier.shibboleth.admin.ui"])
@EntityScan("edu.internet2.tier.shibboleth.admin.ui")
@DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD)
class EntityDescriptorRepositoryTest extends Specification {
@Autowired
EntityDescriptorRepository entityDescriptorRepository
Expand All @@ -42,7 +47,7 @@ class EntityDescriptorRepositoryTest extends Specification {
UserRepository userRepository

OpenSamlObjects openSamlObjects = new OpenSamlObjects().with {
init()
it.init()
it
}

Expand All @@ -61,4 +66,30 @@ class EntityDescriptorRepositoryTest extends Specification {
then:
item1.hashCode() == item2.hashCode()
}

def "SHIBUI-950"() {
when:
def input = openSamlObjects.unmarshalFromXml(this.class.getResource('/metadata/SHIBUI-950.xml').bytes) as EntityDescriptor
entityDescriptorRepository.save(input)

then:
noExceptionThrown()
}

@TestConfiguration
static class Config {
@Bean
MetadataResolver metadataResolver() {
new OpenSamlChainingMetadataResolver().with {
it.id = 'tester'
it.initialize()
return it
}
}

@Bean
Analyzer analyzer() {
return new EnglishAnalyzer()
}
}
}
Loading

0 comments on commit 7c74fe8

Please sign in to comment.