Skip to content

Commit

Permalink
Merge branch 'master' of bitbucket.org:unicon/shib-idp-ui into featur…
Browse files Browse the repository at this point in the history
…e/SHIBUI-1528
  • Loading branch information
rmathis committed Oct 28, 2019
2 parents 8fc121a + 8bce8ea commit e8f6f71
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,9 @@ gradle-app.setting

# pac4j
pac4j-module/out/

#Local run shell script wrapper
r

#Local integration test run shell script wrapper
rinteg
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ public edu.internet2.tier.shibboleth.admin.ui.domain.Attribute createAttributeWi
}

public edu.internet2.tier.shibboleth.admin.ui.domain.Attribute createAttributeWithStringValues(String name, String friendlyName, List<String> values) {
return createAttributeWithStringValues(name, friendlyName, values.toArray(new String[]{}));
if(values.size() > 0) {
return createAttributeWithStringValues(name, friendlyName, values.toArray(new String[]{}));
}
return null;
}

/* Calling this method with name = MDDCConstants.RELEASE_ATTRIBUTES seems to be a special case. In this case,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public ModelRepresentationConversions(CustomPropertiesConfiguration customProper
OpenSamlObjects openSamlObjects = new OpenSamlObjects();
try {
openSamlObjects.init();
}
catch (ComponentInitializationException e) {
} catch (ComponentInitializationException e) {
throw new IllegalStateException(e);
}
ATTRIBUTE_UTILITY = new AttributeUtility(openSamlObjects);
Expand Down Expand Up @@ -81,7 +80,7 @@ public static List<String> getStringListValueOfAttribute(Attribute attribute) {

public static Optional getOverrideByAttributeName(String attributeName) {
return customPropertiesConfiguration.getOverrides().stream().filter(it -> it.getAttributeName().equals(attributeName)).findFirst();
}
}

public static Map<String, Object> getRelyingPartyOverridesRepresentationFromAttributeList(List<Attribute> attributeList) {
Map<String, Object> relyingPartyOverrides = new HashMap<>();
Expand All @@ -91,8 +90,8 @@ public static Map<String, Object> getRelyingPartyOverridesRepresentationFromAttr

Optional override = getOverrideByAttributeName(jpaAttribute.getName());
if (override.isPresent()) {
relyingPartyOverrides.put(((RelyingPartyOverrideProperty)override.get()).getName(),
getOverrideFromAttribute(jpaAttribute));
relyingPartyOverrides.put(((RelyingPartyOverrideProperty) override.get()).getName(),
getOverrideFromAttribute(jpaAttribute));
}
}

Expand All @@ -112,7 +111,7 @@ public static Object getOverrideFromAttribute(Attribute attribute) {
.filter(it -> it.getAttributeFriendlyName().equals(attribute.getFriendlyName())).findFirst().get();

List<XMLObject> attributeValues = attribute.getAttributeValues();
switch(AttributeTypes.valueOf(relyingPartyOverrideProperty.getDisplayType().toUpperCase())) {
switch (AttributeTypes.valueOf(relyingPartyOverrideProperty.getDisplayType().toUpperCase())) {
case BOOLEAN:
if (relyingPartyOverrideProperty.getPersistType() != null
&& (!relyingPartyOverrideProperty.getPersistType().equalsIgnoreCase("boolean"))) {
Expand Down Expand Up @@ -140,11 +139,11 @@ public static String getValueFromXMLObject(XMLObject xmlObject) {
String objectType = xmlObject.getClass().getSimpleName();
switch (objectType) {
case "XSAny":
return ((XSAny)xmlObject).getTextContent();
return ((XSAny) xmlObject).getTextContent();
case "XSString":
return ((XSString)xmlObject).getValue();
return ((XSString) xmlObject).getValue();
case "XSBoolean":
return ((XSBoolean)xmlObject).getStoredValue();
return ((XSBoolean) xmlObject).getStoredValue();
default:
throw new RuntimeException(String.format("Unsupported XML Object type [%s]", objectType));
}
Expand All @@ -157,7 +156,7 @@ public static List<org.opensaml.saml.saml2.core.Attribute> getAttributeListFromA
attributeList.add(ATTRIBUTE_UTILITY.createAttributeWithStringValues(MDDCConstants.RELEASE_ATTRIBUTES, attributeReleaseList));
}

return (List<org.opensaml.saml.saml2.core.Attribute>)(List<? extends org.opensaml.saml.saml2.core.Attribute>)attributeList;
return (List<org.opensaml.saml.saml2.core.Attribute>) (List<? extends org.opensaml.saml.saml2.core.Attribute>) attributeList;
}

public static List<org.opensaml.saml.saml2.core.Attribute> getAttributeListFromRelyingPartyOverridesRepresentation
Expand All @@ -182,8 +181,8 @@ public static List<org.opensaml.saml.saml2.core.Attribute> getAttributeListFromA
public static Attribute getAttributeFromObjectAndRelyingPartyOverrideProperty(Object o, RelyingPartyOverrideProperty overrideProperty) {
switch (ModelRepresentationConversions.AttributeTypes.valueOf(overrideProperty.getDisplayType().toUpperCase())) {
case BOOLEAN:
if ((o instanceof Boolean && ((Boolean)o)) ||
(o instanceof String) && Boolean.valueOf((String)o)) {
if ((o instanceof Boolean && ((Boolean) o)) ||
(o instanceof String) && Boolean.valueOf((String) o)) {
if (overrideProperty.getPersistType() != null &&
!overrideProperty.getPersistType().equalsIgnoreCase("boolean")) {
return ATTRIBUTE_UTILITY.createAttributeWithStringValues(overrideProperty.getAttributeName(),
Expand All @@ -195,7 +194,7 @@ public static Attribute getAttributeFromObjectAndRelyingPartyOverrideProperty(Ob
overrideProperty.getAttributeFriendlyName(),
Boolean.valueOf((String) o));
} else {
Boolean value = Boolean.valueOf(overrideProperty.getInvert()) ^ (Boolean)o;
Boolean value = Boolean.valueOf(overrideProperty.getInvert()) ^ (Boolean) o;
return ATTRIBUTE_UTILITY.createAttributeWithBooleanValue(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
value);
Expand All @@ -215,16 +214,17 @@ public static Attribute getAttributeFromObjectAndRelyingPartyOverrideProperty(Ob
return ATTRIBUTE_UTILITY.createAttributeWithStringValues(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
(List<String>) o);

case LIST:
return ATTRIBUTE_UTILITY.createAttributeWithStringValues(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
(List<String>) o);

default:
throw new UnsupportedOperationException("getAttributeListFromRelyingPartyOverridesRepresentation was called with an unsupported type (" + overrideProperty.getDisplayType() + ")!");
}
}


public enum AttributeTypes {
BOOLEAN,
INTEGER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
import edu.internet2.tier.shibboleth.admin.ui.ShibbolethUiApplication
import edu.internet2.tier.shibboleth.admin.ui.configuration.CoreShibUiConfiguration
import edu.internet2.tier.shibboleth.admin.ui.configuration.CustomPropertiesConfiguration
import edu.internet2.tier.shibboleth.admin.ui.domain.Attribute
import edu.internet2.tier.shibboleth.admin.ui.domain.EntityDescriptor
import edu.internet2.tier.shibboleth.admin.ui.domain.XSAny
import edu.internet2.tier.shibboleth.admin.ui.domain.XSAnyBuilder
Expand All @@ -25,6 +26,7 @@ import edu.internet2.tier.shibboleth.admin.ui.security.service.UserService
import edu.internet2.tier.shibboleth.admin.ui.util.RandomGenerator
import edu.internet2.tier.shibboleth.admin.ui.util.TestObjectGenerator
import edu.internet2.tier.shibboleth.admin.util.AttributeUtility
import org.opensaml.saml.ext.saml2mdattr.EntityAttributes
import org.skyscreamer.jsonassert.JSONAssert
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
Expand Down Expand Up @@ -877,6 +879,31 @@ class JPAEntityDescriptorServiceImplTests extends Specification {
assert representation.relyingPartyOverrides.get('ignoreAuthenticationMethod') instanceof Boolean
}

def "SHIBUI-1522"() {
when:
EntityDescriptor inputEd = openSamlObjects.unmarshalFromXml this.class.getResource('/metadata/SHIBUI-1522.xml').bytes
EntityDescriptorRepresentation edr = service.createRepresentationFromDescriptor(inputEd)
edr.relyingPartyOverrides = [nameIdFormats: [], authenticationMethods: []]
EntityDescriptor outputEd = service.createDescriptorFromRepresentation(edr)

then:
outputEd.getExtensions().unknownXMLObjects[0].attributes.size() == 0

when:
edr.relyingPartyOverrides = [nameIdFormats: ['format1', 'format2']]
outputEd = service.createDescriptorFromRepresentation(edr)

then:
outputEd.getExtensions().unknownXMLObjects[0].attributes.size() == 1

when:
edr.relyingPartyOverrides = [nameIdFormats: ['format1', 'format2'], authenticationMethods: ['auth1', 'auth2']]
outputEd = service.createDescriptorFromRepresentation(edr)

then:
outputEd.getExtensions().unknownXMLObjects[0].attributes.size() == 2
}

EntityDescriptor generateRandomEntityDescriptor() {
EntityDescriptor ed = new EntityDescriptor()

Expand Down
16 changes: 16 additions & 0 deletions backend/src/test/resources/metadata/SHIBUI-1522.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<md:EntityDescriptor entityID="https://www.concursolutions2.net"
xmlns:mdui="urn:oasis:names:tc:SAML:metadata:ui"
xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata">
<md:SPSSODescriptor AuthnRequestsSigned="false" WantAssertionsSigned="true" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
<md:Extensions>
<mdui:UIInfo>
<mdui:DisplayName xml:lang="en">Concur Solutions</mdui:DisplayName>
<!-- <mdui:Description xml:lang="en">Logon using your 8-digit SMU ID and password.</mdui:Description> -->
<mdui:Logo height="146" width="148">https://www.concur.com/sites/all/themes/Concur6/images/Concur_logo.png</mdui:Logo>
</mdui:UIInfo>
</md:Extensions>
<md:NameIDFormat>urn:oid:1.3.6.1.4.1.5923.1.1.1.6</md:NameIDFormat>
<md:AssertionConsumerService index="1" Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://www.concursolutions.com/SAMLRedirector/ClientSAMLLogin.aspx"/>
</md:SPSSODescriptor>
</md:EntityDescriptor>

0 comments on commit e8f6f71

Please sign in to comment.