[ce6ad22] | 1 | package parkup.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;
|
---|
[9dd526f] | 6 | import parkup.data.enumarations.UserRole;
|
---|
[ce6ad22] | 7 |
|
---|
| 8 | import javax.persistence.*;
|
---|
| 9 | import java.util.Collection;
|
---|
| 10 | import java.util.Collections;
|
---|
| 11 |
|
---|
| 12 | @Entity
|
---|
| 13 | @Table(name = "administrator")
|
---|
| 14 | public class Administrator implements UserDetails {
|
---|
| 15 | @Id
|
---|
| 16 | @SequenceGenerator(
|
---|
| 17 | name="administrator_sequence_generator",
|
---|
| 18 | sequenceName = "administrator_sequence",
|
---|
| 19 | allocationSize = 1,
|
---|
| 20 | initialValue = 100
|
---|
| 21 | )
|
---|
| 22 | @GeneratedValue( //za postgres treba sequence da se namesti i ime na generator mi ga davamo kako od gore sto e
|
---|
| 23 | strategy = GenerationType.SEQUENCE,
|
---|
| 24 | generator = "administrator_sequence_generator"
|
---|
| 25 | )
|
---|
| 26 | @Column(name = "administratorId")
|
---|
| 27 | private int administratorId;
|
---|
| 28 |
|
---|
| 29 | @Column(name = "firstName")
|
---|
| 30 | private String firstName;
|
---|
| 31 |
|
---|
| 32 | @Column(name = "lastName")
|
---|
| 33 | private String lastName;
|
---|
| 34 |
|
---|
| 35 | @Column(name = "email")
|
---|
| 36 | private String email;
|
---|
| 37 |
|
---|
| 38 | @Column(name = "password")
|
---|
| 39 | private String password;
|
---|
| 40 |
|
---|
| 41 | @Column(name = "mobile")
|
---|
| 42 | private String mobile;
|
---|
| 43 |
|
---|
[9dd526f] | 44 | @Enumerated
|
---|
[ce6ad22] | 45 | @Column(name = "role")
|
---|
[9dd526f] | 46 | private UserRole role;
|
---|
[ce6ad22] | 47 |
|
---|
| 48 | private boolean locked;
|
---|
| 49 |
|
---|
| 50 | private boolean enabled;
|
---|
| 51 |
|
---|
| 52 | public Administrator(){
|
---|
[98f448a] | 53 | this.role = UserRole.ROLE_ADMIN;
|
---|
[9dd526f] | 54 | this.enabled=true;
|
---|
[ce6ad22] | 55 | }
|
---|
| 56 |
|
---|
| 57 | public Administrator(int administratorId, String firstName, String lastName, String email, String password, String mobile) {
|
---|
| 58 | this.administratorId = administratorId;
|
---|
| 59 | this.firstName = firstName;
|
---|
| 60 | this.lastName = lastName;
|
---|
| 61 | this.email = email;
|
---|
| 62 | this.password = password;
|
---|
| 63 | this.mobile = mobile;
|
---|
[9dd526f] | 64 | this.enabled=true;
|
---|
[98f448a] | 65 | this.role = UserRole.ROLE_ADMIN;
|
---|
[ce6ad22] | 66 | }
|
---|
| 67 |
|
---|
| 68 | public Administrator(String firstName, String lastName, String email, String password, String mobile) {
|
---|
| 69 | this.firstName = firstName;
|
---|
| 70 | this.lastName = lastName;
|
---|
| 71 | this.email = email;
|
---|
| 72 | this.password = password;
|
---|
| 73 | this.mobile = mobile;
|
---|
[98f448a] | 74 | this.role = UserRole.ROLE_ADMIN;
|
---|
[9dd526f] | 75 | this.enabled=true;
|
---|
[ce6ad22] | 76 | }
|
---|
| 77 |
|
---|
| 78 | public Administrator(String firstName, String lastName, String email, String password) {
|
---|
| 79 | this.firstName = firstName;
|
---|
| 80 | this.lastName = lastName;
|
---|
| 81 | this.email = email;
|
---|
| 82 | this.password = password;
|
---|
| 83 | this.mobile = mobile;
|
---|
[98f448a] | 84 | this.role = UserRole.ROLE_ADMIN;
|
---|
[9dd526f] | 85 | this.enabled=true;
|
---|
[ce6ad22] | 86 | }
|
---|
| 87 |
|
---|
| 88 | public int getAdministratorId() {
|
---|
| 89 | return administratorId;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | public void setAdministratorId(int administratorId) {
|
---|
| 93 | this.administratorId = administratorId;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | public String getFirstName() {
|
---|
| 97 | return firstName;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | public void setFirstName(String firstName) {
|
---|
| 101 | this.firstName = firstName;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | public String getLastName() {
|
---|
| 105 | return lastName;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | public void setLastName(String lastName) {
|
---|
| 109 | this.lastName = lastName;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | public String getEmail() {
|
---|
| 113 | return email;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | public void setEmail(String email) {
|
---|
| 117 | this.email = email;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | public void setPassword(String password) {
|
---|
| 121 | this.password = password;
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | public String getMobile() {
|
---|
| 125 | return mobile;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | public void setMobile(String mobile) {
|
---|
| 129 | this.mobile = mobile;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
[9dd526f] | 132 | public UserRole getRole() {return role;}
|
---|
[ce6ad22] | 133 |
|
---|
[9dd526f] | 134 | public void setRole(UserRole role) {this.role = role;}
|
---|
[ce6ad22] | 135 |
|
---|
| 136 | @Override
|
---|
| 137 | public Collection<? extends GrantedAuthority> getAuthorities() {
|
---|
[9dd526f] | 138 | SimpleGrantedAuthority authority = new SimpleGrantedAuthority(role.getAuthority());
|
---|
[ce6ad22] | 139 | return Collections.singleton(authority);
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | @Override
|
---|
| 143 | public String getPassword() {
|
---|
| 144 | return password;
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | @Override
|
---|
| 148 | public String getUsername() {
|
---|
| 149 | return email;
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | @Override
|
---|
| 153 | public boolean isAccountNonExpired() {
|
---|
| 154 | return true;
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | @Override
|
---|
| 158 | public boolean isAccountNonLocked() {
|
---|
| 159 | return !locked;
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | @Override
|
---|
| 163 | public boolean isCredentialsNonExpired() {
|
---|
| 164 | return true;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | @Override
|
---|
| 168 | public boolean isEnabled() {
|
---|
| 169 | return enabled;
|
---|
| 170 | }
|
---|
| 171 | } |
---|