/*
* Copyright 2014-2015 the original author or authors.
*
* 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 karthik.oauth.domain;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;
import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
@Table(name="user")
public class User extends AbstractAuditingEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Size(max = 50)
@Column(name = "first_name", length = 50)
private String firstName;
@Size(max = 50)
@Column(name = "last_name", length = 50)
private String lastName;
@NotEmpty
@Column(unique = true, nullable = false)
private String login;
@NotEmpty
private String password;
@Email
@Size(min=5, max = 100)
@Column(length = 100, unique = true)
private String email;
@Column(nullable = false)
private boolean activated = false;
@Size(min = 2, max = 5)
@Column(name = "lang_key", length = 5)
private String langKey;
@Size(max = 20)
@Column(name = "activation_key", length = 20)
private String activationKey;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getLangKey() {
return langKey;
}
public void setLangKey(String langKey) {
this.langKey = langKey;
}
public String getActivationKey() {
return activationKey;
}
public void setActivationKey(String activationKey) {
this.activationKey = activationKey;
}
@JsonIgnore
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "user_authority",
joinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "authority_name", referencedColumnName = "name")})
// @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<Authority> authorities = new HashSet<Authority>();
public boolean isActivated() {
return activated;
}
public void setActivated(boolean activated) {
this.activated = activated;
}
// public Set<Authority> getAuthority() {
// return authorities;
// }
// public Collection<? extends GrantedAuthority> getAuthorities() {
// return (Collection<? extends GrantedAuthority>) authorities;
// }
public void setAuthorities(Set<Authority> authorities) {
this.authorities = authorities;
}
public Set<Authority> getAuthorities() {
return authorities;
}
// public Set<Role> getRoles() {
// return roles;
//}
//
//public void setRoles(Set<Role> roles) {
// this.roles = roles;
//}
// public User() {
// }
// public User(User user) {
// super();
// this.id = user.getId();
// this.login = user.getLogin();
// this.password = user.getPassword();
// this.email=user.getEmail();
// this.firstName=user.getFirstName();
// this.lastName=user.getLastName();
// this.langKey=user.langKey
// this.authorities = user.getAuthority();
// }
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}