getAuthentications();
+ /**
+ * Enforce an authentication scheme using the authentication name.
+ *
+ * @param name of the authentication
+ */
+ void addEnforcedAuthenticationScheme(String name);
+
/**
* Change target server according to the load balancing configuration, applies only for calls to the agent.
* Default implementation does nothing.
diff --git a/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/ApiException.java b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/ApiException.java
index 59520c55b..016c6a8ff 100644
--- a/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/ApiException.java
+++ b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/ApiException.java
@@ -11,85 +11,97 @@
/**
* Main exception raised when invoking {@link ApiClient#invokeAPI(String, String, List, Object, Map, Map, Map, String, String, String[], TypeReference)}.
- *
+ *
* Initially generated by the OpenAPI Maven Generator
*/
@Getter
@API(status = API.Status.STABLE)
public class ApiException extends Exception {
- private int code = 0;
- private Map> responseHeaders = null;
- private String responseBody = null;
+ private int code = 0;
+ private Map> responseHeaders = null;
+ private String responseBody = null;
- /**
- * Creates new {@link ApiException} instance.
- *
- * @param message the detail message.
- * @param throwable the cause.
- */
- public ApiException(String message, Throwable throwable) {
- super(message, throwable);
- }
+ /**
+ * Creates new {@link ApiException} instance.
+ *
+ * @param message the detail message.
+ * @param throwable the cause.
+ */
+ public ApiException(String message, Throwable throwable) {
+ super(message, throwable);
+ }
- /**
- * Creates new {@link ApiException} instance.
- *
- * @param code the HTTP response status code.
- * @param message the detail message.
- */
- public ApiException(int code, String message) {
- super(message);
- this.code = code;
- }
+ /**
+ * Creates new {@link ApiException} instance.
+ *
+ * @param code the HTTP response status code.
+ * @param throwable the cause.
+ */
+ public ApiException(int code, Throwable throwable) {
+ super(throwable);
+ this.code = code;
+ }
- /**
- * Creates new {@link ApiException} instance.
- *
- * @param code the HTTP response status code.
- * @param message the detail message.
- * @param responseHeaders list of headers returned by the server.
- * @param responseBody content of the response sent back by the server.
- */
- public ApiException(int code, String message, Map> responseHeaders, String responseBody) {
- this(code, message);
- this.responseHeaders = responseHeaders;
- this.responseBody = responseBody;
- }
/**
- * Check if response status is unauthorized or not.
- *
- * @return true if response status is 401, false otherwise
- */
- public boolean isUnauthorized() {
- return this.code == HttpURLConnection.HTTP_UNAUTHORIZED;
- }
+ * Creates new {@link ApiException} instance.
+ *
+ * @param code the HTTP response status code.
+ * @param message the detail message.
+ */
+ public ApiException(int code, String message) {
+ super(message);
+ this.code = code;
+ }
- /**
- * Check if response status is client error or not
- *
- * @return true if response status is 400, false otherwise
- */
- public boolean isClientError() {
- return this.code == HttpURLConnection.HTTP_BAD_REQUEST;
- }
+ /**
+ * Creates new {@link ApiException} instance.
+ *
+ * @param code the HTTP response status code.
+ * @param message the detail message.
+ * @param responseHeaders list of headers returned by the server.
+ * @param responseBody content of the response sent back by the server.
+ */
+ public ApiException(int code, String message, Map> responseHeaders, String responseBody) {
+ this(code, message);
+ this.responseHeaders = responseHeaders;
+ this.responseBody = responseBody;
+ }
- /**
- * Check if response status is a server error (5xx) but not an internal server error (500)
- *
- * @return true if response status strictly greater than 500, false otherwise
- */
- public boolean isServerError() {
- return this.code >= HttpURLConnection.HTTP_INTERNAL_ERROR;
- }
+ /**
+ * Check if response status is unauthorized or not.
+ *
+ * @return true if response status is 401, false otherwise
+ */
+ public boolean isUnauthorized() {
+ return this.code == HttpURLConnection.HTTP_UNAUTHORIZED;
+ }
- /**
- * Check if response status corresponds to a too many requests error (429)
- *
- * @return true if error code is 429
- */
- public boolean isTooManyRequestsError() {
- return this.code == 429;
- }
+ /**
+ * Check if response status is client error or not
+ *
+ * @return true if response status is 400, false otherwise
+ */
+ public boolean isClientError() {
+ return this.code == HttpURLConnection.HTTP_BAD_REQUEST;
+ }
+
+ /**
+ * Check if response status is a server error (5xx) but not an internal server error (500)
+ *
+ * @return true if response status strictly greater than 500, false otherwise
+ */
+ public boolean isServerError() {
+ return this.code >= HttpURLConnection.HTTP_INTERNAL_ERROR;
+ }
+
+ /**
+ * Check if response status corresponds to a too many requests error (429)
+ *
+ * @return true if error code is 429
+ */
+ public boolean isTooManyRequestsError() {
+ return this.code == 429;
+ }
}
diff --git a/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/auth/Authentication.java b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/auth/Authentication.java
index daee603d9..341166899 100644
--- a/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/auth/Authentication.java
+++ b/symphony-bdk-http/symphony-bdk-http-api/src/main/java/com/symphony/bdk/http/api/auth/Authentication.java
@@ -1,6 +1,7 @@
package com.symphony.bdk.http.api.auth;
import com.symphony.bdk.http.api.ApiClient;
+import com.symphony.bdk.http.api.ApiException;
import com.symphony.bdk.http.api.Pair;
import org.apiguardian.api.API;
@@ -19,8 +20,7 @@ public interface Authentication {
/**
* Apply authentication settings to header and query params.
*
- * @param queryParams List of query parameters
* @param headerParams Map of header parameters
*/
- void applyToParams(List queryParams, Map headerParams);
+ void apply(Map headerParams) throws ApiException;
}
diff --git a/symphony-bdk-http/symphony-bdk-http-jersey2/src/main/java/com/symphony/bdk/http/jersey2/ApiClientJersey2.java b/symphony-bdk-http/symphony-bdk-http-jersey2/src/main/java/com/symphony/bdk/http/jersey2/ApiClientJersey2.java
index 0e6e2fc7f..073ff4135 100644
--- a/symphony-bdk-http/symphony-bdk-http-jersey2/src/main/java/com/symphony/bdk/http/jersey2/ApiClientJersey2.java
+++ b/symphony-bdk-http/symphony-bdk-http-jersey2/src/main/java/com/symphony/bdk/http/jersey2/ApiClientJersey2.java
@@ -28,6 +28,7 @@
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@@ -35,6 +36,7 @@
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Stream;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.ProcessingException;
@@ -59,6 +61,7 @@ public class ApiClientJersey2 implements ApiClient {
protected Map defaultHeaderMap;
protected String tempFolderPath;
protected Map authentications;
+ protected List enforcedAuthenticationSchemes;
public ApiClientJersey2(final Client httpClient, String basePath, Map defaultHeaders,
String temporaryFolderPath) {
@@ -67,6 +70,7 @@ public ApiClientJersey2(final Client httpClient, String basePath, Map(defaultHeaders);
this.tempFolderPath = temporaryFolderPath;
this.authentications = new HashMap<>();
+ this.enforcedAuthenticationSchemes = new ArrayList<>();
}
/**
@@ -91,7 +95,7 @@ public ApiResponse invokeAPI(
// to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(this.basePath + path);
- this.updateParamsForAuth(authNames, queryParams, headerParams);
+ this.updateParamsForAuth(authNames, headerParams);
if (queryParams != null) {
for (Pair queryParam : queryParams) {
@@ -372,6 +376,14 @@ public Map getAuthentications() {
return this.authentications;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void addEnforcedAuthenticationScheme(String name) {
+ this.enforcedAuthenticationSchemes.add(name);
+ }
+
/**
* Check if the given MIME is a JSON MIME.
* JSON MIME examples:
@@ -552,18 +564,29 @@ protected Map> buildResponseHeaders(Response response) {
*
* @param authNames The authentications to apply
*/
- protected void updateParamsForAuth(String[] authNames, List queryParams, Map headerParams) {
+ protected void updateParamsForAuth(String[] authNames, Map headerParams) throws ApiException {
- if (authNames == null) {
+ if (authNames == null && this.enforcedAuthenticationSchemes.isEmpty()) {
return;
}
+ authNames = withEnforcedSecurityScheme(authNames);
+
for (String authName : authNames) {
Authentication auth = this.authentications.get(authName);
if (auth == null) {
throw new RuntimeException("Authentication undefined: " + authName);
}
- auth.applyToParams(queryParams, headerParams);
+ auth.apply(headerParams);
}
}
+
+ private String[] withEnforcedSecurityScheme(String[] authNames) {
+
+ if (authNames == null) {
+ authNames = new String[0];
+ }
+
+ return Stream.concat(this.enforcedAuthenticationSchemes.stream(), Arrays.stream(authNames)).toArray(String[]::new);
+ }
}
diff --git a/symphony-bdk-http/symphony-bdk-http-jersey2/src/test/java/com/symphony/bdk/http/jersey2/ApiClientJersey2Test.java b/symphony-bdk-http/symphony-bdk-http-jersey2/src/test/java/com/symphony/bdk/http/jersey2/ApiClientJersey2Test.java
index 25bb5b313..255882e13 100644
--- a/symphony-bdk-http/symphony-bdk-http-jersey2/src/test/java/com/symphony/bdk/http/jersey2/ApiClientJersey2Test.java
+++ b/symphony-bdk-http/symphony-bdk-http-jersey2/src/test/java/com/symphony/bdk/http/jersey2/ApiClientJersey2Test.java
@@ -50,9 +50,7 @@ void init(
when(statusInfo.getFamily()).thenReturn(Response.Status.Family.SUCCESSFUL);
when(response.getHeaders()).thenReturn(new MultivaluedHashMap<>());
this.apiClient = new ApiClientJersey2(client, "", Collections.emptyMap(), "");
- this.apiClient.getAuthentications().put("testAuth", (queryParams, headerParams) -> {
- headerParams.put("Authorization", "test");
- });
+ this.apiClient.getAuthentications().put("testAuth", headerParams -> headerParams.put("Authorization", "test"));
}
@Test
diff --git a/symphony-bdk-http/symphony-bdk-http-webclient/src/main/java/com/symphony/bdk/http/webclient/ApiClientWebClient.java b/symphony-bdk-http/symphony-bdk-http-webclient/src/main/java/com/symphony/bdk/http/webclient/ApiClientWebClient.java
index 3c6746250..16e795bd8 100644
--- a/symphony-bdk-http/symphony-bdk-http-webclient/src/main/java/com/symphony/bdk/http/webclient/ApiClientWebClient.java
+++ b/symphony-bdk-http/symphony-bdk-http-webclient/src/main/java/com/symphony/bdk/http/webclient/ApiClientWebClient.java
@@ -30,11 +30,13 @@
import java.io.File;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
/**
* Spring WebClient implementation for the {@link ApiClient} interface called by generated code.
@@ -46,12 +48,14 @@ public class ApiClientWebClient implements ApiClient {
protected final String basePath;
protected final Map defaultHeaderMap;
protected Map authentications;
+ protected List enforcedAuthenticationSchemes;
public ApiClientWebClient(final WebClient webClient, String basePath, Map defaultHeaders) {
this.webClient = webClient;
this.basePath = basePath;
this.defaultHeaderMap = new HashMap<>(defaultHeaders);
this.authentications = new HashMap<>();
+ this.enforcedAuthenticationSchemes = new ArrayList<>();
}
/**
@@ -77,7 +81,7 @@ public ApiResponse invokeAPI(
throw new ApiException(500, "unknown method type " + method);
}
- this.updateParamsForAuth(authNames, queryParams, headerParams);
+ this.updateParamsForAuth(authNames, headerParams);
WebClient.RequestBodySpec requestBodySpec =
this.webClient.method(httpMethod).uri(uriBuilder -> {
@@ -258,21 +262,30 @@ private void serializeApiClientBodyPart(String paramKey, ApiClientBodyPart bodyP
*
* @param authNames The authentications to apply
*/
- private void updateParamsForAuth(String[] authNames, List queryParams, Map headerParams) {
+ private void updateParamsForAuth(String[] authNames, Map headerParams) throws ApiException {
- if (authNames == null) {
+ if (authNames == null && this.enforcedAuthenticationSchemes.isEmpty()) {
return;
}
-
+ authNames = withEnforcedSecurityScheme(authNames);
for (String authName : authNames) {
Authentication auth = this.authentications.get(authName);
if (auth == null) {
throw new RuntimeException("Authentication undefined: " + authName);
}
- auth.applyToParams(queryParams, headerParams);
+ auth.apply(headerParams);
}
}
+ private String[] withEnforcedSecurityScheme(String[] authNames) {
+ if (authNames == null) {
+ authNames = new String[0];
+ }
+
+ return Stream.concat(this.enforcedAuthenticationSchemes.stream(), Arrays.stream(authNames)).toArray(String[]::new);
+ }
+
+
/**
* {@inheritDoc}
*/
@@ -418,4 +431,12 @@ public String escapeString(String str) {
public Map getAuthentications() {
return this.authentications;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void addEnforcedAuthenticationScheme(String name) {
+ this.enforcedAuthenticationSchemes.add(name);
+ }
}
diff --git a/symphony-bdk-http/symphony-bdk-http-webclient/src/test/java/com/symphony/bdk/http/webclient/ApiClientWebClientTest.java b/symphony-bdk-http/symphony-bdk-http-webclient/src/test/java/com/symphony/bdk/http/webclient/ApiClientWebClientTest.java
index cf27ccab6..6a8d51238 100644
--- a/symphony-bdk-http/symphony-bdk-http-webclient/src/test/java/com/symphony/bdk/http/webclient/ApiClientWebClientTest.java
+++ b/symphony-bdk-http/symphony-bdk-http-webclient/src/test/java/com/symphony/bdk/http/webclient/ApiClientWebClientTest.java
@@ -45,9 +45,7 @@ class ApiClientWebClientTest {
void setUp(final BdkMockServer mockServer) {
this.apiClient = mockServer.newApiClient("");
- this.apiClient.getAuthentications().put("testAuth", (queryParams, headerParams) -> {
- headerParams.put("Authorization", "test");
- });
+ this.apiClient.getAuthentications().put("testAuth", headerParams -> headerParams.put("Authorization", "test"));
}
@Test
@@ -69,7 +67,7 @@ void testInvokeApiTest(final BdkMockServer mockServer) throws ApiException {
final Map headers = new HashMap<>();
headers.put("sessionToken", "test-token");
-
+ this.apiClient.addEnforcedAuthenticationScheme("testAuth");
ApiResponse response =
this.apiClient.invokeAPI("/test-api", "GET", null, null, headers,
null, null, null, "application/json", new String[] { "testAuth" }, new TypeReference() {});
@@ -343,6 +341,7 @@ void parameterToPairsTest() {
pairs.addAll(this.apiClient.parameterToPairs("ssv", "ssv", Arrays.asList("test1", "test2")));
pairs.addAll(this.apiClient.parameterToPairs("tsv", "tsv", Arrays.asList("test1", "test2")));
pairs.addAll(this.apiClient.parameterToPairs("pipes", "pipes", Arrays.asList("test1", "test2")));
+ pairs.addAll(this.apiClient.parameterToPairs("pipes", "", Arrays.asList("test1", "test2")));
assertEquals(7, pairs.size());
assertEquals("test-value", pairs.get(0).getValue());
diff --git a/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/main/java/com/symphony/bdk/spring/config/BdkCoreConfig.java b/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/main/java/com/symphony/bdk/spring/config/BdkCoreConfig.java
index 4a13c3f4e..fbac79436 100644
--- a/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/main/java/com/symphony/bdk/spring/config/BdkCoreConfig.java
+++ b/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/main/java/com/symphony/bdk/spring/config/BdkCoreConfig.java
@@ -1,17 +1,20 @@
package com.symphony.bdk.spring.config;
+import static com.symphony.bdk.core.auth.impl.OAuthentication.BEARER_AUTH;
+
import com.symphony.bdk.core.auth.AuthSession;
import com.symphony.bdk.core.auth.AuthenticatorFactory;
import com.symphony.bdk.core.auth.ExtensionAppTokensRepository;
+import com.symphony.bdk.core.auth.impl.OAuthSession;
+import com.symphony.bdk.core.auth.impl.OAuthentication;
import com.symphony.bdk.core.auth.exception.AuthInitializationException;
import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException;
import com.symphony.bdk.core.auth.impl.InMemoryTokensRepository;
import com.symphony.bdk.core.client.ApiClientFactory;
-import com.symphony.bdk.gen.api.model.ExtensionAppTokens;
+import com.symphony.bdk.core.config.model.BdkConfig;
import com.symphony.bdk.http.api.ApiClient;
import com.symphony.bdk.http.jersey2.ApiClientBuilderProviderJersey2;
import com.symphony.bdk.spring.SymphonyBdkCoreProperties;
-
import com.symphony.bdk.template.api.TemplateEngine;
import com.symphony.bdk.template.freemarker.FreeMarkerEngine;
@@ -21,6 +24,8 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
+import java.util.Optional;
+
/**
* Configuration and injection of the main BDK/Core classes as beans within the Spring application context.
*/
@@ -30,7 +35,8 @@ public class BdkCoreConfig {
@Bean
@ConditionalOnMissingBean
public ApiClientFactory apiClientFactory(SymphonyBdkCoreProperties properties) {
- return new ApiClientFactory(properties, new ApiClientBuilderProviderJersey2()); // TODO create RestTemplate/or WebClient implementation
+ return new ApiClientFactory(properties,
+ new ApiClientBuilderProviderJersey2()); // TODO create RestTemplate/or WebClient implementation
}
@Bean(name = "agentApiClient")
@@ -44,8 +50,19 @@ public ApiClient datafeedAgentApiClient(ApiClientFactory apiClientFactory) {
}
@Bean(name = "podApiClient")
- public ApiClient podApiClient(ApiClientFactory apiClientFactory) {
- return apiClientFactory.getPodClient();
+ public ApiClient podApiClient(ApiClientFactory apiClientFactory, Optional botSession, BdkConfig config) {
+ ApiClient client = apiClientFactory.getPodClient();
+ if (config.isCommonJwtEnabled()) {
+ if (config.isOboConfigured()) {
+ throw new UnsupportedOperationException(
+ "Common JWT feature is not available yet in OBO mode, please set commonJwt.enabled to false.");
+ } else if (botSession.isPresent()) {
+ final OAuthSession oAuthSession = new OAuthSession(botSession.get());
+ client.getAuthentications().put(BEARER_AUTH, new OAuthentication(oAuthSession::getBearerToken));
+ client.addEnforcedAuthenticationScheme(BEARER_AUTH);
+ }
+ }
+ return client;
}
@Bean(name = "relayApiClient")
@@ -78,7 +95,8 @@ public ExtensionAppTokensRepository extensionAppTokensRepository() {
@Bean
@ConditionalOnMissingBean
- public AuthenticatorFactory authenticatorFactory(SymphonyBdkCoreProperties properties, ApiClientFactory apiClientFactory, ExtensionAppTokensRepository extensionAppTokensRepository) {
+ public AuthenticatorFactory authenticatorFactory(SymphonyBdkCoreProperties properties,
+ ApiClientFactory apiClientFactory, ExtensionAppTokensRepository extensionAppTokensRepository) {
return new AuthenticatorFactory(properties, apiClientFactory, extensionAppTokensRepository);
}
diff --git a/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/test/java/com/symphony/bdk/spring/SymphonyBdkAutoConfigurationTest.java b/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/test/java/com/symphony/bdk/spring/SymphonyBdkAutoConfigurationTest.java
index b4e944cab..8717e8ac5 100644
--- a/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/test/java/com/symphony/bdk/spring/SymphonyBdkAutoConfigurationTest.java
+++ b/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/test/java/com/symphony/bdk/spring/SymphonyBdkAutoConfigurationTest.java
@@ -10,6 +10,7 @@
import com.symphony.bdk.core.client.loadbalancing.DatafeedLoadBalancedApiClient;
import com.symphony.bdk.core.service.datafeed.DatafeedLoop;
import com.symphony.bdk.gen.api.SystemApi;
+import com.symphony.bdk.http.api.ApiClient;
import com.symphony.bdk.spring.annotation.SlashAnnotationProcessor;
import com.symphony.bdk.spring.config.BdkActivityConfig;
import com.symphony.bdk.spring.config.BdkOboServiceConfig;
@@ -134,6 +135,80 @@ void shouldInitializeCustomAuthenticatorsIfTheyExist() {
});
}
+ @Test
+ void shouldAddAuthenticationIfCommonJwtEnabled() {
+ final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
+ .withPropertyValues(
+ "bdk.pod.scheme=http",
+ "bdk.pod.host=localhost",
+
+ "bdk.agent.scheme=http",
+ "bdk.agent.host=localhost",
+
+ "bdk.keyManager.scheme=http",
+ "bdk.keyManager.host=localhost",
+
+ "bdk.bot.username=testBot",
+ "bdk.bot.privateKey.path=classpath:/privatekey.pem",
+
+ "bdk.commonJwt.enabled=true"
+ )
+ .withUserConfiguration(SymphonyBdkMockedConfiguration.class)
+ .withConfiguration(AutoConfigurations.of(SymphonyBdkAutoConfiguration.class));
+
+ contextRunner.run(context -> {
+ assertThat(context).hasBean("podApiClient");
+ ApiClient podClient = (ApiClient) context.getBean("podApiClient");
+ assertThat(podClient.getAuthentications()).isNotEmpty();
+ assertThat(podClient.getAuthentications()).containsKey("bearerAuth");
+ });
+ }
+
+ @Test
+ void shouldFailOnOboWithCommonJwtEnabled() {
+ final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
+ .withPropertyValues(
+ "bdk.host=localhost",
+
+ "bdk.bot.username=testBot",
+ "bdk.bot.privateKey.path=classpath:/privatekey.pem",
+
+ "bdk.app.appId=my-app",
+ "bdk.app.privateKey.path=classpath:/privatekey.pem",
+
+ "bdk.commonJwt.enabled=true"
+ )
+ .withUserConfiguration(SymphonyBdkMockedConfiguration.class)
+ .withConfiguration(AutoConfigurations.of(SymphonyBdkAutoConfiguration.class));
+
+
+ contextRunner.run(context -> {
+ assertThat(context).hasFailed();
+ assertThat(context).getFailure().hasRootCauseInstanceOf(UnsupportedOperationException.class);
+ });
+ }
+
+ @Test
+ void shouldFailOnOboOnlyWithCommonJwtEnabled() {
+ final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
+ .withPropertyValues(
+ "bdk.host=localhost",
+
+ "bdk.app.appId=my-app",
+ "bdk.app.privateKey.path=classpath:/privatekey.pem",
+
+ "bdk.commonJwt.enabled=true"
+ )
+ .withUserConfiguration(SymphonyBdkMockedConfiguration.class)
+ .withConfiguration(AutoConfigurations.of(SymphonyBdkAutoConfiguration.class));
+
+
+ contextRunner.run(context -> {
+ assertThat(context).hasFailed();
+ assertThat(context).getFailure().hasRootCauseInstanceOf(UnsupportedOperationException.class);
+ });
+ }
+
@Test
void shouldFailOnOboAuthenticatorInitializationIfNotProperlyConfigured() {
final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
diff --git a/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/test/java/com/symphony/bdk/spring/SymphonyBdkMockedConfiguration.java b/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/test/java/com/symphony/bdk/spring/SymphonyBdkMockedConfiguration.java
index 7ee8bcef6..fcdf2acd8 100644
--- a/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/test/java/com/symphony/bdk/spring/SymphonyBdkMockedConfiguration.java
+++ b/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/test/java/com/symphony/bdk/spring/SymphonyBdkMockedConfiguration.java
@@ -15,6 +15,8 @@
import javax.annotation.Nonnull;
+import static com.symphony.bdk.core.auth.JwtHelperTest.JWT;
+
/**
*
*/
@@ -84,7 +86,8 @@ public ApiClient getPodClient() {
@Override
public ApiClient getRelayClient() {
- this.relayApiClient.onPost("/relay/pubkey/authenticate", "{ \"token\":\"123456789\", \"name\":\"keyManagerToken\" }");
+ this.relayApiClient.onPost("/relay/pubkey/authenticate",
+ "{ \"token\":\"123456789\", \"name\":\"keyManagerToken\", \"authorizationToken\":\"Bearer " + JWT + "\" }");
return this.relayApiClient.getApiClient("/relay");
}
@@ -92,7 +95,10 @@ public ApiClient getRelayClient() {
@Override
public ApiClient getLoginClient() {
- this.loginApiClient.onPost("/login/pubkey/authenticate", "{ \"token\":\"123456789\", \"name\":\"sessionToken\" }");
+ this.loginApiClient.onPost("/login/pubkey/authenticate",
+ "{ \"token\":\"123456789\", \"name\":\"sessionToken\", \"authorizationToken\":\"Bearer " + JWT + "\" }");
+ this.loginApiClient.onPost("/login/idm/tokens",
+ "{ \"token_type\": \"Bearer\", \"expires_in\": 300, \"access_token\": \"" +JWT+ "\"}");
return this.loginApiClient.getApiClient("/login");
}
diff --git a/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/test/java/com/symphony/bdk/spring/config/BdkCoreConfigTest.java b/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/test/java/com/symphony/bdk/spring/config/BdkCoreConfigTest.java
index c0b451cd8..8dad84753 100644
--- a/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/test/java/com/symphony/bdk/spring/config/BdkCoreConfigTest.java
+++ b/symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/test/java/com/symphony/bdk/spring/config/BdkCoreConfigTest.java
@@ -5,6 +5,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import com.symphony.bdk.core.auth.AuthSession;
import com.symphony.bdk.core.auth.AuthenticatorFactory;
import com.symphony.bdk.core.auth.BotAuthenticator;
import com.symphony.bdk.core.auth.ExtensionAppAuthenticator;
@@ -12,12 +13,16 @@
import com.symphony.bdk.core.auth.exception.AuthInitializationException;
import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException;
import com.symphony.bdk.core.client.ApiClientFactory;
+import com.symphony.bdk.core.config.model.BdkCommonJwtConfig;
+import com.symphony.bdk.core.config.model.BdkConfig;
import com.symphony.bdk.http.api.ApiClient;
import com.symphony.bdk.spring.SymphonyBdkCoreProperties;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanInitializationException;
+import java.util.Optional;
+
/**
* Test class for the {@link BdkCoreConfig}. Mainly for coverage...
*/
@@ -43,6 +48,18 @@ void shouldCreateApiClientFactory() {
assertNotNull(config.apiClientFactory(props));
}
+ @Test
+ void shouldCreatePodClient() {
+ final BdkCoreConfig config = new BdkCoreConfig();
+ final BdkConfig bdkConfig = new BdkConfig();
+ BdkCommonJwtConfig bdkCommonJwtConfig = new BdkCommonJwtConfig();
+ bdkCommonJwtConfig.setEnabled(true);
+ bdkConfig.setCommonJwt(bdkCommonJwtConfig);
+ final ApiClientFactory factory = mock(ApiClientFactory.class);
+ final AuthSession authSession = mock(AuthSession.class);
+ when(factory.getPodClient()).thenReturn(mock(ApiClient.class));
+ assertNotNull(config.podApiClient(factory, Optional.ofNullable(authSession), bdkConfig));
+ }
@Test
void shouldCreateKeyAuthApiClient() {
final BdkCoreConfig config = new BdkCoreConfig();