Skip to content

Commit

Permalink
SHIBUI-2374
Browse files Browse the repository at this point in the history
Added logic so that entities with the same entity id won't be created.
  • Loading branch information
chasegawa committed Sep 2, 2022
1 parent 02e6572 commit f011dca
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ 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.createNewEntityDescriptorFromXMLOrigin(ed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,6 @@ EntityDescriptorRepresentation update(EntityDescriptorRepresentation edRepresent
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 @@ -113,6 +113,11 @@ public EntityDescriptorRepresentation createNewEntityDescriptorFromXMLOrigin(Ent
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
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,13 @@ 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"))
try {
mockMvc.perform(post("/api/EntityDescriptor").contentType(APPLICATION_XML).content(postedBody).param("spName", spName))
}
catch (Exception e) {
e instanceof ObjectIdExistsException
}
}
@WithMockAdmin
Expand Down

0 comments on commit f011dca

Please sign in to comment.