From 29b5a04a8837fa59b7123367320764e561e9ce10 Mon Sep 17 00:00:00 2001 From: Jj! Date: Wed, 13 Feb 2019 16:51:13 -0600 Subject: [PATCH] [SHIBUI-1226] add implementation for updating relying party overrides --- .../JPAEntityDescriptorServiceImpl.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityDescriptorServiceImpl.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityDescriptorServiceImpl.java index 6004c6a93..a2fb2391e 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityDescriptorServiceImpl.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityDescriptorServiceImpl.java @@ -300,13 +300,11 @@ private EntityDescriptor buildDescriptorFromRepresentation(final EntityDescripto } if (representation.getRelyingPartyOverrides() != null || (representation.getAttributeRelease() != null && representation.getAttributeRelease().size() > 0)) { - // TODO: fix implementation + // TODO: review if we need more than a naive implementation + getOptionalEntityAttributes(ed).ifPresent(entityAttributes -> entityAttributes.getAttributes().clear()); getEntityAttributes(ed).getAttributes().addAll(entityService.getAttributeListFromEntityRepresentation(representation)); } else { - EntityAttributes entityAttributes = getEntityAttributes(ed, false); - if (entityAttributes != null) { - entityAttributes.getAttributes().clear(); - } + getOptionalEntityAttributes(ed).ifPresent(entityAttributes -> entityAttributes.getAttributes().clear()); } return ed; } @@ -387,6 +385,10 @@ private EntityAttributes getEntityAttributes(EntityDescriptor ed) { return getEntityAttributes(ed, true); } + private Optional getOptionalEntityAttributes(EntityDescriptor ed) { + return Optional.ofNullable(getEntityAttributes(ed, false)); + } + private EntityAttributes getEntityAttributes(EntityDescriptor ed, boolean create) { Extensions extensions = ed.getExtensions(); if (extensions == null && !create) { @@ -397,12 +399,14 @@ private EntityAttributes getEntityAttributes(EntityDescriptor ed, boolean create ed.setExtensions(extensions); } - EntityAttributes entityAttributes; + EntityAttributes entityAttributes = null; if (extensions.getUnknownXMLObjects(EntityAttributes.DEFAULT_ELEMENT_NAME).size() > 0) { entityAttributes = (EntityAttributes) extensions.getUnknownXMLObjects(EntityAttributes.DEFAULT_ELEMENT_NAME).get(0); } else { - entityAttributes = ((EntityAttributesBuilder) openSamlObjects.getBuilderFactory().getBuilder(EntityAttributes.DEFAULT_ELEMENT_NAME)).buildObject(); - extensions.getUnknownXMLObjects().add(entityAttributes); + if (create) { + entityAttributes = ((EntityAttributesBuilder) openSamlObjects.getBuilderFactory().getBuilder(EntityAttributes.DEFAULT_ELEMENT_NAME)).buildObject(); + extensions.getUnknownXMLObjects().add(entityAttributes); + } } return entityAttributes; }