[5577566] | 1 | package it.finki.charitable.entities;
|
---|
| 2 |
|
---|
| 3 | import org.springframework.security.core.GrantedAuthority;
|
---|
| 4 | import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
---|
| 5 | import org.springframework.security.core.userdetails.UserDetails;
|
---|
| 6 |
|
---|
| 7 | import javax.persistence.*;
|
---|
| 8 | import java.util.ArrayList;
|
---|
| 9 | import java.util.Collection;
|
---|
| 10 | import java.util.Collections;
|
---|
| 11 | import java.util.List;
|
---|
| 12 |
|
---|
| 13 | @Entity
|
---|
| 14 | @Table(name = "app_user")
|
---|
| 15 | public class AppUser implements UserDetails {
|
---|
| 16 |
|
---|
| 17 | @SequenceGenerator(
|
---|
| 18 | name = "user_sequence",
|
---|
| 19 | sequenceName = "user_sequence",
|
---|
| 20 | allocationSize = 1
|
---|
| 21 | )
|
---|
| 22 | @GeneratedValue(
|
---|
| 23 | strategy = GenerationType.SEQUENCE,
|
---|
| 24 | generator = "user_sequence"
|
---|
| 25 | )
|
---|
| 26 | @Id
|
---|
| 27 | @Column(
|
---|
| 28 | name = "id",
|
---|
| 29 | nullable = false,
|
---|
| 30 | updatable = false
|
---|
| 31 | )
|
---|
| 32 | private Long id;
|
---|
| 33 |
|
---|
| 34 | private String firstName;
|
---|
| 35 | private String lastName;
|
---|
| 36 | private String email;
|
---|
| 37 | private String password;
|
---|
| 38 | @Enumerated(EnumType.STRING)
|
---|
| 39 | private UserRole userRole;
|
---|
| 40 | private Boolean enabled;
|
---|
| 41 |
|
---|
| 42 | public AppUser() {
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | public Long getId() {
|
---|
| 46 | return id;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | public void setId(Long id) {
|
---|
| 50 | this.id = id;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | public String getFirstName() {
|
---|
| 54 | return firstName;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | public void setFirstName(String firstName) {
|
---|
| 58 | this.firstName = firstName;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | public String getLastName() {
|
---|
| 62 | return lastName;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | public void setLastName(String lastName) {
|
---|
| 66 | this.lastName = lastName;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | public String getEmail() {
|
---|
| 70 | return email;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | public void setEmail(String email) {
|
---|
| 74 | this.email = email;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | public void setPassword(String password) {
|
---|
| 78 | this.password = password;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | public UserRole getUserRole() {
|
---|
| 82 | return userRole;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | public void setUserRole(UserRole userRole) {
|
---|
| 86 | this.userRole = userRole;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | public Boolean getEnabled() {
|
---|
| 90 | return enabled;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | public void setEnabled(Boolean enabled) {
|
---|
| 94 | this.enabled = enabled;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | @Override
|
---|
| 98 | public Collection<? extends GrantedAuthority> getAuthorities() {
|
---|
| 99 | SimpleGrantedAuthority authority = new SimpleGrantedAuthority(userRole.name());
|
---|
| 100 | return Collections.singletonList(authority);
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | @Override
|
---|
| 104 | public String getPassword() {
|
---|
| 105 | return password;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | @Override
|
---|
| 109 | public String getUsername() {
|
---|
| 110 | return email;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | @Override
|
---|
| 114 | public boolean isAccountNonExpired() {
|
---|
| 115 | return true;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | @Override
|
---|
| 119 | public boolean isAccountNonLocked() {
|
---|
| 120 | return true;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | @Override
|
---|
| 124 | public boolean isCredentialsNonExpired() {
|
---|
| 125 | return true;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | @Override
|
---|
| 129 | public boolean isEnabled() {
|
---|
| 130 | return enabled;
|
---|
| 131 | }
|
---|
| 132 | }
|
---|