001/*
002 * Copyright 2014 Global Biodiversity Information Facility (GBIF)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.gbif.api.model.common;
017
018import org.gbif.api.model.registry.PostPersist;
019import org.gbif.api.model.registry.PrePersist;
020
021import java.util.Date;
022import javax.annotation.Nullable;
023import javax.validation.constraints.NotNull;
024import javax.validation.constraints.Null;
025
026import com.google.common.base.Objects;
027import org.codehaus.jackson.annotate.JsonIgnore;
028
029/**
030 * A GBIF user account registered in the user Identity database (previously Drupal).
031 * This class is the replacement of {@link User}.
032 */
033public class GbifUser extends AbstractGbifUser {
034
035  protected Integer key;
036
037  private String passwordHash;
038  private Date lastLogin;
039
040  @Null(groups = {PrePersist.class})
041  @NotNull(groups = {PostPersist.class})
042  public Integer getKey() {
043    return key;
044  }
045
046  public void setKey(Integer key) {
047    this.key = key;
048  }
049
050  @Nullable
051  public Date getLastLogin() {
052    return lastLogin;
053  }
054
055  public void setLastLogin(Date lastLogin) {
056    this.lastLogin = lastLogin;
057  }
058
059  /**
060   * @return the hashed version of the user password.
061   */
062  @NotNull
063  @JsonIgnore
064  public String getPasswordHash() {
065    return passwordHash;
066  }
067
068  public void setPasswordHash(String passwordHash) {
069    this.passwordHash = passwordHash;
070  }
071
072  @Override
073  public boolean equals(Object obj) {
074    if (this == obj) {
075      return true;
076    }
077    if (!(obj instanceof GbifUser)) {
078      return false;
079    }
080
081    GbifUser that = (GbifUser) obj;
082    return Objects.equal(this.key, that.key)
083           && Objects.equal(this.userName, that.userName)
084           && Objects.equal(this.firstName, that.firstName)
085           && Objects.equal(this.lastName, that.lastName)
086           && Objects.equal(this.email, that.email)
087           && Objects.equal(this.roles, that.roles)
088           && Objects.equal(this.lastLogin, that.lastLogin)
089           && Objects.equal(this.passwordHash, that.passwordHash)
090           && Objects.equal(this.settings, that.settings);
091  }
092
093  @Override
094  public int hashCode() {
095    return Objects.hashCode(key, userName, firstName, lastName, email, roles, lastLogin, passwordHash, settings);
096  }
097
098  @Override
099  public String toString() {
100    return Objects.toStringHelper(this)
101      .add("key", key)
102      .add("accountName", userName)
103      .add("firstName", firstName)
104      .add("lastName", lastName)
105      .add("email", email)
106      .add("roles", roles)
107      .add("lastLogin", lastLogin)
108      .add("settings", settings)
109      .toString();
110  }
111
112}