исправила модель юзера, добавила класс-перечисление ролей юзера
This commit is contained in:
parent
f62b651f74
commit
2173e08c60
@ -18,17 +18,16 @@ public class UserEntity extends BaseEntity {
|
|||||||
@Column(nullable = false, length = 5)
|
@Column(nullable = false, length = 5)
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@Column(nullable = false)
|
private UserRole role;
|
||||||
private boolean isAdmin;
|
|
||||||
|
|
||||||
public UserEntity() {
|
public UserEntity() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserEntity(Integer id, String username, String password, boolean isAdmin) {
|
public UserEntity(Integer id, String username, String password) {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.isAdmin = isAdmin;
|
this.role = UserRole.USER;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
@ -47,17 +46,17 @@ public class UserEntity extends BaseEntity {
|
|||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getIsAdmin() {
|
public UserRole getRole() {
|
||||||
return isAdmin;
|
return role;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIsAdmin(boolean isAdmin) {
|
public void setRole(UserRole role) {
|
||||||
this.isAdmin = isAdmin;
|
this.role = role;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(id, username, password, isAdmin);
|
return Objects.hash(id, username, password, role);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -69,7 +68,7 @@ public class UserEntity extends BaseEntity {
|
|||||||
final UserEntity other = (UserEntity) obj;
|
final UserEntity other = (UserEntity) obj;
|
||||||
return Objects.equals(other.getId(), id) &&
|
return Objects.equals(other.getId(), id) &&
|
||||||
Objects.equals(other.getUsername(), username) &&
|
Objects.equals(other.getUsername(), username) &&
|
||||||
Objects.equals(other.getIsAdmin(), isAdmin) &&
|
Objects.equals(other.getRole(), role) &&
|
||||||
Objects.equals(other.getPassword(), password);
|
Objects.equals(other.getPassword(), password);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.example.backend.users.model;
|
||||||
|
|
||||||
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
|
|
||||||
|
public enum UserRole implements GrantedAuthority {
|
||||||
|
ADMIN,
|
||||||
|
USER;
|
||||||
|
|
||||||
|
private static final String PREFIX = "ROLE_";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAuthority() {
|
||||||
|
return PREFIX + this.name();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user