|
| 1 | +From c2426a9169f22bd9b955bcde779ce2c248b5f8c0 Mon Sep 17 00:00:00 2001 |
| 2 | +From: dervoeti <lukas.krug@stackable.tech> |
| 3 | +Date: Thu, 5 Feb 2026 15:00:23 +0100 |
| 4 | +Subject: feat: add configurable clientAuthenticationMethod to druid-pac4j OIDC |
| 5 | + config |
| 6 | + |
| 7 | +--- |
| 8 | + .../druid/security/pac4j/OIDCConfig.java | 13 ++++++++- |
| 9 | + .../security/pac4j/Pac4jAuthenticator.java | 5 ++++ |
| 10 | + .../druid/security/pac4j/OIDCConfigTest.java | 28 +++++++++++++++++++ |
| 11 | + 3 files changed, 45 insertions(+), 1 deletion(-) |
| 12 | + |
| 13 | +diff --git a/extensions-core/druid-pac4j/src/main/java/org/apache/druid/security/pac4j/OIDCConfig.java b/extensions-core/druid-pac4j/src/main/java/org/apache/druid/security/pac4j/OIDCConfig.java |
| 14 | +index 50b04455db..d83e04717a 100644 |
| 15 | +--- a/extensions-core/druid-pac4j/src/main/java/org/apache/druid/security/pac4j/OIDCConfig.java |
| 16 | ++++ b/extensions-core/druid-pac4j/src/main/java/org/apache/druid/security/pac4j/OIDCConfig.java |
| 17 | +@@ -44,13 +44,17 @@ public class OIDCConfig |
| 18 | + @JsonProperty |
| 19 | + private final String scope; |
| 20 | + |
| 21 | ++ @JsonProperty |
| 22 | ++ private final String clientAuthenticationMethod; |
| 23 | ++ |
| 24 | + @JsonCreator |
| 25 | + public OIDCConfig( |
| 26 | + @JsonProperty("clientID") String clientID, |
| 27 | + @JsonProperty("clientSecret") PasswordProvider clientSecret, |
| 28 | + @JsonProperty("discoveryURI") String discoveryURI, |
| 29 | + @JsonProperty("oidcClaim") String oidcClaim, |
| 30 | +- @JsonProperty("scope") @Nullable String scope |
| 31 | ++ @JsonProperty("scope") @Nullable String scope, |
| 32 | ++ @JsonProperty("clientAuthenticationMethod") @Nullable String clientAuthenticationMethod |
| 33 | + ) |
| 34 | + { |
| 35 | + this.clientID = Preconditions.checkNotNull(clientID, "null clientID"); |
| 36 | +@@ -58,6 +62,7 @@ public class OIDCConfig |
| 37 | + this.discoveryURI = Preconditions.checkNotNull(discoveryURI, "null discoveryURI"); |
| 38 | + this.oidcClaim = oidcClaim == null ? DEFAULT_SCOPE : oidcClaim; |
| 39 | + this.scope = scope; |
| 40 | ++ this.clientAuthenticationMethod = clientAuthenticationMethod; |
| 41 | + } |
| 42 | + |
| 43 | + @JsonProperty |
| 44 | +@@ -89,4 +94,10 @@ public class OIDCConfig |
| 45 | + { |
| 46 | + return scope; |
| 47 | + } |
| 48 | ++ |
| 49 | ++ @JsonProperty |
| 50 | ++ public String getClientAuthenticationMethod() |
| 51 | ++ { |
| 52 | ++ return clientAuthenticationMethod; |
| 53 | ++ } |
| 54 | + } |
| 55 | +diff --git a/extensions-core/druid-pac4j/src/main/java/org/apache/druid/security/pac4j/Pac4jAuthenticator.java b/extensions-core/druid-pac4j/src/main/java/org/apache/druid/security/pac4j/Pac4jAuthenticator.java |
| 56 | +index ef30f4c7e6..59a6fa0782 100644 |
| 57 | +--- a/extensions-core/druid-pac4j/src/main/java/org/apache/druid/security/pac4j/Pac4jAuthenticator.java |
| 58 | ++++ b/extensions-core/druid-pac4j/src/main/java/org/apache/druid/security/pac4j/Pac4jAuthenticator.java |
| 59 | +@@ -27,6 +27,7 @@ import com.google.common.base.Supplier; |
| 60 | + import com.google.common.base.Suppliers; |
| 61 | + import com.google.common.primitives.Ints; |
| 62 | + import com.google.inject.Provider; |
| 63 | ++import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod; |
| 64 | + import com.nimbusds.oauth2.sdk.http.HTTPRequest; |
| 65 | + import org.apache.druid.server.security.AuthenticationResult; |
| 66 | + import org.apache.druid.server.security.Authenticator; |
| 67 | +@@ -132,6 +133,10 @@ public class Pac4jAuthenticator implements Authenticator |
| 68 | + oidcConf.setSecret(oidcConfig.getClientSecret().getPassword()); |
| 69 | + oidcConf.setDiscoveryURI(oidcConfig.getDiscoveryURI()); |
| 70 | + oidcConf.setScope(oidcConfig.getScope()); |
| 71 | ++ if (oidcConfig.getClientAuthenticationMethod() != null) { |
| 72 | ++ oidcConf.setClientAuthenticationMethod( |
| 73 | ++ ClientAuthenticationMethod.parse(oidcConfig.getClientAuthenticationMethod())); |
| 74 | ++ } |
| 75 | + oidcConf.setExpireSessionWithToken(true); |
| 76 | + oidcConf.setUseNonce(true); |
| 77 | + oidcConf.setReadTimeout(Ints.checkedCast(pac4jCommonConfig.getReadTimeout().getMillis())); |
| 78 | +diff --git a/extensions-core/druid-pac4j/src/test/java/org/apache/druid/security/pac4j/OIDCConfigTest.java b/extensions-core/druid-pac4j/src/test/java/org/apache/druid/security/pac4j/OIDCConfigTest.java |
| 79 | +index c4192c020d..0b6128e61b 100644 |
| 80 | +--- a/extensions-core/druid-pac4j/src/test/java/org/apache/druid/security/pac4j/OIDCConfigTest.java |
| 81 | ++++ b/extensions-core/druid-pac4j/src/test/java/org/apache/druid/security/pac4j/OIDCConfigTest.java |
| 82 | +@@ -46,6 +46,7 @@ public class OIDCConfigTest |
| 83 | + Assert.assertEquals("testdiscoveryuri", conf.getDiscoveryURI()); |
| 84 | + Assert.assertEquals("name", conf.getOidcClaim()); |
| 85 | + Assert.assertEquals("testscope", conf.getScope()); |
| 86 | ++ Assert.assertNull(conf.getClientAuthenticationMethod()); |
| 87 | + } |
| 88 | + |
| 89 | + @Test |
| 90 | +@@ -72,4 +73,31 @@ public class OIDCConfigTest |
| 91 | + Assert.assertEquals("email", conf.getOidcClaim()); |
| 92 | + Assert.assertEquals("testscope", conf.getScope()); |
| 93 | + } |
| 94 | ++ |
| 95 | ++ @Test |
| 96 | ++ public void testSerdeWithClientAuthenticationMethod() throws Exception |
| 97 | ++ { |
| 98 | ++ ObjectMapper jsonMapper = new ObjectMapper(); |
| 99 | ++ |
| 100 | ++ String jsonStr = "{\n" |
| 101 | ++ + " \"clientID\": \"testid\",\n" |
| 102 | ++ + " \"clientSecret\": \"testsecret\",\n" |
| 103 | ++ + " \"discoveryURI\": \"testdiscoveryuri\",\n" |
| 104 | ++ + " \"oidcClaim\": \"email\",\n" |
| 105 | ++ + " \"scope\": \"testscope\",\n" |
| 106 | ++ + " \"clientAuthenticationMethod\": \"client_secret_post\"\n" |
| 107 | ++ + "}\n"; |
| 108 | ++ |
| 109 | ++ OIDCConfig conf = jsonMapper.readValue( |
| 110 | ++ jsonMapper.writeValueAsString(jsonMapper.readValue(jsonStr, OIDCConfig.class)), |
| 111 | ++ OIDCConfig.class |
| 112 | ++ ); |
| 113 | ++ |
| 114 | ++ Assert.assertEquals("testid", conf.getClientID()); |
| 115 | ++ Assert.assertEquals("testsecret", conf.getClientSecret().getPassword()); |
| 116 | ++ Assert.assertEquals("testdiscoveryuri", conf.getDiscoveryURI()); |
| 117 | ++ Assert.assertEquals("email", conf.getOidcClaim()); |
| 118 | ++ Assert.assertEquals("testscope", conf.getScope()); |
| 119 | ++ Assert.assertEquals("client_secret_post", conf.getClientAuthenticationMethod()); |
| 120 | ++ } |
| 121 | + } |
0 commit comments