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.assurance.evidences; 019 020 021import java.util.Objects; 022 023import net.minidev.json.JSONAware; 024import net.minidev.json.JSONObject; 025 026import com.nimbusds.oauth2.sdk.ParseException; 027import com.nimbusds.oauth2.sdk.util.JSONObjectUtils; 028import com.nimbusds.secevent.sdk.claims.TXN; 029 030 031/** 032 * Legal entity that performed an identity verification on behalf of an OpenID 033 * provider. 034 * 035 * <p>Related specifications: 036 * 037 * <ul> 038 * <li>OpenID Connect for Identity Assurance 1.0, section 5.1.1. 039 * </ul> 040 */ 041public class IdentityVerifier implements JSONAware { 042 043 044 /** 045 * The organisation. 046 */ 047 private final Organization organization; 048 049 050 /** 051 * Identifier for the identity verification transaction. 052 */ 053 private final TXN txn; 054 055 056 /** 057 * Creates a new verifier. 058 * 059 * @param organization The organisation, {@code null} if not specified. 060 * @param txn Identifier for the identity verification 061 * transaction, {@code null} if not specified. 062 */ 063 public IdentityVerifier(final Organization organization, final TXN txn) { 064 this.organization = organization; 065 this.txn = txn; 066 } 067 068 069 /** 070 * Creates a new verifier. 071 * 072 * @param organizationString The organisation string, {@code null} if 073 * not specified. 074 * @param txn Identifier for the identity verification 075 * transaction, {@code null} if not 076 * specified. 077 */ 078 @Deprecated 079 public IdentityVerifier(final String organizationString, final TXN txn) { 080 this.organization = organizationString != null ? new Organization(organizationString) : null; 081 this.txn = txn; 082 } 083 084 085 /** 086 * Returns the organisation. 087 * 088 * @return The organisation, {@code null} if not specified. 089 */ 090 public Organization getOrganizationEntity() { 091 return organization; 092 } 093 094 095 /** 096 * Returns the organisation string. 097 * 098 * @return The organisation string, {@code null} if not specified. 099 */ 100 public String getOrganizationString() { 101 return getOrganizationEntity() != null ? getOrganizationEntity().getValue() : null; 102 } 103 104 105 /** 106 * Returns the organisation string. 107 * 108 * @return The organisation string, {@code null} if not specified. 109 * 110 * @deprecated Use {@link #getOrganizationString()} instead. 111 */ 112 @Deprecated 113 public String getOrganization() { 114 // Deprecated to allow for strongly typed Organization in future 115 return getOrganizationString(); 116 } 117 118 119 /** 120 * Returns the identifier for the identity verification transaction. 121 * 122 * @return The identity verification transaction identifier, 123 * {@code null} if not specified. 124 */ 125 public TXN getTXN() { 126 return txn; 127 } 128 129 130 /** 131 * Returns a JSON object representation os this verifier. 132 * 133 * @return The JSON object. 134 */ 135 public JSONObject toJSONObject() { 136 JSONObject o = new JSONObject(); 137 if (getOrganization() != null) { 138 o.put("organization", getOrganizationEntity().getValue()); 139 } 140 if (getTXN() != null) { 141 o.put("txn", getTXN().getValue()); 142 } 143 return o; 144 } 145 146 147 @Override 148 public String toJSONString() { 149 return toJSONObject().toJSONString(); 150 } 151 152 153 @Override 154 public boolean equals(Object o) { 155 if (this == o) return true; 156 if (!(o instanceof IdentityVerifier)) return false; 157 IdentityVerifier verifier = (IdentityVerifier) o; 158 return Objects.equals(getOrganizationEntity(), verifier.getOrganizationEntity()) && Objects.equals(getTXN(), verifier.getTXN()); 159 } 160 161 162 @Override 163 public int hashCode() { 164 return Objects.hash(getOrganizationEntity(), getTXN()); 165 } 166 167 168 /** 169 * Parses a verifier from the specified JSON object. 170 * 171 * @param jsonObject The JSON object. Must not be {@code null}. 172 * 173 * @return The verifier. 174 * 175 * @throws ParseException If parsing failed. 176 */ 177 public static IdentityVerifier parse(final JSONObject jsonObject) 178 throws ParseException { 179 180 Organization org = null; 181 if (jsonObject.get("organization") != null) { 182 org = new Organization(JSONObjectUtils.getString(jsonObject, "organization")); 183 } 184 185 TXN txn = null; 186 if (jsonObject.get("txn") != null) { 187 txn = new TXN(JSONObjectUtils.getString(jsonObject, "txn")); 188 } 189 190 return new IdentityVerifier(org, txn); 191 } 192}