From be4d2414a88c8806074a77899852214d712bcc3f Mon Sep 17 00:00:00 2001 From: forge-bot Date: Tue, 14 Jul 2026 10:32:03 +0000 Subject: [PATCH] =?UTF-8?q?Reviewer=20=EC=97=AD=ED=95=A0=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=EB=B3=B4=EA=B3=A0=EC=84=9C=20smoke=20(runtime-role?= =?UTF-8?q?-matrix-live-20260714101723-v7-reviewer-001)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../klaroworks/runtime/role/RoleContext.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/main/java/com/klaroworks/runtime/role/RoleContext.java diff --git a/src/main/java/com/klaroworks/runtime/role/RoleContext.java b/src/main/java/com/klaroworks/runtime/role/RoleContext.java new file mode 100644 index 0000000..a831717 --- /dev/null +++ b/src/main/java/com/klaroworks/runtime/role/RoleContext.java @@ -0,0 +1,80 @@ +package com.klaroworks.runtime.role; + +import java.util.Map; +import java.util.HashMap; +import java.util.Collections; + +/** + * Role context interface for role-based access control. + * Used by RoleMatrixRuntimeTest for context management testing. + */ +public interface RoleContext { + + /** + * Get the current user ID. + * @return user identifier + */ + String getUserId(); + + /** + * Get the current role. + * @return role name + */ + String getRole(); + + /** + * Get permissions associated with this context. + * @return immutable map of permissions + */ + Map getPermissions(); + + /** + * Check if a specific permission is granted. + * @param permission permission key + * @return true if granted + */ + boolean hasPermission(String permission); + + /** + * Simple implementation of RoleContext. + */ + class SimpleRoleContext implements RoleContext { + private final String userId; + private final String role; + private final Map permissions; + + public SimpleRoleContext(String userId, String role, Map permissions) { + this.userId = userId; + this.role = role; + this.permissions = permissions != null ? Collections.unmodifiableMap(new HashMap<>(permissions)) : Collections.emptyMap(); + } + + @Override + public String getUserId() { + return userId; + } + + @Override + public String getRole() { + return role; + } + + @Override + public Map getPermissions() { + return permissions; + } + + @Override + public boolean hasPermission(String permission) { + return permissions.getOrDefault(permission, false); + } + + public static SimpleRoleContext of(String userId, String role) { + return new SimpleRoleContext(userId, role, Map.of( + "read", true, + "write", role.equals("ADMIN") || role.equals("MANAGER"), + "delete", role.equals("ADMIN") + )); + } + } +}