Files
IoT-OpenApi/src/main/java/com/iot/gateway/oauth/OpenScopeEnum.java
T
wjhandClaude Sonnet 5 761636c2c5 refactor: 网关消除魔法值,scope/事件/请求头/MCP 协议等改为枚举与常量
- 新增 ScopeMatcher、GatewayAuthorities、JwtClaims、GatewayHeaders、InternalPaths、McpProtocol/McpToolArgs 等常量与枚举
- Webhook 消息体改用 ObjectMapper 构建,修复原先仅转义引号的问题
- 管理接口与 OpenAPI 控制器的默认值、响应字段、演示数据集中到 AdminDefaults / OpenApiFields

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-10 16:27:53 +08:00

57 lines
2.4 KiB
Java

package com.iot.gateway.oauth;
import lombok.Getter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 开放平台接口授权作用域 (OAuth 2.0 Scopes) 枚举
*/
@Getter
public enum OpenScopeEnum {
DEVICE_READ(OpenScopeEnum.CODE_DEVICE_READ, "设备台账读取", "允许拉取租户名下设备台账、在线状态与点位元数据", "设备资产", "LOW"),
TELEMETRY_READ(OpenScopeEnum.CODE_TELEMETRY_READ, "实时遥测召测", "允许实时读取料筒温度、射胶压力、螺杆转速及能耗电流等实时点位", "工况监控", "LOW"),
ALARM_READ(OpenScopeEnum.CODE_ALARM_READ, "故障告警检索", "允许检索产线设备的未确认告警、严重级别及历史故障原因", "异常告警", "LOW"),
DEVICE_CONTROL(OpenScopeEnum.CODE_DEVICE_CONTROL, "设备反向控制", "高危权限!允许向边缘设备下发启停控制与工艺参数反写指令", "反向控制", "HIGH");
/** 编码常量,供 @PreAuthorize 等必须是编译期常量的注解表达式引用 */
public static final String CODE_DEVICE_READ = "device.read";
public static final String CODE_TELEMETRY_READ = "telemetry.read";
public static final String CODE_ALARM_READ = "alarm.read";
public static final String CODE_DEVICE_CONTROL = "device.control";
private final String code;
private final String name;
private final String description;
private final String category;
private final String riskLevel;
OpenScopeEnum(String code, String name, String description, String category, String riskLevel) {
this.code = code;
this.name = name;
this.description = description;
this.category = category;
this.riskLevel = riskLevel;
}
/**
* 获取全部枚举的结构化字典列表(供前端下拉/多选使用)
*/
public static List<Map<String, Object>> toList() {
List<Map<String, Object>> list = new ArrayList<>();
for (OpenScopeEnum item : values()) {
Map<String, Object> map = new HashMap<>();
map.put("code", item.getCode());
map.put("name", item.getName());
map.put("description", item.getDescription());
map.put("category", item.getCategory());
map.put("riskLevel", item.getRiskLevel());
list.add(map);
}
return list;
}
}