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 039 * (draft-ietf-oauth-dyn-reg-20), section 4.1. 040 * <li>OAuth 2.0 Dynamic Client Registration Management Protocol 041 * (draft-ietf-oauth-dyn-reg-management-04), section 3.1. 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 068 * {@code null}. 069 * @param issueDate The issue date of the client identifier, 070 * {@code null} if not specified. 071 * @param metadata The OpenID Connect client metadata. Must not 072 * be {@code null}. 073 * @param secret The optional client secret, {@code null} if 074 * not specified. 075 */ 076 public OIDCClientInformation(final ClientID id, 077 final Date issueDate, 078 final OIDCClientMetadata metadata, 079 final Secret secret) { 080 081 this(id, issueDate, metadata, secret, null, null); 082 } 083 084 085 /** 086 * Creates a new OpenID Connect client information instance permitting 087 * dynamic client registration management. 088 * 089 * @param id The client identifier. Must not be 090 * {@code null}. 091 * @param issueDate The issue date of the client identifier, 092 * {@code null} if not specified. 093 * @param metadata The OpenID Connect client metadata. Must not 094 * be {@code null}. 095 * @param secret The optional client secret, {@code null} if 096 * not specified. 097 * @param registrationURI The client registration URI, {@code null} if 098 * not specified. 099 * @param accessToken The client registration access token, 100 * {@code null} if not specified. 101 */ 102 public OIDCClientInformation(final ClientID id, 103 final Date issueDate, 104 final OIDCClientMetadata metadata, 105 final Secret secret, 106 final URI registrationURI, 107 final BearerAccessToken accessToken) { 108 109 super(id, issueDate, metadata, secret, registrationURI, accessToken); 110 } 111 112 113 /** 114 * Gets the registered client metadata parameter names. 115 * 116 * @return The registered parameter names, as an unmodifiable set. 117 */ 118 public static Set<String> getRegisteredParameterNames() { 119 120 return REGISTERED_PARAMETER_NAMES; 121 } 122 123 124 /** 125 * Gets the OpenID Connect client metadata. 126 * 127 * @return The OpenID Connect client metadata. 128 */ 129 public OIDCClientMetadata getOIDCMetadata() { 130 131 return (OIDCClientMetadata) getMetadata(); 132 } 133 134 135 /** 136 * Parses an OpenID Connect client information instance from the 137 * specified JSON object. 138 * 139 * @param jsonObject The JSON object to parse. Must not be 140 * {@code null}. 141 * 142 * @return The client information. 143 * 144 * @throws ParseException If the JSON object couldn't be parsed to an 145 * OpenID Connect client information instance. 146 */ 147 public static OIDCClientInformation parse(final JSONObject jsonObject) 148 throws ParseException { 149 150 return new OIDCClientInformation( 151 ClientCredentialsParser.parseID(jsonObject), 152 ClientCredentialsParser.parseIDIssueDate(jsonObject), 153 OIDCClientMetadata.parse(jsonObject), 154 ClientCredentialsParser.parseSecret(jsonObject), 155 ClientCredentialsParser.parseRegistrationURI(jsonObject), 156 ClientCredentialsParser.parseRegistrationAccessToken(jsonObject)); 157 } 158}