Skip to content

Commit

Permalink
SHIBUI-2341
Browse files Browse the repository at this point in the history
Fixing logic to correctly import the XML
  • Loading branch information
chasegawa committed Aug 31, 2022
1 parent 16e5009 commit 1e04e06
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import edu.internet2.tier.shibboleth.admin.ui.opensaml.OpenSamlObjects;
import edu.internet2.tier.shibboleth.admin.ui.service.EntityDescriptorService;
import edu.internet2.tier.shibboleth.admin.ui.service.EntityDescriptorVersionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.tags.Tags;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -33,6 +34,7 @@
import javax.annotation.PostConstruct;
import java.net.URI;
import java.util.ConcurrentModificationException;
import java.util.Optional;

@RestController
@RequestMapping("/api")
Expand Down Expand Up @@ -127,8 +129,8 @@ public ResponseEntity<?> getSpecificVersion(@PathVariable String resourceId, @Pa
private ResponseEntity<?> handleUploadingEntityDescriptorXml(byte[] rawXmlBytes, String spName) throws Exception {
final EntityDescriptor ed = EntityDescriptor.class.cast(openSamlObjects.unmarshalFromXml(rawXmlBytes));
ed.setServiceProviderName(spName);
EntityDescriptorRepresentation persistedEd = entityDescriptorService.createNew(ed);

EntityDescriptorRepresentation persistedEd = entityDescriptorService.createNewEntityDescriptorFromXMLOrigin(ed);
return ResponseEntity.created(getResourceUriFor(persistedEd.getId())).body(persistedEd);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.EqualsAndHashCode;
import org.hibernate.envers.Audited;
import org.opensaml.core.xml.XMLObject;
import org.opensaml.core.xml.schema.XSBooleanValue;

import javax.persistence.CascadeType;
Expand All @@ -17,7 +18,6 @@
@EqualsAndHashCode(callSuper = true)
@Audited
public class AttributeConsumingService extends AbstractXMLObject implements org.opensaml.saml.saml2.metadata.AttributeConsumingService {

private int acsIndex;

private boolean isDefault;
Expand Down Expand Up @@ -93,4 +93,13 @@ public List<org.opensaml.saml.saml2.metadata.RequestedAttribute> getRequestedAtt
public void setRequestedAttributes(List<RequestedAttribute> requestedAttributes) {
this.requestedAttributes = requestedAttributes;
}

@Override
public List<XMLObject> getOrderedChildren() {
List<XMLObject> childXMLObjects = new ArrayList<>();
childXMLObjects.addAll(serviceNames);
childXMLObjects.addAll(serviceDescriptions);
childXMLObjects.addAll(requestedAttributes);
return childXMLObjects;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public AssertionConsumerService getDefaultAssertionConsumerService() {

@Override
public List<org.opensaml.saml.saml2.metadata.AttributeConsumingService> getAttributeConsumingServices() {
return Lists.newArrayList(attributeConsumingServices);
return (List<org.opensaml.saml.saml2.metadata.AttributeConsumingService>)(List<? extends org.opensaml.saml.saml2.metadata.AttributeConsumingService>) attributeConsumingServices;
}

public void setAttributeConsumingServices(List<AttributeConsumingService> attributeConsumingServices) {
Expand Down Expand Up @@ -124,4 +124,4 @@ public List<XMLObject> getOrderedChildren() {
public Optional<Extensions> getOptionalExtensions() {
return Optional.ofNullable(this.getExtensions());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,6 @@ EntityDescriptorRepresentation update(EntityDescriptorRepresentation edRepresent
void updateDescriptorFromRepresentation(final org.opensaml.saml.saml2.metadata.EntityDescriptor entityDescriptor, final EntityDescriptorRepresentation representation);

EntityDescriptorRepresentation updateEntityDescriptorEnabledStatus(String resourceId, boolean status) throws EntityNotFoundException, ForbiddenException;

EntityDescriptorRepresentation createNewEntityDescriptorFromXMLOrigin(EntityDescriptor ed);
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,17 @@ public EntityDescriptor createDescriptorFromRepresentation(final EntityDescripto
}

@Override
public EntityDescriptorRepresentation createNew(EntityDescriptor ed)
throws ForbiddenException, ObjectIdExistsException, InvalidPatternMatchException {
public EntityDescriptorRepresentation createNew(EntityDescriptor ed) throws ForbiddenException, ObjectIdExistsException, InvalidPatternMatchException {
return createNew(createRepresentationFromDescriptor(ed));
}

@Override
public EntityDescriptorRepresentation createNewEntityDescriptorFromXMLOrigin(EntityDescriptor ed) {
ed.setIdOfOwner(userService.getCurrentUserGroup().getOwnerId());
EntityDescriptor savedEntity = entityDescriptorRepository.save(ed);
return createRepresentationFromDescriptor(savedEntity);
}

@Override
public EntityDescriptorRepresentation createNew(EntityDescriptorRepresentation edRep)
throws ForbiddenException, ObjectIdExistsException, InvalidPatternMatchException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,11 @@ class EntityDescriptorControllerTests extends AbstractBaseDataJpaTest {
<md:SPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
<md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified</md:NameIDFormat>
<md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://test.scaldingspoon.org/test1/acs" index="1"/>
<md:AttributeConsumingService index="1">
<md:ServiceName xml:lang="en">Shrink Space</md:ServiceName>
<md:ServiceDescription xml:lang="en">Shrink Space Authenticator</md:ServiceDescription>
<md:RequestedAttribute FriendlyName="givenName" Name="urn:oid:2.5.4.42" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="true"/>
</md:AttributeConsumingService>
</md:SPSSODescriptor>
</md:EntityDescriptor>
'''
Expand All @@ -551,7 +556,6 @@ class EntityDescriptorControllerTests extends AbstractBaseDataJpaTest {
.andExpect(jsonPath("\$.assertionConsumerServices[0].binding").value("urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"))
.andExpect(jsonPath("\$.assertionConsumerServices[0].makeDefault").value(false))
.andExpect(jsonPath("\$.assertionConsumerServices[0].locationUrl").value("https://test.scaldingspoon.org/test1/acs"))
}
@WithMockAdmin
Expand Down Expand Up @@ -691,4 +695,4 @@ class EntityDescriptorControllerTests extends AbstractBaseDataJpaTest {
e instanceof ConcurrentModificationException
}
}
}
}
2 changes: 2 additions & 0 deletions testbed/postgres/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ services:
- 8080:8080
- 5005:5005
- 8443:8443
- 8000:8000
volumes:
- ./conf:/conf
- ./conf/application.yml:/application.yml
entrypoint: ["/usr/bin/java", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000", "-jar", "app.war"]
networks:
- front
depends_on:
Expand Down

0 comments on commit 1e04e06

Please sign in to comment.