-
Notifications
You must be signed in to change notification settings - Fork 26
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
[ENHANCEMENT] Make the Apisix plugin reactive #1412
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import reactor.core.publisher.Mono; | ||
|
||
@Component | ||
public class TokenRevokedFilter implements PluginFilter { | ||
private final Logger logger = LoggerFactory.getLogger("RevokedTokenPlugin"); | ||
|
@@ -29,25 +31,32 @@ public String name() { | |
@Override | ||
public void filter(HttpRequest request, HttpResponse response, PluginFilterChain chain) { | ||
logger.debug("Received a new request"); | ||
sidFilter(request, response); | ||
chain.filter(request, response); | ||
sidFilter(request, response) | ||
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. It's possible that +1 🍺 if it works 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. It's callback based, it is fine! 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.
Could you refer to any document that prove this "callback"? I agree with Tung. Code we put in reactor could be executed after response is sent to client. 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. You are tiring me, so deeply, some days. 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. Because implementing a callback interface: -> it's clear that though asynchronous the callbacks are still executed in order 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. apache/apisix-java-plugin-runner#313 Please qualify the new plugin with the new plugin runner ;-) 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. Yeah with the updated plugin runner, the reactive code works well. I have tested case token revoked --> pass Regarding updating the plugin runner, I wonder if there is anyone reviewing and approving the PR. In case the repository is no longer maintained, I suggest we fork, create our own repository for the plugin runner (as well as CI/CD) 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.
It is Christmass time. Be patient. We can package, build and deploy the PR for the time being. Can we do a JMAP perf test on top of this change?
(I told you: let's patch the causes and not the consequences) 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. Apisix docker image: hungphan227/apisix:3.9.1-debian-javaplugin 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. It is complicated to update staging env to run jmap perf test with apisix. Therefore, I will update james-gatling and run it locally with tmail-backend memory version. |
||
.doFinally(any -> chain.filter(request, response)) | ||
.subscribe(); | ||
} | ||
|
||
private void sidFilter(HttpRequest request, HttpResponse response) { | ||
Optional.ofNullable(request.getHeader("Authorization")) | ||
private Mono<Void> sidFilter(HttpRequest request, HttpResponse response) { | ||
return Optional.ofNullable(request.getHeader("Authorization")) | ||
.or(() -> Optional.ofNullable(request.getHeader("authorization"))) | ||
.map(String::trim) | ||
.map(bearerToken -> bearerToken.startsWith("Bearer ") ? bearerToken.substring(7) : bearerToken) | ||
.flatMap(ChannelLogoutController::extractSidFromLogoutToken) | ||
.ifPresent(sid -> { | ||
boolean existSid = tokenRepository.exist(sid); | ||
.map(sid -> validateSid(request, response, sid)) | ||
.orElse(Mono.empty()); | ||
} | ||
|
||
private Mono<Void> validateSid(HttpRequest request, HttpResponse response, String sid) { | ||
return tokenRepository.exist(sid) | ||
.doOnNext(existSid -> { | ||
if (existSid) { | ||
logger.info("Token has been revoked, Sid: " + sid); | ||
makeUnAuthorizedRequest(request, response); | ||
} else { | ||
logger.debug("Token valid, Sid: " + sid); | ||
} | ||
}); | ||
}) | ||
.then(); | ||
} | ||
|
||
public static void makeUnAuthorizedRequest(HttpRequest request, HttpResponse response) { | ||
|
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.
+1 for this