Developer 역할 Spring 골격 smoke #4
1 changed files with 37 additions and 0 deletions
37
src/main/java/com/example/demo/service/DeveloperService.java
Normal file
37
src/main/java/com/example/demo/service/DeveloperService.java
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.example.demo.service;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class DeveloperService {
|
||||||
|
|
||||||
|
private final Map<String, String> roleMatrix = new HashMap<>();
|
||||||
|
|
||||||
|
public DeveloperService() {
|
||||||
|
roleMatrix.put("developer", "read-write");
|
||||||
|
roleMatrix.put("viewer", "read-only");
|
||||||
|
roleMatrix.put("admin", "full-access");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRolePermission(String role) {
|
||||||
|
return roleMatrix.getOrDefault(role.toLowerCase(), "no-access");
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getAllRoles() {
|
||||||
|
return List.copyOf(roleMatrix.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPermission(String role, String requiredPermission) {
|
||||||
|
String permission = getRolePermission(role);
|
||||||
|
if ("full-access".equals(permission)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ("read-write".equals(permission)) {
|
||||||
|
return !"delete".equals(requiredPermission);
|
||||||
|
}
|
||||||
|
return "read".equals(requiredPermission);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue