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) 055 * <li>OAuth 2.0 Dynamic Client Registration Management Protocol (RFC 7592) 056 * </ul> 057 */ 058@Immutable 059public final class OIDCClientInformation extends ClientInformation { 060 061 062 /** 063 * The registered parameter names. 064 */ 065 private static final Set<String> REGISTERED_PARAMETER_NAMES; 066 067 068 static { 069 Set<String> p = new HashSet<>(ClientInformation.getRegisteredParameterNames()); 070 p.addAll(OIDCClientMetadata.getRegisteredParameterNames()); 071 REGISTERED_PARAMETER_NAMES = Collections.unmodifiableSet(p); 072 } 073 074 075 /** 076 * Creates a new minimal OpenID Connect client information instance 077 * without a client secret. 078 * 079 * @param id The client identifier. Must not be {@code null}. 080 * @param metadata The OpenID Connect client metadata. Must not be 081 * {@code null}. 082 */ 083 public OIDCClientInformation(final ClientID id, final OIDCClientMetadata metadata) { 084 085 this(id, null, metadata, null); 086 } 087 088 089 /** 090 * Creates a new OpenID Connect client information instance. 091 * 092 * @param id The client identifier. Must not be {@code null}. 093 * @param issueDate The issue date of the client identifier, 094 * {@code null} if not specified. 095 * @param metadata The OpenID Connect client metadata. Must not be 096 * {@code null}. 097 * @param secret The optional client secret, {@code null} if not 098 * specified. 099 */ 100 public OIDCClientInformation(final ClientID id, 101 final Date issueDate, 102 final OIDCClientMetadata metadata, 103 final Secret secret) { 104 105 this(id, issueDate, metadata, secret, null, null); 106 } 107 108 109 /** 110 * Creates a new OpenID Connect client information instance permitting 111 * dynamic client registration management. 112 * 113 * @param id The client identifier. Must not be 114 * {@code null}. 115 * @param issueDate The issue date of the client identifier, 116 * {@code null} if not specified. 117 * @param metadata The OpenID Connect client metadata. Must not 118 * be {@code null}. 119 * @param secret The optional client secret, {@code null} if 120 * not specified. 121 * @param registrationURI The client registration URI, {@code null} if 122 * not specified. 123 * @param accessToken The client registration access token, 124 * {@code null} if not specified. 125 */ 126 public OIDCClientInformation(final ClientID id, 127 final Date issueDate, 128 final OIDCClientMetadata metadata, 129 final Secret secret, 130 final URI registrationURI, 131 final BearerAccessToken accessToken) { 132 133 super(id, issueDate, metadata, secret, registrationURI, accessToken); 134 } 135 136 137 /** 138 * Gets the registered client metadata parameter names. 139 * 140 * @return The registered parameter names, as an unmodifiable set. 141 */ 142 public static Set<String> getRegisteredParameterNames() { 143 144 return REGISTERED_PARAMETER_NAMES; 145 } 146 147 148 /** 149 * Gets the OpenID Connect client metadata. 150 * 151 * @return The OpenID Connect client metadata. 152 */ 153 public OIDCClientMetadata getOIDCMetadata() { 154 155 return (OIDCClientMetadata) getMetadata(); 156 } 157 158 159 /** 160 * Parses an OpenID Connect client information instance from the 161 * specified JSON object. 162 * 163 * @param jsonObject The JSON object to parse. Must not be 164 * {@code null}. 165 * 166 * @return The client information. 167 * 168 * @throws ParseException If the JSON object couldn't be parsed to an 169 * OpenID Connect client information instance. 170 */ 171 public static OIDCClientInformation parse(final JSONObject jsonObject) 172 throws ParseException { 173 174 return new OIDCClientInformation( 175 ClientCredentialsParser.parseID(jsonObject), 176 ClientCredentialsParser.parseIDIssueDate(jsonObject), 177 OIDCClientMetadata.parse(jsonObject), 178 ClientCredentialsParser.parseSecret(jsonObject), 179 ClientCredentialsParser.parseRegistrationURI(jsonObject), 180 ClientCredentialsParser.parseRegistrationAccessToken(jsonObject)); 181 } 182}