|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2022 the original author or authors. |
| 2 | + * Copyright 2002-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -208,30 +208,49 @@ private static RelyingPartyRegistration.Builder getBuilderFromMetadataLocationIf
|
208 | 208 | ParserContext parserContext) {
|
209 | 209 | String registrationId = relyingPartyRegistrationElt.getAttribute(ATT_REGISTRATION_ID);
|
210 | 210 | String metadataLocation = relyingPartyRegistrationElt.getAttribute(ATT_METADATA_LOCATION);
|
| 211 | + RelyingPartyRegistration.Builder builder; |
| 212 | + if (StringUtils.hasText(metadataLocation)) { |
| 213 | + builder = RelyingPartyRegistrations.fromMetadataLocation(metadataLocation).registrationId(registrationId); |
| 214 | + } |
| 215 | + else { |
| 216 | + builder = RelyingPartyRegistration.withRegistrationId(registrationId) |
| 217 | + .assertingPartyDetails((apBuilder) -> buildAssertingParty(relyingPartyRegistrationElt, |
| 218 | + assertingParties, apBuilder, parserContext)); |
| 219 | + } |
| 220 | + addRemainingProperties(relyingPartyRegistrationElt, builder); |
| 221 | + return builder; |
| 222 | + } |
| 223 | + |
| 224 | + private static void addRemainingProperties(Element relyingPartyRegistrationElt, |
| 225 | + RelyingPartyRegistration.Builder builder) { |
| 226 | + String entityId = relyingPartyRegistrationElt.getAttribute(ATT_ENTITY_ID); |
211 | 227 | String singleLogoutServiceLocation = relyingPartyRegistrationElt
|
212 | 228 | .getAttribute(ATT_SINGLE_LOGOUT_SERVICE_LOCATION);
|
213 | 229 | String singleLogoutServiceResponseLocation = relyingPartyRegistrationElt
|
214 | 230 | .getAttribute(ATT_SINGLE_LOGOUT_SERVICE_RESPONSE_LOCATION);
|
215 | 231 | Saml2MessageBinding singleLogoutServiceBinding = getSingleLogoutServiceBinding(relyingPartyRegistrationElt);
|
216 |
| - if (StringUtils.hasText(metadataLocation)) { |
217 |
| - return RelyingPartyRegistrations.fromMetadataLocation(metadataLocation).registrationId(registrationId) |
218 |
| - .singleLogoutServiceLocation(singleLogoutServiceLocation) |
219 |
| - .singleLogoutServiceResponseLocation(singleLogoutServiceResponseLocation) |
220 |
| - .singleLogoutServiceBinding(singleLogoutServiceBinding); |
221 |
| - } |
222 |
| - String entityId = relyingPartyRegistrationElt.getAttribute(ATT_ENTITY_ID); |
223 | 232 | String assertionConsumerServiceLocation = relyingPartyRegistrationElt
|
224 | 233 | .getAttribute(ATT_ASSERTION_CONSUMER_SERVICE_LOCATION);
|
225 | 234 | Saml2MessageBinding assertionConsumerServiceBinding = getAssertionConsumerServiceBinding(
|
226 | 235 | relyingPartyRegistrationElt);
|
227 |
| - return RelyingPartyRegistration.withRegistrationId(registrationId).entityId(entityId) |
228 |
| - .assertionConsumerServiceLocation(assertionConsumerServiceLocation) |
229 |
| - .assertionConsumerServiceBinding(assertionConsumerServiceBinding) |
230 |
| - .singleLogoutServiceLocation(singleLogoutServiceLocation) |
231 |
| - .singleLogoutServiceResponseLocation(singleLogoutServiceResponseLocation) |
232 |
| - .singleLogoutServiceBinding(singleLogoutServiceBinding) |
233 |
| - .assertingPartyDetails((builder) -> buildAssertingParty(relyingPartyRegistrationElt, assertingParties, |
234 |
| - builder, parserContext)); |
| 236 | + if (StringUtils.hasText(entityId)) { |
| 237 | + builder.entityId(entityId); |
| 238 | + } |
| 239 | + if (StringUtils.hasText(singleLogoutServiceLocation)) { |
| 240 | + builder.singleLogoutServiceLocation(singleLogoutServiceLocation); |
| 241 | + } |
| 242 | + if (StringUtils.hasText(singleLogoutServiceResponseLocation)) { |
| 243 | + builder.singleLogoutServiceResponseLocation(singleLogoutServiceResponseLocation); |
| 244 | + } |
| 245 | + if (singleLogoutServiceBinding != null) { |
| 246 | + builder.singleLogoutServiceBinding(singleLogoutServiceBinding); |
| 247 | + } |
| 248 | + if (StringUtils.hasText(assertionConsumerServiceLocation)) { |
| 249 | + builder.assertionConsumerServiceLocation(assertionConsumerServiceLocation); |
| 250 | + } |
| 251 | + if (assertionConsumerServiceBinding != null) { |
| 252 | + builder.assertionConsumerServiceBinding(assertionConsumerServiceBinding); |
| 253 | + } |
235 | 254 | }
|
236 | 255 |
|
237 | 256 | private static void buildAssertingParty(Element relyingPartyElt, Map<String, Map<String, Object>> assertingParties,
|
@@ -309,15 +328,15 @@ private static Saml2MessageBinding getAssertionConsumerServiceBinding(Element re
|
309 | 328 | if (StringUtils.hasText(assertionConsumerServiceBinding)) {
|
310 | 329 | return Saml2MessageBinding.valueOf(assertionConsumerServiceBinding);
|
311 | 330 | }
|
312 |
| - return Saml2MessageBinding.REDIRECT; |
| 331 | + return null; |
313 | 332 | }
|
314 | 333 |
|
315 | 334 | private static Saml2MessageBinding getSingleLogoutServiceBinding(Element relyingPartyRegistrationElt) {
|
316 | 335 | String singleLogoutServiceBinding = relyingPartyRegistrationElt.getAttribute(ATT_SINGLE_LOGOUT_SERVICE_BINDING);
|
317 | 336 | if (StringUtils.hasText(singleLogoutServiceBinding)) {
|
318 | 337 | return Saml2MessageBinding.valueOf(singleLogoutServiceBinding);
|
319 | 338 | }
|
320 |
| - return Saml2MessageBinding.POST; |
| 339 | + return null; |
321 | 340 | }
|
322 | 341 |
|
323 | 342 | private static Saml2X509Credential getSaml2VerificationCredential(String certificateLocation) {
|
|
0 commit comments