Skip to content

Commit

Permalink
Add 'spring-security-messaging' if integration and securty is selected
Browse files Browse the repository at this point in the history
With Spring Integration 6.3+, which is included in Spring Boor 3.3+,
there's no longer a spring-integration-security module. It has been
superseded by spring-security-messaging. See https://docs.spring
.io/spring-integration/reference/security.html

Closes gh-1626
  • Loading branch information
mhalbritter committed Oct 23, 2024
1 parent 507ddf0 commit 356d151
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@

package io.spring.start.site.extension.dependency.springintegration;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import io.spring.initializr.generator.buildsystem.Build;
import io.spring.initializr.generator.buildsystem.Dependency;
import io.spring.initializr.generator.buildsystem.DependencyScope;
import io.spring.initializr.generator.spring.documentation.HelpDocument;
import io.spring.initializr.generator.version.Version;
import io.spring.initializr.generator.version.VersionParser;
import io.spring.initializr.generator.version.VersionRange;
import io.spring.start.site.support.implicit.ImplicitDependency;
import io.spring.start.site.support.implicit.ImplicitDependency.Builder;

Expand All @@ -32,48 +36,57 @@
*
* @author Artem Bilan
* @author Stephane Nicoll
* @author Moritz Halbritter
*/
abstract class SpringIntegrationModuleRegistry {

static Iterable<ImplicitDependency> create() {
return create(
onDependencies("activemq", "artemis").customizeBuild(addDependency("jms"))
.customizeHelpDocument(addReferenceLink("JMS Module", "jms")),
onDependencies("amqp", "amqp-streams").customizeBuild(addDependency("amqp"))
.customizeHelpDocument(addReferenceLink("AMQP Module", "amqp")),
onDependencies("data-jdbc", "jdbc").customizeBuild(addDependency("jdbc"))
.customizeHelpDocument(addReferenceLink("JDBC Module", "jdbc")),
onDependencies("data-jpa").customizeBuild(addDependency("jpa"))
.customizeHelpDocument(addReferenceLink("JPA Module", "jpa")),
onDependencies("data-mongodb", "data-mongodb-reactive").customizeBuild(addDependency("mongodb"))
.customizeHelpDocument(addReferenceLink("MongoDB Module", "mongodb")),
onDependencies("data-r2dbc").customizeBuild(addDependency("r2dbc"))
.customizeHelpDocument(addReferenceLink("R2DBC Module", "r2dbc")),
onDependencies("data-redis", "data-redis-reactive").customizeBuild(addDependency("redis"))
.customizeHelpDocument(addReferenceLink("Redis Module", "redis")),
onDependencies("integration").customizeBuild(addDependency("test", DependencyScope.TEST_COMPILE))
.customizeHelpDocument(addReferenceLink("Test Module", "testing")),
onDependencies("kafka", "kafka-streams").customizeBuild(addDependency("kafka"))
.customizeHelpDocument(addReferenceLink("Apache Kafka Module", "kafka")),
onDependencies("mail").customizeBuild(addDependency("mail"))
.customizeHelpDocument(addReferenceLink("Mail Module", "mail")),
onDependencies("rsocket").customizeBuild(addDependency("rsocket"))
.customizeHelpDocument(addReferenceLink("RSocket Module", "rsocket")),
onDependencies("security").customizeBuild(addDependency("security"))
.customizeHelpDocument(addReferenceLink("Security Module", "security")),
onDependencies("web").customizeBuild(addDependency("http"))
.customizeHelpDocument(addReferenceLink("HTTP Module", "http")),
onDependencies("webflux").customizeBuild(addDependency("webflux"))
.customizeHelpDocument(addReferenceLink("WebFlux Module", "webflux")),
onDependencies("websocket").customizeBuild(addDependency("stomp").andThen(addDependency("websocket")))
.customizeHelpDocument(addReferenceLink("STOMP Module", "stomp")
.andThen(addReferenceLink("WebSocket Module", "web-sockets"))),
onDependencies("web-services").customizeBuild(addDependency("ws"))
.customizeHelpDocument(addReferenceLink("Web Services Module", "ws")));
}
private static final VersionRange SPRING_BOOT_3_3_OR_LATER = VersionParser.DEFAULT.parseRange("3.3.0");

private static Iterable<ImplicitDependency> create(ImplicitDependency.Builder... dependencies) {
return Arrays.stream(dependencies).map(Builder::build).collect(Collectors.toList());
static Iterable<ImplicitDependency> create(Version platformVersion) {
List<Builder> builders = new ArrayList<>();
builders.add(onDependencies("activemq", "artemis").customizeBuild(addDependency("jms"))
.customizeHelpDocument(addReferenceLink("JMS Module", "jms")));
builders.add(onDependencies("amqp", "amqp-streams").customizeBuild(addDependency("amqp"))
.customizeHelpDocument(addReferenceLink("AMQP Module", "amqp")));
builders.add(onDependencies("data-jdbc", "jdbc").customizeBuild(addDependency("jdbc"))
.customizeHelpDocument(addReferenceLink("JDBC Module", "jdbc")));
builders.add(onDependencies("data-jpa").customizeBuild(addDependency("jpa"))
.customizeHelpDocument(addReferenceLink("JPA Module", "jpa")));
builders.add(onDependencies("data-mongodb", "data-mongodb-reactive").customizeBuild(addDependency("mongodb"))
.customizeHelpDocument(addReferenceLink("MongoDB Module", "mongodb")));
builders.add(onDependencies("data-r2dbc").customizeBuild(addDependency("r2dbc"))
.customizeHelpDocument(addReferenceLink("R2DBC Module", "r2dbc")));
builders.add(onDependencies("data-redis", "data-redis-reactive").customizeBuild(addDependency("redis"))
.customizeHelpDocument(addReferenceLink("Redis Module", "redis")));
builders.add(onDependencies("integration").customizeBuild(addDependency("test", DependencyScope.TEST_COMPILE))
.customizeHelpDocument(addReferenceLink("Test Module", "testing")));
builders.add(onDependencies("kafka", "kafka-streams").customizeBuild(addDependency("kafka"))
.customizeHelpDocument(addReferenceLink("Apache Kafka Module", "kafka")));
builders.add(onDependencies("mail").customizeBuild(addDependency("mail"))
.customizeHelpDocument(addReferenceLink("Mail Module", "mail")));
builders.add(onDependencies("rsocket").customizeBuild(addDependency("rsocket"))
.customizeHelpDocument(addReferenceLink("RSocket Module", "rsocket")));
if (SPRING_BOOT_3_3_OR_LATER.match(platformVersion)) {
builders.add(onDependencies("security")
.customizeBuild(addDependency("spring-security-messaging", "org.springframework.security",
"spring-security-messaging", DependencyScope.COMPILE))
.customizeHelpDocument(addReferenceLink("Security Module", "security")));
}
else {
builders.add(onDependencies("security").customizeBuild(addDependency("security"))
.customizeHelpDocument(addReferenceLink("Security Module", "security")));
}
builders.add(onDependencies("web").customizeBuild(addDependency("http"))
.customizeHelpDocument(addReferenceLink("HTTP Module", "http")));
builders.add(onDependencies("webflux").customizeBuild(addDependency("webflux"))
.customizeHelpDocument(addReferenceLink("WebFlux Module", "webflux")));
builders
.add(onDependencies("websocket").customizeBuild(addDependency("stomp").andThen(addDependency("websocket")))
.customizeHelpDocument(addReferenceLink("STOMP Module", "stomp")
.andThen(addReferenceLink("WebSocket Module", "web-sockets"))));
builders.add(onDependencies("web-services").customizeBuild(addDependency("ws"))
.customizeHelpDocument(addReferenceLink("Web Services Module", "ws")));
return builders.stream().map(Builder::build).collect(Collectors.toList());
}

private static ImplicitDependency.Builder onDependencies(String... dependencyIds) {
Expand All @@ -85,15 +98,16 @@ private static Consumer<Build> addDependency(String id) {
}

private static Consumer<Build> addDependency(String id, DependencyScope scope) {
return (build) -> build.dependencies()
.add("integration-" + id,
Dependency.withCoordinates("org.springframework.integration", "spring-integration-" + id)
.scope(scope));
return addDependency("integration-" + id, "org.springframework.integration", "spring-integration-" + id, scope);
}

private static Consumer<Build> addDependency(String id, String groupId, String artifactId, DependencyScope scope) {
return (build) -> build.dependencies().add(id, Dependency.withCoordinates(groupId, artifactId).scope(scope));
}

private static Consumer<HelpDocument> addReferenceLink(String name, String id) {
return (helpDocument) -> {
String href = String.format("https://docs.spring.io/spring-integration/reference/html/%s.html", id);
String href = "https://docs.spring.io/spring-integration/reference/%s.html".formatted(id);
String description = String.format("Spring Integration %s Reference Guide", name);
helpDocument.gettingStarted().addReferenceDocLink(href, description);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import io.spring.initializr.generator.buildsystem.Build;
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency;
import io.spring.initializr.generator.project.ProjectDescription;
import io.spring.initializr.generator.project.ProjectGenerationConfiguration;
import io.spring.start.site.support.implicit.ImplicitDependency;
import io.spring.start.site.support.implicit.ImplicitDependencyBuildCustomizer;
Expand All @@ -37,8 +38,8 @@ class SpringIntegrationProjectGenerationConfiguration {

private final Iterable<ImplicitDependency> dependencies;

SpringIntegrationProjectGenerationConfiguration() {
this.dependencies = SpringIntegrationModuleRegistry.create();
SpringIntegrationProjectGenerationConfiguration(ProjectDescription projectDescription) {
this.dependencies = SpringIntegrationModuleRegistry.create(projectDescription.getPlatformVersion());
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@
* @author Stephane Nicoll
* @author Artem Bilan
* @author Brian Clozel
* @author Moritz Halbritter
*/
class SpringIntegrationProjectGenerationConfigurationTests extends AbstractExtensionTests {

@Test
void buildWithOnlySpringIntegration() {
Dependency integrationTest = integrationDependency("test");
integrationTest.setScope(Dependency.SCOPE_TEST);
assertThat(generateProject("integration")).mavenBuild()
assertThat(generateProject("3.2.0", "integration")).mavenBuild()
.hasDependency(getDependency("integration"))
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST))
.hasDependency(integrationTest);
Expand All @@ -52,7 +53,7 @@ void buildWithOnlySpringIntegration() {
@ParameterizedTest
@MethodSource("supportedEntries")
void buildWithSupportedEntries(String springBootDependencyId, String integrationModuleId) {
assertThat(generateProject("integration", springBootDependencyId)).mavenBuild()
assertThat(generateProject("3.2.0", "integration", springBootDependencyId)).mavenBuild()
.hasDependency(getDependency("integration"))
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST))
.hasDependency(integrationDependency(integrationModuleId));
Expand All @@ -76,14 +77,14 @@ static Stream<Arguments> supportedEntries() {
@MethodSource("referenceLinks")
void linkToSupportedEntriesWhenSpringIntegrationIsPresentIsAdded(String dependencyId, String pageName) {
assertHelpDocument("integration", dependencyId)
.contains("https://docs.spring.io/spring-integration/reference/html/" + pageName + ".html");
.contains("https://docs.spring.io/spring-integration/reference/%s.html".formatted(pageName));
}

@ParameterizedTest
@MethodSource("referenceLinks")
void linkToSupportedEntriesWhenSpringIntegrationIsNotPresentIsNotAdded(String dependencyId, String pageName) {
assertHelpDocument(dependencyId)
.doesNotContain("https://docs.spring.io/spring-integration/reference/html/" + pageName + ".html");
.doesNotContain("https://docs.spring.io/spring-integration/reference/%s.html".formatted(pageName));
}

static Stream<Arguments> referenceLinks() {
Expand All @@ -106,14 +107,23 @@ void linkToSupportedEntriesWhenTwoMatchesArePresentOnlyAddLinkOnce() {
.containsOnlyOnce("https://java.testcontainers.org/modules/databases/mongodb/");
}

@Test
void securityAddsSpringSecurityMessagingOnBoot3dot3() {
assertThat(generateProject("3.3.0", "integration", "security")).mavenBuild()
.hasDependency("org.springframework.security", "spring-security-messaging")
.doesNotHaveDependency("org.springframework.integration", "spring-integration-security");

}

private static Dependency integrationDependency(String id) {
String integrationModule = "spring-integration-" + id;
return io.spring.initializr.metadata.Dependency.withId(integrationModule, "org.springframework.integration",
integrationModule, null, io.spring.initializr.metadata.Dependency.SCOPE_COMPILE);
}

private ProjectStructure generateProject(String... dependencies) {
private ProjectStructure generateProject(String bootVersion, String... dependencies) {
ProjectRequest request = createProjectRequest(dependencies);
request.setBootVersion(bootVersion);
request.setType("maven-build");
return generateProject(request);
}
Expand Down

0 comments on commit 356d151

Please sign in to comment.