Advertisement
Guest User

Untitled

a guest
Jan 11th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. @EqualsAndHashCode(includes='username')
  2. @ToString(includes='username', includeNames=true, includePackage=false)
  3. class User implements Serializable {
  4.  
  5. private static final long serialVersionUID = 1
  6.  
  7. transient springSecurityService
  8.  
  9. String username
  10. String password
  11. boolean enabled = true
  12. boolean accountExpired
  13. boolean accountLocked
  14. boolean passwordExpired
  15.  
  16. User(String username, String password) {
  17. this()
  18. this.username = username
  19. this.password = password
  20. }
  21.  
  22. Set<Role> getAuthorities() {
  23. UserRole.findAllByUser(this)*.role
  24. }
  25.  
  26. def beforeInsert() {
  27. encodePassword()
  28. }
  29.  
  30. def beforeUpdate() {
  31. if (isDirty('password')) {
  32. encodePassword()
  33. }
  34. }
  35.  
  36. protected void encodePassword() {
  37. password = springSecurityService?.passwordEncoder ?
  38. springSecurityService.encodePassword(password) :
  39. password
  40. }
  41.  
  42. static transients = ['springSecurityService']
  43.  
  44. static constraints = {
  45. username blank: false, unique: true
  46. password blank: false
  47. }
  48.  
  49. static mapping = {
  50. password column: '`password`'
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement