24
24
import edu .umd .cs .findbugs .annotations .Nullable ;
25
25
import java .lang .reflect .InvocationTargetException ;
26
26
import java .lang .reflect .Method ;
27
+ import java .net .URI ;
28
+ import java .net .URISyntaxException ;
27
29
import java .nio .file .Path ;
28
30
import java .util .HashMap ;
29
31
import java .util .Map ;
@@ -40,61 +42,10 @@ public class AuthenticatorConfig extends AbstractConfig {
40
42
public static final String KEYTAB_OPT = "auth.gssapi.keyTab" ;
41
43
public static final String PRINCIPAL_OPT = "auth.gssapi.principal" ;
42
44
public static final String SERVICE_OPT = "auth.gssapi.service" ;
43
-
44
- /*
45
- # oidc_options:
46
- # # OIDC Authentication server url (required when "oidc" authentication scheme is used).
47
- # issuer: https://auth.example.com/realms/my-realm
48
- #
49
- # # Array of accepted OIDC clients (by default all clients are accepted).
50
- # accepted_audience: []
51
- #
52
- # # Access token claim used to identify the user in the database (by default the "preferred_username"
53
- # # claim is used). When defined, the claim must exist at the top-level of the access token's JWT.
54
- # user_name_claim:
55
- #
56
- # # Array of claims used to identify the user roles in the database. For example, setting this
57
- # # configuration to "[ realm_roles.roles ]" will assume all OIDC realm roles. If the claim doesn't
58
- # # exist or does not identify an array of strings in the JWT, the setting will be ignored. Roles
59
- # # defined in these claims must be previously defined in the database such that any privilege grant
60
- # # is recognized and validated.
61
- # user_roles_claims: []
62
- #
63
- # # Set to true to initiate a TLS encrypted connections. Defaults to false. If case of
64
- # # truststore_path being set, it will default to true.
65
- # use_tls: false
66
- #
67
- # # Sets the keystore path with valid certificates to establish encrypted connections with the OIDC Server.
68
- # # When TLS is enabled, failure to set this option or an invalid path will result in an error.
69
- # truststore_path:
70
- # # Keystore password
71
- # truststore_password:
72
- # # Keystore type (JKS or PKCS12). By default, the trustore type is inferred from the keystore
73
- # # extension. For `.p12`, `.pkcs12`, or `.pfx` files, PKCS12 is used. For `.keystore` or
74
- # # `.jks` files, JKS is used. In case the keystore type cannot be inferred from the extension,
75
- # # this option must be set.
76
- # truststore_type: jks
77
- #
78
- # # Compatibility option, allowing older drivers to use OIDC authentication via password
79
- # # authentication, by using a pre-configurable username and passing an OIDC JWT access token as
80
- # # password. Defaults to false.
81
- # # allow_token_via_password_authentication: false
82
- # # When the above option is true, it allows configuring the username which will be used
83
- # # to detect that an OIDC JWT access token is being sent as password.
84
- # # token_username: oauth-bearer
85
- */
86
-
87
- public static final String OIDC_ISSUER = "auth.oidc.issuer" ;
88
- public static final String OIDC_ACCEPTED_AUDIENCE = "auth.oidc.accepted_audience" ;
89
- public static final String OIDC_USER_NAME_CLAIM = "auth.oidc.user_name_claim" ;
90
- public static final String OIDC_USER_ROLES_CLAIMS = "auth.oidc.user_roles_claims" ;
91
- public static final String OIDC_USE_TLS = "auth.oidc.use_tls" ;
92
- public static final String OIDC_TRUSTSTORE_PATH = "auth.oidc.truststore_path" ;
93
- public static final String OIDC_TRUSTSTORE_PASSWORD = "auth.oidc.truststore_password" ;
94
- public static final String OIDC_TRUSTSTORE_TYPE = "auth.oidc.truststore_type" ;
95
- public static final String OIDC_ALLOW_TOKEN_VIA_PASSWORD_AUTHENTICATION =
96
- "auth.oidc.allow_token_via_password_authentication" ;
97
- public static final String OIDC_TOKEN_USERNAME = "auth.oidc.token_username" ;
45
+ public static final String OIDC_ISSUER_OPT = "auth.oidc.issuer" ;
46
+ public static final String OIDC_CLIENT_ID_OPT = "auth.oidc.client_id" ;
47
+ public static final String OIDC_CLIENT_SECRET_OPT = "auth.oidc.client_secret" ;
48
+ public static final String OIDC_USE_TLS_OPT = "auth.oidc.use_tls" ;
98
49
99
50
private static final Logger log = LoggerFactory .getLogger (AuthenticatorConfig .class );
100
51
public static final ConfigDef CONFIG_DEF =
@@ -137,72 +88,29 @@ public class AuthenticatorConfig extends AbstractConfig {
137
88
ConfigDef .Importance .HIGH ,
138
89
"SASL service name to use for GSSAPI provider authentication" )
139
90
.define (
140
- OIDC_ISSUER ,
91
+ OIDC_ISSUER_OPT ,
141
92
ConfigDef .Type .STRING ,
142
93
"" ,
143
94
ConfigDef .Importance .HIGH ,
144
95
"OIDC Authentication server url" )
145
96
.define (
146
- OIDC_ACCEPTED_AUDIENCE ,
147
- ConfigDef .Type .LIST ,
148
- "" ,
149
- ConfigDef .Importance .HIGH ,
150
- "Array of accepted OIDC clients" )
151
- .define (
152
- OIDC_USER_NAME_CLAIM ,
97
+ OIDC_CLIENT_ID_OPT ,
153
98
ConfigDef .Type .STRING ,
154
- "preferred_username" ,
155
- ConfigDef .Importance .HIGH ,
156
- "Access token claim used to identify the user in the database" )
157
- .define (
158
- OIDC_USER_ROLES_CLAIMS ,
159
- ConfigDef .Type .LIST ,
160
99
"" ,
161
100
ConfigDef .Importance .HIGH ,
162
- "Array of claims used to identify the user roles in the database " )
101
+ "OIDC Client Id to use for authentication " )
163
102
.define (
164
- OIDC_USE_TLS ,
165
- ConfigDef .Type .BOOLEAN ,
166
- false ,
167
- ConfigDef .Importance .HIGH ,
168
- "Set to true to initiate a TLS encrypted connections. Defaults to false. If case of "
169
- + "truststore_path being set, it will default to true." )
170
- .define (
171
- OIDC_TRUSTSTORE_PATH ,
172
- ConfigDef .Type .STRING ,
173
- "" ,
174
- ConfigDef .Importance .HIGH ,
175
- "Sets the keystore path with valid certificates to establish encrypted connections with the OIDC Server." )
176
- .define (
177
- OIDC_TRUSTSTORE_PASSWORD ,
103
+ OIDC_CLIENT_SECRET_OPT ,
178
104
ConfigDef .Type .PASSWORD ,
179
105
"" ,
180
106
ConfigDef .Importance .HIGH ,
181
- "Keystore password " )
107
+ "OIDC Client Secret to use for authentication " )
182
108
.define (
183
- OIDC_TRUSTSTORE_TYPE ,
184
- ConfigDef .Type .STRING ,
185
- "jks" ,
186
- ConfigDef .Importance .HIGH ,
187
- "Keystore type (JKS or PKCS12). By default, the trustore type is inferred from the keystore "
188
- + "extension. For `.p12`, `.pkcs12`, or `.pfx` files, PKCS12 is used. For `.keystore` or "
189
- + "`.jks` files, JKS is used. In case the keystore type cannot be inferred from the extension, "
190
- + "this option must be set." )
191
- .define (
192
- OIDC_ALLOW_TOKEN_VIA_PASSWORD_AUTHENTICATION ,
109
+ OIDC_USE_TLS_OPT ,
193
110
ConfigDef .Type .BOOLEAN ,
194
111
false ,
195
112
ConfigDef .Importance .HIGH ,
196
- "Compatibility option, allowing older drivers to use OIDC authentication via password "
197
- + "authentication, by using a pre-configurable username and passing an OIDC JWT access token as "
198
- + "password." )
199
- .define (
200
- OIDC_TOKEN_USERNAME ,
201
- ConfigDef .Type .STRING ,
202
- "oauth-bearer" ,
203
- ConfigDef .Importance .HIGH ,
204
- "When the above option is true, it allows configuring the username which will be used "
205
- + "to detect that an OIDC JWT access token is being sent as password." );
113
+ "Set to true to initiate a TLS encrypted connections. Defaults to false." );
206
114
207
115
@ Nullable private final Path keyTabPath ;
208
116
@@ -227,8 +135,23 @@ public AuthenticatorConfig(Map<String, String> authSettings) {
227
135
}
228
136
229
137
if (provider == Provider .OIDC ) {
230
- if (getString (OIDC_ISSUER ).isEmpty ()) {
231
- throw new ConfigException (OIDC_ISSUER , "<empty>" , "is required" );
138
+ if (getString (OIDC_ISSUER_OPT ).isEmpty ()) {
139
+ throw new ConfigException (OIDC_ISSUER_OPT , "<empty>" , "is required" );
140
+ }
141
+
142
+ try {
143
+ new URI (getString (OIDC_ISSUER_OPT ));
144
+ }
145
+ catch (URISyntaxException e ) {
146
+ throw new ConfigException (
147
+ OIDC_ISSUER_OPT , getString (OIDC_ISSUER_OPT ), "is not a valid URI: " + e .getMessage ());
148
+ }
149
+
150
+ if (getString (OIDC_CLIENT_ID_OPT ).isEmpty ()) {
151
+ throw new ConfigException (OIDC_CLIENT_ID_OPT , "<empty>" , "is required" );
152
+ }
153
+ if (getPassword (OIDC_CLIENT_SECRET_OPT ).value ().isEmpty ()) {
154
+ throw new ConfigException (OIDC_CLIENT_SECRET_OPT , "<empty>" , "is required" );
232
155
}
233
156
}
234
157
}
@@ -268,14 +191,8 @@ private static Map<String, String> sanitizeAuthSettings(Map<String, String> auth
268
191
}
269
192
270
193
if ("OIDC" .equals (provider )) {
271
- // OIDC provider requires issuer to be set.
272
- if (!mutated .containsKey (OIDC_ISSUER ) || mutated .get (OIDC_ISSUER ).isEmpty ()) {
273
- throw new ConfigException (OIDC_ISSUER , "<empty>" , "is required for OIDC authentication" );
274
- }
275
- // If truststore path is set, use TLS.
276
- if (mutated .containsKey (OIDC_TRUSTSTORE_PATH )
277
- && !mutated .get (OIDC_TRUSTSTORE_PATH ).isEmpty ()) {
278
- mutated .put (OIDC_USE_TLS , "true" );
194
+ if (!mutated .containsKey (OIDC_USE_TLS_OPT ) || mutated .get (OIDC_USE_TLS_OPT ).isEmpty ()) {
195
+ mutated .put (OIDC_USE_TLS_OPT , "true" );
279
196
}
280
197
}
281
198
@@ -356,6 +273,24 @@ public String getService() {
356
273
return getString (SERVICE_OPT );
357
274
}
358
275
276
+ public URI getOIDCIssuer () {
277
+ try {
278
+ return new URI (getString (OIDC_ISSUER_OPT ));
279
+ }
280
+ catch (URISyntaxException e ) {
281
+ // This should never happen because we validate the URI in the constructor.
282
+ return null ;
283
+ }
284
+ }
285
+
286
+ public String getOIDCClientId () {
287
+ return getString (OIDC_CLIENT_ID_OPT );
288
+ }
289
+
290
+ public String getOIDCClientSecret () {
291
+ return getPassword (OIDC_CLIENT_SECRET_OPT ).value ();
292
+ }
293
+
359
294
@ Override
360
295
public String toString () {
361
296
return configToString (
@@ -367,16 +302,9 @@ public String toString() {
367
302
KEYTAB_OPT ,
368
303
PRINCIPAL_OPT ,
369
304
SERVICE_OPT ,
370
- // OIDC opts
371
- OIDC_ISSUER ,
372
- OIDC_ACCEPTED_AUDIENCE ,
373
- OIDC_USER_NAME_CLAIM ,
374
- OIDC_USE_TLS ,
375
- OIDC_TRUSTSTORE_PATH ,
376
- OIDC_TRUSTSTORE_PASSWORD ,
377
- OIDC_TRUSTSTORE_TYPE ,
378
- OIDC_ALLOW_TOKEN_VIA_PASSWORD_AUTHENTICATION ,
379
- OIDC_TOKEN_USERNAME );
305
+ OIDC_ISSUER_OPT ,
306
+ OIDC_CLIENT_ID_OPT ,
307
+ OIDC_CLIENT_SECRET_OPT );
380
308
}
381
309
382
310
public enum Provider {
0 commit comments