diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1f65c57ee..bf431987a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,3 @@ -# This workflow will build a Java project with Gradle -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle - name: Build on: @@ -17,25 +14,14 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up JDK 1.17 + + - name: Set up JDK 17 uses: actions/setup-java@v3 with: distribution: 'temurin' java-version: '17' - - name: Cache Gradle packages - uses: actions/cache@v3 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: | - ${{ runner.os }}-gradle- + - name: Build with Gradle - run: ./gradlew build jacocoTestReport jacocoTestCoverageVerification - - name: Cleanup Gradle Cache - # Remove some files from the Gradle cache, so they aren't cached by GitHub Actions. - # Restoring these files from a GitHub Actions cache might cause problems for future builds. - run: | - rm -f ~/.gradle/caches/modules-2/modules-2.lock - rm -f ~/.gradle/caches/modules-2/gc.properties + uses: gradle/gradle-build-action@v2 + with: + arguments: build jacocoTestReport jacocoTestCoverageVerification diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 14ee1c9b8..fcf0fd98d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,6 +1,3 @@ -# Release any branch to Maven Central. -# This workflow currently assumes that the target branch is ready to be release (i.e. version is correct) - name: Release on: @@ -15,34 +12,25 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Set up JDK 17 uses: actions/setup-java@v3 with: distribution: 'temurin' java-version: '17' - - name: Cache Gradle packages - uses: actions/cache@v3 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: | - ${{ runner.os }}-gradle- - - name: Build with Gradle + + - name: Prepare key run: | mkdir -p ~/.gnupg/ printf "$GPG_KEY_BASE64" | base64 --decode > ~/.gnupg/secring.gpg - ./gradlew -PmavenRepoUsername=$MAVEN_USERNAME -PmavenRepoPassword=$MAVEN_PASSWORD -Psigning.keyId=$GPG_KEY_ID -Psigning.secretKeyRingFile=$HOME/.gnupg/secring.gpg -Psigning.password=$GPG_KEY_PASSPHRASE publishToSonatype closeAndReleaseStagingRepository + + - name: Build with Gradle + uses: gradle/gradle-build-action@v2 env: GPG_KEY_BASE64: ${{ secrets.GPG_KEY_BASE64 }} MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} GPG_KEY_PASSPHRASE: ${{ secrets.GPG_KEY_PASSPHRASE }} - - name: Cleanup Gradle Cache - # Remove some files from the Gradle cache, so they aren't cached by GitHub Actions. - # Restoring these files from a GitHub Actions cache might cause problems for future builds. - run: | - rm -f ~/.gradle/caches/modules-2/modules-2.lock - rm -f ~/.gradle/caches/modules-2/gc.properties + with: + arguments: -PmavenRepoUsername=$MAVEN_USERNAME -PmavenRepoPassword=$MAVEN_PASSWORD -Psigning.keyId=$GPG_KEY_ID -Psigning.secretKeyRingFile=$HOME/.gnupg/secring.gpg -Psigning.password=$GPG_KEY_PASSPHRASE publishToSonatype closeAndReleaseStagingRepository diff --git a/allow-list.xml b/allow-list.xml index 1769b82d3..3b1f67777 100644 --- a/allow-list.xml +++ b/allow-list.xml @@ -2,77 +2,24 @@ - org.yaml:snakeyaml:1.30 - CVE-2022-25857 - CVE-2022-38751 - CVE-2022-38749 - CVE-2022-38752 - CVE-2022-41854 - CVE-2022-38750 - CVE-2022-1471 - - - - org.yaml:snakeyaml:1.31 - CVE-2022-38751 - CVE-2022-38752 - CVE-2022-41854 - CVE-2022-1471 - - - - org.yaml:snakeyaml:1.33 - CVE-2022-1471 - - - - org.springframework.security:spring-security-crypto:5.7.8 - CVE-2020-5408 - - - - org.springframework:spring-web:5.3.27 - CVE-2016-1000027 - - - - ^(?!pkg:maven/commons-net/commons-net).*$ - cpe:/a:apache:commons_net - - - - org.json:json:20231013 - CVE-2022-45688 - CVE-2023-5072 + ^pkg:maven/org\.json/json@.*$ + CVE-2022-45688 + CVE-2023-5072 - net.minidev:json-smart:2.4.8 - CVE-2023-1370 + ch.qos.logback:logback-core:1.4.11 + CVE-2023-6378 - io.netty:netty-bom:4.1.101.Final - CVE-2023-4586 + ch.qos.logback:logback-classic:1.4.11 + CVE-2023-6378 diff --git a/buildSrc/src/main/groovy/bdk.java-common-conventions.gradle b/buildSrc/src/main/groovy/bdk.java-common-conventions.gradle index fccbaa768..d264a0fca 100644 --- a/buildSrc/src/main/groovy/bdk.java-common-conventions.gradle +++ b/buildSrc/src/main/groovy/bdk.java-common-conventions.gradle @@ -13,6 +13,7 @@ sourceCompatibility = JavaVersion.VERSION_17 tasks.withType(JavaCompile) { options.encoding = 'UTF-8' + options.compilerArgs << '-parameters' } javadoc { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f398c33c4..3499ded5c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle index ba21a8969..c4e128535 100644 --- a/settings.gradle +++ b/settings.gradle @@ -23,7 +23,6 @@ include(':symphony-bdk-spring:symphony-bdk-app-spring-boot-starter') // examples include(':symphony-bdk-examples:bdk-core-examples') include(':symphony-bdk-examples:bdk-spring-boot-example') -include(':symphony-bdk-examples:bdk-template-examples') include(':symphony-bdk-examples:bdk-app-spring-boot-example') include(':symphony-bdk-examples:bdk-multi-instances-example') include(':symphony-bdk-examples:bdk-group-example') @@ -34,4 +33,3 @@ include(':symphony-bdk-extensions:symphony-group-extension') // test framework include(':symphony-bdk-test:symphony-bdk-test-spring-boot') include(':symphony-bdk-test:symphony-bdk-test-jupiter') - diff --git a/symphony-bdk-bom/build.gradle b/symphony-bdk-bom/build.gradle index b17639f3c..4848f84d8 100644 --- a/symphony-bdk-bom/build.gradle +++ b/symphony-bdk-bom/build.gradle @@ -16,13 +16,13 @@ repositories { dependencies { // import Spring Boot's BOM - api platform('org.springframework.boot:spring-boot-dependencies:3.0.13') + api platform('org.springframework.boot:spring-boot-dependencies:3.2.0') // import Jackson's BOM - api platform('com.fasterxml.jackson:jackson-bom:2.15.3') + api platform('com.fasterxml.jackson:jackson-bom:2.16.0') // import Jersey's BOM - api platform('org.glassfish.jersey:jersey-bom:3.1.2') + api platform('org.glassfish.jersey:jersey-bom:3.1.5') // import Log4j's BOM - api platform('org.apache.logging.log4j:log4j-bom:2.20.0') + api platform('org.apache.logging.log4j:log4j-bom:2.22.0') // define all our dependencies versions constraints { @@ -42,46 +42,41 @@ dependencies { api "org.finos.symphony.bdk.ext:symphony-group-extension:$project.version" // External dependencies - api 'org.projectlombok:lombok:1.18.26' api 'org.apiguardian:apiguardian-api:1.1.2' - api 'org.slf4j:slf4j-api:2.0.7' - api 'org.slf4j:slf4j-log4j12:2.0.7' + api 'org.slf4j:slf4j-api:2.0.9' + api 'org.slf4j:slf4j-log4j12:2.0.9' - // Logback is used by default for Spring based projects, force the version for LOGBACK-1591 - api 'ch.qos.logback:logback-classic:1.4.7' - api 'ch.qos.logback:logback-core:1.4.7' - - api 'commons-io:commons-io:2.11.0' - api 'commons-codec:commons-codec:1.15' + api 'commons-io:commons-io:2.15.1' + api 'commons-codec:commons-codec:1.16.0' api 'commons-beanutils:commons-beanutils:1.9.4' - api 'org.apache.commons:commons-lang3:3.12.0' - api 'org.apache.commons:commons-text:1.10.0' - api 'commons-logging:commons-logging:1.2' + api 'org.apache.commons:commons-lang3:3.14.0' + api 'org.apache.commons:commons-text:1.11.0' + api 'commons-logging:commons-logging:1.3.0' api 'com.brsanthu:migbase64:2.2' - api 'io.jsonwebtoken:jjwt:0.9.1' - api 'org.bouncycastle:bcpkix-jdk18on:1.74' + api 'io.jsonwebtoken:jjwt:0.12.3' + api 'org.bouncycastle:bcpkix-jdk18on:1.77' api 'com.google.code.findbugs:jsr305:3.0.2' - api 'io.github.resilience4j:resilience4j-retry:2.1.0' + api 'io.github.resilience4j:resilience4j-retry:2.2.0' - api 'io.swagger:swagger-annotations:1.6.0' - api 'org.openapitools:jackson-databind-nullable:0.2.2' + api 'io.swagger:swagger-annotations:1.6.12' + api 'org.openapitools:jackson-databind-nullable:0.2.6' api 'org.projectreactor:reactor-spring:1.0.1.RELEASE' api 'org.freemarker:freemarker:2.3.32' api 'com.github.jknack:handlebars:4.3.1' - api 'org.reflections:reflections:0.9.12' + api 'org.reflections:reflections:0.10.2' - api 'org.junit.jupiter:junit-jupiter:5.9.2' - api 'org.junit.jupiter:junit-jupiter-api:5.9.2' - api 'org.junit.jupiter:junit-jupiter-engine:5.9.2' - api 'com.tngtech.archunit:archunit-junit5:0.22.0' + api 'org.junit.jupiter:junit-jupiter:5.10.1' + api 'org.junit.jupiter:junit-jupiter-api:5.10.1' + api 'org.junit.jupiter:junit-jupiter-engine:5.10.1' + api 'com.tngtech.archunit:archunit-junit5:1.2.1' api 'org.mock-server:mockserver-netty:5.15.0' - api 'org.mockito:mockito-core:4.11.0' - api 'org.mockito:mockito-junit-jupiter:4.11.0' + api 'org.mockito:mockito-core:5.8.0' + api 'org.mockito:mockito-junit-jupiter:5.8.0' api 'org.assertj:assertj-core:3.24.2' api 'jakarta.ws.rs:jakarta.ws.rs-api:3.1.0' diff --git a/symphony-bdk-config/src/main/java/com/symphony/bdk/core/config/BdkConfigLoader.java b/symphony-bdk-config/src/main/java/com/symphony/bdk/core/config/BdkConfigLoader.java index b63f154fa..413005510 100644 --- a/symphony-bdk-config/src/main/java/com/symphony/bdk/core/config/BdkConfigLoader.java +++ b/symphony-bdk-config/src/main/java/com/symphony/bdk/core/config/BdkConfigLoader.java @@ -1,8 +1,6 @@ package com.symphony.bdk.core.config; import com.symphony.bdk.core.config.exception.BdkConfigException; -import com.symphony.bdk.core.config.legacy.LegacyConfigMapper; -import com.symphony.bdk.core.config.legacy.model.LegacySymConfig; import com.symphony.bdk.core.config.model.BdkConfig; import com.fasterxml.jackson.databind.DeserializationFeature; @@ -60,16 +58,7 @@ public static BdkConfig loadFromFile(String configPath) throws BdkConfigExceptio */ public static BdkConfig loadFromInputStream(InputStream inputStream) throws BdkConfigException { BdkConfigParser parser = new BdkConfigParser(); - return parseConfig(parser.parse(inputStream)); - } - - private static BdkConfig parseConfig(JsonNode jsonNode) { - if (jsonNode.at("/botUsername").isMissingNode()) { - return JSON_MAPPER.convertValue(jsonNode, BdkConfig.class); - } else { - LegacySymConfig legacySymConfig = JSON_MAPPER.convertValue(jsonNode, LegacySymConfig.class); - return LegacyConfigMapper.map(legacySymConfig); - } + return JSON_MAPPER.convertValue(parser.parse(inputStream), BdkConfig.class); } /** @@ -118,9 +107,9 @@ public static BdkConfig loadFromClasspath(String configPath) throws BdkConfigExc * @param properties {@link Properties} with BDK properties * @return Symphony Bot Configuration */ + @SuppressWarnings("unchecked") public static BdkConfig loadFromProperties(Properties properties) throws IOException { - final Map propertyMap = (Map) properties; - return loadFromPropertyMap(propertyMap); + return loadFromPropertyMap((Map) (Map) properties); } /** @@ -132,5 +121,4 @@ public static BdkConfig loadFromProperties(Properties properties) throws IOExcep public static BdkConfig loadFromPropertyMap(Map properties) throws IOException { return PROPS_MAPPER.readMapAs(properties, BdkConfig.class); } - } diff --git a/symphony-bdk-config/src/main/java/com/symphony/bdk/core/config/legacy/LegacyConfigMapper.java b/symphony-bdk-config/src/main/java/com/symphony/bdk/core/config/legacy/LegacyConfigMapper.java deleted file mode 100644 index 11734b109..000000000 --- a/symphony-bdk-config/src/main/java/com/symphony/bdk/core/config/legacy/LegacyConfigMapper.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.symphony.bdk.core.config.legacy; - -import com.symphony.bdk.core.config.legacy.model.LegacySymConfig; -import com.symphony.bdk.core.config.model.*; - -import org.apiguardian.api.API; - -/** - * Legacy config mapper. - * - *

