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