Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c968059

Browse files
committedFeb 4, 2024·
changed plugin
1 parent c547f37 commit c968059

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed
 

‎frontend/server/src/main/java/org/pytorch/serve/http/TokenAuthorizationHandler.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ private void checkTokenAuthorization(FullHttpRequest req, String type) throws Mo
9292
"checkTokenAuthorization",
9393
io.netty.handler.codec.http.FullHttpRequest.class,
9494
String.class);
95-
boolean result = (boolean) (method.invoke(tokenObject, req, type));
96-
95+
// boolean result = (boolean) (method.invoke(tokenObject, req, type));
96+
String result = (String) (method.invoke(tokenObject, req, type));
97+
System.out.println("TEST-----: " + result);
9798
// System.out.println("TEST -----" + type + "-----");
9899
// String tokenBearer = req.headers().get("Authorization");
99100
// if (tokenBearer == null) {
@@ -106,10 +107,10 @@ private void checkTokenAuthorization(FullHttpRequest req, String type) throws Mo
106107
// String token = arrOfStr[1];
107108
// System.out.println("TEST -----" + token + "-----");
108109

109-
if (!result) {
110-
throw new InvalidKeyException(
111-
"Token Authentication failed. Token either incorrect, expired, or not provided correctly");
112-
}
110+
// if (!result) {
111+
// throw new InvalidKeyException(
112+
// "Token Authentication failed. Token either incorrect, expired, or not provided correctly");
113+
// }
113114
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
114115
e.printStackTrace();
115116
throw new InvalidKeyException(

‎plugins/endpoints/src/main/java/org/pytorch/serve/plugins/endpoint/Token.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public boolean setFilePermissions() {
152152
}
153153

154154
// checks the token provided in the http with the saved keys depening on parameters
155-
public boolean checkTokenAuthorization(FullHttpRequest req, String type) {
155+
public String checkTokenAuthorization(FullHttpRequest req, String type) {
156156
String key;
157157
Instant expiration;
158158
switch (type) {
@@ -171,22 +171,22 @@ public boolean checkTokenAuthorization(FullHttpRequest req, String type) {
171171

172172
String tokenBearer = req.headers().get("Authorization");
173173
if (tokenBearer == null) {
174-
return false;
174+
return "false"; // false;
175175
}
176176
String[] arrOfStr = tokenBearer.split(" ", 2);
177177
if (arrOfStr.length == 1) {
178-
return false;
178+
return "false"; // false;
179179
}
180180
String token = arrOfStr[1];
181181

182182
if (token.equals(key)) {
183183
if (expiration != null && isTokenExpired(expiration)) {
184-
return false;
184+
return token + "-" + key; // false;
185185
}
186186
} else {
187-
return false;
187+
return token + "-" + key; // false;
188188
}
189-
return true;
189+
return token + "-" + key; // true;
190190
}
191191

192192
public boolean isTokenExpired(Instant expirationTime) {

0 commit comments

Comments
 (0)
Please sign in to comment.