- * This class will have to be removed in the future. - *

- */ -@Deprecated -@API(status = API.Status.DEPRECATED) -public class LegacyConfigMapper { - - public static BdkConfig map(LegacySymConfig legacySymConfig) { - BdkClientConfig pod = new BdkClientConfig(); - pod.setHost(legacySymConfig.getPodHost()); - pod.setPort(legacySymConfig.getPodPort()); - pod.setContext(legacySymConfig.getPodContextPath()); - - BdkAgentConfig agent = new BdkAgentConfig(); - agent.setHost(legacySymConfig.getAgentHost()); - agent.setPort(legacySymConfig.getAgentPort()); - agent.setContext(legacySymConfig.getAgentContextPath()); - - BdkClientConfig keyManager = new BdkClientConfig(); - keyManager.setHost(legacySymConfig.getKeyAuthHost()); - keyManager.setPort(legacySymConfig.getKeyAuthPort()); - keyManager.setContext(legacySymConfig.getKeyAuthContextPath()); - - BdkBotConfig bot = new BdkBotConfig(); - bot.setUsername(legacySymConfig.getBotUsername()); - if (legacySymConfig.getBotPrivateKeyPath() != null && legacySymConfig.getBotPrivateKeyName() != null) { - bot.setPrivateKeyPath(legacySymConfig.getBotPrivateKeyPath() + legacySymConfig.getBotPrivateKeyName()); - } - if (legacySymConfig.getBotCertPath() != null && legacySymConfig.getAppCertName() != null) { - bot.setCertificatePath(legacySymConfig.getBotCertPath() + legacySymConfig.getBotCertName()); - } - bot.setCertificatePassword(legacySymConfig.getBotCertPassword()); - - BdkExtAppConfig app = new BdkExtAppConfig(); - app.setAppId(legacySymConfig.getAppId()); - if (legacySymConfig.getAppPrivateKeyPath() != null && legacySymConfig.getAppPrivateKeyName() != null) { - app.setPrivateKeyPath(legacySymConfig.getAppPrivateKeyPath() + legacySymConfig.getAppPrivateKeyName()); - } - if (legacySymConfig.getAppCertPath() != null && legacySymConfig.getAppCertName() != null) { - app.setCertificatePath(legacySymConfig.getAgentContextPath() + legacySymConfig.getAppCertName()); - } - app.setCertificatePassword(legacySymConfig.getAppCertPassword()); - - BdkSslConfig ssl = new BdkSslConfig(); - ssl.setTrustStorePath(legacySymConfig.getTruststorePath()); - ssl.setTrustStorePassword(legacySymConfig.getTruststorePassword()); - - BdkDatafeedConfig datafeed = new BdkDatafeedConfig(); - datafeed.setIdFilePath(legacySymConfig.getDatafeedIdFilePath()); - datafeed.setVersion(legacySymConfig.getDatafeedVersion()); - - BdkRetryConfig retry = new BdkRetryConfig(); - retry.setInitialIntervalMillis(legacySymConfig.getRetry().getInitialIntervalMillis()); - retry.setMultiplier(legacySymConfig.getRetry().getMultiplier()); - retry.setMaxAttempts(legacySymConfig.getRetry().getMaxAttempts()); - - BdkConfig config = new BdkConfig(); - config.setAgent(agent); - config.setPod(pod); - config.setKeyManager(keyManager); - config.setBot(bot); - config.setApp(app); - config.setSsl(ssl); - config.setDatafeed(datafeed); - config.setRetry(retry); - return config; - } -} diff --git a/symphony-bdk-config/src/main/java/com/symphony/bdk/core/config/legacy/model/LegacyRetryConfiguration.java b/symphony-bdk-config/src/main/java/com/symphony/bdk/core/config/legacy/model/LegacyRetryConfiguration.java deleted file mode 100644 index b90c789bd..000000000 --- a/symphony-bdk-config/src/main/java/com/symphony/bdk/core/config/legacy/model/LegacyRetryConfiguration.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.symphony.bdk.core.config.legacy.model; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import org.apiguardian.api.API; - -/** - * Sub-configuration class for Retry parametrization. Experimental, the contract might change in the future. - * - *

- * This class will have to be removed in the future. - *

- */ -@ToString -@Getter @Setter -@Deprecated -@API(status = API.Status.DEPRECATED) -public class LegacyRetryConfiguration { - - public static final int DEFAULT_MAX_ATTEMPTS = 10; - public static final long DEFAULT_INITIAL_INTERVAL_MILLIS = 500L; - public static final double DEFAULT_MULTIPLIER = 1.5; - - private int maxAttempts = DEFAULT_MAX_ATTEMPTS; - private long initialIntervalMillis = DEFAULT_INITIAL_INTERVAL_MILLIS; - private double multiplier = DEFAULT_MULTIPLIER; -} diff --git a/symphony-bdk-config/src/main/java/com/symphony/bdk/core/config/legacy/model/LegacySymConfig.java b/symphony-bdk-config/src/main/java/com/symphony/bdk/core/config/legacy/model/LegacySymConfig.java deleted file mode 100644 index 423505b0e..000000000 --- a/symphony-bdk-config/src/main/java/com/symphony/bdk/core/config/legacy/model/LegacySymConfig.java +++ /dev/null @@ -1,167 +0,0 @@ -package com.symphony.bdk.core.config.legacy.model; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import lombok.Getter; -import lombok.Setter; -import org.apiguardian.api.API; - -import java.io.File; -import java.util.ArrayList; - -/** - * Legacy config model. - * - *

- * This class will have to be removed in the future. - *

- */ -@Getter -@Setter -@JsonIgnoreProperties(ignoreUnknown = true) -@Deprecated -@API(status = API.Status.DEPRECATED) -public class LegacySymConfig { - - private static final int DEFAULT_CONNECTION_TIMEOUT = 10_000; - private static final int DEFAULT_READ_TIMEOUT = 35_000; - private static final String DEFAULT_SCHEME = "https"; - private static final int DEFAULT_PORT = 443; - - private String _version = "1.0"; - - // ---------------------------------------------------------------------------------------------------------------// - // NETWORK - // - private String scheme = DEFAULT_SCHEME; - private String sessionAuthHost; - private int sessionAuthPort = DEFAULT_PORT; - private String sessionAuthContextPath = ""; - - private String keyAuthHost; - private int keyAuthPort = DEFAULT_PORT; - private String keyAuthContextPath = ""; - private String keyManagerProxyURL; - private String keyManagerProxyUsername; - private String keyManagerProxyPassword; - - private String podHost; - private int podPort = DEFAULT_PORT; - private String podContextPath = ""; - private String podProxyURL; - private String podProxyUsername; - private String podProxyPassword; - - private String agentHost; - private int agentPort = DEFAULT_PORT; - private String agentContextPath = ""; - private String agentProxyURL; - private String agentProxyUsername; - private String agentProxyPassword; - - private String proxyURL; - private String proxyUsername; - private String proxyPassword; - - - - private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT; - private int readTimeout = DEFAULT_READ_TIMEOUT; - - // ---------------------------------------------------------------------------------------------------------------// - // AUTHENTICATION - // - private String botUsername; - private String botEmailAddress; - // rsa - private String botPrivateKeyPath; - private String botPrivateKeyName; - // cert - private String botCertPath; - private String botCertName; - private String botCertPassword; - - private String appId; - // rsa - private String appPrivateKeyPath; - private String appPrivateKeyName; - // cert - private String appCertPath; - private String appCertName; - private String appCertPassword; - - // ---------------------------------------------------------------------------------------------------------------// - // SSL - // - private String truststorePath; - private String truststorePassword; - - // ---------------------------------------------------------------------------------------------------------------// - // DATAFEED - private String datafeedVersion = "v1"; - private int datafeedEventsThreadpoolSize; - private int datafeedEventsErrorTimeout; - private Boolean reuseDatafeedID; - private String datafeedIdFilePath; - - // ---------------------------------------------------------------------------------------------------------------// - // MISC - // - private String authenticationFilterUrlPattern; - private boolean showFirehoseErrors; - private ArrayList supportedUriSchemes = new ArrayList<>(); - private LegacyRetryConfiguration retry = new LegacyRetryConfiguration(); - - public String getAgentUrl() { - String port = (this.getAgentPort() == DEFAULT_PORT) ? "" : ":" + this.getAgentPort(); - String contextPath = formatContextPath(this.getAgentContextPath()); - return this.getScheme() + "://" + this.getAgentHost() + port + contextPath; - } - - public String getPodUrl() { - String port = (this.getPodPort() == DEFAULT_PORT) ? "" : ":" + this.getPodPort(); - String contextPath = formatContextPath(this.getPodContextPath()); - return this.getScheme() + "://" + this.getPodHost() + port + contextPath; - } - - public String getKeyAuthUrl() { - String port = (this.getKeyAuthPort() == DEFAULT_PORT) ? "" : ":" + this.getKeyAuthPort(); - String contextPath = formatContextPath(this.getKeyAuthContextPath()); - return this.getScheme() + "://" + this.getKeyAuthHost() + port + contextPath; - } - - public String getSessionAuthUrl() { - String port = (this.getSessionAuthPort() == DEFAULT_PORT) ? "" : ":" + this.getSessionAuthPort(); - String contextPath = formatContextPath(this.getSessionAuthContextPath()); - return this.getScheme() + "://" + this.getSessionAuthHost() + port + contextPath; - } - - public String getDatafeedIdFilePath() { - if (datafeedIdFilePath == null || datafeedIdFilePath.isEmpty()) { - return "." + File.separator; - } - if (!datafeedIdFilePath.endsWith(File.separator)) { - return datafeedIdFilePath + File.separator; - } - return datafeedIdFilePath; - } - - private String formatContextPath(String contextPath) { - String formattedPath = (contextPath == null) ? "" : contextPath; - if (!formattedPath.equals("") && formattedPath.charAt(0) != '/') { - formattedPath = "/" + formattedPath; - } - if (!formattedPath.equals("") && formattedPath.endsWith("/")) { - formattedPath = formattedPath.substring(0, formattedPath.length() - 1); - } - return formattedPath; - } - - public int getDatafeedEventsThreadpoolSize() { - return this.datafeedEventsThreadpoolSize > 0 ? this.datafeedEventsThreadpoolSize : 5; - } - - public int getDatafeedEventsErrorTimeout() { - return this.datafeedEventsErrorTimeout > 0 ? this.datafeedEventsErrorTimeout : 30; - } - -} diff --git a/symphony-bdk-config/src/main/java/com/symphony/bdk/core/config/model/BdkConfig.java b/symphony-bdk-config/src/main/java/com/symphony/bdk/core/config/model/BdkConfig.java index 3f2c50304..425fac6d1 100644 --- a/symphony-bdk-config/src/main/java/com/symphony/bdk/core/config/model/BdkConfig.java +++ b/symphony-bdk-config/src/main/java/com/symphony/bdk/core/config/model/BdkConfig.java @@ -42,7 +42,7 @@ public boolean isBotConfigured() { } /** - * Check if Common JWT feature is enabled. Checks {@link BdkCommonJwtConfig#getEnabled()} ()} on field {@link #commonJwt}. + * Check if Common JWT feature is enabled. Checks {@link BdkCommonJwtConfig#enabled} ()} on field {@link #commonJwt}. * * @return true if Common JWT is enabled. */ @@ -53,7 +53,7 @@ public boolean isCommonJwtEnabled() { /** * Returns the retry configuration used for DataFeed services. * - * @return {@link BdkDatafeedConfig#getRetry()} from {@link #datafeed} if not null, {@link #retry} otherwise + * @return {@link BdkDatafeedConfig#retry} from {@link #datafeed} if not null, {@link #retry} otherwise */ public BdkRetryConfig getDatafeedRetryConfig() { return datafeed.getRetry() == null ? retry : datafeed.getRetry(); diff --git a/symphony-bdk-config/src/test/java/com/symphony/bdk/core/config/BdkConfigLoaderTest.java b/symphony-bdk-config/src/test/java/com/symphony/bdk/core/config/BdkConfigLoaderTest.java index 954b7f48c..76b1334a4 100644 --- a/symphony-bdk-config/src/test/java/com/symphony/bdk/core/config/BdkConfigLoaderTest.java +++ b/symphony-bdk-config/src/test/java/com/symphony/bdk/core/config/BdkConfigLoaderTest.java @@ -84,16 +84,6 @@ void loadFromFileNotFoundTest() { .hasMessage("Config file has not been found from location: /wrong_path/config.yaml"); } - @Test - void loadLegacyFromInputStreamTest() throws BdkConfigException { - final String configPath = "/config/legacy_config.json"; - final InputStream inputStream = BdkConfigLoaderTest.class.getResourceAsStream(configPath); - final BdkConfig config = BdkConfigLoader.loadFromInputStream(inputStream); - assertThat(config.getBot().getUsername()).isEqualTo(BOT_USERNAME); - assertThat(config.getBot().getPrivateKeyPath()).isEqualTo("/Users/local/conf/agent/privatekey.pem"); - assertThat(config.getApp().getPrivateKeyPath()).isEqualTo("/Users/local/conf/agent/privatekey.pem"); - } - @Test void loadFromClasspathNotFoundTest() { assertThatThrownBy(() -> BdkConfigLoader.loadFromClasspath("/wrong_classpath/config.yaml")) diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/jwt/JwtHelper.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/jwt/JwtHelper.java index 74c361f2d..08a99e813 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/jwt/JwtHelper.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/auth/jwt/JwtHelper.java @@ -117,8 +117,8 @@ public static UserClaim validateJwt(String jwt, String certificate) throws AuthI final Certificate x509Certificate = parseX509Certificate(certificate); try { - final Claims body = Jwts.parser().setSigningKey(x509Certificate.getPublicKey()).parseClaimsJws(jwt).getBody(); - + final Claims body = Jwts.parser().verifyWith(x509Certificate.getPublicKey()) + .build().parseSignedClaims(jwt).getPayload(); return mapper.convertValue(body.get("user"), UserClaim.class); } catch (JwtException e) { throw new AuthInitializationException("Unable to validate JWT", e); diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/stream/util/StreamUtil.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/stream/util/StreamUtil.java index 168f7789c..7de9e9c1d 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/stream/util/StreamUtil.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/stream/util/StreamUtil.java @@ -30,6 +30,7 @@ public final class StreamUtil { * @return stream id after conversion * @deprecated Use {@link com.symphony.bdk.core.util.IdUtil#toUrlSafeId(String)} instead. */ + @Deprecated public static String toUrlSafeStreamId(String streamId) { return IdUtil.toUrlSafeIdIfNeeded(streamId); } @@ -46,6 +47,7 @@ public static String toUrlSafeStreamId(String streamId) { * @return stream id after conversion * @deprecated Use {@link com.symphony.bdk.core.util.IdUtil#fromUrlSafeId(String)} instead. */ + @Deprecated public static String fromUrlSafeStreamId(String streamId) { return IdUtil.fromUrlSafeId(streamId); } diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/user/mapper/UserDetailMapper.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/user/mapper/UserDetailMapper.java index 7e5ca7fd1..1de473e7f 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/user/mapper/UserDetailMapper.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/user/mapper/UserDetailMapper.java @@ -5,6 +5,7 @@ import org.apiguardian.api.API; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; @Mapper @@ -13,5 +14,13 @@ public interface UserDetailMapper { UserDetailMapper INSTANCE = Mappers.getMapper(UserDetailMapper.class); + @Mapping(target = "userAttributes.twoFactorAuthPhone", ignore = true) + @Mapping(target = "userAttributes.recommendedLanguage", ignore = true) + @Mapping(target = "userAttributes.marketCoverage", ignore = true) + @Mapping(target = "userAttributes.responsibility", ignore = true) + @Mapping(target = "userAttributes.function", ignore = true) + @Mapping(target = "userAttributes.instrument", ignore = true) + @Mapping(target = "userAttributes.currentKey", ignore = true) + @Mapping(target = "userAttributes.previousKey", ignore = true) V2UserDetail userDetailToV2UserDetail(UserDetail userDetail); } diff --git a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/test/RsaTestHelper.java b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/test/RsaTestHelper.java index 8bab3c8d7..543fbecdb 100644 --- a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/test/RsaTestHelper.java +++ b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/test/RsaTestHelper.java @@ -14,14 +14,14 @@ public class RsaTestHelper { @SneakyThrows public static KeyPair generateKeyPair() { final KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); - kpg.initialize(1024); + kpg.initialize(2048); return kpg.generateKeyPair(); } @SneakyThrows public static String generatePrivateKeyAsString() { final KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); - kpg.initialize(1024); + kpg.initialize(2048); final KeyPair kp = generateKeyPair(); return "-----BEGIN PRIVATE KEY-----\n" + Base64.encodeToString(kp.getPrivate().getEncoded(), true) + diff --git a/symphony-bdk-examples/bdk-app-spring-boot-example/build.gradle b/symphony-bdk-examples/bdk-app-spring-boot-example/build.gradle index 204756eb6..9369a1630 100644 --- a/symphony-bdk-examples/bdk-app-spring-boot-example/build.gradle +++ b/symphony-bdk-examples/bdk-app-spring-boot-example/build.gradle @@ -1,6 +1,6 @@ plugins { id 'bdk.java-common-conventions' - id 'org.springframework.boot' version "2.7.9" + id 'org.springframework.boot' version "3.2.0" } description = 'Symphony Java BDK Examples for the SpringBoot integration' diff --git a/symphony-bdk-examples/bdk-app-spring-boot-example/src/main/java/com/symphony/bdk/examples/app/spring/SecurityConfig.java b/symphony-bdk-examples/bdk-app-spring-boot-example/src/main/java/com/symphony/bdk/examples/app/spring/SecurityConfig.java index b80b4d5de..40001d47b 100644 --- a/symphony-bdk-examples/bdk-app-spring-boot-example/src/main/java/com/symphony/bdk/examples/app/spring/SecurityConfig.java +++ b/symphony-bdk-examples/bdk-app-spring-boot-example/src/main/java/com/symphony/bdk/examples/app/spring/SecurityConfig.java @@ -4,6 +4,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; +import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer; import org.springframework.security.web.SecurityFilterChain; @Configuration @@ -12,10 +14,10 @@ public class SecurityConfig { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { // This configuration is not recommended in production setup - http.authorizeRequests().anyRequest().permitAll(); - http.csrf().disable(); - http.headers().frameOptions().disable(); - return http.build(); + return http.csrf(AbstractHttpConfigurer::disable) + .authorizeHttpRequests(a -> a.anyRequest().permitAll()) + .headers(h -> h.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable)) + .build(); } @Bean diff --git a/symphony-bdk-examples/bdk-spring-boot-example/build.gradle b/symphony-bdk-examples/bdk-spring-boot-example/build.gradle index 8bf6f1f9c..5e1af14dc 100644 --- a/symphony-bdk-examples/bdk-spring-boot-example/build.gradle +++ b/symphony-bdk-examples/bdk-spring-boot-example/build.gradle @@ -1,6 +1,6 @@ plugins { id 'bdk.java-common-conventions' - id 'org.springframework.boot' version "2.7.9" + id 'org.springframework.boot' version "3.2.0" } description = 'Symphony Java BDK Examples for the SpringBoot integration' diff --git a/symphony-bdk-spring/symphony-bdk-app-spring-boot-starter/src/main/java/com/symphony/bdk/app/spring/config/BdkExtAppSecurityConfig.java b/symphony-bdk-spring/symphony-bdk-app-spring-boot-starter/src/main/java/com/symphony/bdk/app/spring/config/BdkExtAppSecurityConfig.java index bc74fca67..20f8ce4f3 100644 --- a/symphony-bdk-spring/symphony-bdk-app-spring-boot-starter/src/main/java/com/symphony/bdk/app/spring/config/BdkExtAppSecurityConfig.java +++ b/symphony-bdk-spring/symphony-bdk-app-spring-boot-starter/src/main/java/com/symphony/bdk/app/spring/config/BdkExtAppSecurityConfig.java @@ -3,73 +3,38 @@ import com.symphony.bdk.app.spring.SymphonyBdkAppProperties; import com.symphony.bdk.app.spring.properties.CorsProperties; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Bean; -import org.springframework.web.servlet.config.annotation.CorsRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; import java.util.List; -import java.util.Map; /** * Configuration and injection of the security beans within the Spring application context. */ @Slf4j +@RequiredArgsConstructor public class BdkExtAppSecurityConfig { + private final SymphonyBdkAppProperties properties; @Bean - public WebMvcConfigurer corsConfigurer(SymphonyBdkAppProperties properties) { - return new BdkExtAppWebMvcConfigurer(properties); - } - - static class BdkExtAppWebMvcConfigurer implements WebMvcConfigurer { - - private static final String WARN_MSG = "CORS property '{}' (mapping '{}') is now deprecated and has been replaced by '{}'. " - + "Please update your application.yaml accordingly."; - - private final SymphonyBdkAppProperties properties; - - public BdkExtAppWebMvcConfigurer(SymphonyBdkAppProperties properties) { - this.properties = properties; - } - - @Override - public void addCorsMappings(CorsRegistry registry) { - for (Map.Entry urlMapping : this.properties.getCors().entrySet()) { - final CorsProperties corsProperties = urlMapping.getValue(); - registry.addMapping(urlMapping.getKey()) - .allowedOrigins(corsProperties.getAllowedOrigins().toArray(new String[0])) - .allowCredentials(getAllowCredentials(urlMapping.getKey(), corsProperties)) - .allowedHeaders(corsProperties.getAllowedHeaders().toArray(new String[0])) - .allowedMethods(getAllowedMethods(urlMapping.getKey(), corsProperties).toArray(new String[0])) - .exposedHeaders(corsProperties.getExposedHeaders().toArray(new String[0])); - } - } - - /** - * Preserve backward compatibility after renaming 'allowed-method' property to 'allowed-methods' - */ - private static List getAllowedMethods(String urlMapping, CorsProperties corsProperties) { - - if (corsProperties.getAllowedMethod() != null) { - log.warn(WARN_MSG, "allowed-method", urlMapping, "allowed-methods"); - return corsProperties.getAllowedMethod(); - } - - return corsProperties.getAllowedMethods(); - } - - /** - * Preserve backward compatibility after renaming 'allowed-credentials' property to 'allow-credentials' - */ - private static boolean getAllowCredentials(String urlMapping, CorsProperties corsProperties) { - - if (corsProperties.getAllowedCredentials() != null) { - log.warn(WARN_MSG, "allowed-credentials", urlMapping, "allow-credentials"); - return corsProperties.getAllowedCredentials(); - } - - return corsProperties.getAllowCredentials(); - } + public List corsFilters() { + return properties.getCors().keySet().stream() + .map(mapping -> { + final CorsProperties props = properties.getCors().get(mapping); + var config = new CorsConfiguration(); + config.setAllowedOrigins(props.getAllowedOrigins()); + config.setAllowedHeaders(props.getAllowedHeaders()); + config.setAllowedMethods(props.getAllowedMethods()); + config.setExposedHeaders(props.getExposedHeaders()); + config.setAllowCredentials(props.getAllowCredentials()); + var source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration(mapping, config); + return new CorsFilter(source); + }) + .toList(); } } diff --git a/symphony-bdk-spring/symphony-bdk-app-spring-boot-starter/src/main/java/com/symphony/bdk/app/spring/properties/CorsProperties.java b/symphony-bdk-spring/symphony-bdk-app-spring-boot-starter/src/main/java/com/symphony/bdk/app/spring/properties/CorsProperties.java index b674221f6..83c15415d 100644 --- a/symphony-bdk-spring/symphony-bdk-app-spring-boot-starter/src/main/java/com/symphony/bdk/app/spring/properties/CorsProperties.java +++ b/symphony-bdk-spring/symphony-bdk-app-spring-boot-starter/src/main/java/com/symphony/bdk/app/spring/properties/CorsProperties.java @@ -2,7 +2,6 @@ import lombok.Getter; import lombok.Setter; -import org.apiguardian.api.API; import java.util.Collections; import java.util.List; @@ -19,13 +18,6 @@ public class CorsProperties { */ private List allowedOrigins = Collections.singletonList("/**"); - /** - * @deprecated use property "allow-credentials" instead - */ - @Deprecated - @API(status = API.Status.DEPRECATED, since = "2.0") - private Boolean allowedCredentials = null; - /** * Access-Control-Allow-Credentials response header for CORS request */ @@ -41,13 +33,6 @@ public class CorsProperties { */ private List exposedHeaders = Collections.emptyList(); - /** - * @deprecated use property "allow-credentials" instead - */ - @Deprecated - @API(status = API.Status.DEPRECATED, since = "2.0") - private List allowedMethod = null; - /** * List of HTTP methods to allow */ diff --git a/symphony-bdk-spring/symphony-bdk-app-spring-boot-starter/src/test/java/com/symphony/bdk/app/spring/SymphonyBdkAppAutoConfigurationTest.java b/symphony-bdk-spring/symphony-bdk-app-spring-boot-starter/src/test/java/com/symphony/bdk/app/spring/SymphonyBdkAppAutoConfigurationTest.java index 2ad9023c8..d8d63e57a 100644 --- a/symphony-bdk-spring/symphony-bdk-app-spring-boot-starter/src/test/java/com/symphony/bdk/app/spring/SymphonyBdkAppAutoConfigurationTest.java +++ b/symphony-bdk-spring/symphony-bdk-app-spring-boot-starter/src/test/java/com/symphony/bdk/app/spring/SymphonyBdkAppAutoConfigurationTest.java @@ -18,7 +18,7 @@ void shouldLoadContextWithSuccess() { final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withPropertyValues( "bdk.app.appId=test-app", - "bdk.app.privateKeyPath=classpath:/privatekey.pem", + "bdk.app.privateKey.path=classpath:/privatekey.pem", "bdk-app.auth.enabled=true", "bdk-app.auth.jwtCookies.enabled=true", "bdk-app.auth.jwtCookies.maxAge=1d", @@ -33,7 +33,7 @@ void shouldLoadContextWithSuccess() { assertThat(context).hasSingleBean(SymphonyBdkAppAutoConfiguration.class); assertThat(context).hasSingleBean(BdkExtAppControllerConfig.class); assertThat(context).hasSingleBean(CircleOfTrustController.class); - assertThat(context).hasBean("corsConfigurer"); + assertThat(context).hasBean("corsFilters"); assertThat(context).hasBean("tracingFilter"); SymphonyBdkAppProperties properties = context.getBean(SymphonyBdkAppProperties.class); @@ -47,7 +47,7 @@ void shouldLoadContextWithoutCircleOfTrust() { final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withPropertyValues( "bdk.app.appId=test-app", - "bdk.app.privateKeyPath=classpath:/privatekey.pem", + "bdk.app.privateKey.path=classpath:/privatekey.pem", "bdk-app.auth.enabled=false" ) .withUserConfiguration(SymphonyBdkMockedConfiguration.class) @@ -64,7 +64,7 @@ void shouldLoadContextWithoutTracingFilter() { final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withPropertyValues( "bdk.app.appId=test-app", - "bdk.app.privateKeyPath=classpath:/privatekey.pem", + "bdk.app.privateKey.path=classpath:/privatekey.pem", "bdk-app.tracing.enabled=false" ) .withUserConfiguration(SymphonyBdkMockedConfiguration.class) diff --git a/symphony-bdk-spring/symphony-bdk-app-spring-boot-starter/src/test/java/com/symphony/bdk/app/spring/config/BdkExtAppSecurityConfigTest.java b/symphony-bdk-spring/symphony-bdk-app-spring-boot-starter/src/test/java/com/symphony/bdk/app/spring/config/BdkExtAppSecurityConfigTest.java index be3acc02e..82ffab3bc 100644 --- a/symphony-bdk-spring/symphony-bdk-app-spring-boot-starter/src/test/java/com/symphony/bdk/app/spring/config/BdkExtAppSecurityConfigTest.java +++ b/symphony-bdk-spring/symphony-bdk-app-spring-boot-starter/src/test/java/com/symphony/bdk/app/spring/config/BdkExtAppSecurityConfigTest.java @@ -1,86 +1,36 @@ package com.symphony.bdk.app.spring.config; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyBoolean; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import com.symphony.bdk.app.spring.SymphonyBdkAppProperties; - -import com.symphony.bdk.app.spring.properties.CorsProperties; - +import static org.assertj.core.api.Assertions.assertThat; +import com.symphony.bdk.app.spring.SymphonyBdkAppAutoConfiguration; +import com.symphony.bdk.app.spring.SymphonyBdkMockedConfiguration; import org.junit.jupiter.api.Test; -import org.springframework.web.servlet.config.annotation.CorsRegistration; -import org.springframework.web.servlet.config.annotation.CorsRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -import java.util.Arrays; -import java.util.Collections; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.web.filter.CorsFilter; +import java.util.List; public class BdkExtAppSecurityConfigTest { - - @Test - void createCorsConfigurer() { - - final BdkExtAppSecurityConfig config = new BdkExtAppSecurityConfig(); - final SymphonyBdkAppProperties props = new SymphonyBdkAppProperties(); - final CorsProperties cors = new CorsProperties(); - cors.setAllowedMethods(Collections.singletonList("GET")); - cors.setAllowCredentials(false); - cors.setExposedHeaders(Arrays.asList("header1", "header2")); - cors.setAllowedHeaders(Arrays.asList("header1", "header2")); - props.setCors(Collections.singletonMap("*", cors)); - - WebMvcConfigurer configurer = config.corsConfigurer(props); - CorsRegistry registry = mock(CorsRegistry.class); - CorsRegistration registration = mock(CorsRegistration.class); - when(registry.addMapping(any())).thenReturn(registration); - when(registration.allowedOrigins(any())).thenReturn(registration); - when(registration.allowCredentials(anyBoolean())).thenReturn(registration); - when(registration.allowedHeaders(any())).thenReturn(registration); - when(registration.allowedMethods(any())).thenReturn(registration); - when(registration.exposedHeaders(any())).thenReturn(registration); - configurer.addCorsMappings(registry); - - verify(registry).addMapping("*"); - verify(registration).allowedMethods("GET"); - verify(registration).exposedHeaders("header1", "header2"); - verify(registration).allowCredentials(false); - verify(registration).allowedOrigins("/**"); - verify(registration).allowedHeaders("header1", "header2"); - } - @Test - void createCorsConfigurer_withBackwardCompatibility() { - - final BdkExtAppSecurityConfig config = new BdkExtAppSecurityConfig(); - final SymphonyBdkAppProperties props = new SymphonyBdkAppProperties(); - final CorsProperties cors = new CorsProperties(); - cors.setAllowedMethod(Collections.singletonList("POST")); - cors.setAllowedMethods(Collections.singletonList("GET")); - cors.setAllowedCredentials(true); - cors.setAllowCredentials(false); - cors.setExposedHeaders(Arrays.asList("header1", "header2")); - cors.setAllowedHeaders(Arrays.asList("header1", "header2")); - props.setCors(Collections.singletonMap("*", cors)); - - WebMvcConfigurer configurer = config.corsConfigurer(props); - CorsRegistry registry = mock(CorsRegistry.class); - CorsRegistration registration = mock(CorsRegistration.class); - when(registry.addMapping(any())).thenReturn(registration); - when(registration.allowedOrigins(any())).thenReturn(registration); - when(registration.allowCredentials(anyBoolean())).thenReturn(registration); - when(registration.allowedHeaders(any())).thenReturn(registration); - when(registration.allowedMethods(any())).thenReturn(registration); - when(registration.exposedHeaders(any())).thenReturn(registration); - configurer.addCorsMappings(registry); - - verify(registry).addMapping("*"); - verify(registration).allowedMethods("POST"); - verify(registration).exposedHeaders("header1", "header2"); - verify(registration).allowCredentials(true); - verify(registration).allowedOrigins("/**"); - verify(registration).allowedHeaders("header1", "header2"); + void corsFilters() { + final ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withPropertyValues( + "bdk-app.cors.[/**].allowed-origins=*", + "bdk-app.cors.[/**].allow-credentials=false", + "bdk-app.cors.[/**].allowed-methods=POST,GET", + "bdk-app.cors.[/**].allowed-headers=*", + "bdk-app.cors.[/**].exposed-headers=header-name-1,header-name-2", + "bdk-app.cors.[/magic/**].allowed-origins=magic", + "bdk-app.cors.[/magic/**].allow-credentials=false", + "bdk-app.cors.[/magic/**].allowed-methods=POST,GET,DELETE", + "bdk-app.cors.[/magic/**].allowed-headers=magic", + "bdk-app.cors.[/magic/**].exposed-headers=magic-1,magic-2" + ) + .withUserConfiguration(SymphonyBdkMockedConfiguration.class) + .withConfiguration(AutoConfigurations.of(SymphonyBdkAppAutoConfiguration.class)); + + contextRunner.run(context -> { + List corsFilters = (List) context.getBean("corsFilters"); + assertThat(corsFilters).hasSize(2); + }); } } diff --git a/symphony-bdk-spring/symphony-bdk-app-spring-boot-starter/src/test/resources/application.yaml b/symphony-bdk-spring/symphony-bdk-app-spring-boot-starter/src/test/resources/application.yaml index 78396224d..95dcbb939 100644 --- a/symphony-bdk-spring/symphony-bdk-app-spring-boot-starter/src/test/resources/application.yaml +++ b/symphony-bdk-spring/symphony-bdk-app-spring-boot-starter/src/test/resources/application.yaml @@ -10,10 +10,10 @@ bdk: host: localhost bot: username: testbot - privateKeyPath: classpath:/privatekey.pem + privateKey.path: classpath:/privatekey.pem app: appId: testapp - privateKeyPath: classpath:/privatekey.pem + privateKey.path: classpath:/privatekey.pem bdk-app: auth: diff --git a/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/test/resources/application.yaml b/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/test/resources/application.yaml index 9aac8baaf..1de3b61b9 100644 --- a/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/test/resources/application.yaml +++ b/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/test/resources/application.yaml @@ -13,5 +13,5 @@ bdk: bot: username: tibot - privateKeyPath: classpath:/privatekey.pem + privateKey.path: classpath:/privatekey.pem