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