001/*-
002 * #%L
003 * Smile CDR - CDR
004 * %%
005 * Copyright (C) 2016 - 2025 Smile CDR, Inc.
006 * %%
007 * All rights reserved.
008 * #L%
009 */
010package ca.cdr.api.model.json.oauth;
011
012import ca.cdr.api.model.json.IModelJson;
013import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
014import com.fasterxml.jackson.annotation.JsonAnySetter;
015import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
016import com.fasterxml.jackson.annotation.JsonProperty;
017import com.fasterxml.jackson.core.JsonProcessingException;
018import com.fasterxml.jackson.databind.ObjectMapper;
019import io.swagger.v3.oas.annotations.media.Schema;
020
021import java.lang.reflect.Field;
022import java.util.ArrayList;
023import java.util.HashMap;
024import java.util.List;
025import java.util.Map;
026
027@JsonIgnoreProperties(ignoreUnknown = true)
028@Schema(
029                name = "OpenIdWellKnownOpenIdConfigurationResponse",
030                description = "This object represents the response from an Identity Provider's .well-known endpoint.")
031public class OpenIdWellKnownOpenIdConfigurationResponseJson implements IModelJson {
032
033        /* CHECKSTYLE.OFF: RegexpSingleLine - these json property names are spec compliant and should not be changed */
034
035        /**
036         * Authorization server's issuer identifier url
037         */
038        @JsonProperty(value = "issuer", required = true)
039        private String myIssuer;
040
041        /**
042         * URL of the authorization server's authorization endpoint
043         * REQUIRED unless no grant types are supported that use authorization endpoint
044         */
045        @JsonProperty("authorization_endpoint")
046        private String myAuthorizationEndpoint;
047
048        /**
049         * URL of the auth server's token endpoint
050         * REQUIRED unless only the implicit grant type is supported
051         */
052        @JsonProperty("token_endpoint")
053        private String myTokenEndpoint;
054
055        /**
056         * JSON array of subject identifier types that this OP supports
057         * (pairwise, public)
058         */
059        @JsonProperty(value = "subject_types_supported", required = true)
060        private List<String> mySubjectTypesSupported;
061
062        /**
063         * URL of the auth server's JWK Set document
064         */
065        @JsonProperty(value = "jwks_uri", required = false)
066        private String myJwkUri;
067
068        /**
069         * URL of the auth server's OAuth 2.0 Dynamic Client Registration Endpoint
070         */
071        @JsonProperty(value = "registration_endpoint", required = false)
072        private String myDynamicClientRegistrationEndpoint;
073
074        /**
075         * JSON array containing a list of the OAuth 2.0 "scopes" values that this auth
076         * server supports.
077         * RECOMMENDED
078         */
079        @JsonProperty("scopes_supported")
080        private List<String> mySupportedScopes;
081
082        /**
083         * JSON array containing a list of the oauth 2.0 "response_type" values
084         * that this auth server supports.
085         */
086        @JsonProperty(value = "response_types_supported", required = true)
087        private List<String> mySupportedResponseTypes;
088
089        /**
090         * JSON array containing a list of the oauth 2.0 "response_mode" values that this
091         * auth server supports
092         */
093        @JsonProperty(value = "response_modes_supported", required = false)
094        private List<String> mySupportedResponseModes;
095
096        /**
097         * JSON array containing a list of the oauth
098         * 2.0 grant type values that this auth server supports
099         */
100        @JsonProperty(value = "grant_types_supported", required = false)
101        private List<String> mySupportedGrantTypes;
102
103        /**
104         * JSON array containing a list of the client authentication methods supported by this token
105         * endpoint
106         */
107        @JsonProperty(value = "token_endpoint_auth_methods_supported", required = false)
108        private List<String> mySupportedAuthenticationMethods;
109
110        /**
111         * JSON array of list of the JWS Signing algorithms supported by
112         * the token endpoint for the signature on the JWT used
113         * to authenticate the client at the token endpoint
114         */
115        @JsonProperty(value = "token_endpoint_auth_signing_alg_values_supported", required = false)
116        private List<String> mySupportedJWSSigningAlgorithms;
117
118        /**
119         * URL of the auth server's oauth 2.0
120         * revocation endpoint
121         */
122        @JsonProperty(value = "revocation_endpoint", required = false)
123        private String myRevocationEndpoint;
124
125        /**
126         * JSON array of client auth methods supported by this
127         * revocation endpoint.
128         */
129        @JsonProperty(value = "revocation_endpoint_auth_methods_supported", required = false)
130        private List<String> mySupportedAuthMethodsForRevocation;
131
132        /**
133         * JSON array of the JWS signing algorithms supported by the
134         * revocation endpoint for the signature on the JWT used to authenticate the client.
135         */
136        @JsonProperty(value = "revocation_endpoint_auth_signing_alg_values_supported", required = false)
137        private List<String> myRevocationEndpointSigningAlgorithms;
138
139        /**
140         * URL of the auth server's oauth2.0 introspection endpoint
141         */
142        @JsonProperty(value = "introspection_endpoint", required = false)
143        private String myIntrospectionEndpoint;
144
145        /**
146         * JSON array of the client auth methods supported by this introspection
147         * endpoint.
148         */
149        @JsonProperty(value = "introspection_endpoint_auth_methods_supported", required = false)
150        private List<String> mySupportedIntrospectionEndpointAuthMethods;
151
152        /**
153         * User info url.
154         * RECOMMENDED
155         */
156        @JsonProperty("userinfo_endpoint")
157        private String myUserInfoEndpoint;
158
159        /**
160         * JSON array of signing algs supported for id token
161         */
162        @JsonProperty(value = "id_token_signing_alg_values_supported", required = true)
163        private List<String> mySupportedIdTokenSigningAlgs;
164
165        /**
166         * JSON array containing a list of proof key for code exchange (PCKE flow) code
167         * challenge methods supported by this auth server
168         */
169        @JsonProperty(value = "code_challenge_methods_supported", required = false)
170        private List<String> myCodeChallengeMethodsSupported;
171
172        /* CHECKSTYLE.ON: RegexpSingleLine */
173
174        /**
175         * We will store all unknown properties in a map during deserialization;
176         * if these properties are not in fact "unknown" but part of the spec,
177         * please add them above, but leave this map.
178         */
179        private final Map<String, Object> myUnknownProperties = new HashMap<>();
180
181        public String getIssuer() {
182                return myIssuer;
183        }
184
185        public void setIssuer(String theIssuer) {
186                myIssuer = theIssuer;
187        }
188
189        public String getAuthorizationEndpoint() {
190                return myAuthorizationEndpoint;
191        }
192
193        public void setAuthorizationEndpoint(String theAuthorizationEndpoint) {
194                myAuthorizationEndpoint = theAuthorizationEndpoint;
195        }
196
197        public String getTokenEndpoint() {
198                return myTokenEndpoint;
199        }
200
201        public void setTokenEndpoint(String theTokenEndpoint) {
202                myTokenEndpoint = theTokenEndpoint;
203        }
204
205        public String getJwkUri() {
206                return myJwkUri;
207        }
208
209        public void setJwkUri(String theJwkUri) {
210                myJwkUri = theJwkUri;
211        }
212
213        public String getDynamicClientRegistrationEndpoint() {
214                return myDynamicClientRegistrationEndpoint;
215        }
216
217        public void setDynamicClientRegistrationEndpoint(String theDynamicClientRegistrationEndpoint) {
218                myDynamicClientRegistrationEndpoint = theDynamicClientRegistrationEndpoint;
219        }
220
221        public List<String> getSupportedScopes() {
222                if (mySupportedScopes == null) {
223                        mySupportedScopes = new ArrayList<>();
224                }
225                return mySupportedScopes;
226        }
227
228        public void setSupportedScopes(List<String> theSupportedScopes) {
229                mySupportedScopes = theSupportedScopes;
230        }
231
232        public void addSupportedScope(String theScope) {
233                getSupportedScopes().add(theScope);
234        }
235
236        public List<String> getSupportedResponseTypes() {
237                if (mySupportedResponseTypes == null) {
238                        mySupportedResponseTypes = new ArrayList<>();
239                }
240                return mySupportedResponseTypes;
241        }
242
243        public void setSupportedResponseTypes(List<String> theSupportedResponseTypes) {
244                mySupportedResponseTypes = theSupportedResponseTypes;
245        }
246
247        public void addSupportedResponseType(String theResponseType) {
248                getSupportedResponseTypes().add(theResponseType);
249        }
250
251        public List<String> getSupportedResponseModes() {
252                if (mySupportedResponseModes == null) {
253                        mySupportedResponseModes = new ArrayList<>();
254                }
255                return mySupportedResponseModes;
256        }
257
258        public void setSupportedResponseModes(List<String> theSupportedResponseModes) {
259                mySupportedResponseModes = theSupportedResponseModes;
260        }
261
262        public void addSupportedResponseMode(String theMode) {
263                getSupportedResponseModes().add(theMode);
264        }
265
266        public List<String> getSupportedGrantTypes() {
267                if (mySupportedGrantTypes == null) {
268                        mySupportedGrantTypes = new ArrayList<>();
269                }
270                return mySupportedGrantTypes;
271        }
272
273        public void setSupportedGrantTypes(List<String> theSupportedGrantTypes) {
274                mySupportedGrantTypes = theSupportedGrantTypes;
275        }
276
277        public void addSupportedGrantType(String theGrantType) {
278                getSupportedGrantTypes().add(theGrantType);
279        }
280
281        public List<String> getSupportedAuthenticationMethods() {
282                if (mySupportedAuthenticationMethods == null) {
283                        mySupportedAuthenticationMethods = new ArrayList<>();
284                }
285                return mySupportedAuthenticationMethods;
286        }
287
288        public void setSupportedAuthenticationMethods(List<String> theSupportedAuthenticationMethods) {
289                mySupportedAuthenticationMethods = theSupportedAuthenticationMethods;
290        }
291
292        public void addSupportedAuthenticationMethod(String theMethod) {
293                getSupportedAuthenticationMethods().add(theMethod);
294        }
295
296        public List<String> getSupportedJWSSigningAlgorithms() {
297                if (mySupportedJWSSigningAlgorithms == null) {
298                        mySupportedJWSSigningAlgorithms = new ArrayList<>();
299                }
300                return mySupportedJWSSigningAlgorithms;
301        }
302
303        public void setSupportedJWSSigningAlgorithms(List<String> theSupportedJWSSigningAlgorithms) {
304                mySupportedJWSSigningAlgorithms = theSupportedJWSSigningAlgorithms;
305        }
306
307        public void addSupportedJWSSigningAlgorithm(String theAlg) {
308                getSupportedJWSSigningAlgorithms().add(theAlg);
309        }
310
311        public String getRevocationEndpoint() {
312                return myRevocationEndpoint;
313        }
314
315        public void setRevocationEndpoint(String theRevocationEndpoint) {
316                myRevocationEndpoint = theRevocationEndpoint;
317        }
318
319        public List<String> getSupportedAuthMethodsForRevocation() {
320                if (mySupportedAuthMethodsForRevocation == null) {
321                        mySupportedAuthMethodsForRevocation = new ArrayList<>();
322                }
323                return mySupportedAuthMethodsForRevocation;
324        }
325
326        public void setSupportedAuthMethodsForRevocation(List<String> theSupportedAuthMethodsForRevocation) {
327                mySupportedAuthMethodsForRevocation = theSupportedAuthMethodsForRevocation;
328        }
329
330        public void addSupportedAuthMethodForRevocation(String theMethod) {
331                getSupportedAuthenticationMethods().add(theMethod);
332        }
333
334        public List<String> getRevocationEndpointSigningAlgorithms() {
335                if (myRevocationEndpointSigningAlgorithms == null) {
336                        myRevocationEndpointSigningAlgorithms = new ArrayList<>();
337                }
338                return myRevocationEndpointSigningAlgorithms;
339        }
340
341        public void setRevocationEndpointSigningAlgorithms(List<String> theRevocationEndpointSigningAlgorithms) {
342                myRevocationEndpointSigningAlgorithms = theRevocationEndpointSigningAlgorithms;
343        }
344
345        public void addRevocationEndpointSigningAlgorithm(String theAlg) {
346                getRevocationEndpointSigningAlgorithms().add(theAlg);
347        }
348
349        public String getIntrospectionEndpoint() {
350                return myIntrospectionEndpoint;
351        }
352
353        public void setIntrospectionEndpoint(String theIntrospectionEndpoint) {
354                myIntrospectionEndpoint = theIntrospectionEndpoint;
355        }
356
357        public List<String> getSupportedIntrospectionEndpointAuthMethods() {
358                if (mySupportedIntrospectionEndpointAuthMethods == null) {
359                        mySupportedIntrospectionEndpointAuthMethods = new ArrayList<>();
360                }
361                return mySupportedIntrospectionEndpointAuthMethods;
362        }
363
364        public void setSupportedIntrospectionEndpointAuthMethods(
365                        List<String> theSupportedIntrospectionEndpointAuthMethods) {
366                mySupportedIntrospectionEndpointAuthMethods = theSupportedIntrospectionEndpointAuthMethods;
367        }
368
369        public void addSupportedIntrospectionEndpointAuthMethod(String theMethod) {
370                getSupportedIntrospectionEndpointAuthMethods().add(theMethod);
371        }
372
373        public String getUserInfoEndpoint() {
374                return myUserInfoEndpoint;
375        }
376
377        public void setUserInfoEndpoint(String theUserInfoEndpoint) {
378                myUserInfoEndpoint = theUserInfoEndpoint;
379        }
380
381        public List<String> getSupportedIdTokenSigningAlgs() {
382                if (mySupportedIdTokenSigningAlgs == null) {
383                        mySupportedIdTokenSigningAlgs = new ArrayList<>();
384                }
385                return mySupportedIdTokenSigningAlgs;
386        }
387
388        public void setSupportedIdTokenSigningAlgs(List<String> theSupportedIdTokenSigningAlgs) {
389                mySupportedIdTokenSigningAlgs = theSupportedIdTokenSigningAlgs;
390        }
391
392        public void addSupportedIdTokenSigningAlg(String theAlg) {
393                getSupportedIdTokenSigningAlgs().add(theAlg);
394        }
395
396        public List<String> getCodeChallengeMethodsSupported() {
397                if (myCodeChallengeMethodsSupported == null) {
398                        myCodeChallengeMethodsSupported = new ArrayList<>();
399                }
400                return myCodeChallengeMethodsSupported;
401        }
402
403        public void setCodeChallengeMethodsSupported(List<String> theCodeChallengeMethodsSupported) {
404                myCodeChallengeMethodsSupported = theCodeChallengeMethodsSupported;
405        }
406
407        public void addCodeChallengeMethodSupported(String theCode) {
408                getCodeChallengeMethodsSupported().add(theCode);
409        }
410
411        public List<String> getSubjectTypesSupported() {
412                if (mySubjectTypesSupported == null) {
413                        mySubjectTypesSupported = new ArrayList<>();
414                }
415                return mySubjectTypesSupported;
416        }
417
418        public void setSubjectTypesSupported(List<String> theSubjectTypesSupported) {
419                mySubjectTypesSupported = theSubjectTypesSupported;
420        }
421
422        public void addSubjectTypeSupported(String theType) {
423                getSubjectTypesSupported().add(theType);
424        }
425
426        @JsonAnySetter
427        public void add(String theProp, Object theVal) {
428                myUnknownProperties.put(theProp, theVal);
429        }
430
431        Map<String, Object> getUnknownProperties() {
432                return myUnknownProperties;
433        }
434
435        Map<String, Object> toMap() {
436                Map<String, Object> map = new HashMap<>();
437                Field[] fields = OpenIdWellKnownOpenIdConfigurationResponseJson.class.getDeclaredFields();
438
439                try {
440                        for (Field field : fields) {
441                                if (field.isAnnotationPresent(JsonProperty.class)) {
442                                        Object value = field.get(this);
443                                        if (value != null) {
444                                                // we want the names to be whatever's in the json annotation
445                                                JsonProperty jsonProperty = field.getAnnotation(JsonProperty.class);
446                                                String name = jsonProperty.value();
447                                                map.put(name, value);
448                                        }
449                                }
450                        }
451                } catch (IllegalAccessException ex) {
452                        throw new InternalErrorException(ex);
453                }
454
455                map.putAll(myUnknownProperties);
456
457                return map;
458        }
459
460        @Override
461        public String toString() {
462                ObjectMapper mapper = new ObjectMapper();
463                Map<String, Object> map = toMap();
464
465                try {
466                        return mapper.writeValueAsString(map);
467                } catch (JsonProcessingException ex) {
468                        throw new InternalErrorException(ex);
469                }
470        }
471}
472
473/**
474 * @deprecated Use ca.cdr.api.model.json.oauth.OpenIdWellKnownOpenIdConfigurationResponseJson
475 */
476@Deprecated(since = "2025.11.R01", forRemoval = true)
477class OpenIdWellKnownOpenIdConfigurationResponse extends OpenIdWellKnownOpenIdConfigurationResponseJson {}