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.jcip.annotations.Immutable; 024import net.minidev.json.JSONAware; 025import net.minidev.json.JSONObject; 026 027import com.nimbusds.oauth2.sdk.ParseException; 028import com.nimbusds.oauth2.sdk.util.JSONObjectUtils; 029import com.nimbusds.secevent.sdk.claims.TXN; 030 031 032/** 033 * Legal entity that performed an identity verification on behalf of an OpenID 034 * provider. 035 * 036 * <p>Related specifications: 037 * 038 * <ul> 039 * <li>OpenID Connect for Identity Assurance 1.0, section 4.1.1.1. 040 * </ul> 041 */ 042@Immutable 043public final class IdentityVerifier implements JSONAware { 044 045 046 /** 047 * The organisation. 048 */ 049 private final String organization; 050 051 052 /** 053 * Identifier for the identity verification transaction. 054 */ 055 private final TXN txn; 056 057 058 /** 059 * Creates a new verifier. 060 * 061 * @param organization The organisation, {@code null} if not specified. 062 * @param txn Identifier for the identity verification 063 * transaction, {@code null} if not specified. 064 */ 065 public IdentityVerifier(final String organization, final TXN txn) { 066 this.organization = organization; 067 this.txn = txn; 068 } 069 070 071 /** 072 * Returns the organisation. 073 * 074 * @return The organisation, {@code null} if not specified. 075 */ 076 public String getOrganization() { 077 return organization; 078 } 079 080 081 /** 082 * Returns the identifier for the identity verification transaction. 083 * 084 * @return The identity verification transaction identifier, 085 * {@code null} if not specified. 086 */ 087 public TXN getTXN() { 088 return txn; 089 } 090 091 092 /** 093 * Returns a JSON object representation os this verifier. 094 * 095 * @return The JSON object. 096 */ 097 public JSONObject toJSONObject() { 098 JSONObject o = new JSONObject(); 099 if (getOrganization() != null) { 100 o.put("organization", getOrganization()); 101 } 102 if (getTXN() != null) { 103 o.put("txn", getTXN().getValue()); 104 } 105 return o; 106 } 107 108 109 @Override 110 public String toJSONString() { 111 return toJSONObject().toJSONString(); 112 } 113 114 115 @Override 116 public boolean equals(Object o) { 117 if (this == o) return true; 118 if (!(o instanceof IdentityVerifier)) return false; 119 IdentityVerifier verifier = (IdentityVerifier) o; 120 return getOrganization().equals(verifier.getOrganization()) && 121 txn.equals(verifier.txn); 122 } 123 124 125 @Override 126 public int hashCode() { 127 return Objects.hash(getOrganization(), txn); 128 } 129 130 131 /** 132 * Parses a verifier from the specified JSON object. 133 * 134 * @param jsonObject The JSON object. Must not be {@code null}. 135 * 136 * @return The verifier. 137 * 138 * @throws ParseException If parsing failed. 139 */ 140 public static IdentityVerifier parse(final JSONObject jsonObject) 141 throws ParseException { 142 143 String org = JSONObjectUtils.getString(jsonObject, "organization", null); 144 TXN txn = null; 145 if (jsonObject.get("txn") != null) { 146 txn = new TXN(JSONObjectUtils.getString(jsonObject, "txn")); 147 } 148 return new IdentityVerifier(org, txn); 149 } 150}