Skip to content

Commit 78c2349

Browse files
Support Agent CommonJWT Authentication (#850)
* Support Agent CommonJWT Authentication * Revert "Support Agent CommonJWT Authentication" This reverts commit d4d34d4. * Support Agent CommonJWT Authentication * Update BdkCoreConfig.java
1 parent 0597624 commit 78c2349

2 files changed

Lines changed: 42 additions & 19 deletions

File tree

  • symphony-bdk-core/src/main/java/com/symphony/bdk/core
  • symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/main/java/com/symphony/bdk/spring/config

symphony-bdk-core/src/main/java/com/symphony/bdk/core/ServiceFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,18 @@ public ServiceFactory(ApiClientFactory apiClientFactory, AuthSession authSession
9393
+ " please set commonJwt.enabled to false.");
9494
} else {
9595
final OAuthSession oAuthSession = new OAuthSession(authSession);
96+
9697
this.podClient.getAuthentications().put(BEARER_AUTH, new OAuthentication(oAuthSession::getBearerToken));
9798
this.podClient.addEnforcedAuthenticationScheme(BEARER_AUTH);
99+
100+
this.agentClient.getAuthentications().put(BEARER_AUTH, new OAuthentication(oAuthSession::getBearerToken));
101+
this.agentClient.addEnforcedAuthenticationScheme(BEARER_AUTH);
102+
103+
this.datafeedAgentClient.getAuthentications().put(BEARER_AUTH, new OAuthentication(oAuthSession::getBearerToken));
104+
this.datafeedAgentClient.addEnforcedAuthenticationScheme(BEARER_AUTH);
105+
106+
this.datahoseAgentClient.getAuthentications().put(BEARER_AUTH, new OAuthentication(oAuthSession::getBearerToken));
107+
this.datahoseAgentClient.addEnforcedAuthenticationScheme(BEARER_AUTH);
98108
}
99109
}
100110
}

symphony-bdk-spring/symphony-bdk-core-spring-boot-starter/src/main/java/com/symphony/bdk/spring/config/BdkCoreConfig.java

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
import com.symphony.bdk.core.auth.AuthSession;
66
import com.symphony.bdk.core.auth.AuthenticatorFactory;
7-
import com.symphony.bdk.core.auth.impl.AuthenticatorFactoryImpl;
87
import com.symphony.bdk.core.auth.ExtensionAppTokensRepository;
9-
import com.symphony.bdk.core.auth.impl.OAuthSession;
10-
import com.symphony.bdk.core.auth.impl.OAuthentication;
118
import com.symphony.bdk.core.auth.exception.AuthInitializationException;
129
import com.symphony.bdk.core.auth.exception.AuthUnauthorizedException;
10+
import com.symphony.bdk.core.auth.impl.AuthenticatorFactoryImpl;
1311
import com.symphony.bdk.core.auth.impl.InMemoryTokensRepository;
12+
import com.symphony.bdk.core.auth.impl.OAuthSession;
13+
import com.symphony.bdk.core.auth.impl.OAuthentication;
1414
import com.symphony.bdk.core.client.ApiClientFactory;
1515
import com.symphony.bdk.core.config.model.BdkConfig;
1616
import com.symphony.bdk.http.api.ApiClient;
@@ -41,33 +41,33 @@ public ApiClientFactory apiClientFactory(SymphonyBdkCoreProperties properties) {
4141
}
4242

4343
@Bean(name = "agentApiClient")
44-
public ApiClient agentApiClient(ApiClientFactory apiClientFactory) {
45-
return apiClientFactory.getAgentClient();
44+
public ApiClient agentApiClient(ApiClientFactory apiClientFactory, Optional<AuthSession> botSession,
45+
BdkConfig config) {
46+
ApiClient client = apiClientFactory.getAgentClient();
47+
addCommonJwtConfig(client, botSession, config);
48+
return client;
4649
}
4750

4851
@Bean(name = "datafeedAgentApiClient")
49-
public ApiClient datafeedAgentApiClient(ApiClientFactory apiClientFactory) {
50-
return apiClientFactory.getDatafeedAgentClient();
52+
public ApiClient datafeedAgentApiClient(ApiClientFactory apiClientFactory, Optional<AuthSession> botSession,
53+
BdkConfig config) {
54+
ApiClient client = apiClientFactory.getDatafeedAgentClient();
55+
addCommonJwtConfig(client, botSession, config);
56+
return client;
5157
}
5258

5359
@Bean(name = "datahoseAgentApiClient")
54-
public ApiClient datahoseAgentApiClient(ApiClientFactory apiClientFactory) {
55-
return apiClientFactory.getDatahoseAgentClient();
60+
public ApiClient datahoseAgentApiClient(ApiClientFactory apiClientFactory, Optional<AuthSession> botSession,
61+
BdkConfig config) {
62+
ApiClient client = apiClientFactory.getDatahoseAgentClient();
63+
addCommonJwtConfig(client, botSession, config);
64+
return client;
5665
}
5766

5867
@Bean(name = "podApiClient")
5968
public ApiClient podApiClient(ApiClientFactory apiClientFactory, Optional<AuthSession> botSession, BdkConfig config) {
6069
ApiClient client = apiClientFactory.getPodClient();
61-
if (config.isCommonJwtEnabled()) {
62-
if (config.isOboConfigured()) {
63-
throw new UnsupportedOperationException(
64-
"Common JWT feature is not available yet in OBO mode, please set commonJwt.enabled to false.");
65-
} else if (botSession.isPresent()) {
66-
final OAuthSession oAuthSession = new OAuthSession(botSession.get());
67-
client.getAuthentications().put(BEARER_AUTH, new OAuthentication(oAuthSession::getBearerToken));
68-
client.addEnforcedAuthenticationScheme(BEARER_AUTH);
69-
}
70-
}
70+
addCommonJwtConfig(client, botSession, config);
7171
return client;
7272
}
7373

@@ -122,4 +122,17 @@ public AuthSession botSession(AuthenticatorFactory authenticatorFactory) {
122122
throw new BeanInitializationException("Unable to authenticate bot", e);
123123
}
124124
}
125+
126+
private void addCommonJwtConfig(ApiClient client, Optional<AuthSession> botSession, BdkConfig config) {
127+
if (config.isCommonJwtEnabled()) {
128+
if (config.isOboConfigured()) {
129+
throw new UnsupportedOperationException(
130+
"Common JWT feature is not available yet in OBO mode, please set commonJwt.enabled to false.");
131+
} else if (botSession.isPresent()) {
132+
final OAuthSession oAuthSession = new OAuthSession(botSession.get());
133+
client.getAuthentications().put(BEARER_AUTH, new OAuthentication(oAuthSession::getBearerToken));
134+
client.addEnforcedAuthenticationScheme(BEARER_AUTH);
135+
}
136+
}
137+
}
125138
}

0 commit comments

Comments
 (0)