Skip to content

RelyingPartyRegistrations#fromMetadataLocation: prioritize REDIRECT binding for sso and logout #10961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -139,7 +139,9 @@ else if (singleSignOnService.getBinding().equals(Saml2MessageBinding.REDIRECT.ge
continue;
}
party.singleSignOnServiceLocation(singleSignOnService.getLocation()).singleSignOnServiceBinding(binding);
break;
if (binding.equals(Saml2MessageBinding.REDIRECT)) {
break;
}
}
for (SingleLogoutService singleLogoutService : idpssoDescriptor.getSingleLogoutServices()) {
Saml2MessageBinding binding;
@@ -156,7 +158,9 @@ else if (singleLogoutService.getBinding().equals(Saml2MessageBinding.REDIRECT.ge
? singleLogoutService.getLocation() : singleLogoutService.getResponseLocation();
party.singleLogoutServiceLocation(singleLogoutService.getLocation())
.singleLogoutServiceResponseLocation(responseLocation).singleLogoutServiceBinding(binding);
break;
if (binding.equals(Saml2MessageBinding.REDIRECT)) {
break;
}
}
return party;
}
Original file line number Diff line number Diff line change
@@ -54,8 +54,10 @@ public class OpenSamlMetadataAssertingPartyDetailsConverterTests {
private static final String EXTENSIONS_TEMPLATE = "<md:Extensions>" + "<alg:SigningMethod Algorithm=\""
+ SignatureConstants.ALGO_ID_DIGEST_SHA512 + "\"/>" + "</md:Extensions>";

private static final String SINGLE_SIGN_ON_SERVICE_TEMPLATE = "<md:SingleSignOnService Binding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect\" "
+ "Location=\"sso-location\"/>";
private static final String SINGLE_SIGN_ON_SERVICE_TEMPLATE = "<md:SingleSignOnService Binding=\"%s\" Location=\"sso-location\"/>";

private static final String SINGLE_LOGOUT_SERVICE_TEMPLATE = "<md:SingleLogoutService Binding=\"%s\" "
+ "Location=\"logout-location\" ResponseLocation=\"logout-response-location\"/>";

private OpenSamlMetadataAssertingPartyDetailsConverter converter;

@@ -94,17 +96,20 @@ public void readWhenMissingSingleSignOnServiceThenException() {
@Test
public void readWhenDescriptorFullySpecifiedThenConfigures() throws Exception {
String payload = String.format(ENTITY_DESCRIPTOR_TEMPLATE,
String.format(IDP_SSO_DESCRIPTOR_TEMPLATE,
String.format(KEY_DESCRIPTOR_TEMPLATE, "use=\"signing\"")
+ String.format(KEY_DESCRIPTOR_TEMPLATE, "use=\"encryption\"") + EXTENSIONS_TEMPLATE
+ String.format(SINGLE_SIGN_ON_SERVICE_TEMPLATE)));
String.format(IDP_SSO_DESCRIPTOR_TEMPLATE, String.format(KEY_DESCRIPTOR_TEMPLATE, "use=\"signing\"")
+ String.format(KEY_DESCRIPTOR_TEMPLATE, "use=\"encryption\"") + EXTENSIONS_TEMPLATE
+ String.format(SINGLE_SIGN_ON_SERVICE_TEMPLATE, Saml2MessageBinding.REDIRECT.getUrn())
+ String.format(SINGLE_LOGOUT_SERVICE_TEMPLATE, Saml2MessageBinding.REDIRECT.getUrn())));
InputStream inputStream = new ByteArrayInputStream(payload.getBytes());
RelyingPartyRegistration.AssertingPartyDetails details = this.converter.convert(inputStream).iterator().next()
.build();
assertThat(details.getWantAuthnRequestsSigned()).isFalse();
assertThat(details.getSigningAlgorithms()).containsExactly(SignatureConstants.ALGO_ID_DIGEST_SHA512);
assertThat(details.getSingleSignOnServiceLocation()).isEqualTo("sso-location");
assertThat(details.getSingleSignOnServiceBinding()).isEqualTo(Saml2MessageBinding.REDIRECT);
assertThat(details.getSingleLogoutServiceLocation()).isEqualTo("logout-location");
assertThat(details.getSingleLogoutServiceResponseLocation()).isEqualTo("logout-response-location");
assertThat(details.getSingleLogoutServiceBinding()).isEqualTo(Saml2MessageBinding.REDIRECT);
assertThat(details.getEntityId()).isEqualTo("entity-id");
assertThat(details.getVerificationX509Credentials()).hasSize(1);
assertThat(details.getVerificationX509Credentials().iterator().next().getCertificate())
@@ -122,12 +127,10 @@ public void readWhenDescriptorFullySpecifiedThenConfigures() throws Exception {
// gh-9051
@Test
public void readWhenEntitiesDescriptorThenConfigures() throws Exception {
String payload = String.format(ENTITIES_DESCRIPTOR_TEMPLATE,
String.format(ENTITY_DESCRIPTOR_TEMPLATE,
String.format(IDP_SSO_DESCRIPTOR_TEMPLATE,
String.format(KEY_DESCRIPTOR_TEMPLATE, "use=\"signing\"")
+ String.format(KEY_DESCRIPTOR_TEMPLATE, "use=\"encryption\"")
+ String.format(SINGLE_SIGN_ON_SERVICE_TEMPLATE))));
String payload = String.format(ENTITIES_DESCRIPTOR_TEMPLATE, String.format(ENTITY_DESCRIPTOR_TEMPLATE,
String.format(IDP_SSO_DESCRIPTOR_TEMPLATE, String.format(KEY_DESCRIPTOR_TEMPLATE, "use=\"signing\"")
+ String.format(KEY_DESCRIPTOR_TEMPLATE, "use=\"encryption\"")
+ String.format(SINGLE_SIGN_ON_SERVICE_TEMPLATE, Saml2MessageBinding.REDIRECT.getUrn()))));
InputStream inputStream = new ByteArrayInputStream(payload.getBytes());
RelyingPartyRegistration.AssertingPartyDetails details = this.converter.convert(inputStream).iterator().next()
.build();
@@ -145,8 +148,9 @@ public void readWhenEntitiesDescriptorThenConfigures() throws Exception {

@Test
public void readWhenKeyDescriptorHasNoUseThenConfiguresBothKeyTypes() throws Exception {
String payload = String.format(ENTITY_DESCRIPTOR_TEMPLATE, String.format(IDP_SSO_DESCRIPTOR_TEMPLATE,
String.format(KEY_DESCRIPTOR_TEMPLATE, "") + String.format(SINGLE_SIGN_ON_SERVICE_TEMPLATE)));
String payload = String.format(ENTITY_DESCRIPTOR_TEMPLATE,
String.format(IDP_SSO_DESCRIPTOR_TEMPLATE, String.format(KEY_DESCRIPTOR_TEMPLATE, "")
+ String.format(SINGLE_SIGN_ON_SERVICE_TEMPLATE, Saml2MessageBinding.REDIRECT.getUrn())));
InputStream inputStream = new ByteArrayInputStream(payload.getBytes());
RelyingPartyRegistration.AssertingPartyDetails details = this.converter.convert(inputStream).iterator().next()
.build();
@@ -157,6 +161,38 @@ public void readWhenKeyDescriptorHasNoUseThenConfiguresBothKeyTypes() throws Exc
.isEqualTo(x509Certificate(CERTIFICATE));
}

@Test
public void readWhenSSOBindingSupportsPostAndRedirectThenConfiguresRedirect() throws Exception {
String payload = String.format(ENTITY_DESCRIPTOR_TEMPLATE,
String.format(IDP_SSO_DESCRIPTOR_TEMPLATE,
String.format(KEY_DESCRIPTOR_TEMPLATE, "")
+ String.format(SINGLE_SIGN_ON_SERVICE_TEMPLATE, Saml2MessageBinding.POST.getUrn())
+ String.format(SINGLE_SIGN_ON_SERVICE_TEMPLATE, Saml2MessageBinding.REDIRECT.getUrn())
+ String.format(SINGLE_SIGN_ON_SERVICE_TEMPLATE, Saml2MessageBinding.POST.getUrn())));
InputStream inputStream = new ByteArrayInputStream(payload.getBytes());
RelyingPartyRegistration.AssertingPartyDetails details = this.converter.convert(inputStream).iterator().next()
.build();
assertThat(details.getSingleSignOnServiceLocation()).isEqualTo("sso-location");
assertThat(details.getSingleSignOnServiceBinding()).isEqualTo(Saml2MessageBinding.REDIRECT);
}

@Test
public void readWhenLogoutBindingSupportsPostAndRedirectThenConfiguresRedirect() throws Exception {
String payload = String.format(ENTITY_DESCRIPTOR_TEMPLATE,
String.format(IDP_SSO_DESCRIPTOR_TEMPLATE,
String.format(KEY_DESCRIPTOR_TEMPLATE, "")
+ String.format(SINGLE_SIGN_ON_SERVICE_TEMPLATE, Saml2MessageBinding.REDIRECT.getUrn())
+ String.format(SINGLE_LOGOUT_SERVICE_TEMPLATE, Saml2MessageBinding.POST.getUrn())
+ String.format(SINGLE_LOGOUT_SERVICE_TEMPLATE, Saml2MessageBinding.REDIRECT.getUrn())
+ String.format(SINGLE_LOGOUT_SERVICE_TEMPLATE, Saml2MessageBinding.POST.getUrn())));
InputStream inputStream = new ByteArrayInputStream(payload.getBytes());
RelyingPartyRegistration.AssertingPartyDetails details = this.converter.convert(inputStream).iterator().next()
.build();
assertThat(details.getSingleLogoutServiceLocation()).isEqualTo("logout-location");
assertThat(details.getSingleLogoutServiceResponseLocation()).isEqualTo("logout-response-location");
assertThat(details.getSingleLogoutServiceBinding()).isEqualTo(Saml2MessageBinding.REDIRECT);
}

X509Certificate x509Certificate(String data) {
try {
InputStream certificate = new ByteArrayInputStream(Base64.getDecoder().decode(data.getBytes()));