исправила модель юзера, добавила класс-перечисление ролей юзера
This commit is contained in:
parent
f62b651f74
commit
2173e08c60
@ -18,17 +18,16 @@ public class UserEntity extends BaseEntity {
|
||||
@Column(nullable = false, length = 5)
|
||||
private String password;
|
||||
|
||||
@Column(nullable = false)
|
||||
private boolean isAdmin;
|
||||
private UserRole role;
|
||||
|
||||
public UserEntity() {
|
||||
|
||||
}
|
||||
|
||||
public UserEntity(Integer id, String username, String password, boolean isAdmin) {
|
||||
public UserEntity(Integer id, String username, String password) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.isAdmin = isAdmin;
|
||||
this.role = UserRole.USER;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
@ -47,17 +46,17 @@ public class UserEntity extends BaseEntity {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public boolean getIsAdmin() {
|
||||
return isAdmin;
|
||||
public UserRole getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setIsAdmin(boolean isAdmin) {
|
||||
this.isAdmin = isAdmin;
|
||||
public void setRole(UserRole role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, username, password, isAdmin);
|
||||
return Objects.hash(id, username, password, role);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -69,7 +68,7 @@ public class UserEntity extends BaseEntity {
|
||||
final UserEntity other = (UserEntity) obj;
|
||||
return Objects.equals(other.getId(), id) &&
|
||||
Objects.equals(other.getUsername(), username) &&
|
||||
Objects.equals(other.getIsAdmin(), isAdmin) &&
|
||||
Objects.equals(other.getRole(), role) &&
|
||||
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