Skip to content

Commit 73cb1e9

Browse files
Fix API key auth (#2438)
1 parent 6b05cd8 commit 73cb1e9

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

temporal-sdk/src/main/java/io/temporal/worker/WorkerFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ public synchronized void start() {
216216

217217
// Workers check and require that Temporal Server is available during start to fail-fast in case
218218
// of configuration issues.
219-
workflowClient.getWorkflowServiceStubs().connect(null);
219+
// TODO(https://github.com/temporalio/sdk-java/issues/2060) consider using describeNamespace as
220+
// a connection check.
221+
workflowClient.getWorkflowServiceStubs().getServerCapabilities();
220222

221223
for (Worker worker : workers.values()) {
222224
worker.start();

temporal-spring-boot-autoconfigure/src/main/java/io/temporal/spring/boot/autoconfigure/template/ServiceStubOptionsTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public WorkflowServiceStubsOptions createServiceStubOptions() {
6464

6565
stubsOptionsBuilder.setEnableHttps(Boolean.TRUE.equals(connectionProperties.isEnableHttps()));
6666

67-
if (connectionProperties.getApiKey() != null && connectionProperties.getApiKey().isEmpty()) {
67+
if (connectionProperties.getApiKey() != null && !connectionProperties.getApiKey().isEmpty()) {
6868
stubsOptionsBuilder.addApiKey(() -> connectionProperties.getApiKey());
6969
// Unless HTTPS is explicitly disabled, enable it by default for API keys
7070
if (connectionProperties.isEnableHttps() == null) {

temporal-spring-boot-autoconfigure/src/test/java/io/temporal/spring/boot/autoconfigure/ApiKeyAuthTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
package io.temporal.spring.boot.autoconfigure;
2222

23+
import io.temporal.authorization.AuthorizationGrpcMetadataProvider;
2324
import io.temporal.client.WorkflowClient;
25+
import io.temporal.serviceclient.WorkflowServiceStubs;
2426
import io.temporal.spring.boot.autoconfigure.properties.TemporalProperties;
2527
import org.junit.jupiter.api.*;
2628
import org.springframework.beans.factory.annotation.Autowired;
@@ -38,6 +40,7 @@ public class ApiKeyAuthTest {
3840

3941
@Autowired TemporalProperties temporalProperties;
4042
@Autowired WorkflowClient workflowClient;
43+
@Autowired WorkflowServiceStubs workflowServiceStubs;
4144

4245
@BeforeEach
4346
void setUp() {
@@ -47,6 +50,15 @@ void setUp() {
4750
@Test
4851
public void testProperties() {
4952
Assertions.assertEquals("my-api-key", temporalProperties.getConnection().getApiKey());
53+
Assertions.assertEquals(1, workflowServiceStubs.getOptions().getGrpcMetadataProviders().size());
54+
Assertions.assertTrue(
55+
workflowServiceStubs.getOptions().getGrpcMetadataProviders().stream()
56+
.allMatch(
57+
provider ->
58+
provider
59+
.getMetadata()
60+
.get(AuthorizationGrpcMetadataProvider.AUTHORIZATION_HEADER_KEY)
61+
.equals("Bearer my-api-key")));
5062
}
5163

5264
@ComponentScan(

0 commit comments

Comments
 (0)