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.federation.entities; 019 020 021import java.net.URI; 022import java.util.List; 023 024import net.minidev.json.JSONObject; 025 026import com.nimbusds.oauth2.sdk.ParseException; 027import com.nimbusds.oauth2.sdk.util.JSONObjectUtils; 028 029 030/** 031 * Federation entity metadata. 032 * 033 * <p>Related specifications: 034 * 035 * <ul> 036 * <li>OpenID Connect Federation 1.0, section 4.8. 037 * </ul> 038 */ 039public class FederationEntityMetadata { 040 041 042 /** 043 * The federation fetch endpoint. 044 */ 045 private URI federationFetchEndpoint; 046 047 048 /** 049 * The federation list endpoint. 050 */ 051 private URI federationListEndpoint; 052 053 054 /** 055 * The federation resolve endpoint. 056 */ 057 private URI federationResolveEndpoint; 058 059 060 /** 061 * The federation trust mark status endpoint. 062 */ 063 private URI federationTrustMarkStatusEndpoint; 064 065 066 /** 067 * The organisation name. 068 */ 069 private String organizationName; 070 071 072 /** 073 * The contacts. 074 */ 075 private List<String> contacts; 076 077 078 /** 079 * The logo URI. 080 */ 081 private URI logoURI; 082 083 084 /** 085 * The policy URI. 086 */ 087 private URI policyURI; 088 089 090 /** 091 * The homepage URI. 092 */ 093 private URI homepageURI; 094 095 096 /** 097 * Creates a new federation entity metadata. 098 */ 099 public FederationEntityMetadata() {} 100 101 102 /** 103 * Creates a new federation entity metadata. 104 * 105 * @param federationFetchEndpoint The federation fetch endpoint, 106 * required for trust anchors and 107 * intermediate entities, optional for 108 * leaf entities. 109 */ 110 public FederationEntityMetadata(final URI federationFetchEndpoint) { 111 this.federationFetchEndpoint = federationFetchEndpoint; 112 } 113 114 115 /** 116 * Gets the federation fetch endpoint. Corresponds to the 117 * {@code federation_fetch_endpoint} metadata field. 118 * 119 * @return The federation fetch endpoint, {@code null} if not 120 * specified. 121 */ 122 public URI getFederationFetchEndpointURI() { 123 return federationFetchEndpoint; 124 } 125 126 127 /** 128 * Sets the federation fetch endpoint. Corresponds to the 129 * {@code federation_fetch_endpoint} metadata field. 130 * 131 * @param federationFetchEndpoint The federation fetch endpoint, 132 * {@code null} if not specified. 133 */ 134 public void setFederationFetchEndpointURI(final URI federationFetchEndpoint) { 135 this.federationFetchEndpoint = federationFetchEndpoint; 136 } 137 138 139 /** 140 * Gets the federation list endpoint. Corresponds to the 141 * {@code federation_list_endpoint} metadata field. 142 * 143 * @return The federation list endpoint, {@code null} if not specified. 144 */ 145 public URI getFederationListEndpointURI() { 146 return federationListEndpoint; 147 } 148 149 150 /** 151 * Sets the federation list endpoint. Corresponds to the 152 * {@code federation_list_endpoint} metadata field. 153 * 154 * @param federationListEndpoint The federation list endpoint, 155 * {@code null} if not specified. 156 */ 157 public void setFederationListEndpointURI(final URI federationListEndpoint) { 158 this.federationListEndpoint = federationListEndpoint; 159 } 160 161 162 /** 163 * Gets the federation resolve endpoint. Corresponds to the 164 * {@code federation_resolve_endpoint} metadata field. 165 * 166 * @return The federation resolve endpoint, {@code null} if not 167 * specified. 168 */ 169 public URI getFederationResolveEndpointURI() { 170 return federationResolveEndpoint; 171 } 172 173 174 /** 175 * Sets the federation resolve endpoint. Corresponds to the 176 * {@code federation_resolve_endpoint} metadata field. 177 * 178 * @param federationResolveEndpoint The federation resolve endpoint, 179 * {@code null} if not specified. 180 */ 181 public void setFederationResolveEndpointURI(final URI federationResolveEndpoint) { 182 this.federationResolveEndpoint = federationResolveEndpoint; 183 } 184 185 186 /** 187 * Gets the federation trust mark status endpoint. 188 * 189 * @return The federation trust mark status endpoint, {@code null} if 190 * not specified. 191 */ 192 public URI getFederationTrustMarkStatusEndpointURI() { 193 return federationTrustMarkStatusEndpoint; 194 } 195 196 197 /** 198 * Sets the federation trust mark status endpoint. 199 * 200 * @param federationTrustMarkStatusEndpoint The federation trust mark 201 * status endpoint, 202 * {@code null} if not 203 * specified. 204 */ 205 public void setFederationTrustMarkStatusEndpointURI(final URI federationTrustMarkStatusEndpoint) { 206 this.federationTrustMarkStatusEndpoint = federationTrustMarkStatusEndpoint; 207 } 208 209 210 /** 211 * Gets the organisation name. Corresponds to the 212 * {@code organization_name} metadata field. 213 * 214 * @return The organisation name, {@code null} if not specified. 215 */ 216 public String getOrganizationName() { 217 return organizationName; 218 } 219 220 221 /** 222 * Sets the organisation name. Corresponds to the 223 * {@code organization_name} metadata field. 224 * 225 * @param organizationName The organisation name, {@code null} if not 226 * specified. 227 */ 228 public void setOrganizationName(final String organizationName) { 229 this.organizationName = organizationName; 230 } 231 232 233 /** 234 * Gets the entity contacts. Corresponds to the {@code contacts} 235 * metadata field. 236 * 237 * @return The contacts, such as names, e-mail addresses and phone 238 * numbers, {@code null} if not specified. 239 */ 240 public List<String> getContacts() { 241 return contacts; 242 } 243 244 245 /** 246 * Sets the entity contacts. Corresponds to the {@code contacts} 247 * metadata field. 248 * 249 * @param contacts The contacts, such as names, e-mail addresses and 250 * phone numbers, {@code null} if not specified. 251 */ 252 public void setContacts(final List<String> contacts) { 253 this.contacts = contacts; 254 } 255 256 257 /** 258 * Gets the logo URI. Corresponds to the {@code logo_uri} metadata 259 * field. 260 * 261 * @return The logo URI, {@code null} if not specified. 262 */ 263 public URI getLogoURI() { 264 return logoURI; 265 } 266 267 268 /** 269 * Sets the logo URI. Corresponds to the {@code logo_uri} metadata 270 * field. 271 * 272 * @param logoURI The logo URI, {@code null} if not specified. 273 */ 274 public void setLogoURI(final URI logoURI) { 275 this.logoURI = logoURI; 276 } 277 278 279 /** 280 * Gets the conditions and policies documentation URI. Corresponds to 281 * the {@code policy_uri} metadata field. 282 * 283 * @return The policy URI, {@code null} if not specified. 284 */ 285 public URI getPolicyURI() { 286 return policyURI; 287 } 288 289 290 /** 291 * Sets the conditions and policies documentation URI. Corresponds to 292 * the {@code policy_uri} metadata field. 293 * 294 * @param policyURI The policy URI, {@code null} if not specified. 295 */ 296 public void setPolicyURI(final URI policyURI) { 297 this.policyURI = policyURI; 298 } 299 300 301 /** 302 * Gets the homepage URI. Corresponds to the {@code homepage_uri} 303 * metadata field. 304 * 305 * @return The homepage URI, {@code null} if not specified. 306 */ 307 public URI getHomepageURI() { 308 return homepageURI; 309 } 310 311 312 /** 313 * Sets the homepage URI. Corresponds to the {@code homepage_uri} 314 * metadata field. 315 * 316 * @param homepageURI The homepage URI, {@code null} if not specified. 317 */ 318 public void setHomepageURI(final URI homepageURI) { 319 this.homepageURI = homepageURI; 320 } 321 322 323 /** 324 * Returns a JSON object representation of this federation entity 325 * metadata. 326 * 327 * <p>Example: 328 * 329 * <pre> 330 * { 331 * "federation_fetch_endpoint" : "https://example.com/federation_fetch", 332 * "federation_list_endpoint" : "https://example.com/federation_list", 333 * "federation_trust_mark_status_endpoint" : "https://example.com/federation_status", 334 * "name" : "The example cooperation", 335 * "homepage_uri" : "https://www.example.com" 336 * } 337 * </pre> 338 * 339 * @return The JSON object. 340 */ 341 public JSONObject toJSONObject() { 342 343 JSONObject o = new JSONObject(); 344 if (getFederationFetchEndpointURI() != null) { 345 o.put("federation_fetch_endpoint", getFederationFetchEndpointURI().toString()); 346 } 347 if (getFederationListEndpointURI() != null) { 348 o.put("federation_list_endpoint", getFederationListEndpointURI().toString()); 349 } 350 if (getFederationResolveEndpointURI() != null) { 351 o.put("federation_resolve_endpoint", getFederationResolveEndpointURI().toString()); 352 } 353 if (getFederationTrustMarkStatusEndpointURI() != null) { 354 o.put("federation_trust_mark_status_endpoint", getFederationTrustMarkStatusEndpointURI().toString()); 355 } 356 if (getOrganizationName() != null) { 357 o.put("organization_name", getOrganizationName()); 358 } 359 if (getContacts() != null) { 360 o.put("contacts", getContacts()); 361 } 362 if (getLogoURI() != null) { 363 o.put("logo_uri", getLogoURI().toString()); 364 } 365 if (getPolicyURI() != null) { 366 o.put("policy_uri", getPolicyURI().toString()); 367 } 368 if (getHomepageURI() != null) { 369 o.put("homepage_uri", getHomepageURI().toString()); 370 } 371 return o; 372 } 373 374 375 /** 376 * Parses a federation entity metadata from the specified a JSON 377 * object. 378 * 379 * <p>Example: 380 * 381 * <pre> 382 * { 383 * "federation_fetch_endpoint" : "https://example.com/federation_fetch", 384 * "federation_list_endpoint" : "https://example.com/federation_list", 385 * "name" : "The example cooperation", 386 * "homepage_uri" : "https://www.example.com" 387 * } 388 * </pre> 389 * 390 * @param jsonObject The JSON object. Must not be {@code null}. 391 * 392 * @return The federation entity metadata. 393 * 394 * @throws ParseException If parsing failed. 395 */ 396 public static FederationEntityMetadata parse(final JSONObject jsonObject) 397 throws ParseException { 398 399 FederationEntityMetadata metadata = new FederationEntityMetadata(JSONObjectUtils.getURI(jsonObject, "federation_fetch_endpoint", null)); 400 metadata.setFederationListEndpointURI(JSONObjectUtils.getURI(jsonObject, "federation_list_endpoint", null)); 401 metadata.setFederationResolveEndpointURI(JSONObjectUtils.getURI(jsonObject, "federation_resolve_endpoint", null)); 402 metadata.setFederationTrustMarkStatusEndpointURI(JSONObjectUtils.getURI(jsonObject, "federation_trust_mark_status_endpoint", null)); 403 metadata.setOrganizationName(JSONObjectUtils.getString(jsonObject, "organization_name", null)); 404 metadata.setContacts(JSONObjectUtils.getStringList(jsonObject, "contacts", null)); 405 metadata.setLogoURI(JSONObjectUtils.getURI(jsonObject, "logo_uri", null)); 406 metadata.setPolicyURI(JSONObjectUtils.getURI(jsonObject, "policy_uri", null)); 407 metadata.setHomepageURI(JSONObjectUtils.getURI(jsonObject, "homepage_uri", null)); 408 return metadata; 409 } 410 411 412 /** 413 * Parses a federation entity metadata from the specified JSON object 414 * string. 415 * 416 * <p>Example: 417 * 418 * <pre> 419 * { 420 * "federation_fetch_endpoint" : "https://example.com/federation_fetch", 421 * "federation_list_endpoint" : "https://example.com/federation_list", 422 * "federation_trust_mark_status_endpoint" : "https://example.com/federation_status", 423 * "name" : "The example cooperation", 424 * "homepage_uri" : "https://www.example.com" 425 * } 426 * </pre> 427 * 428 * @param json The JSON object string. Must not be {@code null}. 429 * 430 * @return The federation entity metadata. 431 * 432 * @throws ParseException If parsing failed. 433 */ 434 public static FederationEntityMetadata parse(final String json) 435 throws ParseException { 436 437 return parse(JSONObjectUtils.parse(json)); 438 } 439}