Skip to content

Commit

Permalink
[SHIBUI-1226]
Browse files Browse the repository at this point in the history
refactor
  • Loading branch information
jj committed Feb 14, 2019
1 parent c8bd24e commit 20a1598
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -171,6 +172,16 @@ public SPSSODescriptor getSPSSODescriptor(String s) {
.orElse(null);
}

@Transient
public Optional<SPSSODescriptor> getOptionalSPSSODescriptor(String s) {
return Optional.ofNullable(this.getSPSSODescriptor(s));
}

@Transient
public Optional<SPSSODescriptor> getOptionalSPSSODescriptor() {
return this.getOptionalSPSSODescriptor("");
}

@Override
public AuthnAuthorityDescriptor getAuthnAuthorityDescriptor(String s) {
return authnAuthorityDescriptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -144,15 +144,15 @@ 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());
}
}

void setupACSs(EntityDescriptor ed, EntityDescriptorRepresentation representation) {
// 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);
Expand All @@ -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());
}
}

Expand All @@ -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();
Expand All @@ -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()));
Expand All @@ -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()));
Expand All @@ -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()));
Expand All @@ -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()));
Expand All @@ -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()));
Expand Down Expand Up @@ -339,10 +339,6 @@ void setupSPSSODescriptor(EntityDescriptor ed, EntityDescriptorRepresentation re
}
}

private Optional<SPSSODescriptor> getOptionalSPSSODescriptorFromEntityDescriptor(EntityDescriptor entityDescriptor) {
return Optional.ofNullable(getSPSSODescriptorFromEntityDescriptor(entityDescriptor, false));
}

private SPSSODescriptor getSPSSODescriptorFromEntityDescriptor(EntityDescriptor entityDescriptor) {
return getSPSSODescriptorFromEntityDescriptor(entityDescriptor, true);
}
Expand Down

0 comments on commit 20a1598

Please sign in to comment.