All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.gerrit.reviewdb.client.AccountExternalId Maven / Gradle / Ivy

There is a newer version: 3.10.0-rc4
Show newest version
// Copyright (C) 2008 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.gerrit.reviewdb.client;

import com.google.gerrit.extensions.client.AuthType;
import com.google.gwtorm.client.Column;
import com.google.gwtorm.client.StringKey;
import java.util.Objects;

/** Association of an external account identifier to a local {@link Account}. */
public final class AccountExternalId {
  /**
   * Scheme used for {@link AuthType#LDAP}, {@link AuthType#CLIENT_SSL_CERT_LDAP}, {@link
   * AuthType#HTTP_LDAP}, and {@link AuthType#LDAP_BIND} usernames.
   *
   * 

The name {@code gerrit:} was a very poor choice. */ public static final String SCHEME_GERRIT = "gerrit:"; /** Scheme used for randomly created identities constructed by a UUID. */ public static final String SCHEME_UUID = "uuid:"; /** Scheme used to represent only an email address. */ public static final String SCHEME_MAILTO = "mailto:"; /** Scheme for the username used to authenticate an account, e.g. over SSH. */ public static final String SCHEME_USERNAME = "username:"; /** Scheme used for GPG public keys. */ public static final String SCHEME_GPGKEY = "gpgkey:"; /** Scheme for external auth used during authentication, e.g. OAuth Token */ public static final String SCHEME_EXTERNAL = "external:"; public static class Key extends StringKey> { private static final long serialVersionUID = 1L; @Column(id = 1) protected String externalId; protected Key() {} public Key(String scheme, final String identity) { if (!scheme.endsWith(":")) { scheme += ":"; } externalId = scheme + identity; } public Key(final String e) { externalId = e; } @Override public String get() { return externalId; } @Override protected void set(String newValue) { externalId = newValue; } public String getScheme() { int c = externalId.indexOf(':'); return 0 < c ? externalId.substring(0, c) : null; } } @Column(id = 1, name = Column.NONE) protected Key key; @Column(id = 2) protected Account.Id accountId; @Column(id = 3, notNull = false) protected String emailAddress; // Encoded version of the hashed and salted password, to be interpreted by the // {@link HashedPassword} class. @Column(id = 4, notNull = false) protected String password; /** computed value is this identity trusted by the site administrator? */ protected boolean trusted; /** computed value can this identity be removed from the account? */ protected boolean canDelete; protected AccountExternalId() {} /** * Create a new binding to an external identity. * * @param who the account this binds to. * @param k the binding key. */ public AccountExternalId(final Account.Id who, final AccountExternalId.Key k) { accountId = who; key = k; } public AccountExternalId.Key getKey() { return key; } /** Get local id of this account, to link with in other entities */ public Account.Id getAccountId() { return accountId; } public String getExternalId() { return key.externalId; } public String getEmailAddress() { return emailAddress; } public void setEmailAddress(final String e) { emailAddress = e; } public boolean isScheme(final String scheme) { final String id = getExternalId(); return id != null && id.startsWith(scheme); } public String getSchemeRest() { String scheme = key.getScheme(); return null != scheme ? getExternalId().substring(scheme.length() + 1) : null; } public void setPassword(String hashed) { password = hashed; } public String getPassword() { return password; } public boolean isTrusted() { return trusted; } public void setTrusted(final boolean t) { trusted = t; } public boolean canDelete() { return canDelete; } public void setCanDelete(final boolean t) { canDelete = t; } @Override public boolean equals(Object o) { if (o instanceof AccountExternalId) { AccountExternalId extId = (AccountExternalId) o; return Objects.equals(key, extId.key) && Objects.equals(accountId, extId.accountId) && Objects.equals(emailAddress, extId.emailAddress) && Objects.equals(password, extId.password); } return false; } @Override public int hashCode() { return Objects.hash(key, accountId, emailAddress, password); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy