Skip to content

Commit

Permalink
Merged in bugfix/dupes (pull request #305)
Browse files Browse the repository at this point in the history
Bugfix/dupes
  • Loading branch information
Jonathan Johnson committed Feb 27, 2019
2 parents f9fd9bc + 8eca83a commit 6570a4e
Show file tree
Hide file tree
Showing 6 changed files with 999 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.internet2.tier.shibboleth.admin.ui.domain;

import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Type;
import org.joda.time.DateTime;
import org.opensaml.core.xml.XMLObject;
Expand All @@ -16,6 +17,7 @@


@MappedSuperclass
@EqualsAndHashCode(callSuper = true)
public abstract class AbstractDescriptor extends AbstractAttributeExtensibleXMLObject implements CacheableSAMLObject, TimeBoundSAMLObject, SignableXMLObject {
private Long cacheDuration;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.internet2.tier.shibboleth.admin.ui.domain;

import lombok.EqualsAndHashCode;
import org.opensaml.core.xml.ElementExtensibleXMLObject;
import org.opensaml.core.xml.XMLObject;

Expand All @@ -18,6 +19,7 @@

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@EqualsAndHashCode(callSuper = true)
public abstract class AbstractElementExtensibleXMLObject extends AbstractXMLObject implements ElementExtensibleXMLObject {
@OneToMany(cascade = CascadeType.ALL)
@OrderColumn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public List<Logo> getLogos() {
return this.xmlObjects.stream().filter(p -> p instanceof Logo).map(p -> (Logo) p).collect(Collectors.toList());
}

public void addLog(edu.internet2.tier.shibboleth.admin.ui.domain.Logo logo) {
public void addLogo(edu.internet2.tier.shibboleth.admin.ui.domain.Logo logo) {
this.xmlObjects.add(logo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import net.shibboleth.utilities.java.support.xml.BasicParserPool;
import net.shibboleth.utilities.java.support.xml.ParserPool;
import net.shibboleth.utilities.java.support.xml.XMLParserException;
import org.opensaml.core.config.ConfigurationService;
import org.opensaml.core.config.InitializationException;
import org.opensaml.core.xml.XMLObject;
Expand All @@ -15,6 +16,7 @@
import org.opensaml.core.xml.io.MarshallingException;
import org.opensaml.core.xml.io.Unmarshaller;
import org.opensaml.core.xml.io.UnmarshallerFactory;
import org.opensaml.core.xml.io.UnmarshallingException;
import org.opensaml.saml.saml2.metadata.EntityDescriptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -130,6 +132,17 @@ public EntityDescriptor unmarshalFromXml(byte[] entityDescriptorXml) throws Exce
}
}

public <T> T unmarshallFromXml(byte[] xml, Class<T> type) throws IOException, XMLParserException, UnmarshallingException {
try (InputStream is = ByteSource.wrap(xml).openBufferedStream()) {
Document d = this.parserPool.parse(is);
Unmarshaller unmarshaller = this.unmarshallerFactory.getUnmarshaller(d.getDocumentElement());
if (unmarshaller != null) {
return type.cast(unmarshaller.unmarshall(d.getDocumentElement()));
}
return null;
}
}

// TODO: yeah, I'm not happy with this...
public <T extends XMLObject> T buildDefaultInstanceOfType(Class<T> type) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.SecurityInfoRepresentation;
import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.ServiceProviderSsoDescriptorRepresentation;
import edu.internet2.tier.shibboleth.admin.ui.opensaml.OpenSamlObjects;
import edu.internet2.tier.shibboleth.admin.ui.security.model.User;
import edu.internet2.tier.shibboleth.admin.ui.security.service.UserService;
import edu.internet2.tier.shibboleth.admin.util.MDDCConstants;
import edu.internet2.tier.shibboleth.admin.util.ModelRepresentationConversions;
Expand All @@ -59,6 +58,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -178,6 +178,8 @@ void setupSecurity(EntityDescriptor ed, EntityDescriptorRepresentation represent
if (securityInfoRepresentation.isWantAssertionsSigned()) {
getSPSSODescriptorFromEntityDescriptor(ed).setWantAssertionsSigned(true);
}
// TODO: review if we need more than a naive implementation
ed.getOptionalSPSSODescriptor().ifPresent( i -> i.getKeyDescriptors().clear());
if (securityInfoRepresentation.isX509CertificateAvailable()) {
for (SecurityInfoRepresentation.X509CertificateRepresentation x509CertificateRepresentation : securityInfoRepresentation.getX509Certificates()) {
KeyDescriptor keyDescriptor = createKeyDescriptor(x509CertificateRepresentation.getName(), x509CertificateRepresentation.getType(), x509CertificateRepresentation.getValue());
Expand All @@ -196,6 +198,8 @@ void setupSecurity(EntityDescriptor ed, EntityDescriptorRepresentation represent
void setupUIInfo(EntityDescriptor ed, EntityDescriptorRepresentation representation) {
// set up mdui
if (representation.getMdui() != null) {
// TODO: check if we need more than a naive implementation
removeUIInfo(ed);
MduiRepresentation mduiRepresentation = representation.getMdui();

if (!Strings.isNullOrEmpty(mduiRepresentation.getDisplayName())) {
Expand Down Expand Up @@ -248,7 +252,7 @@ void setupUIInfo(EntityDescriptor ed, EntityDescriptorRepresentation representat

if (!Strings.isNullOrEmpty(mduiRepresentation.getLogoUrl())) {
Logo logo = openSamlObjects.buildDefaultInstanceOfType(Logo.class);
getUIInfo(ed).addLog(logo);
getUIInfo(ed).addLogo(logo);
logo.setURL(mduiRepresentation.getLogoUrl());
logo.setHeight(mduiRepresentation.getLogoHeight());
logo.setWidth(mduiRepresentation.getLogoWidth());
Expand Down Expand Up @@ -320,6 +324,7 @@ void setupSPSSODescriptor(EntityDescriptor ed, EntityDescriptorRepresentation re
if (representation.getServiceProviderSsoDescriptor() != null) {
SPSSODescriptor spssoDescriptor = getSPSSODescriptorFromEntityDescriptor(ed);

spssoDescriptor.setSupportedProtocols(Collections.EMPTY_LIST);
if (!Strings.isNullOrEmpty(representation.getServiceProviderSsoDescriptor().getProtocolSupportEnum())) {
spssoDescriptor.setSupportedProtocols(
Arrays.stream(representation.getServiceProviderSsoDescriptor().getProtocolSupportEnum().split(",")).map(p -> MDDCConstants.PROTOCOL_BINDINGS.get(p.trim())).collect(Collectors.toList())
Expand Down Expand Up @@ -388,7 +393,7 @@ private Attribute createAttributeWithArbitraryValues(String name, String friendl
return createAttributeWithArbitraryValues(name, friendlyName, values.toArray(new String[]{}));
}

private KeyDescriptor createKeyDescriptor(String name, String type, String value) {
KeyDescriptor createKeyDescriptor(String name, String type, String value) {
KeyDescriptor keyDescriptor = openSamlObjects.buildDefaultInstanceOfType(KeyDescriptor.class);

if (!Strings.isNullOrEmpty(name)) {
Expand Down
Loading

0 comments on commit 6570a4e

Please sign in to comment.