question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Policy Enforcer consumes body if a Claim extracts value from Request body and results in an error in the Java application

See original GitHub issue

Describe the bug

In our Spring Boot application we try to retrieve a value from the request body to evaluate it in our Javascript Policy. We are able to extract the value from the request body as explained in the documentation via: "claim-from-json-body-object": "{request.body['/a/b/c']}". After Keycloak evaluation succeeds we get a 400 Bad Request error in Spring Boot as the request body is null. The behavior was also described on Stack overflow a few months ago.

Version

18

Expected behavior

The Keycloak Policy Enforcer extracts the desired value from the request body, the evaluation succeeds and afterwards the body is still available for further processing to the Spring Boot application.

Actual behavior

The Policy Enforcer retrieves the request body and consumes it. Afterwards the body is no longer available in Spring Boot and the result is a 400 Bad Request error.

How to Reproduce?

  1. add configuration to a Spring Boot application to retrieve values from a request body, e.g.: claimInformationPointConfig.claims[user.id]={request.body['/userId']}
  2. create a Javascript Policy that retrieves the value
  3. create an Endpoint in the Java Application that is secured by the Policy

Anything else?

The behavior was also described on Stack overflow a few months ago.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
janstrohscheincommented, Sep 12, 2022

Hey Pedro, I have been looking into it with a colleague and we found a solution to make the body readable multiple times with all the subsequent valves/filters. However, as a new sprint started we did not have the time yet to integrate it into the Keycloak Adapter or write any tests. I will follow the discussion around the adapter deprecation though. Thank you for your help!

0reactions
janstrohscheincommented, Oct 20, 2022

Hey @robinhh, it was mentioned by Pedro (@pedroigor) that there is a discussion about adapter deprecation in this ticket: https://github.com/keycloak/keycloak/discussions/11681

However, the discussion there also stopped.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Policy Enforcer consumes body if a Claim extracts value from ...
Policy Enforcer consumes body if a Claim extracts value from Request body and results in an error in the Java application.
Read more >
Request Body removed after Keycloak's Policy Enforcer ...
It seems like the policy enforcer from keycloak somehow "removed" the request body from the request after the permission evaluation. It is weird ......
Read more >
Authorization Services Guide - Keycloak
Keycloak provides some built-in Policy Enforcers. ... From this page, you can simulate authorization requests and view the result of the ...
Read more >
All configuration options - Quarkus
AWS Lambda Type Default AWS Lambda Common Type Default AWS Lambda Gateway REST API Type Default Agroal ‑ Database connection pool Type Default
Read more >
Jersey 2.37 User Guide - GitHub Pages
This is user guide for Jersey 2.37. We are trying to keep it up to date as we add new features. When reading...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found