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
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2021 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 org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
public class ComposeFilePropertyPlaceholderApplicationContextInitializer
|
||||
implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext context) {
|
||||
DockerProtocolResolver.environment = context.getEnvironment();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2021 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.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.ProtocolResolver;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
|
||||
public class DockerProtocolResolver implements ProtocolResolver {
|
||||
|
||||
private static final String PREFIX = "docker:";
|
||||
|
||||
static Environment environment;
|
||||
|
||||
@Override
|
||||
public Resource resolve(String location, ResourceLoader resourceLoader) {
|
||||
if (!location.startsWith(PREFIX)) {
|
||||
return null;
|
||||
}
|
||||
Resource resource = resourceLoader.getResource(location.replace(PREFIX, "classpath:"));
|
||||
try {
|
||||
String content = resource.getContentAsString(StandardCharsets.UTF_8);
|
||||
content = environment.resolvePlaceholders(content);
|
||||
File file = resource.getFile();
|
||||
File tmp = new File(file.getAbsolutePath() + ".tmp");
|
||||
tmp.createNewFile();
|
||||
Files.write(tmp.toPath(), content.getBytes(StandardCharsets.UTF_8));
|
||||
tmp.deleteOnExit();
|
||||
return new FileSystemResource(tmp);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,2 +1 @@
|
||||
org.springframework.context.ApplicationContextInitializer=example.ComposeFilePropertyPlaceholderApplicationContextInitializer
|
||||
org.springframework.core.io.ProtocolResolver=example.DockerProtocolResolver
|
||||
org.springframework.test.context.TestExecutionListener=example.IdentityProviderTestExecutionListener
|
||||
@@ -5,7 +5,7 @@ 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
|
||||
@@ -13,7 +13,7 @@ services:
|
||||
- ./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
|
||||
|
||||
Reference in New Issue
Block a user