Skip to content

Commit

Permalink
Merge branch 'flush-user-cache' of https://github.com/dlin2028/security
Browse files Browse the repository at this point in the history
… into flush-user-cache

Signed-off-by: David Lin <[email protected]>
  • Loading branch information
dlin2028 committed May 5, 2024
2 parents cc6c4ac + e1a5b3f commit 2c8e63a
Showing 1 changed file with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ public List<Route> routes() {
}

private void flushCacheApiRequestHandlers(RequestHandler.RequestHandlersBuilder requestHandlersBuilder) {
requestHandlersBuilder.allMethodsNotImplemented().override(Method.DELETE, (channel, request, client) -> {
final ConfigUpdateRequest configUpdateRequest;
if (request.path().contains("/user/")) {
// Extract the username from the request
final String username = request.param("username");
if (username == null || username.isEmpty()) {
internalSeverError(channel, "No username provided for cache invalidation.");
return;
}
// Validate and handle user-specific cache invalidation
configUpdateRequest = new ConfigUpdateRequest(CType.INTERNALUSERS.toLCString(), new String[] { username });
} else {
configUpdateRequest = new ConfigUpdateRequest(CType.lcStringValues().toArray(new String[0]));
}
client.execute(ConfigUpdateAction.INSTANCE, configUpdateRequest, new ActionListener<>() {
requestHandlersBuilder.allMethodsNotImplemented().override(Method.DELETE, (channel, request, client) -> {
final ConfigUpdateRequest configUpdateRequest;
if (request.path().contains("/user/")) {
Expand Down Expand Up @@ -105,16 +120,11 @@ public void onResponse(ConfigUpdateResponse configUpdateResponse) {
ok(channel, "Cache flushed successfully.");
}

@Override
public void onFailure(final Exception e) {
LOGGER.error("Cannot flush cache due to", e);
internalSeverError(channel, "Cannot flush cache due to " + e.getMessage() + ".");
}
@Override
public void onFailure(final Exception e) {
LOGGER.error("Cannot flush cache due to", e);
internalServerError(channel, "Cannot flush cache due to " + e.getMessage() + ".");
}
@Override
public void onFailure(final Exception e) {
LOGGER.error("Cannot flush cache due to", e);
internalSeverError(channel, "Cannot flush cache due to " + e.getMessage() + ".");
}

});
});
Expand Down

0 comments on commit 2c8e63a

Please sign in to comment.