001package com.nimbusds.openid.connect.sdk.rp;
002
003
004import java.net.URI;
005import java.util.Collections;
006import java.util.Date;
007import java.util.HashSet;
008import java.util.Set;
009
010import net.jcip.annotations.Immutable;
011
012import net.minidev.json.JSONObject;
013
014import com.nimbusds.oauth2.sdk.ParseException;
015import com.nimbusds.oauth2.sdk.auth.Secret;
016import com.nimbusds.oauth2.sdk.client.ClientCredentialsParser;
017import com.nimbusds.oauth2.sdk.client.ClientInformation;
018import com.nimbusds.oauth2.sdk.id.ClientID;
019import com.nimbusds.oauth2.sdk.token.BearerAccessToken;
020
021
022/**
023 * OpenID Connect client information. Encapsulates the registration and 
024 * metadata details of an OpenID Connect client:
025 * 
026 * <ul>
027 *     <li>The client identifier.
028 *     <li>The client OpenID Connect metadata.
029 *     <li>The optional client secret for a confidential client.
030 *     <li>The optional registration URI and access token if dynamic client
031 *         registration is permitted.
032 * </ul>
033 *
034 * <p>Related specifications:
035 *
036 * <ul>
037 *     <li>OpenID Connect Dynamic Client Registration 1.0.
038 *     <li>OAuth 2.0 Dynamic Client Registration Protocol (RFC 7591), section
039 *         3.2.1.
040 *     <li>OAuth 2.0 Dynamic Client Registration Management Protocol (RFC
041 *         7592), section 3.
042 * </ul>
043 */
044@Immutable
045public final class OIDCClientInformation extends ClientInformation {
046
047
048        /**
049         * The registered parameter names.
050         */
051        private static final Set<String> REGISTERED_PARAMETER_NAMES;
052
053
054        /**
055         * Initialises the registered parameter name set.
056         */
057        static {
058                Set<String> p = new HashSet<>(ClientInformation.getRegisteredParameterNames());
059                p.addAll(OIDCClientMetadata.getRegisteredParameterNames());
060                REGISTERED_PARAMETER_NAMES = Collections.unmodifiableSet(p);
061        }
062
063
064        /**
065         * Creates a new OpenID Connect client information instance.
066         *
067         * @param id        The client identifier. Must not be {@code null}.
068         * @param issueDate The issue date of the client identifier,
069         *                  {@code null} if not specified.
070         * @param metadata  The OpenID Connect client metadata. Must not be
071         *                  {@code null}.
072         * @param secret    The optional client secret, {@code null} if not
073         *                  specified.
074         */
075        public OIDCClientInformation(final ClientID id,
076                                 final Date issueDate,
077                                 final OIDCClientMetadata metadata,
078                                 final Secret secret) {
079
080                this(id, issueDate, metadata, secret, null, null);
081        }
082
083        
084        /**
085         * Creates a new OpenID Connect client information instance permitting
086         * dynamic client registration management.
087         * 
088         * @param id              The client identifier. Must not be 
089         *                        {@code null}.
090         * @param issueDate       The issue date of the client identifier,
091         *                        {@code null} if not specified.
092         * @param metadata        The OpenID Connect client metadata. Must not
093         *                        be {@code null}.
094         * @param secret          The optional client secret, {@code null} if
095         *                        not specified.
096         * @param registrationURI The client registration URI, {@code null} if
097         *                        not specified.
098         * @param accessToken     The client registration access token,
099         *                        {@code null} if not specified.
100         */
101        public OIDCClientInformation(final ClientID id,
102                                     final Date issueDate,
103                                     final OIDCClientMetadata metadata,
104                                     final Secret secret,
105                                     final URI registrationURI,
106                                     final BearerAccessToken accessToken) {
107                
108                super(id, issueDate, metadata, secret, registrationURI, accessToken);
109        }
110
111
112        /**
113         * Gets the registered client metadata parameter names.
114         *
115         * @return The registered parameter names, as an unmodifiable set.
116         */
117        public static Set<String> getRegisteredParameterNames() {
118
119                return REGISTERED_PARAMETER_NAMES;
120        }
121        
122        
123        /**
124         * Gets the OpenID Connect client metadata.
125         * 
126         * @return The OpenID Connect client metadata.
127         */
128        public OIDCClientMetadata getOIDCMetadata() {
129                
130                return (OIDCClientMetadata) getMetadata();
131        }
132        
133        
134        /**
135         * Parses an OpenID Connect client information instance from the 
136         * specified JSON object.
137         *
138         * @param jsonObject The JSON object to parse. Must not be 
139         *                   {@code null}.
140         *
141         * @return The client information.
142         *
143         * @throws ParseException If the JSON object couldn't be parsed to an
144         *                        OpenID Connect client information instance.
145         */
146        public static OIDCClientInformation parse(final JSONObject jsonObject)
147                throws ParseException {
148
149                return new OIDCClientInformation(
150                        ClientCredentialsParser.parseID(jsonObject),
151                        ClientCredentialsParser.parseIDIssueDate(jsonObject),
152                        OIDCClientMetadata.parse(jsonObject),
153                        ClientCredentialsParser.parseSecret(jsonObject),
154                        ClientCredentialsParser.parseRegistrationURI(jsonObject),
155                        ClientCredentialsParser.parseRegistrationAccessToken(jsonObject));
156        }
157}