From 2173e08c60c2c529173694d8f15024d6290d5afa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=91=D0=B0=D0=BA=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D1=81=D0=BA=D0=B0=D1=8F?= Date: Sat, 11 May 2024 18:43:10 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B0=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D1=8C=20=D1=8E?= =?UTF-8?q?=D0=B7=D0=B5=D1=80=D0=B0,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=D0=B0=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81-=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D1=87=D0=B8=D1=81=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=80=D0=BE=D0=BB=D0=B5=D0=B9=20=D1=8E=D0=B7=D0=B5?= =?UTF-8?q?=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/users/model/UserEntity.java | 19 +++++++++---------- .../example/backend/users/model/UserRole.java | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 backend/src/main/java/com/example/backend/users/model/UserRole.java diff --git a/backend/src/main/java/com/example/backend/users/model/UserEntity.java b/backend/src/main/java/com/example/backend/users/model/UserEntity.java index f36562b..54c7a0e 100644 --- a/backend/src/main/java/com/example/backend/users/model/UserEntity.java +++ b/backend/src/main/java/com/example/backend/users/model/UserEntity.java @@ -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); } } diff --git a/backend/src/main/java/com/example/backend/users/model/UserRole.java b/backend/src/main/java/com/example/backend/users/model/UserRole.java new file mode 100644 index 0000000..c6bffe5 --- /dev/null +++ b/backend/src/main/java/com/example/backend/users/model/UserRole.java @@ -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(); + } + +}