Skip to content

Commit c06dd68

Browse files
authored
Merge pull request #67 from yunionio/auth-context
feat(keystone): add auth context of token credential
2 parents 4018bd4 + fbb448f commit c06dd68

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.yunionyun.mcp</groupId>
66
<artifactId>mcclient</artifactId>
7-
<version>3.2.19</version>
7+
<version>3.2.20</version>
88
<packaging>jar</packaging>
99

1010
<name>${project.groupId}:${project.artifactId}</name>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.yunionyun.mcp.mcclient.keystone;
2+
3+
import com.alibaba.fastjson.JSONObject;
4+
5+
public class AuthContext {
6+
private String source;
7+
private String ip;
8+
9+
public AuthContext(String source, String ip) {
10+
this.source = source;
11+
this.ip = ip;
12+
}
13+
14+
public AuthContext(JSONObject context) {
15+
this(context.getString("source"), context.getString("ip"));
16+
}
17+
18+
public String getSource() {
19+
return source;
20+
}
21+
22+
public String getIp() {
23+
return ip;
24+
}
25+
}

src/main/java/com/yunionyun/mcp/mcclient/keystone/TokenCredential.java

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class TokenCredential {
1919
private Role[] roles;
2020
private Service[] services;
2121
private Date expires;
22+
private AuthContext context;
2223

2324
public TokenCredential(String token) {
2425
this.token = token;
@@ -52,6 +53,8 @@ public void parseJSON(JSONObject result) {
5253
this.services[i] = new Service();
5354
this.services[i].parseJSON(serviceJSON.getJSONObject(i));
5455
}
56+
JSONObject context = token.getJSONObject("context");
57+
this.context = new AuthContext(context);
5558
}
5659

5760
public String getToken() {
@@ -90,6 +93,10 @@ public String getProjectName() {
9093
return this.project.getName();
9194
}
9295

96+
public AuthContext getContext() {
97+
return context;
98+
}
99+
93100
public boolean isValid() {
94101
Date now = new Date();
95102
return this.expires.after(now);

0 commit comments

Comments
 (0)