001/* 002 * oauth2-oidc-sdk 003 * 004 * Copyright 2012-2021, 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.trust.marks; 019 020 021import java.net.URI; 022 023import net.minidev.json.JSONObject; 024 025import com.nimbusds.oauth2.sdk.ParseException; 026import com.nimbusds.oauth2.sdk.util.JSONObjectUtils; 027 028 029/** 030 * Trust mark issuer metadata. 031 * 032 * <p>Related specifications: 033 * 034 * <ul> 035 * <li>OpenID Connect Federation 1.0, section 4.8. 036 * </ul> 037 */ 038public class TrustMarkIssuerMetadata { 039 040 041 /** 042 * The federation status endpoint. 043 */ 044 private final URI federationStatusEndpoint; 045 046 047 /** 048 * Creates a new trust mark issuer metadata. 049 * 050 * @param federationStatusEndpoint The federation status endpoint, 051 * {@code null} if not specified. 052 */ 053 public TrustMarkIssuerMetadata(final URI federationStatusEndpoint) { 054 this.federationStatusEndpoint = federationStatusEndpoint; 055 } 056 057 058 /** 059 * Gets the federation status endpoint URI. Corresponds to the 060 * {@code federation_status_endpoint} metadata field. 061 * 062 * @return The federation status endpoint URI, {@code null} if not 063 * specified. 064 */ 065 public URI getFederationStatusEndpointURI() { 066 return federationStatusEndpoint; 067 } 068 069 070 /** 071 * Returns a JSON object representation of this trust mark issuer 072 * metadata. 073 * 074 * <p>Example: 075 * 076 * <pre> 077 * { 078 * "endpoint": "https://trust_marks_are_us.example.com/status" 079 * } 080 * </pre> 081 * 082 * @return The JSON object. 083 */ 084 public JSONObject toJSONObject() { 085 086 JSONObject o = new JSONObject(); 087 if (getFederationStatusEndpointURI() != null) { 088 o.put("federation_status_endpoint", getFederationStatusEndpointURI().toString()); 089 } 090 return o; 091 } 092 093 094 /** 095 * Parses a trust mark issuer metadata from the specified JSON object. 096 * 097 * <p>Example: 098 * 099 * <pre> 100 * { 101 * "endpoint": "https://trust_marks_are_us.example.com/status" 102 * } 103 * </pre> 104 * 105 * @param jsonObject The JSON object. Must not be {@code null}. 106 * 107 * @return The trust mark issuer metadata. 108 * 109 * @throws ParseException If parsing failed. 110 */ 111 public static TrustMarkIssuerMetadata parse(final JSONObject jsonObject) 112 throws ParseException { 113 114 return new TrustMarkIssuerMetadata( 115 JSONObjectUtils.getURI(jsonObject, "federation_status_endpoint", null) 116 ); 117 } 118 119 120 /** 121 * Parses a trust mark issuer metadata from the specified JSON object 122 * string. 123 * 124 * <p>Example: 125 * 126 * <pre> 127 * { 128 * "endpoint": "https://trust_marks_are_us.example.com/status" 129 * } 130 * </pre> 131 * 132 * @param json The JSON object string. Must not be {@code null}. 133 * 134 * @return The trust mark issuer metadata. 135 * 136 * @throws ParseException If parsing failed. 137 */ 138 public static TrustMarkIssuerMetadata parse(final String json) 139 throws ParseException { 140 141 return parse(JSONObjectUtils.parse(json)); 142 } 143}