/*******************************************************************************
|
* Copyright (c) 2005, 2014 springside.github.io
|
*
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
*******************************************************************************/
|
package com.northglass.entity;
|
|
import java.util.Date;
|
import java.util.List;
|
|
import javax.persistence.Entity;
|
import javax.persistence.Table;
|
import javax.persistence.Transient;
|
|
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.hibernate.validator.constraints.NotBlank;
|
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.google.common.collect.ImmutableList;
|
|
@Entity
|
@Table(name = "gmms_user")
|
public class User extends IdEntity {
|
private String loginName;
|
private String name;
|
private String plainPassword;
|
private String password;
|
private String salt;
|
private String roles;
|
private String groups;
|
private Date registerDate;
|
|
public User() {
|
}
|
|
public User(Long id) {
|
this.id = id;
|
}
|
|
@NotBlank
|
public String getLoginName() {
|
return loginName;
|
}
|
|
public void setLoginName(String loginName) {
|
this.loginName = loginName;
|
}
|
|
@NotBlank
|
public String getName() {
|
return name;
|
}
|
|
public void setName(String name) {
|
this.name = name;
|
}
|
|
// 不持久化到数据库,也不显示在Restful接口的属性.
|
@Transient
|
@JsonIgnore
|
public String getPlainPassword() {
|
return plainPassword;
|
}
|
|
public void setPlainPassword(String plainPassword) {
|
this.plainPassword = plainPassword;
|
}
|
|
public String getPassword() {
|
return password;
|
}
|
|
public void setPassword(String password) {
|
this.password = password;
|
}
|
|
public String getSalt() {
|
return salt;
|
}
|
|
public void setSalt(String salt) {
|
this.salt = salt;
|
}
|
|
public String getRoles() {
|
return roles;
|
}
|
|
public void setRoles(String roles) {
|
this.roles = roles;
|
}
|
|
public String getGroups() {
|
return groups;
|
}
|
|
public void setGroups(String groups) {
|
this.groups = groups;
|
}
|
|
@Transient
|
@JsonIgnore
|
public List<String> getRoleList() {
|
// 角色列表在数据库中实际以逗号分隔字符串存储,因此返回不能修改的List.
|
return ImmutableList.copyOf(StringUtils.split(roles, ","));
|
}
|
|
// 设定JSON序列化时的日期格式
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
|
public Date getRegisterDate() {
|
return registerDate;
|
}
|
|
public void setRegisterDate(Date registerDate) {
|
this.registerDate = registerDate;
|
}
|
|
@Override
|
public String toString() {
|
return ToStringBuilder.reflectionToString(this);
|
}
|
}
|