Authorization
基于 Spring Security 标准方法安全的薄封装。引入后启用 @PreAuthorize 和 @Secured;UserContext 从
SecurityContextHolder 读取当前用户。
<dependency>
<groupId>io.github.loadup-cloud</groupId>
<artifactId>loadup-components-authorization</artifactId>
</dependency>loadup:
security:
method-security:
enabled: true@PreAuthorize("hasAuthority('order:create')")
public void createOrder(OrderCreateCommand command) {
// ...
}此组件不创建 HTTP SecurityFilterChain,也不验签。需要 JWT 认证时引入 loadup-components-oauth-server-core;自定义认证场景可由应用自行提供
SecurityFilterChain。
LoadUpUser 实现 JDK Principal,getName() 返回稳定的 userId。因此 Authentication.getName() 与审计记录中的
actorId 使用用户 ID,而不是用户名或用户对象的字符串表示;使用自定义认证时应设置 userId。
| 能力 | 说明 |
|---|---|
| 方法级授权 | Spring Security 注解与 SpEL |
| 当前用户上下文 | UserContext 适配 SecurityContextHolder |
| 请求认证 | 由 Resource Server 或应用安全链提供 |
设计与实现
职责与边界
提供Spring Security 方法级授权能力的独立模块。
Maven 依赖边界
直接依赖的外部坐标(不含测试与 provided scope):
org.springframework.boot:spring-boot-starter-securityorg.springframework:spring-contextorg.springframework.boot:spring-boot-autoconfigureorg.slf4j:slf4j-apicom.github.spotbugs:spotbugs-annotations
实现入口
主要入口文件:
分层与调用路径
SecurityContext → Spring 方法安全拦截器 → @PreAuthorize / @Secured → 业务方法装配规则
-
AuthorizationAutoConfiguration是自动配置入口。@ConditionalOnProperty( prefix = "loadup.security.method-security", name = "enabled", havingValue = "true", matchIfMissing = true)
配置归属
AuthorizationProperties绑定loadup.security.method-security。
集成方式与配置示例见 README.md。