diff --git a/.github/workflows/ci-boot.yml b/.github/workflows/ci-boot.yml index ad90dad2..a5cf90ee 100644 --- a/.github/workflows/ci-boot.yml +++ b/.github/workflows/ci-boot.yml @@ -11,8 +11,8 @@ jobs: strategy: matrix: os: [ubuntu-latest] - java: [1.8] - boot: [2.7.0, 2.7.12] + java: [ 17 ] + boot: [ 3.1.0, 3.1.3 ] fail-fast: false steps: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe2c1f5a..08d05268 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - java: [1.8, 11] + java: [ 17 ] fail-fast: false steps: @@ -52,7 +52,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-java@v1 with: - java-version: 1.8 + java-version: 17 - uses: jfrog/setup-jfrog-cli@v3 with: version: 2.39.1 diff --git a/.github/workflows/mongodb.yml b/.github/workflows/mongodb.yml index 068e2fd1..88377678 100644 --- a/.github/workflows/mongodb.yml +++ b/.github/workflows/mongodb.yml @@ -24,7 +24,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - java: [1.8, 11] + java: [ 17 ] fail-fast: false steps: diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 36519a31..2d518025 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - java: [1.8, 11] + java: [ 17 ] fail-fast: false steps: diff --git a/.github/workflows/redis.yml b/.github/workflows/redis.yml index ad921af2..ca46b913 100644 --- a/.github/workflows/redis.yml +++ b/.github/workflows/redis.yml @@ -24,7 +24,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - java: [1.8, 11] + java: [ 17 ] fail-fast: false steps: diff --git a/.github/workflows/release-ga.yml b/.github/workflows/release-ga.yml index 61dc6599..ffea00b2 100644 --- a/.github/workflows/release-ga.yml +++ b/.github/workflows/release-ga.yml @@ -21,7 +21,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-java@v1 with: - java-version: 1.8 + java-version: 17 - uses: jfrog/setup-jfrog-cli@v3 with: version: 2.39.1 diff --git a/.github/workflows/release-milestone.yml b/.github/workflows/release-milestone.yml index e9982ddb..92f83f91 100644 --- a/.github/workflows/release-milestone.yml +++ b/.github/workflows/release-milestone.yml @@ -25,7 +25,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-java@v1 with: - java-version: 1.8 + java-version: 17 - uses: jfrog/setup-jfrog-cli@v3 with: version: 2.39.1 diff --git a/.github/workflows/smoke.yml b/.github/workflows/smoke.yml index 2c0d7c41..46b6f965 100644 --- a/.github/workflows/smoke.yml +++ b/.github/workflows/smoke.yml @@ -18,7 +18,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - java: [1.8, 11] + java: [ 17 ] fail-fast: false steps: diff --git a/build.gradle b/build.gradle index 6bb177e0..8df2b53f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,8 @@ buildscript { ext { log4jVersion = '1.2.17' - springBootVersion = '2.7.0' - eclipsePersistenceVersion = '2.1.1' + springBootVersion = '3.1.3' + jakartaPersistenceVersion = '3.1.0' kryoVersion = '4.0.2' springCloudClusterVersion = '1.0.2.RELEASE' springShellVersion = '1.1.0.RELEASE' @@ -67,13 +67,13 @@ configure(javaProjectsAndRoot) { } compileJava { - sourceCompatibility = 1.8 - targetCompatibility = 1.8 + sourceCompatibility = 17 + targetCompatibility = 17 } compileTestJava { - sourceCompatibility = 1.8 - targetCompatibility = 1.8 + sourceCompatibility = 17 + targetCompatibility = 17 } group = 'org.springframework.statemachine' @@ -218,7 +218,7 @@ project('spring-statemachine-core') { testFixturesImplementation 'org.assertj:assertj-core' testImplementation 'org.springframework.security:spring-security-config' testImplementation 'org.springframework.security:spring-security-test' - testImplementation 'javax.servlet:javax.servlet-api' + testImplementation 'jakarta.servlet:jakarta.servlet-api' testImplementation 'org.awaitility:awaitility' testRuntimeOnly 'org.apache.logging.log4j:log4j-core' } @@ -237,7 +237,7 @@ project('spring-statemachine-autoconfigure') { optional project(':spring-statemachine-data-common:spring-statemachine-data-mongodb') optional 'org.springframework.boot:spring-boot-autoconfigure-processor' optional 'io.micrometer:micrometer-core' - optional 'org.eclipse.persistence:javax.persistence' + optional 'jakarta.persistence:jakarta.persistence-api' optional 'org.springframework.boot:spring-boot-starter-data-jpa' optional 'org.springframework.boot:spring-boot-starter-data-redis' optional 'org.springframework.boot:spring-boot-starter-data-mongodb' @@ -486,8 +486,8 @@ project('spring-statemachine-starter') { configure(sampleProjects()) { apply plugin: 'org.springframework.boot' compileJava { - sourceCompatibility = 1.8 - targetCompatibility = 1.8 + sourceCompatibility = 17 + targetCompatibility = 17 } dependencies { api project(':spring-statemachine-core') diff --git a/gradle/java-test-fixtures.gradle b/gradle/java-test-fixtures.gradle index 89e4e5a4..06cfafd1 100644 --- a/gradle/java-test-fixtures.gradle +++ b/gradle/java-test-fixtures.gradle @@ -1,8 +1,8 @@ apply plugin: 'java-test-fixtures' compileTestFixturesJava { - sourceCompatibility = 1.8 - targetCompatibility = 1.8 + sourceCompatibility = 17 + targetCompatibility = 17 } eclipse.classpath { diff --git a/spring-statemachine-autoconfigure/src/main/java/org/springframework/statemachine/boot/autoconfigure/StateMachineAutoConfiguration.java b/spring-statemachine-autoconfigure/src/main/java/org/springframework/statemachine/boot/autoconfigure/StateMachineAutoConfiguration.java index de0d6f9e..a5ebee97 100644 --- a/spring-statemachine-autoconfigure/src/main/java/org/springframework/statemachine/boot/autoconfigure/StateMachineAutoConfiguration.java +++ b/spring-statemachine-autoconfigure/src/main/java/org/springframework/statemachine/boot/autoconfigure/StateMachineAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 the original author or authors. + * Copyright 2016-2023 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. @@ -17,6 +17,7 @@ package org.springframework.statemachine.boot.autoconfigure; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration; +import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -36,10 +37,9 @@ import io.micrometer.core.instrument.MeterRegistry; * {@link EnableAutoConfiguration Auto-configuration} for Spring Statemachine. * * @author Janne Valkealahti - * */ -@Configuration -@EnableConfigurationProperties({ StateMachineProperties.class }) +@AutoConfiguration +@EnableConfigurationProperties({StateMachineProperties.class}) @ConditionalOnClass(MeterRegistry.class) @ConditionalOnProperty(prefix = "spring.statemachine.monitor", name = "enabled", havingValue = "true", matchIfMissing = true) public class StateMachineAutoConfiguration { @@ -47,20 +47,20 @@ public class StateMachineAutoConfiguration { @ManagementContextConfiguration public static class StateMachineTraceEndpointConfiguration { - @Bean - public StateMachineTraceEndpoint stateMachineTraceEndpoint(StateMachineTraceRepository stateMachineTraceRepository) { + @Bean + public StateMachineTraceEndpoint stateMachineTraceEndpoint(StateMachineTraceRepository stateMachineTraceRepository) { return new StateMachineTraceEndpoint(stateMachineTraceRepository); - } + } } @Configuration public static class StateMachineTraceRepositoryConfiguration { - @ConditionalOnMissingBean(StateMachineTraceRepository.class) - @Bean - public InMemoryStateMachineTraceRepository stateMachineTraceRepository() { - return new InMemoryStateMachineTraceRepository(); - } + @ConditionalOnMissingBean(StateMachineTraceRepository.class) + @Bean + public InMemoryStateMachineTraceRepository stateMachineTraceRepository() { + return new InMemoryStateMachineTraceRepository(); + } } @Configuration @@ -69,7 +69,8 @@ public class StateMachineAutoConfiguration { private final MeterRegistry meterRegistry; private final StateMachineTraceRepository stateMachineTraceRepository; - public StateMachineMonitoringConfiguration(ObjectProvider meterRegistryProvider, + public StateMachineMonitoringConfiguration( + ObjectProvider meterRegistryProvider, ObjectProvider traceRepositoryProvider) { this.meterRegistry = meterRegistryProvider.getIfAvailable(); this.stateMachineTraceRepository = traceRepositoryProvider.getIfAvailable(); diff --git a/spring-statemachine-autoconfigure/src/main/java/org/springframework/statemachine/boot/autoconfigure/StateMachineJpaRepositoriesAutoConfiguration.java b/spring-statemachine-autoconfigure/src/main/java/org/springframework/statemachine/boot/autoconfigure/StateMachineJpaRepositoriesAutoConfiguration.java index 15a23ca8..d46efe57 100644 --- a/spring-statemachine-autoconfigure/src/main/java/org/springframework/statemachine/boot/autoconfigure/StateMachineJpaRepositoriesAutoConfiguration.java +++ b/spring-statemachine-autoconfigure/src/main/java/org/springframework/statemachine/boot/autoconfigure/StateMachineJpaRepositoriesAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2023 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. @@ -15,27 +15,24 @@ */ package org.springframework.statemachine.boot.autoconfigure; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration; import org.springframework.boot.autoconfigure.domain.EntityScan; -import org.springframework.context.annotation.Configuration; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.statemachine.data.jpa.JpaRepositoryState; import org.springframework.statemachine.data.jpa.JpaStateRepository; /** - * {@link EnableAutoConfiguration Auto-configuration} for JPA repositories - * and Entity classes. + * {@link EnableAutoConfiguration Auto-configuration} for JPA repositories and Entity classes. */ -@Configuration +@AutoConfiguration(after = JpaRepositoriesAutoConfiguration.class) @ConditionalOnClass(JpaStateRepository.class) @ConditionalOnProperty(prefix = "spring.statemachine.data.jpa.repositories", name = "enabled", havingValue = "true", matchIfMissing = true) -@AutoConfigureAfter(JpaRepositoriesAutoConfiguration.class) -@EntityScan(basePackageClasses = { JpaRepositoryState.class }) -@EnableJpaRepositories(basePackageClasses = { JpaStateRepository.class }) +@EntityScan(basePackageClasses = {JpaRepositoryState.class}) +@EnableJpaRepositories(basePackageClasses = {JpaStateRepository.class}) public class StateMachineJpaRepositoriesAutoConfiguration { } diff --git a/spring-statemachine-autoconfigure/src/main/java/org/springframework/statemachine/boot/autoconfigure/StateMachineMongoDbRepositoriesAutoConfiguration.java b/spring-statemachine-autoconfigure/src/main/java/org/springframework/statemachine/boot/autoconfigure/StateMachineMongoDbRepositoriesAutoConfiguration.java index 84b36f70..ad1ae1e3 100644 --- a/spring-statemachine-autoconfigure/src/main/java/org/springframework/statemachine/boot/autoconfigure/StateMachineMongoDbRepositoriesAutoConfiguration.java +++ b/spring-statemachine-autoconfigure/src/main/java/org/springframework/statemachine/boot/autoconfigure/StateMachineMongoDbRepositoriesAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2023 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. @@ -15,27 +15,24 @@ */ package org.springframework.statemachine.boot.autoconfigure; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration; import org.springframework.boot.autoconfigure.domain.EntityScan; -import org.springframework.context.annotation.Configuration; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; import org.springframework.statemachine.data.mongodb.MongoDbRepositoryState; import org.springframework.statemachine.data.mongodb.MongoDbStateRepository; /** - * {@link EnableAutoConfiguration Auto-configuration} for MongoDb repositories - * and Entity classes. + * {@link EnableAutoConfiguration Auto-configuration} for MongoDb repositories and Entity classes. */ -@Configuration +@AutoConfiguration(after = MongoRepositoriesAutoConfiguration.class) @ConditionalOnClass(MongoDbStateRepository.class) @ConditionalOnProperty(prefix = "spring.statemachine.data.mongo.repositories", name = "enabled", havingValue = "true", matchIfMissing = true) -@AutoConfigureAfter(MongoRepositoriesAutoConfiguration.class) -@EntityScan(basePackageClasses = { MongoDbRepositoryState.class }) -@EnableMongoRepositories(basePackageClasses = { MongoDbStateRepository.class }) +@EntityScan(basePackageClasses = {MongoDbRepositoryState.class}) +@EnableMongoRepositories(basePackageClasses = {MongoDbStateRepository.class}) public class StateMachineMongoDbRepositoriesAutoConfiguration { } diff --git a/spring-statemachine-autoconfigure/src/main/java/org/springframework/statemachine/boot/autoconfigure/StateMachineRedisRepositoriesAutoConfiguration.java b/spring-statemachine-autoconfigure/src/main/java/org/springframework/statemachine/boot/autoconfigure/StateMachineRedisRepositoriesAutoConfiguration.java index 43e3f97b..6817b930 100644 --- a/spring-statemachine-autoconfigure/src/main/java/org/springframework/statemachine/boot/autoconfigure/StateMachineRedisRepositoriesAutoConfiguration.java +++ b/spring-statemachine-autoconfigure/src/main/java/org/springframework/statemachine/boot/autoconfigure/StateMachineRedisRepositoriesAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2023 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. @@ -15,27 +15,24 @@ */ package org.springframework.statemachine.boot.autoconfigure; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration; import org.springframework.boot.autoconfigure.domain.EntityScan; -import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; import org.springframework.statemachine.data.redis.RedisRepositoryState; import org.springframework.statemachine.data.redis.RedisStateRepository; /** - * {@link EnableAutoConfiguration Auto-configuration} for Redis repositories - * and Entity classes. + * {@link EnableAutoConfiguration Auto-configuration} for Redis repositories and Entity classes. */ -@Configuration +@AutoConfiguration(after = RedisRepositoriesAutoConfiguration.class) @ConditionalOnClass(RedisStateRepository.class) @ConditionalOnProperty(prefix = "spring.statemachine.data.redis.repositories", name = "enabled", havingValue = "true", matchIfMissing = true) -@AutoConfigureAfter(RedisRepositoriesAutoConfiguration.class) -@EntityScan(basePackageClasses = { RedisRepositoryState.class }) -@EnableRedisRepositories(basePackageClasses = { RedisStateRepository.class }) +@EntityScan(basePackageClasses = {RedisRepositoryState.class}) +@EnableRedisRepositories(basePackageClasses = {RedisStateRepository.class}) public class StateMachineRedisRepositoriesAutoConfiguration { } diff --git a/spring-statemachine-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-statemachine-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports similarity index 54% rename from spring-statemachine-autoconfigure/src/main/resources/META-INF/spring.factories rename to spring-statemachine-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 66e58aaa..518faf08 100644 --- a/spring-statemachine-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/spring-statemachine-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,7 +1,4 @@ -# Auto Configure -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.springframework.statemachine.boot.autoconfigure.StateMachineAutoConfiguration,\ -org.springframework.statemachine.boot.autoconfigure.StateMachineJpaRepositoriesAutoConfiguration,\ -org.springframework.statemachine.boot.autoconfigure.StateMachineRedisRepositoriesAutoConfiguration,\ -org.springframework.statemachine.boot.autoconfigure.StateMachineMongoDbRepositoriesAutoConfiguration - +org.springframework.statemachine.boot.autoconfigure.StateMachineAutoConfiguration +org.springframework.statemachine.boot.autoconfigure.StateMachineJpaRepositoriesAutoConfiguration +org.springframework.statemachine.boot.autoconfigure.StateMachineRedisRepositoriesAutoConfiguration +org.springframework.statemachine.boot.autoconfigure.StateMachineMongoDbRepositoriesAutoConfiguration \ No newline at end of file diff --git a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/mongodb/EnabledOnMongoDbCondition.java b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/mongodb/EnabledOnMongoDbCondition.java index 1192b2d8..f1f17555 100644 --- a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/mongodb/EnabledOnMongoDbCondition.java +++ b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/mongodb/EnabledOnMongoDbCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 the original author or authors. + * Copyright 2019-2023 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. @@ -18,24 +18,36 @@ package org.springframework.statemachine.buildtests.tck.mongodb; import static org.junit.jupiter.api.extension.ConditionEvaluationResult.disabled; import static org.junit.jupiter.api.extension.ConditionEvaluationResult.enabled; +import java.net.InetAddress; +import java.net.ServerSocket; + +import javax.net.ServerSocketFactory; + import org.junit.jupiter.api.extension.ConditionEvaluationResult; import org.junit.jupiter.api.extension.ExecutionCondition; import org.junit.jupiter.api.extension.ExtensionContext; -import org.springframework.util.SocketUtils; public class EnabledOnMongoDbCondition implements ExecutionCondition { - static final ConditionEvaluationResult ENABLED_ON_MONGO = enabled("Mongo DB found"); + static final ConditionEvaluationResult ENABLED_ON_MONGO = enabled("Mongo DB found"); - static final ConditionEvaluationResult DISABLED_ON_MONGO = disabled("Mongo DB not found"); + static final ConditionEvaluationResult DISABLED_ON_MONGO = disabled("Mongo DB not found"); - @Override - public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { + @Override + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { + return isPortAvailable(27017) ? DISABLED_ON_MONGO : ENABLED_ON_MONGO; + } + + private static boolean isPortAvailable(int port) { try { - SocketUtils.findAvailableTcpPort(27017, 27017); - return DISABLED_ON_MONGO; - } catch (Exception e) { + ServerSocket serverSocket = ServerSocketFactory.getDefault() + .createServerSocket(port, 1, InetAddress.getByName("localhost")); + serverSocket.close(); + return true; + } + catch (Exception ex) { + return false; } - return ENABLED_ON_MONGO; } + } diff --git a/spring-statemachine-core/src/test/java/org/springframework/statemachine/action/StateDoActivityActionTests.java b/spring-statemachine-core/src/test/java/org/springframework/statemachine/action/StateDoActivityActionTests.java index c6158ff3..bee848af 100644 --- a/spring-statemachine-core/src/test/java/org/springframework/statemachine/action/StateDoActivityActionTests.java +++ b/spring-statemachine-core/src/test/java/org/springframework/statemachine/action/StateDoActivityActionTests.java @@ -253,10 +253,10 @@ public class StateDoActivityActionTests extends AbstractStateMachineTests { Message event = MessageBuilder.withPayload(TestEvents.E1) .setHeader(StateMachineMessageHeaders.HEADER_DO_ACTION_TIMEOUT, 4000).build(); doSendEventAndConsumeAll(machine, event); - assertThat(testActionS2.onExecuteStartLatch.await(2, TimeUnit.SECONDS)).isTrue(); + assertThat(testActionS2.onExecuteStartLatch.await(6, TimeUnit.SECONDS)).isTrue(); doSendEventAndConsumeAll(machine, TestEvents.E2); - assertThat(testActionS2.onExecuteLatch.await(2, TimeUnit.SECONDS)).isTrue(); - assertThat(testActionS2.interruptedLatch.await(2, TimeUnit.SECONDS)).isFalse(); + assertThat(testActionS2.onExecuteLatch.await(6, TimeUnit.SECONDS)).isTrue(); + assertThat(testActionS2.interruptedLatch.await(6, TimeUnit.SECONDS)).isFalse(); } @Test diff --git a/spring-statemachine-core/src/test/java/org/springframework/statemachine/config/ConfigurationErrorTests.java b/spring-statemachine-core/src/test/java/org/springframework/statemachine/config/ConfigurationErrorTests.java index 82392894..0e545376 100644 --- a/spring-statemachine-core/src/test/java/org/springframework/statemachine/config/ConfigurationErrorTests.java +++ b/spring-statemachine-core/src/test/java/org/springframework/statemachine/config/ConfigurationErrorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 the original author or authors. + * Copyright 2016-2023 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. @@ -138,7 +138,7 @@ public class ConfigurationErrorTests extends AbstractStateMachineTests { builder.build(); }).satisfies(e -> { assertThat(e.getCause()).isInstanceOf(MalformedConfigurationException.class); - assertThat(e.getLocalizedMessage()).contains("No transitions for state S2"); + assertThat(e.getCause().getLocalizedMessage()).contains("No transitions for state S2"); }); } diff --git a/spring-statemachine-core/src/test/java/org/springframework/statemachine/docs/DocsConfigurationSampleTests12.java b/spring-statemachine-core/src/test/java/org/springframework/statemachine/docs/DocsConfigurationSampleTests12.java index aafefb30..e469132b 100644 --- a/spring-statemachine-core/src/test/java/org/springframework/statemachine/docs/DocsConfigurationSampleTests12.java +++ b/spring-statemachine-core/src/test/java/org/springframework/statemachine/docs/DocsConfigurationSampleTests12.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 the original author or authors. + * Copyright 2020-2023 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. @@ -74,7 +74,7 @@ public class DocsConfigurationSampleTests12 { StepVerifier.create(machine.sendEvent(Mono.just(MessageBuilder.withPayload("E1").build()))) .consumeNextWith(result -> { StepVerifier.create(result.complete()).consumeErrorWith(e -> { - assertThat(e).isInstanceOf(StateMachineException.class).hasMessageContaining("example error"); + assertThat(e).isInstanceOf(StateMachineException.class).cause().hasMessageContaining("example error"); }).verify(); }) .verifyComplete(); diff --git a/spring-statemachine-core/src/test/java/org/springframework/statemachine/docs/DocsConfigurationSampleTests3.java b/spring-statemachine-core/src/test/java/org/springframework/statemachine/docs/DocsConfigurationSampleTests3.java index a47ce6ca..f86ef9a1 100644 --- a/spring-statemachine-core/src/test/java/org/springframework/statemachine/docs/DocsConfigurationSampleTests3.java +++ b/spring-statemachine-core/src/test/java/org/springframework/statemachine/docs/DocsConfigurationSampleTests3.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2023 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. @@ -15,15 +15,14 @@ */ package org.springframework.statemachine.docs; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.security.access.annotation.Secured; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.provisioning.InMemoryUserDetailsManager; import org.springframework.statemachine.StateContext; import org.springframework.statemachine.action.Action; import org.springframework.statemachine.config.EnableStateMachine; @@ -139,14 +138,16 @@ public class DocsConfigurationSampleTests3 { // tag::snippetE[] @Configuration - @EnableGlobalMethodSecurity(securedEnabled = true) - public static class Config5 extends WebSecurityConfigurerAdapter { + public static class Config5 { - @Autowired - public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { - auth - .inMemoryAuthentication() - .withUser("user").password("password").roles("USER"); + @Bean + public InMemoryUserDetailsManager userDetailsService() { + UserDetails user = User.withDefaultPasswordEncoder() + .username("user") + .password("password") + .roles("USER") + .build(); + return new InMemoryUserDetailsManager(user); } } // end::snippetE[] diff --git a/spring-statemachine-core/src/test/java/org/springframework/statemachine/security/ActionSecurityTests.java b/spring-statemachine-core/src/test/java/org/springframework/statemachine/security/ActionSecurityTests.java index ec43181e..9745ad5d 100644 --- a/spring-statemachine-core/src/test/java/org/springframework/statemachine/security/ActionSecurityTests.java +++ b/spring-statemachine-core/src/test/java/org/springframework/statemachine/security/ActionSecurityTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2020 the original author or authors. + * Copyright 2015-2023 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. @@ -30,9 +30,9 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.security.access.annotation.Secured; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.provisioning.InMemoryUserDetailsManager; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.statemachine.AbstractStateMachineTests; import org.springframework.statemachine.StateContext; @@ -103,16 +103,17 @@ public class ActionSecurityTests extends AbstractStateMachineTests { } @Configuration - @EnableGlobalMethodSecurity(securedEnabled = true) - public static class Config1 extends WebSecurityConfigurerAdapter { + public static class Config1 { - @Autowired - public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { - auth - .inMemoryAuthentication() - .withUser("user").password("password").roles("USER"); + @Bean + public InMemoryUserDetailsManager userDetailsService() { + UserDetails user = User.withDefaultPasswordEncoder() + .username("user") + .password("password") + .roles("USER") + .build(); + return new InMemoryUserDetailsManager(user); } - } @Configuration diff --git a/spring-statemachine-data/build.gradle b/spring-statemachine-data/build.gradle index 929dad5c..f49f1fc4 100644 --- a/spring-statemachine-data/build.gradle +++ b/spring-statemachine-data/build.gradle @@ -11,7 +11,7 @@ project('spring-statemachine-data-jpa') { testImplementation(testFixtures(project(":spring-statemachine-data-common"))) testImplementation(testFixtures(project(":spring-statemachine-core"))) testImplementation 'io.projectreactor:reactor-test' - optional 'org.eclipse.persistence:javax.persistence' + optional 'jakarta.persistence:jakarta.persistence-api' testImplementation 'org.hsqldb:hsqldb' testImplementation 'org.springframework.boot:spring-boot-starter-test' testRuntimeOnly 'org.springframework.boot:spring-boot-starter-data-jpa' @@ -27,7 +27,7 @@ project('spring-statemachine-data-redis') { api project(':spring-statemachine-data-common') api 'org.springframework.data:spring-data-redis' testImplementation project(':spring-statemachine-test') - optional 'org.eclipse.persistence:javax.persistence' + optional 'jakarta.persistence:jakarta.persistence-api' testImplementation(testFixtures(project(":spring-statemachine-data-common"))) testImplementation(testFixtures(project(":spring-statemachine-core"))) testImplementation 'io.projectreactor:reactor-test' @@ -47,7 +47,7 @@ project('spring-statemachine-data-mongodb') { api project(':spring-statemachine-data-common') api 'org.springframework.data:spring-data-mongodb' testImplementation project(':spring-statemachine-test') - optional 'org.eclipse.persistence:javax.persistence' + optional 'jakarta.persistence:jakarta.persistence-api' testImplementation(testFixtures(project(":spring-statemachine-data-common"))) testImplementation(testFixtures(project(":spring-statemachine-core"))) testImplementation 'io.projectreactor:reactor-test' diff --git a/spring-statemachine-data/jpa/src/main/java/org/springframework/statemachine/data/jpa/JpaRepositoryAction.java b/spring-statemachine-data/jpa/src/main/java/org/springframework/statemachine/data/jpa/JpaRepositoryAction.java index 01ec24ac..8f7d2f40 100644 --- a/spring-statemachine-data/jpa/src/main/java/org/springframework/statemachine/data/jpa/JpaRepositoryAction.java +++ b/spring-statemachine-data/jpa/src/main/java/org/springframework/statemachine/data/jpa/JpaRepositoryAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 the original author or authors. + * Copyright 2016-2023 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. @@ -15,18 +15,18 @@ */ package org.springframework.statemachine.data.jpa; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.persistence.Column; - import org.springframework.statemachine.data.RepositoryAction; import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.fasterxml.jackson.annotation.ObjectIdGenerators; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; + /** * JPA entity for actions. * diff --git a/spring-statemachine-data/jpa/src/main/java/org/springframework/statemachine/data/jpa/JpaRepositoryGuard.java b/spring-statemachine-data/jpa/src/main/java/org/springframework/statemachine/data/jpa/JpaRepositoryGuard.java index 5b5cf047..5ca39b12 100644 --- a/spring-statemachine-data/jpa/src/main/java/org/springframework/statemachine/data/jpa/JpaRepositoryGuard.java +++ b/spring-statemachine-data/jpa/src/main/java/org/springframework/statemachine/data/jpa/JpaRepositoryGuard.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 the original author or authors. + * Copyright 2016-2023 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. @@ -15,18 +15,18 @@ */ package org.springframework.statemachine.data.jpa; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.persistence.Column; - import org.springframework.statemachine.data.RepositoryGuard; import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.fasterxml.jackson.annotation.ObjectIdGenerators; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; + /** * JPA entity for actions. * diff --git a/spring-statemachine-data/jpa/src/main/java/org/springframework/statemachine/data/jpa/JpaRepositoryState.java b/spring-statemachine-data/jpa/src/main/java/org/springframework/statemachine/data/jpa/JpaRepositoryState.java index 946d2161..fabcd022 100644 --- a/spring-statemachine-data/jpa/src/main/java/org/springframework/statemachine/data/jpa/JpaRepositoryState.java +++ b/spring-statemachine-data/jpa/src/main/java/org/springframework/statemachine/data/jpa/JpaRepositoryState.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 the original author or authors. + * Copyright 2016-2023 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. @@ -17,21 +17,6 @@ package org.springframework.statemachine.data.jpa; import java.util.Set; -import javax.persistence.CollectionTable; -import javax.persistence.Column; -import javax.persistence.ElementCollection; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.ForeignKey; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.ManyToMany; -import javax.persistence.OneToOne; -import javax.persistence.Table; - import org.springframework.statemachine.data.RepositoryAction; import org.springframework.statemachine.data.RepositoryState; import org.springframework.statemachine.state.PseudoStateKind; @@ -39,6 +24,22 @@ import org.springframework.statemachine.state.PseudoStateKind; import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.fasterxml.jackson.annotation.ObjectIdGenerators; +import jakarta.persistence.CollectionTable; +import jakarta.persistence.Column; +import jakarta.persistence.ElementCollection; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.ForeignKey; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinTable; +import jakarta.persistence.ManyToMany; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; + /** * JPA entity for states. * @@ -76,7 +77,7 @@ public class JpaRepositoryState extends RepositoryState { @JoinColumn(foreignKey = @ForeignKey(name = "fk_state_initial_action")) private JpaRepositoryAction initialAction; - @OneToOne(fetch = FetchType.EAGER) + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(foreignKey = @ForeignKey(name = "fk_state_parent_state")) private JpaRepositoryState parentState; diff --git a/spring-statemachine-data/jpa/src/main/java/org/springframework/statemachine/data/jpa/JpaRepositoryStateMachine.java b/spring-statemachine-data/jpa/src/main/java/org/springframework/statemachine/data/jpa/JpaRepositoryStateMachine.java index 7a63d8b6..8a045c40 100644 --- a/spring-statemachine-data/jpa/src/main/java/org/springframework/statemachine/data/jpa/JpaRepositoryStateMachine.java +++ b/spring-statemachine-data/jpa/src/main/java/org/springframework/statemachine/data/jpa/JpaRepositoryStateMachine.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020 the original author or authors. + * Copyright 2017-2023 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. @@ -15,17 +15,17 @@ */ package org.springframework.statemachine.data.jpa; -import javax.persistence.Entity; -import javax.persistence.Lob; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.persistence.Column; - import org.springframework.statemachine.data.RepositoryStateMachine; import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.fasterxml.jackson.annotation.ObjectIdGenerators; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Lob; +import jakarta.persistence.Table; + /** * A {@link RepositoryStateMachine} interface for JPA used for states machines. * diff --git a/spring-statemachine-data/jpa/src/main/java/org/springframework/statemachine/data/jpa/JpaRepositoryTransition.java b/spring-statemachine-data/jpa/src/main/java/org/springframework/statemachine/data/jpa/JpaRepositoryTransition.java index f152674b..ffb92e40 100644 --- a/spring-statemachine-data/jpa/src/main/java/org/springframework/statemachine/data/jpa/JpaRepositoryTransition.java +++ b/spring-statemachine-data/jpa/src/main/java/org/springframework/statemachine/data/jpa/JpaRepositoryTransition.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 the original author or authors. + * Copyright 2016-2023 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. @@ -17,25 +17,25 @@ package org.springframework.statemachine.data.jpa; import java.util.Set; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.persistence.Column; -import javax.persistence.OneToOne; -import javax.persistence.FetchType; -import javax.persistence.JoinColumn; -import javax.persistence.ForeignKey; -import javax.persistence.ManyToMany; -import javax.persistence.JoinTable; - import org.springframework.statemachine.data.RepositoryTransition; import org.springframework.statemachine.transition.TransitionKind; import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.fasterxml.jackson.annotation.ObjectIdGenerators; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.ForeignKey; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinTable; +import jakarta.persistence.ManyToMany; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; + /** * JPA entity for transitions. * @@ -55,11 +55,11 @@ public class JpaRepositoryTransition extends RepositoryTransition { @Column(name = "machine_id") private String machineId; - @OneToOne(fetch = FetchType.EAGER) + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(foreignKey = @ForeignKey(name = "fk_transition_source")) private JpaRepositoryState source; - @OneToOne(fetch = FetchType.EAGER) + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(foreignKey = @ForeignKey(name = "fk_transition_target")) private JpaRepositoryState target; @@ -73,7 +73,7 @@ public class JpaRepositoryTransition extends RepositoryTransition { @JoinTable(foreignKey = @ForeignKey(name = "fk_transition_actions_t"), inverseForeignKey = @ForeignKey(name = "fk_transition_actions_a")) private Set actions; - @OneToOne(fetch = FetchType.EAGER) + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(foreignKey = @ForeignKey(name = "fk_transition_guard")) private JpaRepositoryGuard guard; diff --git a/spring-statemachine-data/mongodb/src/test/java/org/springframework/statemachine/data/mongodb/EnabledOnMongoDbCondition.java b/spring-statemachine-data/mongodb/src/test/java/org/springframework/statemachine/data/mongodb/EnabledOnMongoDbCondition.java index 76512d2f..014553a8 100644 --- a/spring-statemachine-data/mongodb/src/test/java/org/springframework/statemachine/data/mongodb/EnabledOnMongoDbCondition.java +++ b/spring-statemachine-data/mongodb/src/test/java/org/springframework/statemachine/data/mongodb/EnabledOnMongoDbCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 the original author or authors. + * Copyright 2019-2023 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. @@ -18,24 +18,36 @@ package org.springframework.statemachine.data.mongodb; import static org.junit.jupiter.api.extension.ConditionEvaluationResult.disabled; import static org.junit.jupiter.api.extension.ConditionEvaluationResult.enabled; +import java.net.InetAddress; +import java.net.ServerSocket; + +import javax.net.ServerSocketFactory; + import org.junit.jupiter.api.extension.ConditionEvaluationResult; import org.junit.jupiter.api.extension.ExecutionCondition; import org.junit.jupiter.api.extension.ExtensionContext; -import org.springframework.util.SocketUtils; public class EnabledOnMongoDbCondition implements ExecutionCondition { static final ConditionEvaluationResult ENABLED_ON_MONGO = enabled("Mongo DB found"); - static final ConditionEvaluationResult DISABLED_ON_MONGO = disabled("Mongo DB not found"); + static final ConditionEvaluationResult DISABLED_ON_MONGO = disabled("Mongo DB not found"); @Override public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { - try { - SocketUtils.findAvailableTcpPort(27017, 27017); - return DISABLED_ON_MONGO; - } catch (Exception e) { - } - return ENABLED_ON_MONGO; + return isPortAvailable(27017) ? DISABLED_ON_MONGO : ENABLED_ON_MONGO; } + + private static boolean isPortAvailable(int port) { + try { + ServerSocket serverSocket = ServerSocketFactory.getDefault() + .createServerSocket(port, 1, InetAddress.getByName("localhost")); + serverSocket.close(); + return true; + } + catch (Exception ex) { + return false; + } + } + } diff --git a/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisRepositoryAction.java b/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisRepositoryAction.java index 8962fd7c..832a3e0b 100644 --- a/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisRepositoryAction.java +++ b/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisRepositoryAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2023 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. @@ -16,11 +16,6 @@ package org.springframework.statemachine.data.redis; import org.springframework.data.annotation.Id; - -//import javax.persistence.GeneratedValue; -//import javax.persistence.GenerationType; -//import javax.persistence.Id; - import org.springframework.data.redis.core.RedisHash; import org.springframework.statemachine.data.RepositoryAction; diff --git a/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisRepositoryGuard.java b/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisRepositoryGuard.java index bb067cf9..6bcf99a7 100644 --- a/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisRepositoryGuard.java +++ b/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisRepositoryGuard.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2023 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. @@ -16,11 +16,6 @@ package org.springframework.statemachine.data.redis; import org.springframework.data.annotation.Id; - -//import javax.persistence.GeneratedValue; -//import javax.persistence.GenerationType; -//import javax.persistence.Id; - import org.springframework.data.redis.core.RedisHash; import org.springframework.statemachine.data.RepositoryGuard; diff --git a/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisRepositoryState.java b/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisRepositoryState.java index 91699b28..cb8a053e 100644 --- a/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisRepositoryState.java +++ b/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisRepositoryState.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2023 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. @@ -17,14 +17,6 @@ package org.springframework.statemachine.data.redis; import java.util.Set; -//import javax.persistence.ElementCollection; -//import javax.persistence.FetchType; -//import javax.persistence.GeneratedValue; -//import javax.persistence.GenerationType; -//import javax.persistence.Id; -//import javax.persistence.OneToMany; -//import javax.persistence.OneToOne; - import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Reference; import org.springframework.data.redis.core.RedisHash; diff --git a/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisRepositoryTransition.java b/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisRepositoryTransition.java index dfe2aec5..e827837d 100644 --- a/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisRepositoryTransition.java +++ b/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisRepositoryTransition.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2023 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. @@ -19,14 +19,6 @@ import java.util.Set; import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Reference; - -//import javax.persistence.FetchType; -//import javax.persistence.GeneratedValue; -//import javax.persistence.GenerationType; -//import javax.persistence.Id; -//import javax.persistence.OneToMany; -//import javax.persistence.OneToOne; - import org.springframework.data.redis.core.RedisHash; import org.springframework.data.redis.core.index.Indexed; import org.springframework.statemachine.data.RepositoryTransition; diff --git a/spring-statemachine-platform/build.gradle b/spring-statemachine-platform/build.gradle index 90d74ad4..7cf6b95b 100644 --- a/spring-statemachine-platform/build.gradle +++ b/spring-statemachine-platform/build.gradle @@ -10,7 +10,7 @@ dependencies { api platform("org.springframework.boot:spring-boot-dependencies:$springBootVersion") constraints { api "log4j:log4j:$log4jVersion" - api "org.eclipse.persistence:javax.persistence:$eclipsePersistenceVersion" + api "jakarta.persistence:jakarta.persistence-api:$jakartaPersistenceVersion" api "com.esotericsoftware:kryo-shaded:$kryoVersion" api "org.springframework.shell:spring-shell:$springShellVersion" api "org.eclipse.uml2:uml:$eclipseUml2UmlVersion" diff --git a/spring-statemachine-samples/datapersist/src/main/java/demo/datapersist/StateMachineConfig.java b/spring-statemachine-samples/datapersist/src/main/java/demo/datapersist/StateMachineConfig.java index 0975c656..1bb1fc16 100644 --- a/spring-statemachine-samples/datapersist/src/main/java/demo/datapersist/StateMachineConfig.java +++ b/spring-statemachine-samples/datapersist/src/main/java/demo/datapersist/StateMachineConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2018 the original author or authors. + * Copyright 2017-2023 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. diff --git a/spring-statemachine-samples/datapersist/src/main/resources/application.yml b/spring-statemachine-samples/datapersist/src/main/resources/application.yml index 5c16dccf..243f1fc8 100644 --- a/spring-statemachine-samples/datapersist/src/main/resources/application.yml +++ b/spring-statemachine-samples/datapersist/src/main/resources/application.yml @@ -13,7 +13,9 @@ security: --- spring: - profiles: jpa + config: + activate: + on-profile: jpa statemachine: data: mongo: @@ -24,7 +26,9 @@ spring: enabled: false --- spring: - profiles: mongo + config: + activate: + on-profile: mongo statemachine: data: jpa: @@ -35,7 +39,9 @@ spring: enabled: false --- spring: - profiles: redis + config: + activate: + on-profile: redis statemachine: data: jpa: diff --git a/spring-statemachine-samples/security/src/main/java/demo/security/StateMachineConfig.java b/spring-statemachine-samples/security/src/main/java/demo/security/StateMachineConfig.java index 71565c5f..a47b59a4 100644 --- a/spring-statemachine-samples/security/src/main/java/demo/security/StateMachineConfig.java +++ b/spring-statemachine-samples/security/src/main/java/demo/security/StateMachineConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2023 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. @@ -22,17 +22,15 @@ import java.util.Scanner; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.core.io.ClassPathResource; import org.springframework.security.access.annotation.Secured; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.provisioning.InMemoryUserDetailsManager; import org.springframework.statemachine.StateContext; import org.springframework.statemachine.action.Action; import org.springframework.statemachine.config.EnableStateMachine; @@ -47,22 +45,22 @@ public class StateMachineConfig { private static final Log log = LogFactory.getLog(StateMachineConfig.class); -//tag::snippetE[] - @EnableWebSecurity - @EnableGlobalMethodSecurity(securedEnabled = true) - static class SecurityConfig extends WebSecurityConfigurerAdapter { + //tag::snippetE[] + static class SecurityConfig { - @Autowired - public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { - auth - .inMemoryAuthentication() - .withUser("user") - .password("password") - .roles("USER") - .and() - .withUser("admin") - .password("password") - .roles("USER", "ADMIN"); + @Bean + public InMemoryUserDetailsManager userDetailsService() { + UserDetails user = User.withDefaultPasswordEncoder() + .username("user") + .password("password") + .roles("USER") + .build(); + UserDetails admin = User.withDefaultPasswordEncoder() + .username("admin") + .password("password") + .roles("USER", "ADMIN") + .build(); + return new InMemoryUserDetailsManager(user, admin); } } //end::snippetE[] @@ -72,7 +70,7 @@ public class StateMachineConfig { static class Config extends EnumStateMachineConfigurerAdapter { -//tag::snippetA[] + //tag::snippetA[] @Override public void configure(StateMachineConfigurationConfigurer config) throws Exception { @@ -90,12 +88,12 @@ public class StateMachineConfig { public void configure(StateMachineStateConfigurer states) throws Exception { states - .withStates() + .withStates() .initial(States.S0) .states(EnumSet.allOf(States.class)); } -//tag::snippetB[] + //tag::snippetB[] @Override public void configure(StateMachineTransitionConfigurer transitions) throws Exception { @@ -127,7 +125,7 @@ public class StateMachineConfig { } //end::snippetB[] -//tag::snippetC[] + //tag::snippetC[] @Scope(proxyMode = ScopedProxyMode.TARGET_CLASS) @Bean public Action adminAction() { @@ -142,7 +140,7 @@ public class StateMachineConfig { } //end::snippetC[] -//tag::snippetD[] + //tag::snippetD[] @Bean public Action transitionAction() { return new Action() { diff --git a/spring-statemachine-samples/web/src/main/java/demo/web/StateMachineController.java b/spring-statemachine-samples/web/src/main/java/demo/web/StateMachineController.java index cacf99f4..139b0682 100644 --- a/spring-statemachine-samples/web/src/main/java/demo/web/StateMachineController.java +++ b/spring-statemachine-samples/web/src/main/java/demo/web/StateMachineController.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 the original author or authors. + * Copyright 2015-2023 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. @@ -20,8 +20,6 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; -import javax.annotation.PostConstruct; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -49,6 +47,7 @@ import org.springframework.web.bind.annotation.ResponseStatus; import demo.web.StateMachineConfig.Events; import demo.web.StateMachineConfig.States; +import jakarta.annotation.PostConstruct; import reactor.core.publisher.Mono; @Controller