Skip to content

Commit d1630a6

Browse files
committed
Restore Format and CheckFormat for saml2 Projects
- Update the way that the saml2 projects were dependent on identity-provider resource files. - Use TestContainers to simplify runtime dependencies - Update compose.yml to use Docker-standard interpolation Closes gh-335
1 parent 2e39e5e commit d1630a6

File tree

23 files changed

+80
-337
lines changed

23 files changed

+80
-337
lines changed

build.gradle

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,6 @@ allprojects {
2929
options.compilerArgs.add("-parameters")
3030
}
3131

32-
tasks.withType(Format).tap {
33-
configureEach {
34-
it.enabled = !it.identityPath.toString().contains("saml2")
35-
}
36-
}
37-
38-
tasks.withType(CheckFormat).tap {
39-
configureEach {
40-
it.enabled = !it.identityPath.toString().contains("saml2")
41-
}
42-
}
43-
4432
tasks.matching { it.name == 'formatAot' }.all { task ->
4533
task.enabled = false
4634
}

servlet/spring-boot/java/saml2/custom-urls/build.gradle

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ repositories {
1212
maven { url "https://build.shibboleth.net/nexus/content/repositories/releases/" }
1313
}
1414

15-
sourceSets.main.java.srcDirs += "$projectDir/../identity-provider/src/main/java"
16-
sourceSets.main.resources.srcDirs += "$projectDir/../identity-provider/src/main/resources"
17-
1815
dependencies {
1916
constraints {
2017
implementation "org.opensaml:opensaml-saml-api:5.1.3"
@@ -26,10 +23,12 @@ dependencies {
2623
implementation 'org.springframework.security:spring-security-saml2-service-provider'
2724
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
2825

26+
runtimeOnly files("$projectDir/../identity-provider/build/resources/main")
27+
28+
testImplementation project(':servlet:spring-boot:java:saml2:identity-provider')
2929
testImplementation 'org.htmlunit:htmlunit'
3030
testImplementation 'org.springframework.boot:spring-boot-starter-test'
3131
testImplementation 'org.springframework.security:spring-security-test'
32-
runtimeOnly "org.springframework.boot:spring-boot-docker-compose"
3332
}
3433

3534
tasks.withType(Test).configureEach {

servlet/spring-boot/java/saml2/custom-urls/settings.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ pluginManagement {
66
maven { url "https://repo.spring.io/snapshot" }
77
}
88
}
9+
10+
include ":servlet:spring-boot:java:saml2:identity-provider"
11+
project(":servlet:spring-boot:java:saml2:identity-provider").projectDir = file("../identity-provider")

servlet/spring-boot/java/saml2/custom-urls/src/integTest/java/example/PreDockerComposeServerPortInitializer.java

Lines changed: 0 additions & 70 deletions
This file was deleted.

servlet/spring-boot/java/saml2/custom-urls/src/integTest/resources/META-INF/spring.factories

Lines changed: 0 additions & 1 deletion
This file was deleted.

servlet/spring-boot/java/saml2/custom-urls/src/main/resources/application.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ logging.level:
44
spring:
55
docker:
66
compose:
7-
file: docker:docker/compose.yml
7+
file: classpath:docker/compose.yml
88
readiness:
99
wait: never
10-
skip:
11-
in-tests: false
1210
security:
1311
filter:
1412
dispatcher-types: async, error, request, forward

servlet/spring-boot/java/saml2/identity-provider/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ repositories {
1313

1414

1515
dependencies {
16-
implementation 'org.springframework.boot:spring-boot-starter'
17-
runtimeOnly "org.springframework.boot:spring-boot-docker-compose"
16+
implementation 'org.springframework.boot:spring-boot-starter-test'
17+
implementation "org.testcontainers:testcontainers:1.20.3"
18+
implementation "org.testcontainers:junit-jupiter:1.20.3"
1819
}
1920

2021
tasks.withType(Test).configureEach {

servlet/spring-boot/java/saml2/identity-provider/src/main/java/example/ComposeFilePropertyPlaceholderApplicationContextInitializer.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

servlet/spring-boot/java/saml2/identity-provider/src/main/java/example/DockerProtocolResolver.java

Lines changed: 0 additions & 56 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package example;
18+
19+
import java.io.IOException;
20+
import java.net.ServerSocket;
21+
22+
import org.testcontainers.containers.DockerComposeContainer;
23+
24+
import org.springframework.core.io.ClassPathResource;
25+
import org.springframework.test.context.TestContext;
26+
import org.springframework.test.context.support.AbstractTestExecutionListener;
27+
28+
public class IdentityProviderTestExecutionListener extends AbstractTestExecutionListener {
29+
30+
private DockerComposeContainer<?> composed;
31+
32+
@Override
33+
public void beforeTestClass(TestContext testContext) throws Exception {
34+
String port = Integer.toString(getRandomPort());
35+
System.setProperty("SERVER_PORT", port);
36+
System.setProperty("server.port", port);
37+
this.composed = new DockerComposeContainer<>("saml2", new ClassPathResource("docker/compose.yml").getFile())
38+
.withEnv("SERVER_PORT", port);
39+
this.composed.start();
40+
}
41+
42+
@Override
43+
public void afterTestClass(TestContext testContext) throws Exception {
44+
this.composed.stop();
45+
}
46+
47+
static int getRandomPort() throws IOException {
48+
try (ServerSocket serverSocket = new ServerSocket(0)) {
49+
return serverSocket.getLocalPort();
50+
}
51+
}
52+
53+
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
org.springframework.context.ApplicationContextInitializer=example.ComposeFilePropertyPlaceholderApplicationContextInitializer
2-
org.springframework.core.io.ProtocolResolver=example.DockerProtocolResolver
1+
org.springframework.test.context.TestExecutionListener=example.IdentityProviderTestExecutionListener

servlet/spring-boot/java/saml2/identity-provider/src/main/resources/docker/compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ services:
55
- ./metadata/authsources.php:/var/www/simplesamlphp/config/authsources.php
66
- ./metadata/one-relyingparties.php:/var/www/simplesamlphp/metadata/saml20-sp-remote.php
77
environment:
8-
- PORT=${SERVER_PORT:8080}
8+
- PORT=${SERVER_PORT:-8080}
99

1010
idp-two.7f000001.nip.io:
1111
image: kristophjunge/test-saml-idp:1.15
1212
volumes:
1313
- ./metadata/authsources.php:/var/www/simplesamlphp/config/authsources.php
1414
- ./metadata/two-relyingparties.php:/var/www/simplesamlphp/metadata/saml20-sp-remote.php
1515
environment:
16-
- PORT=${SERVER_PORT:8080}
16+
- PORT=${SERVER_PORT:-8080}
1717

1818
nginx:
1919
image: nginx:stable

servlet/spring-boot/java/saml2/login/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ repositories {
1212
maven { url "https://build.shibboleth.net/nexus/content/repositories/releases/" }
1313
}
1414

15-
sourceSets.main.java.srcDirs += "$projectDir/../identity-provider/src/main/java"
16-
sourceSets.main.resources.srcDirs += "$projectDir/../identity-provider/src/main/resources"
17-
1815
dependencies {
1916
constraints {
2017
implementation "org.opensaml:opensaml-saml-api:5.1.3"
@@ -26,6 +23,9 @@ dependencies {
2623
implementation 'org.springframework.security:spring-security-saml2-service-provider'
2724
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
2825

26+
runtimeOnly files("$projectDir/../identity-provider/build/resources/main")
27+
28+
testImplementation project(":servlet:spring-boot:java:saml2:identity-provider")
2929
testImplementation 'org.htmlunit:htmlunit'
3030
testImplementation 'org.springframework.boot:spring-boot-starter-test'
3131
testImplementation 'org.springframework.security:spring-security-test'

servlet/spring-boot/java/saml2/login/settings.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ pluginManagement {
66
maven { url "https://repo.spring.io/snapshot" }
77
}
88
}
9+
10+
include ":servlet:spring-boot:java:saml2:identity-provider"
11+
project(":servlet:spring-boot:java:saml2:identity-provider").projectDir = file("../identity-provider")

0 commit comments

Comments
 (0)