0

Keycloak policy enforcer not working, Sprint boot application.

I use spring boot v 2.3.1 with Keycloak version 10.0.2, i need setup policy enforcer into my app, autnentication part with keycloak work, but if i add policy enforcer config into application.properties, un have an error

===================>application.properties file:

server.port = 8082
# keycloak config
keycloak.realm = my-realm
keycloak.auth-server-url = http://localhost:8080/auth
keycloak.resource = resource_server
keycloak.credentials.secret = 1adb9e31-cd6a-4eb5-95c5-6a45e972b64a
keycloak.ssl-required=external
keycloak.public-client = true
keycloak.bearer-only = true
#keycloak.verify-token-audience = true
keycloak.cors=true
keycloak.use-resource-role-mappings = true   
keycloak.confidential-port=0
keycloak.principal-attribute=preferred_username

keycloak.policy-enforcer-config.enforcement-mode= PERMISSIVE
keycloak.policy-enforcer-config.lazy-load-paths=true
keycloak.policy-enforcer-config.paths[0].name=page_resource
keycloak.policy-enforcer-config.paths[0].path=/uma-protected-resource
keycloak.policy-enforcer-config.paths[0].methods[0].method=GET
keycloak.policy-enforcer-config.paths[0].methods[0].scopes[0]= view

================>test user evaluation in keycloak:

Result 
    *PERMIT
Scopes 
    *view
    *edit
    *delete
Policies
    *edit_permission_resource(User-Managed Policy) 
        decision was PERMIT by AFFIRMATIVE decision. Granted Scopes: edit.
    *view_permission_resource(User-Managed Policy) 
        decision was PERMIT by AFFIRMATIVE decision. Granted Scopes: view.
    *delete_permission_resource(User-Managed Policy) 
        decision was PERMIT by AFFIRMATIVE decision. Granted Scopes: delete.

================>** Error logs**:

java.lang.RuntimeException: Failed to obtain policy enforcer

at org.keycloak.adapters.KeycloakDeployment.getPolicyEnforcer....
at org.keycloak.adapters.AuthenticatedActionsHandler.corsRequest...
at ...
at ...

Caused by: java.lang.RuntimeException: Could not find resource

at ...
at ...

Caused by: Caused by: org.keycloak.authorization.client.util.HttpResponseException: Unexpected response from server: 401 / Unauthorized

at ...
at ...

i use et user token with the right permissions, but i don't know why it doesn't work. I think, he can't find the resource on kaycloak, but he is there with the right rights

client in keycloak: resource_server https://i.stack.imgur.com/d3huA.png https://i.stack.imgur.com/o9xDc.png

resource in keycloak https://i.stack.imgur.com/mslnu.png

Thanks for your help :)

SML31
  • 1
  • 1

0 Answers0