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. Must not be {@code null}. 062 * @param txn Identifier for the identity verification 063 * transaction. Must not be {@code null}. 064 */ 065 public IdentityVerifier(final String organization, final TXN txn) { 066 067 if (organization == null) { 068 throw new IllegalArgumentException("The organization must not be null"); 069 } 070 this.organization = organization; 071 072 if (txn == null) { 073 throw new IllegalArgumentException("The txn must not be null"); 074 } 075 this.txn = txn; 076 } 077 078 079 /** 080 * Returns the organisation. 081 * 082 * @return The organisation. 083 */ 084 public String getOrganization() { 085 return organization; 086 } 087 088 089 /** 090 * Returns the identifier for the identity verification transaction. 091 * 092 * @return The identity verification transaction identifier. 093 */ 094 public TXN getTXN() { 095 return txn; 096 } 097 098 099 /** 100 * Returns a JSON object representation os this verifier. 101 * 102 * @return The JSON object. 103 */ 104 public JSONObject toJSONObject() { 105 JSONObject o = new JSONObject(); 106 o.put("organization", getOrganization()); 107 o.put("txn", getTXN().getValue()); 108 return o; 109 } 110 111 112 @Override 113 public String toJSONString() { 114 return toJSONObject().toJSONString(); 115 } 116 117 118 @Override 119 public boolean equals(Object o) { 120 if (this == o) return true; 121 if (!(o instanceof IdentityVerifier)) return false; 122 IdentityVerifier verifier = (IdentityVerifier) o; 123 return getOrganization().equals(verifier.getOrganization()) && 124 txn.equals(verifier.txn); 125 } 126 127 128 @Override 129 public int hashCode() { 130 return Objects.hash(getOrganization(), txn); 131 } 132 133 134 /** 135 * Parses a verifier from the specified JSON object. 136 * 137 * @param jsonObject The JSON object. Must not be {@code null}. 138 * 139 * @return The verifier. 140 * 141 * @throws ParseException If parsing failed. 142 */ 143 public static IdentityVerifier parse(final JSONObject jsonObject) 144 throws ParseException { 145 146 String org = JSONObjectUtils.getString(jsonObject, "organization"); 147 TXN txn = new TXN(JSONObjectUtils.getString(jsonObject, "txn")); 148 return new IdentityVerifier(org, txn); 149 } 150}