Skip to content

Commit

Permalink
[SHIBUI-906]
Browse files Browse the repository at this point in the history
Unit test fixes WIP.
  • Loading branch information
Bill Smith committed Oct 18, 2018
1 parent 0e99e48 commit d541813
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
import java.util.Optional;
import java.util.stream.Collectors;

import static edu.internet2.tier.shibboleth.admin.util.ModelRepresentationConversions.getStringListOfAttributeValues;

/**
* Default implementation of {@link EntityDescriptorService}
*
Expand Down Expand Up @@ -493,10 +495,14 @@ public EntityDescriptorRepresentation createRepresentationFromDescriptor(org.ope
for (org.opensaml.saml.saml2.core.Attribute attribute : ((EntityAttributes) ed.getExtensions().getUnknownXMLObjects(EntityAttributes.DEFAULT_ELEMENT_NAME).get(0)).getAttributes()) {
Attribute jpaAttribute = (Attribute) attribute;

Optional override = ModelRepresentationConversions.getOverrideByAttributeName(jpaAttribute.getName());
if (override.isPresent()) {
relyingPartyOverrides.put(((RelyingPartyOverrideProperty)override.get()).getName(),
jpaAttribute.getAttributeValues());
if (jpaAttribute.getName().equals(MDDCConstants.RELEASE_ATTRIBUTES)) {
representation.setAttributeRelease(getStringListOfAttributeValues(attribute.getAttributeValues()));
} else {
Optional override = ModelRepresentationConversions.getOverrideByAttributeName(jpaAttribute.getName());
if (override.isPresent()) {
relyingPartyOverrides.put(((RelyingPartyOverrideProperty) override.get()).getName(),
jpaAttribute.getAttributeValues());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class JPAEntityServiceImpl implements EntityService {
private AttributeUtility attributeUtility;

@Autowired
private CustomPropertiesConfiguration customPropertiesConfiguration = new CustomPropertiesConfiguration();
private CustomPropertiesConfiguration customPropertiesConfiguration;

public JPAEntityServiceImpl(OpenSamlObjects openSamlObjects) {
this.openSamlObjects = openSamlObjects;
Expand All @@ -39,6 +39,14 @@ public JPAEntityServiceImpl(OpenSamlObjects openSamlObjects, AttributeUtility at
this.attributeUtility = attributeUtility;
}

public JPAEntityServiceImpl(OpenSamlObjects openSamlObjects,
AttributeUtility attributeUtility,
CustomPropertiesConfiguration customPropertiesConfiguration) {
this.openSamlObjects = openSamlObjects;
this.attributeUtility = attributeUtility;
this.customPropertiesConfiguration = customPropertiesConfiguration;
}

@Override
public List<Attribute> getAttributeListFromEntityRepresentation(EntityDescriptorRepresentation entityDescriptorRepresentation) {
List<edu.internet2.tier.shibboleth.admin.ui.domain.Attribute> list = new ArrayList<>();
Expand Down Expand Up @@ -95,7 +103,7 @@ public List<Attribute> getAttributeListFromRelyingPartyOverridesRepresentation(M

for (Map.Entry entry : relyingPartyOverridesRepresentation.entrySet()) {
String key = (String) entry.getKey();
RelyingPartyOverrideProperty overrideProperty = overridePropertyList.stream().filter(op -> op.getDisplayName().equals(key)).findFirst().get();
RelyingPartyOverrideProperty overrideProperty = overridePropertyList.stream().filter(op -> op.getName().equals(key)).findFirst().get();
switch (ModelRepresentationConversions.AttributeTypes.valueOf(overrideProperty.getDisplayType().toUpperCase())) {
case BOOLEAN:
if (!overrideProperty.getPersistType().equalsIgnoreCase("boolean")) {
Expand All @@ -120,12 +128,12 @@ public List<Attribute> getAttributeListFromRelyingPartyOverridesRepresentation(M
(String) entry.getValue()));
break;
case SET:
list.add(attributeUtility.createAttributeWithArbitraryValues(overrideProperty.getAttributeName(),
list.add(attributeUtility.createAttributeWithStringValues(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
(Set<String>) entry.getValue()));
(List<String>) entry.getValue()));
break;
case LIST:
list.add(attributeUtility.createAttributeWithArbitraryValues(overrideProperty.getAttributeName(),
list.add(attributeUtility.createAttributeWithStringValues(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
(List<String>) entry.getValue()));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public edu.internet2.tier.shibboleth.admin.ui.domain.Attribute createAttributeWi
return attribute;
}


public edu.internet2.tier.shibboleth.admin.ui.domain.Attribute createAttributeWithIntegerValue(String name, String friendlyName, Integer value) {
edu.internet2.tier.shibboleth.admin.ui.domain.Attribute attribute = createNewAttribute(name, friendlyName);

Expand All @@ -45,7 +44,6 @@ public edu.internet2.tier.shibboleth.admin.ui.domain.Attribute createAttributeWi
return attribute;
}


public edu.internet2.tier.shibboleth.admin.ui.domain.Attribute createAttributeWithStringValues(String name, String friendlyName, String... values) {
edu.internet2.tier.shibboleth.admin.ui.domain.Attribute attribute = createNewAttribute(name, friendlyName);

Expand All @@ -58,7 +56,6 @@ public edu.internet2.tier.shibboleth.admin.ui.domain.Attribute createAttributeWi
return attribute;
}


/*
* Provided for calling with name = MDDCConstants.RELEASE_ATTRIBUTES.
*/
Expand All @@ -70,27 +67,6 @@ public edu.internet2.tier.shibboleth.admin.ui.domain.Attribute createAttributeWi
return createAttributeWithStringValues(name, friendlyName, values.toArray(new String[]{}));
}

