Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pl.com.sokaris.bok.domain.model.user;
- import static javax.persistence.GenerationType.IDENTITY;
- import java.io.Serializable;
- import java.util.Collection;
- import java.util.HashSet;
- import javax.persistence.CascadeType;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.FetchType;
- import javax.persistence.GeneratedValue;
- import javax.persistence.Id;
- import javax.persistence.OneToMany;
- import javax.persistence.Table;
- import org.springframework.security.core.GrantedAuthority;
- import org.springframework.security.core.userdetails.UserDetails;
- import pl.com.sokaris.bok.domain.DomainEntity;
- @Entity
- @Table(name = "user")
- public class User implements DomainEntity<User>, UserDetails, Serializable {
- private static final long serialVersionUID = 8489541351526006318L;
- @Id
- @GeneratedValue(strategy = IDENTITY)
- @Column(name = "user_id", unique = true, nullable = false)
- private Long id;
- @Column(name = "username", length = 30)
- private String username;
- @Column(name = "password", length = 30)
- private String password;
- @Column(name = "account_not_expired", nullable = false)
- private boolean accountNotExpired;
- @Column(name = "account_not_locked", nullable = false)
- private boolean accountNotLocked;
- @Column(name = "credentials_not_expiered", nullable = false)
- private boolean credentialsNotExpiered;
- @Column(name = "account_is_enabled", nullable = false)
- private boolean accountIsEnabled;
- @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "user_role")
- private Collection<GrantedAuthority> userRoles;
- public User(Long id, String username, String password, boolean accountNotExpired, boolean accountNotLocked, boolean credentialsNotExpiered,
- boolean accountIsEnabled, Collection<UserRole> userRoles) {
- super();
- this.id = id;
- this.username = username;
- this.password = password;
- this.accountNotExpired = accountNotExpired;
- this.accountNotLocked = accountNotLocked;
- this.credentialsNotExpiered = credentialsNotExpiered;
- this.accountIsEnabled = accountIsEnabled;
- this.userRoles = new HashSet<GrantedAuthority>();
- for (UserRole userRole : userRoles) {
- this.userRoles.add(userRole);
- }
- }
- public Long getId() {
- return id;
- }
- public void setId(Long id) {
- this.id = id;
- }
- @Override
- public Collection<GrantedAuthority> getAuthorities() {
- return userRoles;
- }
- @Override
- public String getPassword() {
- return password;
- }
- @Override
- public String getUsername() {
- return username;
- }
- @Override
- public boolean isAccountNonExpired() {
- return accountNotExpired;
- }
- @Override
- public boolean isAccountNonLocked() {
- return accountNotLocked;
- }
- @Override
- public boolean isCredentialsNonExpired() {
- return credentialsNotExpiered;
- }
- @Override
- public boolean isEnabled() {
- return accountIsEnabled;
- }
- @Override
- public boolean sameAs(User otherEntity) {
- return (otherEntity.getUsername().compareTo(getUsername()) == 0) ? true : false;
- }
- @Override
- public boolean equals(Object obj) {
- if (obj == null || !(obj instanceof User)) {
- return false;
- }
- return ((User) obj).getUsername().equals(this.getUsername());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement