001/* 002 * oauth2-oidc-sdk 003 * 004 * Copyright 2012-2016, Connect2id Ltd and contributors. 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use 007 * this file except in compliance with the License. You may obtain a copy of the 008 * License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software distributed 013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 015 * specific language governing permissions and limitations under the License. 016 */ 017 018package com.nimbusds.openid.connect.sdk.rp; 019 020 021import java.net.URI; 022import java.util.Collections; 023import java.util.Date; 024import java.util.HashSet; 025import java.util.Set; 026 027import net.jcip.annotations.Immutable; 028import net.minidev.json.JSONObject; 029 030import com.nimbusds.oauth2.sdk.ParseException; 031import com.nimbusds.oauth2.sdk.auth.Secret; 032import com.nimbusds.oauth2.sdk.client.ClientCredentialsParser; 033import com.nimbusds.oauth2.sdk.client.ClientInformation; 034import com.nimbusds.oauth2.sdk.id.ClientID; 035import com.nimbusds.oauth2.sdk.token.BearerAccessToken; 036 037 038/** 039 * OpenID Connect client information. Encapsulates the registration and 040 * metadata details of an OpenID Connect client: 041 * 042 * <ul> 043 * <li>The client identifier. 044 * <li>The client OpenID Connect metadata. 045 * <li>The optional client secret for a confidential client. 046 * <li>The optional registration URI and access token if dynamic client 047 * registration is permitted. 048 * </ul> 049 * 050 * <p>Related specifications: 051 * 052 * <ul> 053 * <li>OpenID Connect Dynamic Client Registration 1.0. 054 * <li>OAuth 2.0 Dynamic Client Registration Protocol (RFC 7591), section 055 * 3.2.1. 056 * <li>OAuth 2.0 Dynamic Client Registration Management Protocol (RFC 057 * 7592), section 3. 058 * </ul> 059 */ 060@Immutable 061public final class OIDCClientInformation extends ClientInformation { 062 063 064 /** 065 * The registered parameter names. 066 */ 067 private static final Set<String> REGISTERED_PARAMETER_NAMES; 068 069 070 static { 071 Set<String> p = new HashSet<>(ClientInformation.getRegisteredParameterNames()); 072 p.addAll(OIDCClientMetadata.getRegisteredParameterNames()); 073 REGISTERED_PARAMETER_NAMES = Collections.unmodifiableSet(p); 074 } 075 076 077 /** 078 * Creates a new minimal OpenID Connect client information instance 079 * without a client secret. 080 * 081 * @param id The client identifier. Must not be {@code null}. 082 * @param metadata The OpenID Connect client metadata. Must not be 083 * {@code null}. 084 */ 085 public OIDCClientInformation(final ClientID id, final OIDCClientMetadata metadata) { 086 087 this(id, null, metadata, null); 088 } 089 090 091 /** 092 * Creates a new OpenID Connect client information instance. 093 * 094 * @param id The client identifier. Must not be {@code null}. 095 * @param issueDate The issue date of the client identifier, 096 * {@code null} if not specified. 097 * @param metadata The OpenID Connect client metadata. Must not be 098 * {@code null}. 099 * @param secret The optional client secret, {@code null} if not 100 * specified. 101 */ 102 public OIDCClientInformation(final ClientID id, 103 final Date issueDate, 104 final OIDCClientMetadata metadata, 105 final Secret secret) { 106 107 this(id, issueDate, metadata, secret, null, null); 108 } 109 110 111 /** 112 * Creates a new OpenID Connect client information instance permitting 113 * dynamic client registration management. 114 * 115 * @param id The client identifier. Must not be 116 * {@code null}. 117 * @param issueDate The issue date of the client identifier, 118 * {@code null} if not specified. 119 * @param metadata The OpenID Connect client metadata. Must not 120 * be {@code null}. 121 * @param secret The optional client secret, {@code null} if 122 * not specified. 123 * @param registrationURI The client registration URI, {@code null} if 124 * not specified. 125 * @param accessToken The client registration access token, 126 * {@code null} if not specified. 127 */ 128 public OIDCClientInformation(final ClientID id, 129 final Date issueDate, 130 final OIDCClientMetadata metadata, 131 final Secret secret, 132 final URI registrationURI, 133 final BearerAccessToken accessToken) { 134 135 super(id, issueDate, metadata, secret, registrationURI, accessToken); 136 } 137 138 139 /** 140 * Gets the registered client metadata parameter names. 141 * 142 * @return The registered parameter names, as an unmodifiable set. 143 */ 144 public static Set<String> getRegisteredParameterNames() { 145 146 return REGISTERED_PARAMETER_NAMES; 147 } 148 149 150 /** 151 * Gets the OpenID Connect client metadata. 152 * 153 * @return The OpenID Connect client metadata. 154 */ 155 public OIDCClientMetadata getOIDCMetadata() { 156 157 return (OIDCClientMetadata) getMetadata(); 158 } 159 160 161 /** 162 * Parses an OpenID Connect client information instance from the 163 * specified JSON object. 164 * 165 * @param jsonObject The JSON object to parse. Must not be 166 * {@code null}. 167 * 168 * @return The client information. 169 * 170 * @throws ParseException If the JSON object couldn't be parsed to an 171 * OpenID Connect client information instance. 172 */ 173 public static OIDCClientInformation parse(final JSONObject jsonObject) 174 throws ParseException { 175 176 return new OIDCClientInformation( 177 ClientCredentialsParser.parseID(jsonObject), 178 ClientCredentialsParser.parseIDIssueDate(jsonObject), 179 OIDCClientMetadata.parse(jsonObject), 180 ClientCredentialsParser.parseSecret(jsonObject), 181 ClientCredentialsParser.parseRegistrationURI(jsonObject), 182 ClientCredentialsParser.parseRegistrationAccessToken(jsonObject)); 183 } 184}