public edu.internet2.tier.shibboleth.admin.ui.domain.Attribute createAttributeWithArbitraryValues(String name, String friendlyName, String... values) {
edu.internet2.tier.shibboleth.admin.ui.domain.Attribute attribute = createNewAttribute(name, friendlyName);

for (String value : values) {
XSAny xsAny = (XSAny) openSamlObjects.getBuilderFactory().getBuilder(XSAny.TYPE_NAME).buildObject(AttributeValue.DEFAULT_ELEMENT_NAME);
xsAny.setTextContent(value);
attribute.getAttributeValues().add(xsAny);
}

return attribute;
}

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

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


/* Calling this method with name = MDDCConstants.RELEASE_ATTRIBUTES seems to be a special case. In this case,
* we haven't been setting the friendlyName or nameFormat. Hence the null check.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -121,7 +122,7 @@ public static Object getOverrideFromAttribute(Attribute attribute) {
}
case LIST:
case SET:
return attributeValues.stream().map(it -> ((XSAny) it).getTextContent()).collect(Collectors.toList());
return attributeValues.stream().map(it -> ((XSString) it).getValue()).collect(Collectors.toList());
default:
throw new UnsupportedOperationException("An unsupported persist type was specified (" + relyingPartyOverrideProperty.getPersistType() + ")!");
}
Expand All @@ -142,51 +143,61 @@ public static List<org.opensaml.saml.saml2.core.Attribute> getAttributeListFromA
List<RelyingPartyOverrideProperty> overridePropertyList = customPropertiesConfiguration.getOverrides();
List<edu.internet2.tier.shibboleth.admin.ui.domain.Attribute> list = new ArrayList<>();

for (Map.Entry entry : relyingPartyOverridesRepresentation.entrySet()) {
String key = (String) entry.getKey();
RelyingPartyOverrideProperty overrideProperty = overridePropertyList.stream().filter(op -> op.getName().equals(key)).findFirst().get();
switch (AttributeTypes.valueOf(overrideProperty.getDisplayType().toUpperCase())) {
case BOOLEAN:
if (overrideProperty.getPersistType() != null &&
!overrideProperty.getPersistType().equalsIgnoreCase("boolean")) {
// we must be persisting a string then
list.add(ATTRIBUTE_UTILITY.createAttributeWithStringValues(overrideProperty.getAttributeName(),
if (relyingPartyOverridesRepresentation != null) {
for (Map.Entry entry : relyingPartyOverridesRepresentation.entrySet()) {
String key = (String) entry.getKey();
RelyingPartyOverrideProperty overrideProperty = overridePropertyList.stream().filter(op -> op.getName().equals(key)).findFirst().get();
switch (AttributeTypes.valueOf(overrideProperty.getDisplayType().toUpperCase())) {
case BOOLEAN:
if (overrideProperty.getPersistType() != null &&
!overrideProperty.getPersistType().equalsIgnoreCase("boolean")) {
// we must be persisting a string then
list.add(ATTRIBUTE_UTILITY.createAttributeWithStringValues(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
overrideProperty.getPersistValue()));
} else {
list.add(ATTRIBUTE_UTILITY.createAttributeWithBooleanValue(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
(Boolean) entry.getValue()));
}
break;
case INTEGER:
list.add(ATTRIBUTE_UTILITY.createAttributeWithIntegerValue(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
overrideProperty.getPersistValue()));
} else {
list.add(ATTRIBUTE_UTILITY.createAttributeWithBooleanValue(overrideProperty.getAttributeName(),
(Integer) entry.getValue()));
break;
case STRING:
list.add(ATTRIBUTE_UTILITY.createAttributeWithStringValues(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
(Boolean) entry.getValue()));
}
break;
case INTEGER:
list.add(ATTRIBUTE_UTILITY.createAttributeWithIntegerValue(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
(Integer) entry.getValue()));
break;
case STRING:
list.add(ATTRIBUTE_UTILITY.createAttributeWithStringValues(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
(String) entry.getValue()));
break;
case SET:
Set<String> setValues = (Set<String>) entry.getValue();
if (setValues.size() > 0) {
list.add(ATTRIBUTE_UTILITY.createAttributeWithArbitraryValues(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
setValues));
}
break;
case LIST:
List<String> listValues = (List<String>) entry.getValue();
if (listValues.size() > 0) {
list.add(ATTRIBUTE_UTILITY.createAttributeWithArbitraryValues(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
listValues));
}
break;
default:
throw new UnsupportedOperationException("getAttributeListFromRelyingPartyOverridesRepresentation was called with an unsupported type (" + overrideProperty.getDisplayType() + ")!");
(String) entry.getValue()));
break;
case SET:
Set<String> setValues;
if (entry.getValue() instanceof Set) {
setValues = (Set<String>) entry.getValue();
} else if (entry.getValue() instanceof List) {
setValues = new HashSet<>();
setValues.addAll((List<String>) entry.getValue());
} else {
throw new UnsupportedOperationException("The collection passed from the UI is neither a Set or List. This shouldn't happen. Fix this!");
}
if (setValues.size() > 0) {
list.add(ATTRIBUTE_UTILITY.createAttributeWithStringValues(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
new ArrayList<>(setValues)));
}
break;
case LIST:
List<String> listValues = (List<String>) entry.getValue();
if (listValues.size() > 0) {
list.add(ATTRIBUTE_UTILITY.createAttributeWithStringValues(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
listValues));
}
break;
default:
throw new UnsupportedOperationException("getAttributeListFromRelyingPartyOverridesRepresentation was called with an unsupported type (" + overrideProperty.getDisplayType() + ")!");
}
}
}

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

import edu.internet2.tier.shibboleth.admin.ui.opensaml.OpenSamlObjects
import groovy.json.JsonOutput
import net.shibboleth.ext.spring.resource.ResourceHelper
import org.joda.time.DateTime
import org.opensaml.saml.metadata.resolver.ChainingMetadataResolver
Expand All @@ -15,6 +16,7 @@ import org.springframework.context.annotation.Bean
import org.springframework.core.io.ClassPathResource
import org.springframework.test.context.ActiveProfiles
import org.springframework.test.web.reactive.server.WebTestClient
import org.springframework.test.web.servlet.result.MockMvcResultHandlers
import org.springframework.web.util.DefaultUriBuilderFactory
import org.xmlunit.builder.DiffBuilder
import org.xmlunit.builder.Input
Expand Down Expand Up @@ -59,17 +61,7 @@ class EntitiesControllerIntegrationTests extends Specification {
"serviceEnabled":false,
"createdDate":null,
"modifiedDate":null,
"relyingPartyOverrides":{
"signAssertion":false,
"dontSignResponse":false,
"turnOffEncryption":false,
"useSha":false,
"ignoreAuthenticationMethod":false,
"omitNotBefore":false,
"responderId":null,
"nameIdFormats":[],
"authenticationMethods":[]
},
"relyingPartyOverrides":{},
"attributeRelease":["givenName","employeeNumber"]
}
'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,7 @@ class EntitiesControllerTests extends Specification {
"serviceEnabled":false,
"createdDate":null,
"modifiedDate":null,
"relyingPartyOverrides":{
"signAssertion":false,
"dontSignResponse":false,
"turnOffEncryption":false,
"useSha":false,
"ignoreAuthenticationMethod":false,
"omitNotBefore":false,
"responderId":null,
"nameIdFormats":[],
"authenticationMethods":[]
},
"relyingPartyOverrides":{},
"attributeRelease":["givenName","employeeNumber"]
}
'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,18 +448,7 @@ class EntityDescriptorControllerTests extends Specification {
"serviceEnabled": false,
"createdDate": null,
"modifiedDate": null,
"relyingPartyOverrides": {
"signAssertion": false,
"dontSignResponse": false,
"turnOffEncryption": false,
"useSha": false,
"ignoreAuthenticationMethod": false,
"omitNotBefore": false,
"responderId": null,
"nameIdFormats": [],
"authenticationMethods": [],
"forceAuthn": false
},
"relyingPartyOverrides": {},
"attributeRelease": [
"givenName",
"employeeNumber"
Expand Down Expand Up @@ -577,18 +566,7 @@ class EntityDescriptorControllerTests extends Specification {
"serviceEnabled": false,
"createdDate": null,
"modifiedDate": null,
"relyingPartyOverrides": {
"signAssertion": false,
"dontSignResponse": false,
"turnOffEncryption": false,
"useSha": false,
"ignoreAuthenticationMethod": false,
"omitNotBefore": false,
"responderId": null,
"nameIdFormats": [],
"authenticationMethods": [],
"forceAuthn": false
},
"relyingPartyOverrides": {},
"attributeRelease": [
"givenName",
"employeeNumber"
Expand Down
Loading

0 comments on commit d541813

Please sign in to comment.