Advertisement
Guest User

Untitled

a guest
Nov 10th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.24 KB | None | 0 0
  1. package me.is201g4.vitiaapi.model.user;
  2.  
  3. import me.is201g4.vitiaapi.util.AuthenticationUtil;
  4. import org.codehaus.jackson.annotate.JsonIgnore;
  5.  
  6. import javax.persistence.*;
  7. import javax.ws.rs.GET;
  8. import javax.ws.rs.Path;
  9.  
  10. /**
  11.  * @author Finn Bon
  12.  */
  13. @Entity
  14. public class User {
  15.  
  16.     @Column(name = "userID")
  17.     @Id
  18.     @GeneratedValue
  19.     private int id;
  20.  
  21.     private String username;
  22.  
  23.     private String email;
  24.  
  25.     @Enumerated(value = EnumType.STRING)
  26.     @Column(name = "type")
  27.     private Role role;
  28.  
  29.     private String resetCode;
  30.  
  31.     private transient byte[] password;
  32.  
  33.     private transient byte[] salt;
  34.  
  35.     public User(int id, String username, String email, Role role, byte[] password, byte[] salt) {
  36.         this.id = id;
  37.         this.username = username;
  38.         this.email = email;
  39.         this.role = role;
  40.         this.password = password;
  41.         this.salt = salt;
  42.     }
  43.  
  44.     public User(int id, String username, String email, Role role) {
  45.         this(id, username, email, role, null, null);
  46.     }
  47.  
  48.     // ORM wants this
  49.     public User() {
  50.     }
  51.  
  52.     public boolean match(String password) {
  53.         if (this.password == null)
  54.             throw new UnsupportedOperationException("This user object does not support password matching!");
  55.         return AuthenticationUtil.compare(password.toCharArray(), salt, this.password);
  56.     }
  57.  
  58.     public boolean isValid() {
  59.         return id != -1;
  60.     }
  61.  
  62.     public void setRole(Role role) {
  63.         this.role = role;
  64.     }
  65.  
  66.     public void setPasswordAndSalt(byte[][] passwordAndSalt) {
  67.         this.password = passwordAndSalt[0];
  68.         this.salt = passwordAndSalt[1];
  69.     }
  70.  
  71.     public void setUsername(String username) {
  72.         this.username = username;
  73.     }
  74.  
  75.     public void setEmail(String email) {
  76.         this.email = email;
  77.     }
  78.  
  79.     public void setResetCode(String resetCode) {
  80.         this.resetCode = resetCode;
  81.     }
  82.  
  83.     public int getId() {
  84.         return id;
  85.     }
  86.  
  87.     public String getUsername() {
  88.         return username;
  89.     }
  90.  
  91.     public String getEmail() {
  92.         return email;
  93.     }
  94.  
  95.     public Role getRole() {
  96.         return role;
  97.     }
  98.  
  99.     public String getResetCode() {
  100.         return resetCode;
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement