Line data Source code
1 : // Copyright (C) 2017 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.extensions.common; 16 : 17 : import static com.google.common.base.MoreObjects.toStringHelper; 18 : 19 : import com.google.common.collect.ComparisonChain; 20 : import java.util.Objects; 21 : 22 : /** 23 : * Representation of an external ID in the REST API. 24 : * 25 : * <p>This class determines the JSON format of external IDs in the REST API. 26 : * 27 : * <p>External IDs are user identities that are assigned to an account. Often they are used to link 28 : * user identities in external systems. 29 : */ 30 4 : public class AccountExternalIdInfo implements Comparable<AccountExternalIdInfo> { 31 : /** The external ID key, formatted as {@code <scheme>:<ID>}. */ 32 : public String identity; 33 : 34 : /** The email address of the external ID. */ 35 : public String emailAddress; 36 : 37 : /** 38 : * Whether the external ID is trusted. 39 : * 40 : * <p>Also see {@link 41 : * com.google.gerrit.server.config.AuthConfig#isIdentityTrustable(java.util.Collection)}. 42 : */ 43 : public Boolean trusted; 44 : 45 : /** Whether the external ID can be deleted by the calling user. */ 46 : public Boolean canDelete; 47 : 48 : @Override 49 : public int compareTo(AccountExternalIdInfo a) { 50 0 : return ComparisonChain.start() 51 0 : .compare(a.identity, identity) 52 0 : .compare(a.emailAddress, emailAddress) 53 0 : .result(); 54 : } 55 : 56 : @Override 57 : public boolean equals(Object o) { 58 1 : if (o instanceof AccountExternalIdInfo) { 59 1 : AccountExternalIdInfo a = (AccountExternalIdInfo) o; 60 1 : return Objects.equals(a.identity, identity) 61 1 : && Objects.equals(a.emailAddress, emailAddress) 62 1 : && Objects.equals(a.trusted, trusted) 63 1 : && Objects.equals(a.canDelete, canDelete); 64 : } 65 0 : return false; 66 : } 67 : 68 : @Override 69 : public int hashCode() { 70 0 : return Objects.hash(identity, emailAddress, trusted, canDelete); 71 : } 72 : 73 : @Override 74 : public String toString() { 75 0 : return toStringHelper(this) 76 0 : .add("identity", identity) 77 0 : .add("emailAddress", emailAddress) 78 0 : .add("trusted", trusted) 79 0 : .add("canDelete", canDelete) 80 0 : .toString(); 81 : } 82 : }