Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.is201g4.vitiaapi.model.user;
- import me.is201g4.vitiaapi.util.AuthenticationUtil;
- import org.codehaus.jackson.annotate.JsonIgnore;
- import javax.persistence.*;
- import javax.ws.rs.GET;
- import javax.ws.rs.Path;
- /**
- * @author Finn Bon
- */
- @Entity
- public class User {
- @Column(name = "userID")
- @Id
- @GeneratedValue
- private int id;
- private String username;
- private String email;
- @Enumerated(value = EnumType.STRING)
- @Column(name = "type")
- private Role role;
- private String resetCode;
- private transient byte[] password;
- private transient byte[] salt;
- public User(int id, String username, String email, Role role, byte[] password, byte[] salt) {
- this.id = id;
- this.username = username;
- this.email = email;
- this.role = role;
- this.password = password;
- this.salt = salt;
- }
- public User(int id, String username, String email, Role role) {
- this(id, username, email, role, null, null);
- }
- // ORM wants this
- public User() {
- }
- public boolean match(String password) {
- if (this.password == null)
- throw new UnsupportedOperationException("This user object does not support password matching!");
- return AuthenticationUtil.compare(password.toCharArray(), salt, this.password);
- }
- public boolean isValid() {
- return id != -1;
- }
- public void setRole(Role role) {
- this.role = role;
- }
- public void setPasswordAndSalt(byte[][] passwordAndSalt) {
- this.password = passwordAndSalt[0];
- this.salt = passwordAndSalt[1];
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public void setEmail(String email) {
- this.email = email;
- }
- public void setResetCode(String resetCode) {
- this.resetCode = resetCode;
- }
- public int getId() {
- return id;
- }
- public String getUsername() {
- return username;
- }
- public String getEmail() {
- return email;
- }
- public Role getRole() {
- return role;
- }
- public String getResetCode() {
- return resetCode;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement