JwtService
@Service public class JwtService
io/agentscope/builder/web/auth/JwtService.java:43–104JWT 服务,承载智能体的部署、调度与服务化运行。位于 io.agentscope.builder.web.auth 包。核心成员包括 generate、parse、extractUserId、extractRoles、JwtService。
HS256 JWT service for the claw web application.
Tokens contain the following claims:
-
sub—userId(stable identity key for HarnessAgent namespace) -
username— display name -
roles— list of role strings
The signing secret is read from builder.jwt.secret (with claw.jwt.secret as a
legacy fallback). Defaults to a development-only placeholder — must be overridden in
production.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public JwtService(String secret) | 初始化 `JwtService` 实例。 Creates a new instance. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public String generate(String userId, String username, List<String> roles) | 执行 `generate` 方法。 Generates a signed JWT for the given user. |
public Claims parse(String token) | 设置解析。 Parses and validates a JWT, returning its claims. |
public String extractUserId(Claims claims) | 设置该参数。 Extracts the `userId` (subject) from a token without full validation (caller must
call `#parse` for secure extraction). |
public List<String> extractRoles(Claims claims) | 设置该参数。 Performs the extract roles operation. |
构造器详情Constructor Detail
JwtService
public JwtService(String secret)
初始化 JwtService 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
secret | String | 密钥(类型 `String`)。The secret. |
io/agentscope/builder/web/auth/JwtService.java:50–62方法详情Method Detail
generate
public String generate(String userId, String username, List<String> roles)
执行 generate 方法。
Generates a signed JWT for the given user.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
userId | String | 用户标识(类型 `String`)。The user id. |
username | String | username(类型 `String`)。The username. |
roles | List<String> | roles(类型 `List`)。The roles. |
Stringio/agentscope/builder/web/auth/JwtService.java:67–77parse
public Claims parse(String token)
设置解析。
Parses and validates a JWT, returning its claims.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
token | String | 令牌(类型 `String`)。The token. |
ClaimsJwtException当if 令牌是无效或已过期时抛出 `JwtException`。if the token is invalid or expired
io/agentscope/builder/web/auth/JwtService.java:84–86extractUserId
public String extractUserId(Claims claims)
设置该参数。
Extracts the userId (subject) from a token without full validation (caller must call #parse for secure extraction).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
claims | Claims | claims(类型 `Claims`)。The claims. |
Stringio/agentscope/builder/web/auth/JwtService.java:92–94extractRoles
public List<String> extractRoles(Claims claims)
设置该参数。
Performs the extract roles operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
claims | Claims | claims(类型 `Claims`)。The claims. |
List<String>io/agentscope/builder/web/auth/JwtService.java:96–103