Skip to content

Commit 3afd411

Browse files
authored
Merge pull request #3662 from fhanik/pr/issue-3661
Fix SAML Metadata when EntityID is a URL
2 parents eaef258 + b2e36ec commit 3afd411

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

server/src/main/java/org/cloudfoundry/identity/uaa/provider/saml/SamlRelyingPartyRegistrationRepositoryConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import lombok.extern.slf4j.Slf4j;
44
import org.cloudfoundry.identity.uaa.provider.SamlIdentityProviderDefinition;
55
import org.cloudfoundry.identity.uaa.util.KeyWithCert;
6+
import org.cloudfoundry.identity.uaa.util.UaaStringUtils;
67
import org.springframework.beans.factory.annotation.Qualifier;
78
import org.springframework.beans.factory.annotation.Value;
89
import org.springframework.context.annotation.Bean;
@@ -49,7 +50,8 @@ RelyingPartyRegistrationRepository relyingPartyRegistrationRepository(SamlIdenti
4950
List<KeyWithCert> defaultKeysWithCerts = samlKeyManager.getAvailableCredentials();
5051

5152
List<RelyingPartyRegistration> relyingPartyRegistrations = new ArrayList<>();
52-
String uaaWideSamlEntityIDAlias = samlConfigProps.getEntityIDAlias() != null ? samlConfigProps.getEntityIDAlias() : samlEntityID;
53+
String uaaWideSamlEntityIDAlias = samlConfigProps.getEntityIDAlias() != null ? samlConfigProps.getEntityIDAlias() :
54+
UaaStringUtils.getHostIfArgIsURL(samlEntityID);
5355

5456
@SuppressWarnings("java:S125")
5557
// Spring Security requires at least one relyingPartyRegistration before SAML SP metadata generation;

uaa/src/test/java/org/cloudfoundry/identity/uaa/mock/saml/SamlMetadataEndpointMockMvcTests.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,44 @@ void nonDefaultZoneSamlMetadataXMLValidationZoneSamlEntityIDNotSet() throws Exce
177177
}
178178
}
179179

180+
@Nested
181+
@DefaultTestContext
182+
@TestPropertySource(properties = {
183+
"login.entityID = http://some.saml.provider/url/entityId"
184+
})
185+
class SamlMetadataWhenEntityIDIsAUrlMockMvcTests {
186+
@Autowired
187+
private MockMvc mockMvc;
188+
189+
@Test
190+
void samlMetadataXMLValidation() throws Exception {
191+
192+
mockMvc.perform(get(new URI("/saml/metadata")))
193+
.andDo(print())
194+
.andExpectAll(
195+
status().isOk(),
196+
header().string(HttpHeaders.CONTENT_DISPOSITION, containsString("filename=\"saml-sp.xml\";")),
197+
xpath("/EntityDescriptor/SPSSODescriptor/AssertionConsumerService/@Location").string(containsString("/saml/SSO/alias/some.saml.provider")),
198+
xpath("/EntityDescriptor/@entityID").string("http://some.saml.provider/url/entityId")
199+
);
200+
}
201+
202+
@Test
203+
void samlMetadataXMLValidationInZone() throws Exception {
204+
IdentityZone alternativeSpZone = setupIdentityZone(false);
205+
String zoneSubdomain = alternativeSpZone.getSubdomain();
206+
mockMvc.perform(get(new URI("/saml/metadata"))
207+
.header(HOST, zoneSubdomain + ".localhost:8080"))
208+
.andDo(print())
209+
.andExpectAll(
210+
status().isOk(),
211+
header().string(HttpHeaders.CONTENT_DISPOSITION, containsString("filename=\"saml-%s-sp.xml\";".formatted(zoneSubdomain))),
212+
xpath("/EntityDescriptor/SPSSODescriptor/AssertionConsumerService/@Location").string(containsString("/saml/SSO/alias/%s.some.saml.provider".formatted(zoneSubdomain))),
213+
xpath("/EntityDescriptor/@entityID").string("http://%s.some.saml.provider/url/entityId".formatted(zoneSubdomain))
214+
);
215+
}
216+
}
217+
180218
private IdentityZone setupIdentityZone(boolean hasEntityId) throws Exception {
181219
UaaClientDetails adminClient = new UaaClientDetails("admin", "", "", "client_credentials", "uaa.admin");
182220
adminClient.setClientSecret("adminsecret");

0 commit comments

Comments
 (0)