content: package cn.abel.rest.shiro;
  
  import java.io.Serializable;
  
  import com.google.common.base.Objects;
  
  /**
   * 自定义Authentication对象，使得Subject除了携带用户的登录名外还可以携带更多信息.
   *
   */
  public class ShiroUser implements Serializable {
  
      private static final long serialVersionUID = -1373760761780840081L;
  
      private Long userId;
  
      private String loginName;
  
      private String nickName;
  
      private String token;
  
      public Long getUserId() {
          return userId;
      }
  
      public void setUserId(Long userId) {
          this.userId = userId;
      }
  
      public String getLoginName() {
          return loginName;
      }
  
      public void setLoginName(String loginName) {
          this.loginName = loginName;
      }
  
      public void setNickName(String nickName) {
          this.nickName = nickName;
      }
  
      public ShiroUser(Long userId, String loginName, String nickName) {
          this.userId = userId;
          this.loginName = loginName;
          this.nickName = nickName;
      }
  
      public String getNickName() {
          return nickName;
      }
  
      public String getToken() {
          return token;
      }
  
      public void setToken(String token) {
          this.token = token;
      }
  
      /**
       * 本函数输出将作为默认的<shiro:principal/>输出.
       */
      @Override
      public String toString() {
          return loginName;
      }
  
      /**
       * 重载hashCode,只计算loginName;
       */
      @Override
      public int hashCode() {
          return Objects.hashCode(loginName);
      }
  
      /**
       * 重载equals,只计算loginName;
       */
      @Override
      public boolean equals(Object obj) {
          if (this == obj) {
              return true;
          }
          if (obj == null) {
              return false;
          }
          if (getClass() != obj.getClass()) {
              return false;
          }
          ShiroUser other = (ShiroUser) obj;
          if (loginName == null) {
              if (other.loginName != null) {
                  return false;
              }
          } else if (!loginName.equals(other.loginName)) {
              return false;
          }
          return true;
      }
  
  }