From 20a159860cf500691e705f1ddb613b820237654f Mon Sep 17 00:00:00 2001 From: Jj! Date: Thu, 14 Feb 2019 12:46:04 -0600 Subject: [PATCH] [SHIBUI-1226] refactor --- .../admin/ui/domain/EntityDescriptor.java | 11 +++++++++ .../JPAEntityDescriptorServiceImpl.java | 24 ++++++++----------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/domain/EntityDescriptor.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/domain/EntityDescriptor.java index 498e46f32..2f53e5cc8 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/domain/EntityDescriptor.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/domain/EntityDescriptor.java @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors; @@ -171,6 +172,16 @@ public SPSSODescriptor getSPSSODescriptor(String s) { .orElse(null); } + @Transient + public Optional getOptionalSPSSODescriptor(String s) { + return Optional.ofNullable(this.getSPSSODescriptor(s)); + } + + @Transient + public Optional getOptionalSPSSODescriptor() { + return this.getOptionalSPSSODescriptor(""); + } + @Override public AuthnAuthorityDescriptor getAuthnAuthorityDescriptor(String s) { return authnAuthorityDescriptor; 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 8bd4c678a..ba3680ee7 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 @@ -135,7 +135,7 @@ void setupLogout(EntityDescriptor ed, EntityDescriptorRepresentation representat // setup logout if (representation.getLogoutEndpoints() != null && !representation.getLogoutEndpoints().isEmpty()) { // TODO: review if we need more than a naive implementation - getOptionalSPSSODescriptorFromEntityDescriptor(ed).ifPresent(spssoDescriptor -> spssoDescriptor.getSingleLogoutServices().clear()); + ed.getOptionalSPSSODescriptor().ifPresent(spssoDescriptor -> spssoDescriptor.getSingleLogoutServices().clear()); for (LogoutEndpointRepresentation logoutEndpointRepresentation : representation.getLogoutEndpoints()) { SingleLogoutService singleLogoutService = openSamlObjects.buildDefaultInstanceOfType(SingleLogoutService.class); singleLogoutService.setBinding(logoutEndpointRepresentation.getBindingType()); @@ -144,7 +144,7 @@ void setupLogout(EntityDescriptor ed, EntityDescriptorRepresentation representat getSPSSODescriptorFromEntityDescriptor(ed).getSingleLogoutServices().add(singleLogoutService); } } else { - getOptionalSPSSODescriptorFromEntityDescriptor(ed).ifPresent(spssoDescriptor -> spssoDescriptor.getSingleLogoutServices().clear()); + ed.getOptionalSPSSODescriptor().ifPresent(spssoDescriptor -> spssoDescriptor.getSingleLogoutServices().clear()); } } @@ -152,7 +152,7 @@ void setupACSs(EntityDescriptor ed, EntityDescriptorRepresentation representatio // setup ACSs if (representation.getAssertionConsumerServices() != null && representation.getAssertionConsumerServices().size() > 0) { // TODO: review if we need more than a naive implementation - getOptionalSPSSODescriptorFromEntityDescriptor(ed).ifPresent(spssoDescriptor -> spssoDescriptor.getAssertionConsumerServices().clear()); + ed.getOptionalSPSSODescriptor().ifPresent(spssoDescriptor -> spssoDescriptor.getAssertionConsumerServices().clear()); for (AssertionConsumerServiceRepresentation acsRepresentation : representation.getAssertionConsumerServices()) { AssertionConsumerService assertionConsumerService = openSamlObjects.buildDefaultInstanceOfType(AssertionConsumerService.class); getSPSSODescriptorFromEntityDescriptor(ed).getAssertionConsumerServices().add(assertionConsumerService); @@ -163,7 +163,7 @@ void setupACSs(EntityDescriptor ed, EntityDescriptorRepresentation representatio assertionConsumerService.setLocation(acsRepresentation.getLocationUrl()); } } else { - getOptionalSPSSODescriptorFromEntityDescriptor(ed).ifPresent(spssoDescriptor -> spssoDescriptor.getAssertionConsumerServices().clear()); + ed.getOptionalSPSSODescriptor().ifPresent(spssoDescriptor -> spssoDescriptor.getAssertionConsumerServices().clear()); } } @@ -184,7 +184,7 @@ void setupSecurity(EntityDescriptor ed, EntityDescriptorRepresentation represent } } } else { - getOptionalSPSSODescriptorFromEntityDescriptor(ed).ifPresent( spssoDescriptor -> { + ed.getOptionalSPSSODescriptor().ifPresent( spssoDescriptor -> { spssoDescriptor.setAuthnRequestsSigned((Boolean) null); spssoDescriptor.setWantAssertionsSigned((Boolean) null); spssoDescriptor.getKeyDescriptors().clear(); @@ -203,7 +203,7 @@ void setupUIInfo(EntityDescriptor ed, EntityDescriptorRepresentation representat displayName.setValue(mduiRepresentation.getDisplayName()); displayName.setXMLLang("en"); } else { - getOptionalSPSSODescriptorFromEntityDescriptor(ed) + ed.getOptionalSPSSODescriptor() .flatMap(SPSSODescriptor::getOptionalExtensions) .flatMap(Extensions::getOptionalUIInfo) .ifPresent(u -> u.getXMLObjects().removeAll(u.getDisplayNames())); @@ -215,7 +215,7 @@ void setupUIInfo(EntityDescriptor ed, EntityDescriptorRepresentation representat informationURL.setValue(mduiRepresentation.getInformationUrl()); informationURL.setXMLLang("en"); } else { - getOptionalSPSSODescriptorFromEntityDescriptor(ed) + ed.getOptionalSPSSODescriptor() .flatMap(SPSSODescriptor::getOptionalExtensions) .flatMap(Extensions::getOptionalUIInfo) .ifPresent(u -> u.getXMLObjects().removeAll(u.getInformationURLs())); @@ -227,7 +227,7 @@ void setupUIInfo(EntityDescriptor ed, EntityDescriptorRepresentation representat privacyStatementURL.setValue(mduiRepresentation.getPrivacyStatementUrl()); privacyStatementURL.setXMLLang("en"); } else { - getOptionalSPSSODescriptorFromEntityDescriptor(ed) + ed.getOptionalSPSSODescriptor() .flatMap(SPSSODescriptor::getOptionalExtensions) .flatMap(Extensions::getOptionalUIInfo) .ifPresent(u -> u.getXMLObjects().removeAll(u.getPrivacyStatementURLs())); @@ -239,7 +239,7 @@ void setupUIInfo(EntityDescriptor ed, EntityDescriptorRepresentation representat description.setValue(mduiRepresentation.getDescription()); description.setXMLLang("en"); } else { - getOptionalSPSSODescriptorFromEntityDescriptor(ed) + ed.getOptionalSPSSODescriptor() .flatMap(SPSSODescriptor::getOptionalExtensions) .flatMap(Extensions::getOptionalUIInfo) .ifPresent(u -> u.getXMLObjects().removeAll(u.getDescriptions())); @@ -253,7 +253,7 @@ void setupUIInfo(EntityDescriptor ed, EntityDescriptorRepresentation representat logo.setWidth(mduiRepresentation.getLogoWidth()); logo.setXMLLang("en"); } else { - getOptionalSPSSODescriptorFromEntityDescriptor(ed) + ed.getOptionalSPSSODescriptor() .flatMap(SPSSODescriptor::getOptionalExtensions) .flatMap(Extensions::getOptionalUIInfo) .ifPresent(u -> u.getXMLObjects().removeAll(u.getLogos())); @@ -339,10 +339,6 @@ void setupSPSSODescriptor(EntityDescriptor ed, EntityDescriptorRepresentation re } } - private Optional getOptionalSPSSODescriptorFromEntityDescriptor(EntityDescriptor entityDescriptor) { - return Optional.ofNullable(getSPSSODescriptorFromEntityDescriptor(entityDescriptor, false)); - } - private SPSSODescriptor getSPSSODescriptorFromEntityDescriptor(EntityDescriptor entityDescriptor) { return getSPSSODescriptorFromEntityDescriptor(entityDescriptor, true); }