-
Notifications
You must be signed in to change notification settings - Fork 362
/
OAuthServerConfiguration.java
3991 lines (3465 loc) · 191 KB
/
OAuthServerConfiguration.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
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2013-2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.identity.oauth.config;
import org.apache.axiom.om.OMElement;
import org.apache.axis2.util.JavaUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.oltu.oauth2.as.issuer.OAuthIssuer;
import org.apache.oltu.oauth2.as.issuer.OAuthIssuerImpl;
import org.apache.oltu.oauth2.as.issuer.UUIDValueGenerator;
import org.apache.oltu.oauth2.as.issuer.ValueGenerator;
import org.apache.oltu.oauth2.as.validator.CodeValidator;
import org.apache.oltu.oauth2.as.validator.TokenValidator;
import org.apache.oltu.oauth2.common.message.types.GrantType;
import org.apache.oltu.oauth2.common.message.types.ResponseType;
import org.apache.oltu.oauth2.common.validators.OAuthValidator;
import org.wso2.carbon.base.ServerConfigurationException;
import org.wso2.carbon.identity.application.common.cache.BaseCache;
import org.wso2.carbon.identity.core.util.IdentityConfigParser;
import org.wso2.carbon.identity.core.util.IdentityCoreConstants;
import org.wso2.carbon.identity.core.util.IdentityUtil;
import org.wso2.carbon.identity.oauth.common.CodeTokenResponseValidator;
import org.wso2.carbon.identity.oauth.common.IDTokenResponseValidator;
import org.wso2.carbon.identity.oauth.common.IDTokenTokenResponseValidator;
import org.wso2.carbon.identity.oauth.common.OAuthConstants;
import org.wso2.carbon.identity.oauth.common.SAML2GrantValidator;
import org.wso2.carbon.identity.oauth.tokenprocessor.HashingPersistenceProcessor;
import org.wso2.carbon.identity.oauth.tokenprocessor.PlainTextPersistenceProcessor;
import org.wso2.carbon.identity.oauth.tokenprocessor.TokenPersistenceProcessor;
import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception;
import org.wso2.carbon.identity.oauth2.authz.handlers.ResponseTypeHandler;
import org.wso2.carbon.identity.oauth2.model.CarbonOAuthAuthzRequest;
import org.wso2.carbon.identity.oauth2.model.TokenIssuerDO;
import org.wso2.carbon.identity.oauth2.responsemode.provider.ResponseModeProvider;
import org.wso2.carbon.identity.oauth2.responsemode.provider.impl.DefaultResponseModeProvider;
import org.wso2.carbon.identity.oauth2.responsemode.provider.impl.FormPostResponseModeProvider;
import org.wso2.carbon.identity.oauth2.responsemode.provider.impl.FragmentResponseModeProvider;
import org.wso2.carbon.identity.oauth2.responsemode.provider.impl.QueryResponseModeProvider;
import org.wso2.carbon.identity.oauth2.token.OauthTokenIssuer;
import org.wso2.carbon.identity.oauth2.token.OauthTokenIssuerImpl;
import org.wso2.carbon.identity.oauth2.token.handlers.grant.AuthorizationGrantHandler;
import org.wso2.carbon.identity.oauth2.token.handlers.grant.saml.SAML2TokenCallbackHandler;
import org.wso2.carbon.identity.oauth2.util.OAuth2Util;
import org.wso2.carbon.identity.oauth2.validators.OAuth2ScopeHandler;
import org.wso2.carbon.identity.oauth2.validators.OAuth2ScopeValidator;
import org.wso2.carbon.identity.oauth2.validators.grant.AuthorizationCodeGrantValidator;
import org.wso2.carbon.identity.oauth2.validators.grant.ClientCredentialGrantValidator;
import org.wso2.carbon.identity.oauth2.validators.grant.PasswordGrantValidator;
import org.wso2.carbon.identity.oauth2.validators.grant.RefreshTokenGrantValidator;
import org.wso2.carbon.identity.openidconnect.CIBARequestObjectValidatorImpl;
import org.wso2.carbon.identity.openidconnect.CustomClaimsCallbackHandler;
import org.wso2.carbon.identity.openidconnect.IDTokenBuilder;
import org.wso2.carbon.identity.openidconnect.RequestObjectBuilder;
import org.wso2.carbon.identity.openidconnect.RequestObjectValidator;
import org.wso2.carbon.identity.openidconnect.RequestObjectValidatorImpl;
import org.wso2.carbon.utils.CarbonUtils;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.xml.namespace.QName;
/**
* Runtime representation of the OAuth Configuration as configured through
* identity.xml
*/
public class OAuthServerConfiguration {
private static final String CONFIG_ELEM_OAUTH = "OAuth";
// Grant Handler Classes
private static final String AUTHORIZATION_CODE_GRANT_HANDLER_CLASS =
"org.wso2.carbon.identity.oauth2.token.handlers.grant.AuthorizationCodeGrantHandler";
private static final String CLIENT_CREDENTIALS_GRANT_HANDLER_CLASS =
"org.wso2.carbon.identity.oauth2.token.handlers.grant.ClientCredentialsGrantHandler";
private static final String PASSWORD_GRANT_HANDLER_CLASS =
"org.wso2.carbon.identity.oauth2.token.handlers.grant.PasswordGrantHandler";
private static final String REFRESH_TOKEN_GRANT_HANDLER_CLASS =
"org.wso2.carbon.identity.oauth2.token.handlers.grant.RefreshGrantHandler";
private static final String SAML20_BEARER_GRANT_HANDLER_CLASS =
"org.wso2.carbon.identity.oauth2.token.handlers.grant.saml.SAML2BearerGrantHandler";
private static final String IWA_NTLM_BEARER_GRANT_HANDLER_CLASS =
"org.wso2.carbon.identity.oauth2.token.handlers.grant.iwa.ntlm.NTLMAuthenticationGrantHandler";
// Request object builder class.
private static final String REQUEST_PARAM_VALUE_BUILDER_CLASS =
"org.wso2.carbon.identity.openidconnect.RequestParamRequestObjectBuilder";
//token issuer classes
private static final String DEFAULT_OAUTH_TOKEN_ISSUER_CLASS =
"org.wso2.carbon.identity.oauth2.token.OauthTokenIssuerImpl";
private static final String JWT_TOKEN_ISSUER_CLASS =
"org.wso2.carbon.identity.oauth2.token.JWTTokenIssuer";
private static final String REQUEST_PARAM_VALUE_BUILDER = "request_param_value_builder";
private static final Log log = LogFactory.getLog(OAuthServerConfiguration.class);
private static OAuthServerConfiguration instance;
private static String oauth1RequestTokenUrl = null;
private static String oauth1AuthorizeUrl = null;
private static String oauth1AccessTokenUrl = null;
private static String oauth2AuthzEPUrl = null;
private static String oauth2ParEPUrl = null;
private static String oauth2TokenEPUrl = null;
private static String oauth2UserInfoEPUrl = null;
private static String oauth2RevocationEPUrl = null;
private static String oauth2IntrospectionEPUrl = null;
private static String oidcConsentPageUrl = null;
private static String oauth2DCREPUrl = null;
private static String oauth2JWKSPageUrl = null;
private static String oidcWebFingerEPUrl = null;
private static String oidcDiscoveryUrl = null;
private static String oauth2ConsentPageUrl = null;
private static String oauth2ErrorPageUrl = null;
private static boolean isOAuthResponseJspPageAvailable = false;
private long authorizationCodeValidityPeriodInSeconds = 300;
private long userAccessTokenValidityPeriodInSeconds = 3600;
private long jarmResponseJwtValidityPeriodInSeconds = 3600;
private long applicationAccessTokenValidityPeriodInSeconds = 3600;
private long refreshTokenValidityPeriodInSeconds = 24L * 3600;
private long timeStampSkewInSeconds = 300;
private boolean enablePasswordFlowEnhancements = false;
private String tokenPersistenceProcessorClassName =
"org.wso2.carbon.identity.oauth.tokenprocessor.PlainTextPersistenceProcessor";
private String oauthTokenGeneratorClassName;
private OAuthIssuer oauthTokenGenerator;
private String oauthIdentityTokenGeneratorClassName;
private String clientIdValidationRegex = "[a-zA-Z0-9_]{15,30}";
private String persistAccessTokenAlias;
private String retainOldAccessTokens;
private String tokenCleanupFeatureEnable;
private OauthTokenIssuer oauthIdentityTokenGenerator;
private boolean scopeValidationConfigValue = true;
private boolean globalRbacScopeIssuerEnabled = false;
private boolean cacheEnabled = false;
private boolean isTokenRenewalPerRequestEnabled = false;
private boolean isRefreshTokenRenewalEnabled = true;
private boolean isExtendRenewedTokenExpiryTimeEnabled = true;
private boolean assertionsUserNameEnabled = false;
private boolean accessTokenPartitioningEnabled = false;
private boolean redirectToRequestedRedirectUriEnabled = true;
private boolean allowCrossTenantIntrospection = true;
private boolean useClientIdAsSubClaimForAppTokens = true;
private boolean removeUsernameFromIntrospectionResponseForAppTokens = true;
private boolean useLegacyScopesAsAliasForNewScopes = false;
private boolean useLegacyPermissionAccessForUserBasedAuth = false;
private String accessTokenPartitioningDomains = null;
private TokenPersistenceProcessor persistenceProcessor = null;
private Set<OAuthCallbackHandlerMetaData> callbackHandlerMetaData = new HashSet<>();
private Map<String, String> supportedGrantTypeClassNames = new HashMap<>();
private Map<String, Boolean> refreshTokenAllowedGrantTypes = new HashMap<>();
private Map<String, String> idTokenAllowedForGrantTypesMap = new HashMap<>();
private Set<String> idTokenNotAllowedGrantTypesSet = new HashSet<>();
private Set<String> userConsentEnabledGrantTypes = new HashSet<>();
private Map<String, AuthorizationGrantHandler> supportedGrantTypes;
private Map<String, RequestObjectBuilder> requestObjectBuilder;
private Map<String, String> supportedGrantTypeValidatorNames = new HashMap<>();
private Map<String, Class<? extends OAuthValidator<HttpServletRequest>>> supportedGrantTypeValidators;
private Map<String, String> supportedResponseTypeClassNames = new HashMap<>();
private Map<String, ResponseTypeHandler> supportedResponseTypes;
private Map<String, String> supportedResponseTypeValidatorNames = new HashMap<>();
private Map<String, String> supportedResponseModeProviderClassNames = new HashMap<>();
private Map<String, ResponseModeProvider> supportedResponseModes;
private String defaultResponseModeProviderClassName;
private ResponseModeProvider defaultResponseModeProvider;
private Map<String, Class<? extends OAuthValidator<HttpServletRequest>>> supportedResponseTypeValidators;
private Map<String, TokenIssuerDO> supportedTokenIssuers = new HashMap<>();
private List<String> supportedTokenTypes = new ArrayList<>();
private List<String> publicClientSupportedGrantTypes = new ArrayList<>();
private List<String> publicClientNotSupportedGrantTypes = new ArrayList<>();
private Map<String, OauthTokenIssuer> oauthTokenIssuerMap = new HashMap<>();
private String[] supportedClaims = null;
private boolean isFapiCiba = false;
private boolean isFapiSecurity = false;
private Map<String, Properties> supportedClientAuthHandlerData = new HashMap<>();
private String saml2TokenCallbackHandlerName = null;
private String saml2BearerTokenUserType;
private boolean saml2UserIdFromClaims = false;
private boolean mapFederatedUsersToLocal = false;
private SAML2TokenCallbackHandler saml2TokenCallbackHandler = null;
private Map<String, String> tokenValidatorClassNames = new HashMap();
private boolean isAuthContextTokGenEnabled = false;
private String tokenGeneratorImplClass = "org.wso2.carbon.identity.oauth2.token.JWTTokenGenerator";
private String claimsRetrieverImplClass = "org.wso2.carbon.identity.oauth2.authcontext.DefaultClaimsRetriever";
private String consumerDialectURI = "http://wso2.org/claims";
private String signatureAlgorithm = "SHA256withRSA";
private String idTokenSignatureAlgorithm = "SHA256withRSA";
private String defaultIdTokenEncryptionAlgorithm = "RSA-OAEP";
private List<String> supportedIdTokenEncryptionAlgorithms = new ArrayList<>();
private String defaultIdTokenEncryptionMethod = "A128GCM";
private List<String> supportedIdTokenEncryptionMethods = new ArrayList<>();
private String userInfoJWTSignatureAlgorithm = "SHA256withRSA";
private String authContextTTL = "15L";
// property added to fix IDENTITY-4551 in backward compatible manner
private boolean useMultiValueSeparatorForAuthContextToken = true;
private boolean addTenantDomainToIdTokenEnabled = false;
private boolean addUserstoreDomainToIdTokenEnabled = false;
private boolean requestObjectEnabled = true;
//default token types
public static final String DEFAULT_TOKEN_TYPE = "Default";
public static final String JWT_TOKEN_TYPE = "JWT";
// OpenID Connect configurations
private String openIDConnectIDTokenBuilderClassName =
"org.wso2.carbon.identity.openidconnect.DefaultIDTokenBuilder";
private String defaultRequestValidatorClassName =
"org.wso2.carbon.identity.openidconnect.RequestObjectValidatorImpl";
private String defaultCibaRequestValidatorClassName =
"org.wso2.carbon.identity.openidconnect.CIBARequestObjectValidatorImpl";
private String oAuthAuthzRequestClassName;
public static final String DEFAULT_OAUTH_AUTHZ_REQUEST_CLASSNAME = CarbonOAuthAuthzRequest.class.getName();
private String openIDConnectIDTokenCustomClaimsHanlderClassName =
"org.wso2.carbon.identity.openidconnect.SAMLAssertionClaimsCallback";
private IDTokenBuilder openIDConnectIDTokenBuilder = null;
private Map<String, String> requestObjectBuilderClassNames = new HashMap<>();
private volatile RequestObjectValidator requestObjectValidator = null;
private volatile RequestObjectValidator cibaRequestObjectValidator = null;
private CustomClaimsCallbackHandler openidConnectIDTokenCustomClaimsCallbackHandler = null;
private String openIDConnectIDTokenIssuerIdentifier = null;
private String openIDConnectIDTokenSubClaim = "http://wso2.org/claims/fullname";
private Boolean openIDConnectSkipUserConsent = true;
private Boolean openIDConnectSkipLoginConsent;
private Boolean openIDConnectSkipLogoutConsent;
private String openIDConnectIDTokenExpiration = "3600";
private long openIDConnectIDTokenExpiryTimeInSeconds = 3600;
private String openIDConnectUserInfoEndpointClaimDialect = "http://wso2.org/claims";
private String openIDConnectUserInfoEndpointClaimRetriever =
"org.wso2.carbon.identity.oauth.endpoint.user.impl.UserInfoUserStoreClaimRetriever";
private String openIDConnectUserInfoEndpointRequestValidator =
"org.wso2.carbon.identity.oauth.endpoint.user.impl.UserInforRequestDefaultValidator";
private String openIDConnectUserInfoEndpointAccessTokenValidator =
"org.wso2.carbon.identity.oauth.endpoint.user.impl.UserInfoISAccessTokenValidator";
private String openIDConnectUserInfoEndpointResponseBuilder =
"org.wso2.carbon.identity.oauth.endpoint.user.impl.UserInfoJSONResponseBuilder";
// Property added to preserve the backward compatibility to send the original claim uris comes in the assertion.
private boolean convertOriginalClaimsFromAssertionsToOIDCDialect = false;
// This property will decide whether to send only mapped roles received from the federated IdP
private boolean returnOnlyMappedLocalRoles = false;
// Property to check whether to add remaining user attributes
private boolean addUnmappedUserAttributes = false;
private OAuth2ScopeValidator oAuth2ScopeValidator;
private Set<OAuth2ScopeValidator> oAuth2ScopeValidators = new HashSet<>();
private Set<OAuth2ScopeHandler> oAuth2ScopeHandlers = new HashSet<>();
// property added to fix IDENTITY-4492 in backward compatible manner
private boolean isJWTSignedWithSPKey = true;
// property added to fix IDENTITY-4534 in backward compatible manner
private boolean isImplicitErrorFragment = true;
// property added to fix IDENTITY-4112 in backward compatible manner
private boolean isRevokeResponseHeadersEnabled = true;
// property to make DisplayName property to be used in consent page
private boolean showDisplayNameInConsentPage = false;
// Use the SP tenant domain instead of user domain.
private boolean useSPTenantDomainValue;
// Property added to customize the token valued generation method. (IDENTITY-6139)
private ValueGenerator tokenValueGenerator;
// property to skip OIDC claims retrieval for client credential grant type.
// By default, this is true because OIDC claims are not required for client credential grant type
// and CC grant doesn't involve a user.
private boolean skipOIDCClaimsForClientCredentialGrant = true;
private String tokenValueGeneratorClassName;
//property to define hashing algorithm when enabling hashing of tokens and authorization codes.
private String hashAlgorithm = "SHA-256";
private boolean isClientSecretHashEnabled = false;
// Property added to determine the expiration of logout token in oidc back-channel logout.
private String openIDConnectBCLogoutTokenExpiryInSeconds = "120";
// Property to determine whether data providers should be executed during token introspection.
private boolean enableIntrospectionDataProviders = false;
// Property to define the allowed scopes.
private List<String> allowedScopes = new ArrayList<>();
// Property to define the filtered claims.
private List<String> filteredIntrospectionClaims = new ArrayList<>();
// Property to check whether to drop unregistered scopes.
private boolean dropUnregisteredScopes = false;
// Properties for OAuth2 Device Code Grant type.
private int deviceCodeKeyLength = 6;
private long deviceCodeExpiryTime = 600000L;
private int deviceCodePollingInterval = 5000;
private String deviceCodeKeySet = "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz23456789";
private String deviceAuthzEPUrl = null;
private List<String> supportedTokenEndpointSigningAlgorithms = new ArrayList<>();
private Boolean roleBasedScopeIssuerEnabledConfig = false;
private OAuthServerConfiguration() {
buildOAuthServerConfiguration();
}
public static OAuthServerConfiguration getInstance() {
CarbonUtils.checkSecurity();
if (instance == null) {
synchronized (OAuthServerConfiguration.class) {
if (instance == null) {
instance = new OAuthServerConfiguration();
}
}
}
return instance;
}
private void buildOAuthServerConfiguration() {
IdentityConfigParser configParser = IdentityConfigParser.getInstance();
OMElement oauthElem = configParser.getConfigElement(CONFIG_ELEM_OAUTH);
if (oauthElem == null) {
warnOnFaultyConfiguration("OAuth element is not available.");
return;
}
// read callback handler configurations
parseOAuthCallbackHandlers(oauthElem.getFirstChildWithName(
getQNameWithIdentityNS(ConfigElements.OAUTH_CALLBACK_HANDLERS)));
// get the token validators by type
parseTokenValidators(oauthElem.getFirstChildWithName(
getQNameWithIdentityNS(ConfigElements.TOKEN_VALIDATORS)));
// Get the configured jdbc scope validator
OMElement scopeValidatorElem = oauthElem.getFirstChildWithName(
getQNameWithIdentityNS(ConfigElements.SCOPE_VALIDATOR));
//Get the configured scope validators
OMElement scopeValidatorsElem = oauthElem.getFirstChildWithName(
getQNameWithIdentityNS(ConfigElements.SCOPE_VALIDATORS));
//Get the configured scopeValidationEnabledConfigValue.
OMElement scopeValidationElem = oauthElem.getFirstChildWithName(
getQNameWithIdentityNS(ConfigElements.SCOPE_VALIDATION_FOR_AUTHZ_CODE_AND_IMPLICIT));
if (scopeValidationElem != null) {
scopeValidationConfigValue = Boolean.parseBoolean(scopeValidationElem.getText());
}
if (scopeValidatorElem != null) {
parseScopeValidator(scopeValidatorElem);
} else if (scopeValidatorsElem != null) {
parseScopeValidator(scopeValidatorsElem);
}
//Get the configured scope handlers
OMElement scopeHandlersElem = oauthElem.getFirstChildWithName(
getQNameWithIdentityNS(ConfigElements.SCOPE_HANDLERS));
if (scopeHandlersElem != null) {
parseScopeHandlers(scopeHandlersElem);
}
OMElement globalRoleBasedScopeIssuer = oauthElem.getFirstChildWithName(
getQNameWithIdentityNS(ConfigElements.ENABLE_GLOBAL_ROLE_BASED_SCOPE_ISSUER)
);
if (globalRoleBasedScopeIssuer != null) {
setGlobalRbacScopeIssuerEnabled(Boolean.parseBoolean(globalRoleBasedScopeIssuer.getText()));
}
// read default timeout periods
parseDefaultValidityPeriods(oauthElem);
parseEnablePasswordFlowEnhancements(oauthElem);
// read OAuth URLs
parseOAuthURLs(oauthElem);
// read token renewal per request config.
// if enabled access token and refresh token will be renewed for each token endpoint call.
parseTokenRenewalPerRequestConfiguration(oauthElem);
// Read map federated users to local config.
parseMapFederatedUsersToLocalConfiguration(oauthElem);
// read refresh token renewal config
parseRefreshTokenRenewalConfiguration(oauthElem);
// read token persistence processor config
parseTokenPersistenceProcessorConfig(oauthElem);
// read supported grant types
parseSupportedGrantTypesConfig(oauthElem);
// Read <UserConsentEnabledGrantTypes> under <OAuth> tag and populate data.
parseUserConsentEnabledGrantTypesConfig(oauthElem);
// read supported response types
parseSupportedResponseTypesConfig(oauthElem);
// read supported response modes
parseSupportedResponseModesConfig(oauthElem);
// read supported response types
parseSupportedClientAuthHandlersConfig(oauthElem.getFirstChildWithName(
getQNameWithIdentityNS(ConfigElements.CLIENT_AUTH_HANDLERS)));
// read SAML2 grant config
parseSAML2GrantConfig(oauthElem);
// read JWT generator config
parseAuthorizationContextTokenGeneratorConfig(oauthElem);
// read the assertions user name config
parseEnableAssertionsUserNameConfig(oauthElem);
// read access token partitioning config
parseAccessTokenPartitioningConfig(oauthElem);
// read access token partitioning domains config
parseAccessTokenPartitioningDomainsConfig(oauthElem);
// read openid connect configurations
parseOpenIDConnectConfig(oauthElem);
parseSkipOIDCClaimsForClientCredentialGrantConfig(oauthElem);
// parse OAuth 2.0 token generator
parseOAuthTokenGeneratorConfig(oauthElem);
// parse OAuth2 implicit grant error in fragment property for backward compatibility
parseImplicitErrorFragment(oauthElem);
// parse identity OAuth 2.0 token generator
parseOAuthTokenIssuerConfig(oauthElem);
// parse client is validation regex pattern
parseClientIdValidationRegex(oauthElem);
// Parse Persist Access Token Alias element.
parsePersistAccessTokenAliasConfig(oauthElem);
//read supported token types
parseSupportedTokenTypesConfig(oauthElem);
// Parse token value generator class name.
parseOAuthTokenValueGenerator(oauthElem);
// Parse values of DeviceCodeGrant config.
parseOAuthDeviceCodeGrantConfig(oauthElem);
// Read the value of UseSPTenantDomain config.
parseUseSPTenantDomainConfig(oauthElem);
parseRevokeResponseHeadersEnableConfig(oauthElem);
parseShowDisplayNameInConsentPage(oauthElem);
// read hash algorithm type config
parseHashAlgorithm(oauthElem);
// read hash mode config
parseEnableHashMode(oauthElem);
// Read the value of retain Access Tokens config. If true old token will be stored in Audit table else drop it.
parseRetainOldAccessTokensConfig(oauthElem);
// Read the value of old Access Tokens cleanup enable config. If true cleanup feature will be enable.
tokenCleanupFeatureConfig(oauthElem);
// Read token introspection related configurations.
parseTokenIntrospectionConfig(oauthElem);
// Read the property for error redirection URI
parseRedirectToOAuthErrorPageConfig(oauthElem);
// Read config for allowed scopes.
parseAllowedScopesConfiguration(oauthElem);
// Read config for filtered claims for introspection response.
parseFilteredClaimsForIntrospectionConfiguration(oauthElem);
// Read config for dropping unregistered scopes.
parseDropUnregisteredScopes(oauthElem);
// Read config for cross tenant allow.
parseAllowCrossTenantIntrospection(oauthElem);
// Read config for using client id as sub claim for application tokens.
parseUseClientIdAsSubClaimForAppTokens(oauthElem);
// Read config for remove username from introspection response for application tokens.
parseRemoveUsernameFromIntrospectionResponseForAppTokens(oauthElem);
// Set the availability of oauth_response.jsp page.
setOAuthResponseJspPageAvailable();
// Read config for RoleBasedScopeIssuer in GlobalScopeValidators enabled.
parseRoleBasedScopeIssuerEnabled(oauthElem);
// Read config for using legacy scopes as alias for new scopes.
parseUseLegacyScopesAsAliasForNewScopes(oauthElem);
// Read config for using legacy permission access for user based auth.
parseUseLegacyPermissionAccessForUserBasedAuth(oauthElem);
}
/**
* Parse role based scope issuer enabled configuration under global scope validators.
*
* @param oauthConfigElem oauthConfigElem.
*/
private void parseRoleBasedScopeIssuerEnabled(OMElement oauthConfigElem) {
OMElement globalScopeValidatorsElem = oauthConfigElem.getFirstChildWithName(
getQNameWithIdentityNS(ConfigElements.GLOBAL_SCOPE_VALIDATORS));
if (globalScopeValidatorsElem != null) {
OMElement roleBasedScopeIssuerEnabledElem = globalScopeValidatorsElem.getFirstChildWithName(
getQNameWithIdentityNS(ConfigElements.ROLE_BASED_SCOPE_ISSUER_ENABLED));
if (roleBasedScopeIssuerEnabledElem != null) {
OMElement enableElem = roleBasedScopeIssuerEnabledElem.getFirstChildWithName(
getQNameWithIdentityNS(ConfigElements.ENABLE));
roleBasedScopeIssuerEnabledConfig = Boolean.parseBoolean(enableElem.getText().trim());
}
}
}
/**
* Parse allowed scopes configuration.
*
* @param oauthConfigElem oauthConfigElem.
*/
private void parseAllowedScopesConfiguration(OMElement oauthConfigElem) {
OMElement allowedScopesElem = oauthConfigElem.getFirstChildWithName(
getQNameWithIdentityNS(ConfigElements.ALLOWED_SCOPES_ELEMENT));
if (allowedScopesElem != null) {
Iterator scopeIterator = allowedScopesElem.getChildrenWithName(getQNameWithIdentityNS(
ConfigElements.SCOPES_ELEMENT));
while (scopeIterator.hasNext()) {
OMElement scopeElement = (OMElement) scopeIterator.next();
allowedScopes.add(scopeElement.getText());
}
}
}
/**
* Parse config for skipping OIDC claims for client credentials
*
* @param oauthElem OauthConfigElem.
*/
private void parseSkipOIDCClaimsForClientCredentialGrantConfig(OMElement oauthElem) {
OMElement skipOIDCClaimsForClientCredentialGrantElement = oauthElem
.getFirstChildWithName(getQNameWithIdentityNS(ConfigElements
.SKIP_OIDC_CLAIMS_FOR_CLIENT_CREDENTIAL_GRANT));
if (skipOIDCClaimsForClientCredentialGrantElement != null) {
skipOIDCClaimsForClientCredentialGrant = Boolean.parseBoolean(
skipOIDCClaimsForClientCredentialGrantElement.getText().trim());
}
}
/**
* Parse filtered claims for introspection response configuration.
*
* @param oauthConfigElem oauthConfigElem.
*/
private void parseFilteredClaimsForIntrospectionConfiguration(OMElement oauthConfigElem) {
OMElement introspectionClaimsElem = oauthConfigElem.getFirstChildWithName(
getQNameWithIdentityNS(ConfigElements.INTROSPECTION_CONFIG));
if (introspectionClaimsElem != null) {
OMElement filteredClaimsElem = introspectionClaimsElem.getFirstChildWithName(
getQNameWithIdentityNS(ConfigElements.FILTERED_CLAIMS));
if (filteredClaimsElem != null) {
Iterator claimIterator = filteredClaimsElem.getChildrenWithName(getQNameWithIdentityNS(
ConfigElements.FILTERED_CLAIM));
while (claimIterator.hasNext()) {
OMElement claimElement = (OMElement) claimIterator.next();
filteredIntrospectionClaims.add(claimElement.getText());
}
}
}
}
private void parseTokenIntrospectionConfig(OMElement oauthElem) {
OMElement introspectionElem = oauthElem.getFirstChildWithName(getQNameWithIdentityNS(
ConfigElements.INTROSPECTION_CONFIG));
if (introspectionElem != null) {
// Reads 'EnableDataProviders' config.
OMElement enableDataProvidersElem = introspectionElem.getFirstChildWithName(
getQNameWithIdentityNS(ConfigElements.ENABLE_DATA_PROVIDERS_CONFIG));
if (enableDataProvidersElem != null) {
enableIntrospectionDataProviders = Boolean.parseBoolean(enableDataProvidersElem.getText().trim());
}
}
}
private void parseShowDisplayNameInConsentPage(OMElement oauthElem) {
OMElement showApplicationNameInConsentPageElement = oauthElem
.getFirstChildWithName(getQNameWithIdentityNS(ConfigElements
.IDENTITY_OAUTH_SHOW_DISPLAY_NAME_IN_CONSENT_PAGE));
if (showApplicationNameInConsentPageElement != null) {
showDisplayNameInConsentPage = Boolean.parseBoolean(showApplicationNameInConsentPageElement.getText());
}
}
private void parseDropUnregisteredScopes(OMElement oauthElem) {
OMElement dropUnregisteredScopesElement =
oauthElem.getFirstChildWithName(getQNameWithIdentityNS(ConfigElements.DROP_UNREGISTERED_SCOPES));
if (dropUnregisteredScopesElement != null) {
dropUnregisteredScopes = Boolean.parseBoolean(dropUnregisteredScopesElement.getText());
}
}
/**
* This method returns if FAPI is enabled for CIBA in identity.xml.
*/
public boolean isFapiCiba() {
return isFapiCiba;
}
public Set<OAuthCallbackHandlerMetaData> getCallbackHandlerMetaData() {
return callbackHandlerMetaData;
}
/**
* Returns the value of ShowDisplayNameInConsentPage configuration.
*
* @return
*/
public boolean isShowDisplayNameInConsentPage() {
return showDisplayNameInConsentPage;
}
/**
* Returns the value of DropUnregisteredScopes configuration.
*
* @return value of DropUnregisteredScopes configuration.
*/
public boolean isDropUnregisteredScopes() {
return dropUnregisteredScopes;
}
/**
* Get the list of alloed scopes.
*
* @return String returns a list of scope string.
*/
public List<String> getAllowedScopes() {
return allowedScopes;
}
public List<String> getFilteredIntrospectionClaims() {
return filteredIntrospectionClaims;
}
public String getOAuth1RequestTokenUrl() {
return oauth1RequestTokenUrl;
}
public String getOAuth1AuthorizeUrl() {
return oauth1AuthorizeUrl;
}
public String getOAuth1AccessTokenUrl() {
return oauth1AccessTokenUrl;
}
public String getOAuth2AuthzEPUrl() {
return oauth2AuthzEPUrl;
}
public String getOAuth2ParEPUrl() {
return oauth2ParEPUrl;
}
public String getOAuth2TokenEPUrl() {
return oauth2TokenEPUrl;
}
public String getOAuth2DCREPUrl() {
return oauth2DCREPUrl;
}
public String getOAuth2JWKSPageUrl() {
return oauth2JWKSPageUrl;
}
public String getOidcDiscoveryUrl() {
return oidcDiscoveryUrl;
}
public String getOidcWebFingerEPUrl() {
return oidcWebFingerEPUrl;
}
public String getOauth2UserInfoEPUrl() {
return oauth2UserInfoEPUrl;
}
public String getOauth2RevocationEPUrl() {
return oauth2RevocationEPUrl;
}
public String getOauth2IntrospectionEPUrl() {
return oauth2IntrospectionEPUrl;
}
public String getDeviceAuthzEPUrl() {
return deviceAuthzEPUrl;
}
public boolean isRoleBasedScopeIssuerEnabled() {
return roleBasedScopeIssuerEnabledConfig;
}
public boolean isSkipOIDCClaimsForClientCredentialGrant() {
return skipOIDCClaimsForClientCredentialGrant;
}
/**
* instantiate the OAuth token generator. to override the default implementation, one can specify the custom class
* in the identity.xml.
*
* @return
*/
public OAuthIssuer getOAuthTokenGenerator() {
if (oauthTokenGenerator == null) {
synchronized (this) {
if (oauthTokenGenerator == null) {
try {
if (oauthTokenGeneratorClassName != null) {
Class clazz = this.getClass().getClassLoader().loadClass(oauthTokenGeneratorClassName);
oauthTokenGenerator = (OAuthIssuer) clazz.newInstance();
log.info("An instance of " + oauthTokenGeneratorClassName
+ " is created for OAuth token generation.");
} else {
oauthTokenGenerator = new OAuthIssuerImpl(getTokenValueGenerator());
log.info("The default OAuth token issuer will be used. No custom token generator is set.");
}
} catch (Exception e) {
String errorMsg = "Error when instantiating the OAuthIssuer : "
+ tokenPersistenceProcessorClassName + ". Defaulting to OAuthIssuerImpl";
log.error(errorMsg, e);
oauthTokenGenerator = new OAuthIssuerImpl(getTokenValueGenerator());
}
}
}
}
return oauthTokenGenerator;
}
/**
* Get the instance of the token value generator according to the identity xml configuration value.
*
* @return ValueGenerator object instance.
*/
public ValueGenerator getTokenValueGenerator() {
if (tokenValueGenerator == null) {
synchronized (this) {
if (tokenValueGenerator == null) {
try {
if (tokenValueGeneratorClassName != null) {
Class clazz = this.getClass().getClassLoader().loadClass(tokenValueGeneratorClassName);
tokenValueGenerator = (ValueGenerator) clazz.newInstance();
if (log.isDebugEnabled()) {
log.debug("An instance of " + tokenValueGeneratorClassName + " is created.");
}
} else {
tokenValueGenerator = new UUIDValueGenerator();
if (log.isDebugEnabled()) {
log.debug("Default token value generator UUIDValueGenerator will be used.");
}
}
} catch (Exception e) {
log.error("Error while initiating the token value generator :" + tokenValueGeneratorClassName +
". Defaulting to UUIDValueGenerator.", e);
tokenValueGenerator = new UUIDValueGenerator();
}
}
}
}
return tokenValueGenerator;
}
/**
* Returns server level default identity oauth token issuer
*
* @return instance of default identity oauth token issuer
*/
public OauthTokenIssuer getIdentityOauthTokenIssuer() {
if (oauthIdentityTokenGenerator == null) {
synchronized (this) {
if (oauthIdentityTokenGenerator == null) {
try {
if (oauthIdentityTokenGeneratorClassName != null) {
Class clazz = this.getClass().getClassLoader().loadClass
(oauthIdentityTokenGeneratorClassName);
oauthIdentityTokenGenerator = (OauthTokenIssuer) clazz.newInstance();
log.info("An instance of " + oauthIdentityTokenGeneratorClassName
+ " is created for Identity OAuth token generation.");
} else {
oauthIdentityTokenGenerator = new OauthTokenIssuerImpl();
log.info("The default Identity OAuth token issuer will be used. No custom token " +
"generator is set.");
}
} catch (Exception e) {
String errorMsg = "Error when instantiating the OAuthIssuer : "
+ tokenPersistenceProcessorClassName + ". Defaulting to OAuthIssuerImpl";
log.error(errorMsg, e);
oauthIdentityTokenGenerator = new OauthTokenIssuerImpl();
}
}
}
}
return oauthIdentityTokenGenerator;
}
public boolean usePersistedAccessTokenAlias() {
if (persistAccessTokenAlias != null) {
return Boolean.TRUE.toString().equalsIgnoreCase(persistAccessTokenAlias);
} else {
return true;
}
}
public boolean useRetainOldAccessTokens() {
return Boolean.TRUE.toString().equalsIgnoreCase(retainOldAccessTokens);
}
public boolean isTokenCleanupEnabled() {
return Boolean.TRUE.toString().equalsIgnoreCase(tokenCleanupFeatureEnable);
}
public String getOIDCConsentPageUrl() {
return oidcConsentPageUrl;
}
public String getOauth2ConsentPageUrl() {
return oauth2ConsentPageUrl;
}
public String getOauth2ErrorPageUrl() {
return oauth2ErrorPageUrl;
}
public boolean isPasswordFlowEnhancementsEnabled() {
return enablePasswordFlowEnhancements;
}
public long getAuthorizationCodeValidityPeriodInSeconds() {
return authorizationCodeValidityPeriodInSeconds;
}
public long getUserAccessTokenValidityPeriodInSeconds() {
return userAccessTokenValidityPeriodInSeconds;
}
public long getJarmResponseJwtValidityPeriodInSeconds() {
return jarmResponseJwtValidityPeriodInSeconds;
}
public long getApplicationAccessTokenValidityPeriodInSeconds() {
return applicationAccessTokenValidityPeriodInSeconds;
}
public long getRefreshTokenValidityPeriodInSeconds() {
return refreshTokenValidityPeriodInSeconds;
}
public long getTimeStampSkewInSeconds() {
return timeStampSkewInSeconds;
}
public String getClientIdValidationRegex() {
return clientIdValidationRegex;
}
/**
* @deprecated From v5.1.3 use @{@link BaseCache#isEnabled()} to check whether a cache is enabled or not instead
* of relying on <EnableOAuthCache> global Cache config
*/
public boolean isCacheEnabled() {
return cacheEnabled;
}
public boolean isRefreshTokenRenewalEnabled() {
return isRefreshTokenRenewalEnabled;
}
public boolean isExtendRenewedTokenExpiryTimeEnabled() {
return isExtendRenewedTokenExpiryTimeEnabled;
}
public Map<String, OauthTokenIssuer> getOauthTokenIssuerMap() {
return oauthTokenIssuerMap;
}
/**
* Check if token renewal is enabled for each call to the token endpoint.
*
* @return Returns true if the config is enabled.
*/
public boolean isTokenRenewalPerRequestEnabled() {
return isTokenRenewalPerRequestEnabled;
}
public Map<String, AuthorizationGrantHandler> getSupportedGrantTypes() {
if (supportedGrantTypes == null) {
synchronized (this) {
if (supportedGrantTypes == null) {
Map<String, AuthorizationGrantHandler> supportedGrantTypesTemp = new HashMap<>();
for (Map.Entry<String, String> entry : supportedGrantTypeClassNames.entrySet()) {
AuthorizationGrantHandler authzGrantHandler = null;
try {
authzGrantHandler =
(AuthorizationGrantHandler) Class.forName(entry.getValue()).newInstance();
authzGrantHandler.init();
} catch (InstantiationException e) {
log.error("Error instantiating " + entry.getValue(), e);
} catch (IllegalAccessException e) {
log.error("Illegal access to " + entry.getValue(), e);
} catch (ClassNotFoundException e) {
log.error("Cannot find class: " + entry.getValue(), e);
} catch (IdentityOAuth2Exception e) {
log.error("Error while initializing " + entry.getValue(), e);
}
if (authzGrantHandler != null) {
supportedGrantTypesTemp.put(entry.getKey(), authzGrantHandler);
} else {
log.warn("Grant type : " + entry.getKey() + ", is not added as a supported grant type. "
+ "Relevant grant handler failed to initiate properly.");
}
}
supportedGrantTypes = supportedGrantTypesTemp;
}
}
}
return supportedGrantTypes;
}
/**
* Returns a map of supported grant type validators that are configured in identity.xml.
* This method loads default grant type validator classes for PASSWORD, CLIENT_CREDENTIALS, AUTHORIZATION_CODE,
* REFRESH_TOKEN and SAML20_BEARER grant types and also loads validator classes configured in identity.xml for
* custom grant types under /Server/OAuth/SupportedGrantTypes/GrantTypeValidatorImplClass element.
* A validator class defined under this element should be an implementation of org.apache.amber.oauth2.common
* .validators.OAuthValidator
*
* @return a map of <Grant type, Oauth validator class>
*/
public Map<String, Class<? extends OAuthValidator<HttpServletRequest>>> getSupportedGrantTypeValidators() {
if (supportedGrantTypeValidators == null) {
synchronized (this) {
if (supportedGrantTypeValidators == null) {
Map<String, Class<? extends OAuthValidator<HttpServletRequest>>> supportedGrantTypeValidatorsTemp =
new Hashtable<>();