Skip to content

Commit

Permalink
Restore Format and CheckFormat for saml2 Projects
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
jzheaux committed Nov 5, 2024
1 parent 2e39e5e commit d1630a6
Show file tree
Hide file tree
Showing 23 changed files with 80 additions and 337 deletions.
12 changes: 0 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ allprojects {
options.compilerArgs.add("-parameters")
}

tasks.withType(Format).tap {
configureEach {
it.enabled = !it.identityPath.toString().contains("saml2")
}
}

tasks.withType(CheckFormat).tap {
configureEach {
it.enabled = !it.identityPath.toString().contains("saml2")
}
}

tasks.matching { it.name == 'formatAot' }.all { task ->
task.enabled = false
}
Expand Down
7 changes: 3 additions & 4 deletions servlet/spring-boot/java/saml2/custom-urls/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ repositories {
maven { url "https://build.shibboleth.net/nexus/content/repositories/releases/" }
}

sourceSets.main.java.srcDirs += "$projectDir/../identity-provider/src/main/java"
sourceSets.main.resources.srcDirs += "$projectDir/../identity-provider/src/main/resources"

dependencies {
constraints {
implementation "org.opensaml:opensaml-saml-api:5.1.3"
Expand All @@ -26,10 +23,12 @@ dependencies {
implementation 'org.springframework.security:spring-security-saml2-service-provider'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'

runtimeOnly files("$projectDir/../identity-provider/build/resources/main")

testImplementation project(':servlet:spring-boot:java:saml2:identity-provider')
testImplementation 'org.htmlunit:htmlunit'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
runtimeOnly "org.springframework.boot:spring-boot-docker-compose"
}

tasks.withType(Test).configureEach {
Expand Down
3 changes: 3 additions & 0 deletions servlet/spring-boot/java/saml2/custom-urls/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ pluginManagement {
maven { url "https://repo.spring.io/snapshot" }
}
}

include ":servlet:spring-boot:java:saml2:identity-provider"
project(":servlet:spring-boot:java:saml2:identity-provider").projectDir = file("../identity-provider")

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ logging.level:
spring:
docker:
compose:
file: docker:docker/compose.yml
file: classpath:docker/compose.yml
readiness:
wait: never
skip:
in-tests: false
security:
filter:
dispatcher-types: async, error, request, forward
Expand Down
5 changes: 3 additions & 2 deletions servlet/spring-boot/java/saml2/identity-provider/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ repositories {


dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
runtimeOnly "org.springframework.boot:spring-boot-docker-compose"
implementation 'org.springframework.boot:spring-boot-starter-test'
implementation "org.testcontainers:testcontainers:1.20.3"
implementation "org.testcontainers:junit-jupiter:1.20.3"
}

tasks.withType(Test).configureEach {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package example;

import java.io.IOException;
import java.net.ServerSocket;

import org.testcontainers.containers.DockerComposeContainer;

import org.springframework.core.io.ClassPathResource;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.support.AbstractTestExecutionListener;

public class IdentityProviderTestExecutionListener extends AbstractTestExecutionListener {

private DockerComposeContainer<?> composed;

@Override
public void beforeTestClass(TestContext testContext) throws Exception {
String port = Integer.toString(getRandomPort());
System.setProperty("SERVER_PORT", port);
System.setProperty("server.port", port);
this.composed = new DockerComposeContainer<>("saml2", new ClassPathResource("docker/compose.yml").getFile())
.withEnv("SERVER_PORT", port);
this.composed.start();
}

@Override
public void afterTestClass(TestContext testContext) throws Exception {
this.composed.stop();
}

static int getRandomPort() throws IOException {
try (ServerSocket serverSocket = new ServerSocket(0)) {
return serverSocket.getLocalPort();
}
}

}
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
org.springframework.context.ApplicationContextInitializer=example.ComposeFilePropertyPlaceholderApplicationContextInitializer
org.springframework.core.io.ProtocolResolver=example.DockerProtocolResolver
org.springframework.test.context.TestExecutionListener=example.IdentityProviderTestExecutionListener
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ services:
- ./metadata/authsources.php:/var/www/simplesamlphp/config/authsources.php
- ./metadata/one-relyingparties.php:/var/www/simplesamlphp/metadata/saml20-sp-remote.php
environment:
- PORT=${SERVER_PORT:8080}
- PORT=${SERVER_PORT:-8080}

idp-two.7f000001.nip.io:
image: kristophjunge/test-saml-idp:1.15
volumes:
- ./metadata/authsources.php:/var/www/simplesamlphp/config/authsources.php
- ./metadata/two-relyingparties.php:/var/www/simplesamlphp/metadata/saml20-sp-remote.php
environment:
- PORT=${SERVER_PORT:8080}
- PORT=${SERVER_PORT:-8080}

nginx:
image: nginx:stable
Expand Down
6 changes: 3 additions & 3 deletions servlet/spring-boot/java/saml2/login/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ repositories {
maven { url "https://build.shibboleth.net/nexus/content/repositories/releases/" }
}

sourceSets.main.java.srcDirs += "$projectDir/../identity-provider/src/main/java"
sourceSets.main.resources.srcDirs += "$projectDir/../identity-provider/src/main/resources"

dependencies {
constraints {
implementation "org.opensaml:opensaml-saml-api:5.1.3"
Expand All @@ -26,6 +23,9 @@ dependencies {
implementation 'org.springframework.security:spring-security-saml2-service-provider'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'

runtimeOnly files("$projectDir/../identity-provider/build/resources/main")

testImplementation project(":servlet:spring-boot:java:saml2:identity-provider")
testImplementation 'org.htmlunit:htmlunit'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
Expand Down
3 changes: 3 additions & 0 deletions servlet/spring-boot/java/saml2/login/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ pluginManagement {
maven { url "https://repo.spring.io/snapshot" }
}
}

include ":servlet:spring-boot:java:saml2:identity-provider"
project(":servlet:spring-boot:java:saml2:identity-provider").projectDir = file("../identity-provider")
Loading

0 comments on commit d1630a6

Please sign in to comment.