-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Keycloak Claim Information Point - NPE when trying to read body #5959
Comments
@sberyozkin @pedroigor any chance you could have a look at that one before tomorrow evening? |
@gsmet Looking ... |
@gsmet @tpenakov I think I'll not be able to deliver this fix until tomorrow. Although I managed to fix the original issue so that we can properly read the request body, it is not possible to read the body again by the application. For this one, I'm stuck and I don't have yet a clue how to allow the request inputstream to be read twice (by security handlers + later on by the application). @sberyozkin @stuartwdouglas Any clue how we can achieve this? Is there some way to buffer the inputstream and/or use a markSupported one ? Or maybe prove a wrapper for vert.x request so that we can buffer the stream .... |
Regarding the original problem (NPE when obtaining the body) the cause of the exception is that the body needs to be read first by a handler (blocking). The solution I found is to reuse the |
I think I have a prototype that might work. But not sure whether or not it is the best way to achieve it. Here are the changes https://github.com/quarkusio/quarkus/compare/master...pedroigor:issue-5959?expand=1. Basically, after reading the request from the security layer, we set a buffered stream in the routing context so that later it can be reused. There is a change to Resteasy that checks whether or not the buffered stream is set and if so, uses it instead of trying to read again from the connection. |
Fixes quarkusio#5959 This change allows the body handler to be used for Undertow and RESTEasy standalone. When the request is fully buffered it can be consumed multiple times, which allows keycloak to also process it.
Fixes quarkusio#5959 This change allows the body handler to be used for Undertow and RESTEasy standalone. When the request is fully buffered it can be consumed multiple times, which allows keycloak to also process it.
Fixes quarkusio#5959 This change allows the body handler to be used for Undertow and RESTEasy standalone. When the request is fully buffered it can be consumed multiple times, which allows keycloak to also process it.
Fixes quarkusio#5959 This change allows the body handler to be used for Undertow and RESTEasy standalone. When the request is fully buffered it can be consumed multiple times, which allows keycloak to also process it.
Fixes quarkusio#5959 This change allows the body handler to be used for Undertow and RESTEasy standalone. When the request is fully buffered it can be consumed multiple times, which allows keycloak to also process it.
@gsmet I have tested changes from @stuartwdouglas and they will serve as a baseline for this fix. Once the PR is merged I'll apply other minor changes and we should be good. |
@pedroigor - You are referring fix in Resteasy. Is this means that the fix will not going to work for Reactive Routes? |
…t fixes processing of json body
Fixes quarkusio#5959 This change allows the body handler to be used for Undertow and RESTEasy standalone. When the request is fully buffered it can be consumed multiple times, which allows keycloak to also process it.
…t fixes processing of json body
Fixes quarkusio#5959 This change allows the body handler to be used for Undertow and RESTEasy standalone. When the request is fully buffered it can be consumed multiple times, which allows keycloak to also process it.
…t fixes processing of json body
Fixes quarkusio#5959 This change allows the body handler to be used for Undertow and RESTEasy standalone. When the request is fully buffered it can be consumed multiple times, which allows keycloak to also process it.
…t fixes processing of json body
…t fixes processing of json body
…t fixes processing of json body
[fixes #5959] - Error when processing request body from policy enforcer
I was just talking about reusing some class to fix the issue, which is part of the PR that fix this issue. AFAIK, you should also have it working for reactive routes as per changes from Stuart. |
Fixes quarkusio#5959 This change allows the body handler to be used for Undertow and RESTEasy standalone. When the request is fully buffered it can be consumed multiple times, which allows keycloak to also process it.
…t fixes processing of json body
I've just tested it with 1.1.1.Final and can confirm that is fixed. |
@pedroigor - I need your help here :)
After commented the very same line in the sample test project it stopped to work too. I understand that this workaround with adding the line to the Could you please help me with that? |
When i was using CIP for api . Request is going twice to Claim information point provider |
When you try to read body through Claim Information Point the result is Null Pointer Exception.
When you add the following to your application.properties file:
quarkus.keycloak.policy-enforcer.claim-information-point.claims.claim-from-body={request.body}
And execute the post request against the endpoint /api/auth-entry
The result is:
Here is the Sample Project
You can create the quarkus realm from src/test/resources/keycloack/quarkus-realm.json file.
Then you can retrieve the token for user (alice/alice) as described here: https://quarkus.io/guides/security-keycloak-authorization
Then you have to put the token in org.otaibe.enforcer.claim.can.not.read.body.web.controller.RestControllerTest#TOKEN
If you execute the test org.otaibe.enforcer.claim.can.not.read.body.web.controller.RestControllerTest#testPostEndpoint
Then you will receive the NPE
The text was updated successfully, but these errors were encountered: