/
OIDCClientConfiguration.java
591 lines (507 loc) · 16.1 KB
/
OIDCClientConfiguration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.contrib.oidc.auth.store;
import java.util.Arrays;
import java.util.List;
import org.xwiki.model.reference.LocalDocumentReference;
import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.objects.BaseObject;
/**
* Helper wrapping a BaseObject to make easier to manipulate OIDC client configuration.
*
* @version $Id$
* @since 1.30
*/
public class OIDCClientConfiguration
{
/**
* The String reference of the class defining the object which contains an OIDC configuration.
*/
public static final String CLASS_FULLNAME = "XWiki.OIDC.ClientConfigurationClass";
/**
* The local reference of the configuration class.
*/
public static final LocalDocumentReference CLASS_REFERENCE = new LocalDocumentReference(Arrays.asList(
XWiki.SYSTEM_SPACE, "OIDC"), "ClientConfigurationClass");
/**
* Name of the property containing the configuration.
*/
public static final String FIELD_CONFIGURATION_NAME = "configurationName";
/**
* Name of the property containing the groups claim.
*/
public static final String FIELD_CLAIM_GROUP = "groupsClaim";
/**
* Name of the property containing the group mappings.
*/
public static final String FIELD_GROUP_MAPPING = "groupsMapping";
/**
* Name of the property containing the allowed groups.
*/
public static final String FIELD_ALLOWED_GROUPS = "allowedGroups";
/**
* Name of the property containing the forbidden groups.
*/
public static final String FIELD_FORBIDDEN_GROUPS = "forbiddenGroups";
/**
* Name of the property containing the ID token claims.
*/
public static final String FIELD_CLAIMS_ID_TOKEN = "idTokenClaims";
/**
* Name of the property containing the user info claims.
*/
public static final String FIELD_CLAIMS_USER_INFO = "userInfoClaims";
/**
* Name of the property containing the user name formatter.
*/
public static final String FIELD_FORMATTER_USER_NAME = "userNameFormatter";
/**
* Name of the property containing the user subject formatter.
*/
public static final String FIELD_FORMATTER_USER_SUBJECT = "userSubjectFormatter";
/**
* Name of the property containing the user mapping.
*/
public static final String FIELD_USER_MAPPING = "userMapping";
/**
* Name of the property containing the XWiki provider.
*/
public static final String FIELD_XWIKI_PROVIDER = "xwikiProvider";
/**
* Name of the property containing the authorization endpoint.
*/
public static final String FIELD_ENDPOINT_AUTHORIZATION = "authorizationEndpoint";
/**
* Name of the property containing the token endpoint.
*/
public static final String FIELD_ENDPOINT_TOKEN = "tokenEndpoint";
/**
* Name of the property containing the user info endpoint.
*/
public static final String FIELD_ENDPOINT_USERINFO = "userInfoEndpoint";
/**
* Name of the property containing the logout endpoint.
*/
public static final String FIELD_ENDPOINT_LOGOUT = "logoutEndpoint";
/**
* Name of the property containing the token endpoint method.
*/
public static final String FIELD_ENDPOINT_TOKEN_METHOD = "tokenEndpointMethod";
/**
* Name of the property containing the user info endpoint method.
*/
public static final String FIELD_ENDPOINT_USERINFO_METHOD = "userInfoEndpointMethod";
/**
* Name of the property containing the user info endpoint headers.
*/
public static final String FIELD_ENDPOINT_USERINFO_HEADERS = "userInfoEndpointHeaders";
/**
* Name of the property containing the logout endpoint method.
*/
public static final String FIELD_ENDPOINT_LOGOUT_METHOD = "logoutEndpointMethod";
/**
* Name of the property containing the client id.
*/
public static final String FIELD_CLIENT_ID = "clientId";
/**
* Name of the property containing the client secret.
*/
public static final String FIELD_CLIENT_SECRET = "clientSecret";
/**
* Name of the property indicating if this client configuration should be skipped.
*/
public static final String FIELD_SKIPPED = "skipped";
/**
* Name of the property containing the scope.
*/
public static final String FIELD_SCOPE = "scope";
/**
* Name of the property containing the user info refresh rate.
*/
public static final String FIELD_USER_INFO_REFRESH_RATE = "userInfoRefreshRate";
/**
* The name of the logout mechanism to be used.
* @since 1.31
*/
public static final String FIELD_LOGOUT_MECHANISM = "logoutMechanism";
private static final String LIST_SPLIT_REGEX = "(\\r?\\n|,|\\|)";
private static final String JOIN_CHAR = "\n";
private final BaseObject xobject;
/**
* @param xobject the actual XWiki object
*/
public OIDCClientConfiguration(BaseObject xobject)
{
this.xobject = xobject;
}
/**
* @return the configuration name
*/
public String getConfigurationName()
{
return this.xobject.getStringValue(FIELD_CONFIGURATION_NAME);
}
/**
* @param configurationName the configuration name
*/
public void setConfigurationName(String configurationName)
{
this.xobject.setStringValue(FIELD_CONFIGURATION_NAME, configurationName);
}
/**
* @return the group claim
*/
public String getGroupClaim()
{
return this.xobject.getStringValue(FIELD_CLAIM_GROUP);
}
/**
* @param groupClaim the group claim
*/
public void setGroupClaim(String groupClaim)
{
this.xobject.setStringValue(FIELD_CLAIM_GROUP, groupClaim);
}
/**
* @return the group mapping
*/
public List<String> getGroupMapping()
{
return Arrays.asList(this.xobject.getLargeStringValue(FIELD_GROUP_MAPPING).split(LIST_SPLIT_REGEX));
}
/**
* @param groupMapping the group mapping
*/
public void setGroupMapping(List<String> groupMapping)
{
this.xobject.setLargeStringValue(FIELD_GROUP_MAPPING, String.join(JOIN_CHAR, groupMapping));
}
/**
* @return the allowed groups
*/
public List<String> getAllowedGroups()
{
return Arrays.asList(this.xobject.getLargeStringValue(FIELD_ALLOWED_GROUPS).split(LIST_SPLIT_REGEX));
}
/**
* @param allowedGroups the allowed groups
*/
public void setAllowedGroups(List<String> allowedGroups)
{
this.xobject.setLargeStringValue(FIELD_ALLOWED_GROUPS, String.join(JOIN_CHAR, allowedGroups));
}
/**
* @return the forbidden groups
*/
public List<String> getForbiddenGroups()
{
return Arrays.asList(this.xobject.getLargeStringValue(FIELD_FORBIDDEN_GROUPS).split(LIST_SPLIT_REGEX));
}
/**
* @param forbiddenGroups the forbidden groups
*/
public void setForbiddenGroups(List<String> forbiddenGroups)
{
this.xobject.setLargeStringValue(FIELD_FORBIDDEN_GROUPS, String.join(JOIN_CHAR, forbiddenGroups));
}
/**
* @return the user subject formatter
*/
public String getUserSubjectFormatter()
{
return this.xobject.getStringValue(FIELD_FORMATTER_USER_SUBJECT);
}
/**
* @param userSubjectFormatter the user subject formatter
*/
public void setUserSubjectFormatter(String userSubjectFormatter)
{
this.xobject.setStringValue(FIELD_FORMATTER_USER_SUBJECT, userSubjectFormatter);
}
/**
* @return the user name formatter
*/
public String getUserNameFormatter()
{
return this.xobject.getStringValue(FIELD_FORMATTER_USER_NAME);
}
/**
* @param userNameFormatter the user name formatter
*/
public void setUserNameFormatter(String userNameFormatter)
{
this.xobject.setStringValue(FIELD_FORMATTER_USER_NAME, userNameFormatter);
}
/**
* @return the user mapping
*/
public List<String> getUserMapping()
{
return Arrays.asList(this.xobject.getLargeStringValue(FIELD_USER_MAPPING).split(LIST_SPLIT_REGEX));
}
/**
* @param userMapping the user mapping
*/
public void setUserMapping(List<String> userMapping)
{
this.xobject.setLargeStringValue(FIELD_USER_MAPPING, String.join(JOIN_CHAR, userMapping));
}
/**
* @return the XWiki provider
*/
public String getXWikiProvider()
{
return this.xobject.getStringValue(FIELD_XWIKI_PROVIDER);
}
/**
* @param xwikiProvider the XWiki provider
*/
public void setXWikiProvider(String xwikiProvider)
{
this.xobject.setStringValue(FIELD_XWIKI_PROVIDER, xwikiProvider);
}
/**
* @return the authorization endpoint
*/
public String getAuthorizationEndpoint()
{
return this.xobject.getStringValue(FIELD_ENDPOINT_AUTHORIZATION);
}
/**
* @param authorizationEndpoint the authorization endpoint
*/
public void setAuthorizationEndpoint(String authorizationEndpoint)
{
this.xobject.setStringValue(FIELD_ENDPOINT_AUTHORIZATION, authorizationEndpoint);
}
/**
* @return the token endpoint
*/
public String getTokenEndpoint()
{
return this.xobject.getStringValue(FIELD_ENDPOINT_TOKEN);
}
/**
* @param tokenEndpoint the token endpoint
*/
public void setTokenEndpoint(String tokenEndpoint)
{
this.xobject.setStringValue(FIELD_ENDPOINT_TOKEN, tokenEndpoint);
}
/**
* @return the user info endpoint
*/
public String getUserInfoEndpoint()
{
return this.xobject.getStringValue(FIELD_ENDPOINT_USERINFO);
}
/**
* @param userInfoEndpoint the user info endpoint
*/
public void setUserInfoEndpoint(String userInfoEndpoint)
{
this.xobject.setStringValue(FIELD_ENDPOINT_USERINFO, userInfoEndpoint);
}
/**
* @return the logout endpoint
*/
public String getLogoutEndpoint()
{
return this.xobject.getStringValue(FIELD_ENDPOINT_LOGOUT);
}
/**
* @param logoutEndpoint the logout endpoint
*/
public void setLogoutEndpoint(String logoutEndpoint)
{
this.xobject.setStringValue(FIELD_ENDPOINT_LOGOUT, logoutEndpoint);
}
/**
* @return the client id
*/
public String getClientId()
{
return this.xobject.getStringValue(FIELD_CLIENT_ID);
}
/**
* @param clientId the client id
*/
public void setClientId(String clientId)
{
this.xobject.setStringValue(FIELD_CLIENT_ID, clientId);
}
/**
* @return the client secret
*/
public String getClientSecret()
{
return this.xobject.getStringValue(FIELD_CLIENT_SECRET);
}
/**
* @param clientSecret the client secret
*/
public void setClientSecret(String clientSecret)
{
this.xobject.setStringValue(FIELD_CLIENT_SECRET, clientSecret);
}
/**
* @return the token endpoint method
*/
public String getTokenEndpointMethod()
{
return this.xobject.getStringValue(FIELD_ENDPOINT_TOKEN_METHOD);
}
/**
* @param tokenEndpointMethod the token endpoint method
*/
public void setTokenEndpointMethod(String tokenEndpointMethod)
{
this.xobject.setStringValue(FIELD_ENDPOINT_TOKEN_METHOD, tokenEndpointMethod);
}
/**
* @return the user info endpoint method
*/
public String getUserInfoEndpointMethod()
{
return this.xobject.getStringValue(FIELD_ENDPOINT_USERINFO_METHOD);
}
/**
* @param userInfoEndpointMethod the user info endpoint method
*/
public void setUserInfoEndpointMethod(String userInfoEndpointMethod)
{
this.xobject.setStringValue(FIELD_ENDPOINT_USERINFO_METHOD, userInfoEndpointMethod);
}
/**
* @return the user info endpoint headers
*/
public List<String> getUserInfoEndpointHeaders()
{
return Arrays.asList(this.xobject.getLargeStringValue(FIELD_ENDPOINT_USERINFO_HEADERS).split(LIST_SPLIT_REGEX));
}
/**
* @param userInfoEndpointHeaders the user info endpoint headers
*/
public void setUserInfoEndpointHeaders(List<String> userInfoEndpointHeaders)
{
this.xobject.setLargeStringValue(FIELD_ENDPOINT_USERINFO_HEADERS,
String.join(JOIN_CHAR, userInfoEndpointHeaders));
}
/**
* @return the logout endpoint method
*/
public String getLogoutEndpointMethod()
{
return this.xobject.getStringValue(FIELD_ENDPOINT_LOGOUT_METHOD);
}
/**
* @param logoutEndpointMethod the logout endpoint method
*/
public void setLogoutEndpointMethod(String logoutEndpointMethod)
{
this.xobject.setStringValue(FIELD_ENDPOINT_LOGOUT_METHOD, logoutEndpointMethod);
}
/**
* @return true if the client configuration should be skipped
*/
public boolean isSkipped()
{
return (this.xobject.getIntValue(FIELD_SKIPPED) == 1);
}
/**
* @param isSkipped whether the client configuration should be skipped
*/
public void setIsSkipped(boolean isSkipped)
{
this.xobject.setIntValue(FIELD_SKIPPED, (isSkipped) ? 1 : 0);
}
/**
* @return the scope
*/
public List<String> getScope()
{
return Arrays.asList(this.xobject.getLargeStringValue(FIELD_SCOPE).split(LIST_SPLIT_REGEX));
}
/**
* @param scope the scope
*/
public void setScope(List<String> scope)
{
this.xobject.setLargeStringValue(FIELD_SCOPE, String.join(JOIN_CHAR, scope));
}
/**
* @return the id token claims
*/
public List<String> getIdTokenClaims()
{
return Arrays.asList(this.xobject.getLargeStringValue(FIELD_CLAIMS_ID_TOKEN).split(LIST_SPLIT_REGEX));
}
/**
* @param idTokenClaims the id token claims
*/
public void setIdTokenClaims(List<String> idTokenClaims)
{
this.xobject.setLargeStringValue(FIELD_CLAIMS_ID_TOKEN, String.join(JOIN_CHAR, idTokenClaims));
}
/**
* @return the user info claims
*/
public List<String> getUserInfoClaims()
{
return Arrays.asList(this.xobject.getLargeStringValue(FIELD_CLAIMS_USER_INFO).split(LIST_SPLIT_REGEX));
}
/**
* @param userInfoClaims the user info claims
*/
public void setUserInfoClaims(List<String> userInfoClaims)
{
this.xobject.setLargeStringValue(FIELD_CLAIMS_USER_INFO, String.join(JOIN_CHAR, userInfoClaims));
}
/**
* @return the user info refresh rate
*/
public Integer getUserInfoRefreshRate()
{
return this.xobject.getIntValue(FIELD_USER_INFO_REFRESH_RATE);
}
/**
* @param userInfoRefreshRate the user info refresh rate
*/
public void setUserInfoRefreshRate(int userInfoRefreshRate)
{
this.xobject.setIntValue(FIELD_USER_INFO_REFRESH_RATE, userInfoRefreshRate);
}
/**
* @return the logout mechanism
* @since 1.31
*/
public String getLogoutMechanism()
{
return this.xobject.getStringValue(FIELD_LOGOUT_MECHANISM);
}
/**
* @param logoutMechanism the logout mechanism
* @since 1.31
*/
public void setLogoutMechanism(String logoutMechanism)
{
this.xobject.setStringValue(FIELD_LOGOUT_MECHANISM, logoutMechanism);
}
}