Skip to content

Commit

Permalink
Merged in feature/shibui-2341 (pull request #613)
Browse files Browse the repository at this point in the history
Feature/shibui 2341

Approved-by: Dmitriy Kopylenko
Approved-by: Sean Porth
  • Loading branch information
chasegawa committed Sep 2, 2022
2 parents f389624 + f011dca commit 748f4c0
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 11 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 @@ -126,9 +128,13 @@ 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));
if (entityDescriptorService.entityExists(ed.getEntityID())) {
throw new ObjectIdExistsException("Entity with ID: " + ed.getEntityID() + "exists");
}

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 @@ -6,6 +6,7 @@
import javax.annotation.Nullable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;

@Entity
@EqualsAndHashCode(callSuper = true)
Expand All @@ -16,6 +17,7 @@ public class Description extends AbstractXMLObject implements org.opensaml.saml.
private String xmlLang;

@Column(name = "descriptionValue")
@Lob
private String value;

@Nullable
Expand All @@ -39,4 +41,4 @@ public String getValue() {
public void setValue(@Nullable String value) {
this.value = value;
}
}
}
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 @@ -18,6 +18,6 @@ public String getValue() {

@Override
public void setValue(String name) {
this.value = value;
this.value = name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,8 @@ 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);

boolean entityExists(String entityID);
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,22 @@ 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 boolean entityExists(String entityID) {
return entityDescriptorRepository.findByEntityID(entityID) != null ;
}

@Override
public EntityDescriptorRepresentation createNew(EntityDescriptorRepresentation edRep)
throws ForbiddenException, ObjectIdExistsException, InvalidPatternMatchException {
Expand Down
22 changes: 21 additions & 1 deletion backend/src/main/resources/db/changelog/changelog.sql
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,24 @@ update file_backed_http_metadata_resolver_aud set max_refresh_delay ='PT4H';
update resource_backed_metadata_resolver set min_refresh_delay ='PT5M';
update resource_backed_metadata_resolver_aud set min_refresh_delay ='PT5M';
update resource_backed_metadata_resolver set max_refresh_delay ='PT4H';
update resource_backed_metadata_resolver_aud set max_refresh_delay ='PT4H';
update resource_backed_metadata_resolver_aud set max_refresh_delay ='PT4H';

-- changeset liquibase:1.13.0.1 dbms:mariadb,mysql
-- preconditions onFail:MARK_RAN
-- precondition-sql-check expectedResult:1 SELECT count(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = N'users'
-- comment: /* we don't need to run this if the system is new */

ALTER TABLE description ALTER COLUMN descriptionValue LONGTEXT;
GO
ALTER TABLE description)aud ALTER COLUMN descriptionValue LONGTEXT;
GO

-- changeset liquibase:1.13.0.2 dbms:postgresql,mssql
-- preconditions onFail:MARK_RAN
-- precondition-sql-check expectedResult:1 SELECT count(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = N'users'
-- comment: /* we don't need to run this if the system is new */

ALTER TABLE description ALTER COLUMN descriptionValue TEXT;
GO
ALTER TABLE description_aud ALTER COLUMN descriptionValue TEXT;
GO
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 @@ -552,6 +557,12 @@ class EntityDescriptorControllerTests extends AbstractBaseDataJpaTest {
.andExpect(jsonPath("\$.assertionConsumerServices[0].makeDefault").value(false))
.andExpect(jsonPath("\$.assertionConsumerServices[0].locationUrl").value("https://test.scaldingspoon.org/test1/acs"))
try {
mockMvc.perform(post("/api/EntityDescriptor").contentType(APPLICATION_XML).content(postedBody).param("spName", spName))
}
catch (Exception e) {
e instanceof ObjectIdExistsException
}
}
@WithMockAdmin
Expand Down Expand Up @@ -691,4 +702,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 748f4c0

Please sign in to comment.