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