-
Notifications
You must be signed in to change notification settings - Fork 525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(server): clear context after req done #2470
Changes from 1 commit
ae90955
bb67693
13f916f
30f1821
2519b39
c787baf
7d75e0d
552dcb8
ba74aaa
4f7fc0f
43288d9
6104ed6
906c0de
177e513
165b5c8
7eeda25
5aa1a40
6030882
41459f5
1435e44
3643116
7484ab3
6a50b99
ed2b24a
80c1634
ed250f2
2e3325c
5817ccd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,7 +76,7 @@ | |
"versions", | ||
"openapi.json" | ||
); | ||
// Remove auth/login API from white list | ||
/** Remove auth/login API from whitelist */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one * is ok |
||
private static final Set<String> FLEXIBLE_WHITE_API_SET = ImmutableSet.of(); | ||
|
||
private static Boolean enabledWhiteIpCheck; | ||
|
@@ -107,7 +107,7 @@ | |
E.checkState(manager != null, "Context GraphManager is absent"); | ||
|
||
if (!manager.requireAuthentication()) { | ||
// Return anonymous user with admin role if disable authentication | ||
// Return anonymous user with an admin role if disable authentication | ||
return User.ANONYMOUS; | ||
} | ||
|
||
|
@@ -135,38 +135,32 @@ | |
boolean whiteIpEnabled = manager.authManager().getWhiteIpStatus(); | ||
if (!path.contains(STRING_WHITE_IP_LIST) && whiteIpEnabled && | ||
!whiteIpList.contains(remoteIp)) { | ||
throw new ForbiddenException( | ||
String.format("Remote ip '%s' is not permitted", | ||
remoteIp)); | ||
throw new ForbiddenException(String.format("Remote ip '%s' is not permitted", | ||
Check warning on line 138 in hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java Codecov / codecov/patchhugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java#L138
|
||
remoteIp)); | ||
} | ||
} | ||
|
||
Map<String, String> credentials = new HashMap<>(); | ||
// Extract authentication credentials | ||
String auth = context.getHeaderString(HttpHeaders.AUTHORIZATION); | ||
if (auth == null) { | ||
throw new NotAuthorizedException( | ||
"Authentication credentials are required", | ||
"Missing authentication credentials"); | ||
throw new NotAuthorizedException("Authentication credentials are required", | ||
"Missing authentication credentials"); | ||
} | ||
|
||
if (auth.startsWith(BASIC_AUTH_PREFIX)) { | ||
auth = auth.substring(BASIC_AUTH_PREFIX.length()); | ||
auth = new String(DatatypeConverter.parseBase64Binary(auth), | ||
Charsets.ASCII_CHARSET); | ||
auth = new String(DatatypeConverter.parseBase64Binary(auth), Charsets.ASCII_CHARSET); | ||
String[] values = auth.split(":"); | ||
if (values.length != 2) { | ||
throw new BadRequestException( | ||
"Invalid syntax for username and password"); | ||
throw new BadRequestException("Invalid syntax for username and password"); | ||
Check warning on line 156 in hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java Codecov / codecov/patchhugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java#L156
|
||
} | ||
|
||
final String username = values[0]; | ||
final String password = values[1]; | ||
|
||
if (StringUtils.isEmpty(username) || | ||
StringUtils.isEmpty(password)) { | ||
throw new BadRequestException( | ||
"Invalid syntax for username and password"); | ||
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) { | ||
throw new BadRequestException("Invalid syntax for username and password"); | ||
Check warning on line 163 in hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java Codecov / codecov/patchhugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java#L163
|
||
} | ||
|
||
credentials.put(HugeAuthenticator.KEY_USERNAME, username); | ||
|
@@ -175,8 +169,7 @@ | |
String token = auth.substring(BEARER_TOKEN_PREFIX.length()); | ||
credentials.put(HugeAuthenticator.KEY_TOKEN, token); | ||
} else { | ||
throw new BadRequestException( | ||
"Only HTTP Basic or Bearer authentication is supported"); | ||
throw new BadRequestException("Only HTTP Basic or Bearer authentication is supported"); | ||
Check warning on line 172 in hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java Codecov / codecov/patchhugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java#L172
|
||
} | ||
|
||
credentials.put(HugeAuthenticator.KEY_ADDRESS, peer); | ||
|
@@ -186,8 +179,7 @@ | |
try { | ||
return manager.authenticate(credentials); | ||
} catch (AuthenticationException e) { | ||
throw new NotAuthorizedException("Authentication failed", | ||
e.getMessage()); | ||
throw new NotAuthorizedException("Authentication failed", e.getMessage()); | ||
} | ||
} | ||
|
||
|
@@ -251,7 +243,7 @@ | |
requiredPerm = RequiredPerm.fromPermission(required); | ||
|
||
/* | ||
* Replace owner value(it may be a variable) if the permission | ||
* Replace owner value (it may be a variable) if the permission | ||
* format like: "$owner=$graph $action=vertex_write" | ||
*/ | ||
String owner = requiredPerm.owner(); | ||
|
@@ -318,7 +310,7 @@ | |
public static boolean isWhiteAPI(ContainerRequestContext context) { | ||
String path = context.getUriInfo().getPath(); | ||
if (FIXED_WHITE_API_SET.contains(path)) { | ||
return true; | ||
Check warning on line 313 in hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java Codecov / codecov/patchhugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AuthenticationFilter.java#L313
|
||
} | ||
|
||
for (String whiteApi : FLEXIBLE_WHITE_API_SET) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,7 +107,7 @@ default User authenticate(final Map<String, String> credentials) | |
} | ||
|
||
HugeGraphAuthProxy.logUser(user, credentials.get(KEY_PATH)); | ||
// Set authentication context & unset in AccessLogFilter | ||
// TODO: Ensure context lifecycle in GraphServer & AuthServer(#AccessLogFilter) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't need TODO mark anymore since it's done |
||
HugeGraphAuthProxy.setContext(new Context(user)); | ||
|
||
return user; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't need TODO mark anymore since it's done