-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathOauthClientConfigurationProperties.java
More file actions
1032 lines (887 loc) · 34.1 KB
/
Copy pathOauthClientConfigurationProperties.java
File metadata and controls
1032 lines (887 loc) · 34.1 KB
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 2017-2023 original authors
*
* Licensed 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
*
* https://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 io.micronaut.security.oauth2.configuration;
import io.micronaut.context.annotation.ConfigurationProperties;
import io.micronaut.context.annotation.Context;
import io.micronaut.context.annotation.EachProperty;
import io.micronaut.context.annotation.Parameter;
import io.micronaut.context.annotation.Requires;
import io.micronaut.security.oauth2.configuration.endpoints.AuthorizationEndpointConfiguration;
import io.micronaut.security.oauth2.configuration.endpoints.ClientAssertionConfiguration;
import io.micronaut.security.oauth2.configuration.endpoints.DefaultEndpointConfiguration;
import io.micronaut.security.oauth2.configuration.endpoints.DefaultSecureEndpointConfiguration;
import io.micronaut.security.oauth2.configuration.endpoints.EndSessionEndpointConfiguration;
import io.micronaut.security.oauth2.configuration.endpoints.EndpointConfiguration;
import io.micronaut.security.oauth2.configuration.endpoints.IntrospectionEndpointConfiguration;
import io.micronaut.security.oauth2.configuration.endpoints.OauthAuthorizationEndpointConfiguration;
import io.micronaut.security.oauth2.configuration.endpoints.RevocationEndpointConfiguration;
import io.micronaut.security.oauth2.configuration.endpoints.SecureEndpointConfiguration;
import io.micronaut.security.oauth2.configuration.endpoints.TokenEndpointConfiguration;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import io.micronaut.core.convert.format.MapFormat;
import io.micronaut.http.MediaType;
import io.micronaut.http.util.OutgoingRequestProcessorMatcher;
import io.micronaut.security.oauth2.client.clientcredentials.ClientCredentialsConfiguration;
import io.micronaut.security.oauth2.client.clientcredentials.propagation.ClientCredentialsHeaderTokenPropagatorConfiguration;
import io.micronaut.security.oauth2.endpoint.authorization.request.Display;
import io.micronaut.security.oauth2.endpoint.authorization.request.OpenIdScope;
import io.micronaut.security.oauth2.endpoint.authorization.request.Prompt;
import io.micronaut.security.oauth2.endpoint.authorization.request.ResponseType;
import io.micronaut.security.oauth2.endpoint.endsession.request.AuthorizationServer;
import io.micronaut.security.oauth2.grants.GrantType;
import io.micronaut.security.token.propagation.AbstractOutgoingRequestProcessorMatcher;
import java.net.URL;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* Stores configuration of each configured OAuth 2.0 client.
*
* @author James Kleeh
* @since 1.2.0
*/
@Context
@EachProperty(OauthConfigurationProperties.PREFIX + ".clients")
@Requires(classes = OutgoingRequestProcessorMatcher.class)
public class OauthClientConfigurationProperties implements OauthClientConfiguration {
/**
* The default enable value.
*/
@SuppressWarnings("WeakerAccess")
public static final boolean DEFAULT_ENABLED = true;
// If you change the default, edit the javadoc of `setScopes` which is exposed in the docs.
private static final List<String> DEFAULT_SCOPES_OPENID = Arrays.asList(OpenIdScope.OPENID.toString(),
OpenIdScope.EMAIL.toString(),
OpenIdScope.PROFILE.toString());
private List<String> defaultScopes = new ArrayList<>();
private final String name;
private String clientId;
private String clientSecret;
private List<String> scopes;
private boolean enabled = DEFAULT_ENABLED;
private GrantType grantType = GrantType.AUTHORIZATION_CODE;
private AuthorizationEndpointConfigurationProperties authorization;
private TokenEndpointConfigurationProperties token;
private IntrospectionEndpointConfigurationProperties introspection;
private RevocationEndpointConfigurationProperties revocation;
private OpenIdClientConfigurationProperties openid;
private ClientCredentialsConfigurationProperties clientCredentials;
private AuthorizationServer authorizationServer;
private boolean proxyWellKnownOauthAuthorizationServer;
private boolean proxyWellKnownOpenidConfiguration;
/**
* @param name The provider name
*/
public OauthClientConfigurationProperties(@Parameter String name) {
this.name = name;
}
@Override
public boolean isProxyWellKnownOauthAuthorizationServer() {
return proxyWellKnownOauthAuthorizationServer;
}
/**
* Whether a request to /.well-known/oauth-authorization-server should be proxied to the authorization server. Default to false.
* @param proxyWellKnownOauthAuthorizationServer Whether a request to /.well-known/oauth-authorization-server should be proxied to the authorization server.
*/
public void setProxyWellKnownOauthAuthorizationServer(boolean proxyWellKnownOauthAuthorizationServer) {
this.proxyWellKnownOauthAuthorizationServer = proxyWellKnownOauthAuthorizationServer;
}
@Override
public boolean isProxyWellKnownOpenidConfiguration() {
return proxyWellKnownOpenidConfiguration;
}
/**
* Whether a request to /.well-known/openid-configuration should be proxied to the authorization server. Default to false.
* @param proxyWellKnownOpenidConfiguration Whether a request to /.well-known/openid-configuration should be proxied to the authorization server.
*/
public void setProxyWellKnownOpenidConfiguration(boolean proxyWellKnownOpenidConfiguration) {
this.proxyWellKnownOpenidConfiguration = proxyWellKnownOpenidConfiguration;
}
/**
* Micronaut attempts to infer the authorization server used by the client based on the issuer. However, if you are using a custom domain, it may be impossible to infer it.
* You can set it explicitly via this property.
* @param authorizationServer The authorization server
*/
public void setAuthorizationServer(@Nullable AuthorizationServer authorizationServer) {
this.authorizationServer = authorizationServer;
}
@Override
@Nullable
public AuthorizationServer getAuthorizationServer() {
return authorizationServer;
}
@NonNull
@Override
public String getClientId() {
return clientId;
}
/**
* OAuth 2.0 client id.
*
* @param clientId The client id
*/
public void setClientId(@NonNull String clientId) {
this.clientId = clientId;
}
@Nullable
@Override
public String getClientSecret() {
return clientSecret;
}
/**
* OAuth 2.0 client secret.
*
* @param clientSecret The client secret
*/
public void setClientSecret(@Nullable String clientSecret) {
this.clientSecret = clientSecret;
}
@Override
public boolean isEnabled() {
return this.enabled;
}
/**
* Sets whether the client is enabled. Default value ({@value #DEFAULT_ENABLED}).
*
* @param enabled The enabled flag
*/
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
@NonNull
@Override
public List<String> getScopes() {
return scopes == null ? defaultScopes : scopes;
}
/**
* Requested scopes. If not specified for OAuth 2.0 clients using OpenID Connect it defaults to `profile`, `email` and `idtoken`
*
* @param scopes The scopes
*/
public void setScopes(List<String> scopes) {
this.scopes = scopes;
}
@NonNull
@Override
public String getName() {
return name;
}
@NonNull
@Override
public GrantType getGrantType() {
return grantType;
}
/**
* OAuth 2.0 grant type. Default value (authorization_code).
*
* @param grantType The grant type
*/
public void setGrantType(@NonNull GrantType grantType) {
this.grantType = grantType;
}
@Override
public Optional<SecureEndpointConfiguration> getToken() {
return Optional.ofNullable(token);
}
/**
* The OAuth 2.0 token endpoint configuration.
*
* @param token The token endpoint configuration
*/
public void setToken(TokenEndpointConfigurationProperties token) {
this.token = token;
}
@Override
public Optional<OauthAuthorizationEndpointConfiguration> getAuthorization() {
return Optional.ofNullable(authorization);
}
@Override
@NonNull
public Optional<ClientCredentialsConfiguration> getClientCredentials() {
return Optional.ofNullable(clientCredentials);
}
/**
* Sets the Client Credentials configuration.
*
* @param clientCredentials client credentials configuration
*/
public void setClientCredentials(@NonNull ClientCredentialsConfigurationProperties clientCredentials) {
this.clientCredentials = clientCredentials;
}
/**
* The OAuth 2.0 authorization endpoint configuration.
*
* @param authorization The authorization endpoint configuration
*/
public void setAuthorization(AuthorizationEndpointConfigurationProperties authorization) {
this.authorization = authorization;
}
/**
* @return The open id configuration
*/
public Optional<OpenIdClientConfiguration> getOpenid() {
return Optional.ofNullable(openid);
}
/**
* The open id configuration.
*
* @param openid The open id configuration
*/
public void setOpenid(OpenIdClientConfigurationProperties openid) {
this.openid = openid;
this.defaultScopes = DEFAULT_SCOPES_OPENID;
}
@Override
public Optional<SecureEndpointConfiguration> getIntrospection() {
return Optional.ofNullable(introspection);
}
/**
* Sets the introspection endpoint configuration.
*
* @param introspection The introspection endpoint configuration
*/
public void setIntrospection(IntrospectionEndpointConfigurationProperties introspection) {
this.introspection = introspection;
}
@Override
public Optional<SecureEndpointConfiguration> getRevocation() {
return Optional.ofNullable(revocation);
}
/**
* Sets the revocation endpoint configuration.
*
* @param revocation The revocation endpoint configuration
*/
public void setRevocation(RevocationEndpointConfigurationProperties revocation) {
this.revocation = revocation;
}
/**
* Client credentials configuration.
*/
@Requires(classes = OutgoingRequestProcessorMatcher.class)
@ConfigurationProperties("client-credentials")
public static class ClientCredentialsConfigurationProperties extends AbstractOutgoingRequestProcessorMatcher implements ClientCredentialsConfiguration {
/**
* The default enable value.
*/
@SuppressWarnings("WeakerAccess")
public static final boolean DEFAULT_ENABLED = true;
private boolean enabled = DEFAULT_ENABLED;
private String scope;
private Duration advancedExpiration = DEFAULT_ADVANCED_EXPIRATION;
private HeaderTokenPropagatorConfigurationProperties headerPropagation;
private Map<String, String> additonalRequestParams = Collections.emptyMap();
@NonNull
@Override
public Duration getAdvancedExpiration() {
return advancedExpiration;
}
@Override
@NonNull
public Optional<ClientCredentialsHeaderTokenPropagatorConfiguration> getHeaderPropagation() {
return Optional.ofNullable(headerPropagation);
}
/**
* Sets the Http Header Client Credentials Token Propagator configuration.
*
* @param headerPropagation client credentials header propagation.
*/
public void setHeaderPropagation(@NonNull HeaderTokenPropagatorConfigurationProperties headerPropagation) {
this.headerPropagation = headerPropagation;
}
/**
* @param advancedExpiration Number of seconds for a token obtained via client credentials grant to be considered expired
* prior to its expiration date. Default value (30 seconds).
*/
public void setAdvancedExpiration(@NonNull Duration advancedExpiration) {
this.advancedExpiration = advancedExpiration;
}
@NonNull
@Override
public Optional<String> getScope() {
return Optional.ofNullable(scope);
}
/**
* Scope to be requested in the client credentials request. Defaults to none.
* @param scope Scope to be requested in the client credentials request
*/
public void setScope(String scope) {
this.scope = scope;
}
@Override
public boolean isEnabled() {
return enabled;
}
/**
* Enables {@link io.micronaut.security.oauth2.client.clientcredentials.ClientCredentialsClient}. Default value {@value #DEFAULT_ENABLED}
* @param enabled enabled flag
*/
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
/**
*
* @return a Map of additional request parameters
*/
@Override
@NonNull
public Map<String, String> getAdditionalRequestParams() {
return additonalRequestParams;
}
/**
* Additional parameters included in the client-credentials flow.
* @param additionalRequestParams Map of additional request parameters to include in client-credentials flow
*/
public void setAdditionalRequestParams(@MapFormat(transformation = MapFormat.MapTransformation.FLAT) Map<String, String> additionalRequestParams) {
this.additonalRequestParams = additionalRequestParams;
}
/**
* Client credentials http header token propagation configuration.
*/
@ConfigurationProperties("header-propagation")
@Requires(classes = OutgoingRequestProcessorMatcher.class)
public static class HeaderTokenPropagatorConfigurationProperties implements ClientCredentialsHeaderTokenPropagatorConfiguration {
private String prefix = DEFAULT_PREFIX;
private String headerName = DEFAULT_HEADER_NAME;
private boolean enabled = DEFAULT_ENABLED;
@Override
public boolean isEnabled() {
return enabled;
}
/**
* Enable {@link ClientCredentialsHeaderTokenPropagatorConfiguration}. Default value ({@value #DEFAULT_ENABLED}).
* @param enabled enabled flag
*/
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
/**
* Value prefix for Http Header. Default value ({@value #DEFAULT_PREFIX}).
* @param prefix preffix before the header value
*/
public void setPrefix(String prefix) {
this.prefix = prefix;
}
/**
*
* @return a Prefix before the token in the header value. E.g. Bearer
*/
@Override
public String getPrefix() {
return this.prefix;
}
/**
* Http Header to be used to propagate the token. Default value ({@value #DEFAULT_HEADER_NAME})
* @param headerName HTTP header name
*/
public void setHeaderName(String headerName) {
this.headerName = headerName;
}
/**
*
* @return an HTTP Header name. e.g. Authorization
*/
@Override
public String getHeaderName() {
return this.headerName;
}
}
}
/**
* OAuth 2.0 authorization endpoint configuration.
*/
@ConfigurationProperties("authorization")
public static class AuthorizationEndpointConfigurationProperties extends DefaultEndpointConfiguration implements OauthAuthorizationEndpointConfiguration {
private String codeChallengeMethod;
@Override
@NonNull
public Optional<String> getCodeChallengeMethod() {
return Optional.ofNullable(codeChallengeMethod);
}
/**
* Code Challenge Method to use for PKCE.
*
* @param codeChallengeMethod Code Challenge Method
*/
public void setCodeChallengeMethod(@Nullable String codeChallengeMethod) {
this.codeChallengeMethod = codeChallengeMethod;
}
}
/**
* OAuth 2.0 token endpoint configuration.
*/
@ConfigurationProperties("token")
@Requires(classes = MediaType.class)
public static class TokenEndpointConfigurationProperties extends AbstractTokenEndpointConfigurationProperties {
/**
* JWT client assertion configuration for token endpoint authentication.
*
* @param clientAssertion JWT client assertion configuration
*/
public void setClientAssertion(@Nullable ClientAssertionConfigurationProperties clientAssertion) {
setClientAssertionConfiguration(clientAssertion);
}
/**
* JWT client assertion configuration.
*/
@ConfigurationProperties("client-assertion")
public static class ClientAssertionConfigurationProperties extends AbstractClientAssertionConfigurationProperties {
}
}
/**
* Shared token endpoint configuration.
*/
abstract static class AbstractTokenEndpointConfigurationProperties extends DefaultSecureEndpointConfiguration implements TokenEndpointConfiguration {
private static final MediaType DEFAULT_CONTENT_TYPE = MediaType.APPLICATION_FORM_URLENCODED_TYPE;
@NonNull
private MediaType contentType = DEFAULT_CONTENT_TYPE;
@Nullable
private ClientAssertionConfiguration clientAssertion;
@NonNull
@Override
public MediaType getContentType() {
return contentType;
}
/**
* The content type of token endpoint requests. Default value (application/x-www-form-urlencoded).
*
* @param contentType The content type
*/
public void setContentType(@NonNull MediaType contentType) {
this.contentType = contentType;
}
@NonNull
@Override
public Optional<ClientAssertionConfiguration> getClientAssertion() {
return Optional.ofNullable(clientAssertion);
}
void setClientAssertionConfiguration(@Nullable ClientAssertionConfiguration clientAssertion) {
this.clientAssertion = clientAssertion;
}
}
/**
* JWT client assertion configuration.
*/
public abstract static class AbstractClientAssertionConfigurationProperties implements ClientAssertionConfiguration {
@NonNull
private Duration lifetime = ClientAssertionConfiguration.DEFAULT_LIFETIME;
@Nullable
private String audience;
@Nullable
private String issuer;
@Nullable
private String subject;
@Nullable
private String signingAlgorithm;
@Nullable
private String signerName;
@NonNull
@Override
public Duration getLifetime() {
return lifetime;
}
/**
* JWT client assertion lifetime. Default value (5 minutes).
*
* @param lifetime JWT client assertion lifetime
*/
public void setLifetime(@NonNull Duration lifetime) {
this.lifetime = lifetime;
}
@NonNull
@Override
public Optional<String> getAudience() {
return Optional.ofNullable(audience);
}
/**
* JWT client assertion audience. Defaults to the token endpoint URL.
*
* @param audience JWT client assertion audience
*/
public void setAudience(@Nullable String audience) {
this.audience = audience;
}
@NonNull
@Override
public Optional<String> getIssuer() {
return Optional.ofNullable(issuer);
}
/**
* JWT client assertion issuer. Defaults to the OAuth client id.
*
* @param issuer JWT client assertion issuer
*/
public void setIssuer(@Nullable String issuer) {
this.issuer = issuer;
}
@NonNull
@Override
public Optional<String> getSubject() {
return Optional.ofNullable(subject);
}
/**
* JWT client assertion subject. Defaults to the OAuth client id.
*
* @param subject JWT client assertion subject
*/
public void setSubject(@Nullable String subject) {
this.subject = subject;
}
@NonNull
@Override
public Optional<String> getSigningAlgorithm() {
return Optional.ofNullable(signingAlgorithm);
}
/**
* JWS signing algorithm used for client_secret_jwt. Defaults to HS256.
*
* @param signingAlgorithm JWS signing algorithm
*/
public void setSigningAlgorithm(@Nullable String signingAlgorithm) {
this.signingAlgorithm = signingAlgorithm;
}
@NonNull
@Override
public Optional<String> getSignerName() {
return Optional.ofNullable(signerName);
}
/**
* Named SignatureGeneratorConfiguration bean used for private_key_jwt.
*
* @param signerName Named SignatureGeneratorConfiguration bean
*/
public void setSignerName(@Nullable String signerName) {
this.signerName = signerName;
}
}
/**
* Introspection endpoint configuration.
*/
@ConfigurationProperties("introspection")
public static class IntrospectionEndpointConfigurationProperties extends DefaultSecureEndpointConfiguration implements IntrospectionEndpointConfiguration { }
/**
* Revocation endpoint configuration.
*/
@ConfigurationProperties("revocation")
public static class RevocationEndpointConfigurationProperties extends DefaultSecureEndpointConfiguration implements RevocationEndpointConfiguration { }
/**
* OpenID client configuration.
*/
@ConfigurationProperties("openid")
public static class OpenIdClientConfigurationProperties implements OpenIdClientConfiguration {
private static final String DEFAULT_CONFIG_PATH = "/.well-known/openid-configuration";
private final String name;
private URL issuer;
private String configurationPath = DEFAULT_CONFIG_PATH;
private String jwksUri;
private RegistrationEndpointConfigurationProperties registration;
private UserInfoEndpointConfigurationProperties userInfo;
private AuthorizationEndpointConfigurationProperties authorization;
private TokenEndpointConfigurationProperties token;
private EndSessionConfigurationProperties endSession = new EndSessionConfigurationProperties();
private boolean protectedResourceMetadata = DEFAULT_PROTECTED_RESOURCE_METADATA;
/**
* @param name The provider name
*/
OpenIdClientConfigurationProperties(@Parameter String name) {
this.name = name;
}
@NonNull
@Override
public String getName() {
return name;
}
@Override
public boolean isProtectedResourceMetadata() {
return protectedResourceMetadata;
}
/**
* Whether the protected resource metadata endpoint should expose the OpenID issuer as an authorization server. Default value: true.
* @param protectedResourceMetadata Whether the protected resource metadata endpoint should expose the OpenID issuer as an authorization server.
*/
public void setProtectedResourceMetadata(boolean protectedResourceMetadata) {
this.protectedResourceMetadata = protectedResourceMetadata;
}
@Override
public Optional<URL> getIssuer() {
return Optional.ofNullable(issuer);
}
/**
* URL using the https scheme with no query or fragment component that the
* Open ID provider asserts as its issuer identifier.
*
* @param issuer The issuer
*/
public void setIssuer(@Nullable URL issuer) {
this.issuer = issuer;
}
@Override
@NonNull
public String getConfigurationPath() {
return configurationPath;
}
/**
* The configuration path to discover openid configuration. Default ({@value #DEFAULT_CONFIG_PATH}).
*
* @param configurationPath The configuration path
*/
public void setConfigurationPath(@NonNull String configurationPath) {
this.configurationPath = configurationPath;
}
@Override
public Optional<String> getJwksUri() {
return Optional.ofNullable(jwksUri);
}
/**
* The JWKS signature URI.
*
* @param jwksUri The signature uri
*/
public void setJwksUri(String jwksUri) {
this.jwksUri = jwksUri;
}
@Override
public Optional<EndpointConfiguration> getRegistration() {
return Optional.ofNullable(registration);
}
/**
* Sets the registration endpoint configuration.
*
* @param registration The registration endpoint configuration
*/
public void setRegistration(RegistrationEndpointConfigurationProperties registration) {
this.registration = registration;
}
@Override
public Optional<EndpointConfiguration> getUserInfo() {
return Optional.ofNullable(userInfo);
}
/**
* Sets the user info endpoint configuration.
*
* @param userInfo The user info endpoint configuration
*/
public void setUserInfo(UserInfoEndpointConfigurationProperties userInfo) {
this.userInfo = userInfo;
}
@Override
public Optional<AuthorizationEndpointConfiguration> getAuthorization() {
return Optional.ofNullable(authorization);
}
/**
* Sets the authorization endpoint configuration.
*
* @param authorization The authorization endpoint configuration
*/
public void setAuthorization(AuthorizationEndpointConfigurationProperties authorization) {
this.authorization = authorization;
}
@Override
public Optional<TokenEndpointConfiguration> getToken() {
return Optional.ofNullable(token);
}
/**
* Sets the token endpoint configuration.
*
* @param token The token endpoint configuration
*/
public void setToken(TokenEndpointConfigurationProperties token) {
this.token = token;
}
@Override
@NonNull
public EndSessionEndpointConfiguration getEndSession() {
return endSession;
}
/**
* Sets the end session endpoint configuration.
*
* @param endSession End session endpoint configuration
*/
public void setEndSession(@NonNull EndSessionConfigurationProperties endSession) {
this.endSession = endSession;
}
/**
* Registration endpoint configuration.
*/
@ConfigurationProperties("registration")
public static class RegistrationEndpointConfigurationProperties extends DefaultEndpointConfiguration { }
/**
* User info endpoint configuration.
*/
@ConfigurationProperties("user-info")
public static class UserInfoEndpointConfigurationProperties extends DefaultEndpointConfiguration { }
/**
* Authorization endpoint configuration.
*/
@ConfigurationProperties("authorization")
public static class AuthorizationEndpointConfigurationProperties extends DefaultEndpointConfiguration implements AuthorizationEndpointConfiguration {
private ResponseType responseType = ResponseType.CODE;
private String responseMode;
private Display display;
private Prompt prompt;
private Integer maxAge;
private List<String> uiLocales;
private List<String> acrValues;
private String codeChallengeMethod;
@NonNull
@Override
public ResponseType getResponseType() {
return responseType;
}
/**
* Determines the authorization processing flow to be used. Default value (code).
*
* @param responseType The response type
*/
public void setResponseType(@NonNull ResponseType responseType) {
this.responseType = responseType;
}
@Override
public Optional<String> getResponseMode() {
return Optional.ofNullable(responseMode);
}
/**
* Mechanism to be used for returning authorization response parameters from the
* authorization endpoint.
*
* @param responseMode The response mode
*/
public void setResponseMode(@Nullable String responseMode) {
this.responseMode = responseMode;
}
@Override
public Optional<Display> getDisplay() {
return Optional.ofNullable(display);
}
/**
* Controls how the authentication interface is displayed.
*
* @param display The display
*/
public void setDisplay(@Nullable Display display) {
this.display = display;
}
@Override
public Optional<Prompt> getPrompt() {
return Optional.ofNullable(prompt);
}
/**
* Controls how the authentication server prompts the user.
*
* @param prompt The prompt type
*/
public void setPrompt(@Nullable Prompt prompt) {
this.prompt = prompt;
}
@Override
public Optional<Integer> getMaxAge() {
return Optional.ofNullable(maxAge);
}
/**
* Maximum authentication age.
*
* @param maxAge Maximum authentication age.
*/
public void setMaxAge(@Nullable Integer maxAge) {
this.maxAge = maxAge;
}
@Override
public Optional<List<String>> getUiLocales() {
return Optional.ofNullable(uiLocales);
}
/**
* Preferred locales for authentication.
*
* @param uiLocales Preferred locales
*/
public void setUiLocales(@Nullable List<String> uiLocales) {
this.uiLocales = uiLocales;
}
@Override
public Optional<List<String>> getAcrValues() {
return Optional.ofNullable(acrValues);
}
@Override
@NonNull
public Optional<String> getCodeChallengeMethod() {
return Optional.ofNullable(codeChallengeMethod);
}
/**
* Code Challenge Method to use for PKCE.
*
* @param codeChallengeMethod Code Challenge Method
*/
public void setCodeChallengeMethod(@Nullable String codeChallengeMethod) {
this.codeChallengeMethod = codeChallengeMethod;
}
/**
* Authentication class reference values.
*
* @param acrValues Authentication class reference values
*/
public void setAcrValues(@Nullable List<String> acrValues) {
this.acrValues = acrValues;
}
}
/**
* Token endpoint configuration.
*/
@ConfigurationProperties("token")
@Requires(classes = MediaType.class)
public static class TokenEndpointConfigurationProperties extends AbstractTokenEndpointConfigurationProperties {
/**
* JWT client assertion configuration for token endpoint authentication.
*
* @param clientAssertion JWT client assertion configuration
*/
public void setClientAssertion(@Nullable ClientAssertionConfigurationProperties clientAssertion) {
setClientAssertionConfiguration(clientAssertion);
}
/**