[KEYCLOAK-18111] - Error when processing path without associated resource

This commit is contained in:
Pedro Igor 2021-05-13 18:34:26 -03:00
parent c49dbd66fa
commit 9ebbc7673c
3 changed files with 32 additions and 1 deletions

View file

@ -287,7 +287,7 @@ public class PolicyEnforcer {
enforcementMode = pathConfig.getEnforcementMode();
} else {
for (PathConfig existingPath : paths.values()) {
if (existingPath.getId().equals(targetResource.getId())
if (targetResource.getId().equals(existingPath.getId())
&& existingPath.isStatic()
&& !PolicyEnforcerConfig.EnforcementMode.DISABLED.equals(existingPath.getEnforcementMode())) {
return null;

View file

@ -621,6 +621,18 @@ public class PolicyEnforcerTest extends AbstractKeycloakTest {
assertEquals(200, policyEnforcer.getPathMatcher().getPathCache().size());
assertEquals(0, policyEnforcer.getPaths().size());
ResourceRepresentation resource = clientResource.authorization().resources()
.findByName("Root").get(0);
clientResource.authorization().resources().resource(resource.getId()).remove();
deployment = KeycloakDeploymentBuilder.build(getAdapterConfiguration("enforcer-lazyload-with-paths.json"));
policyEnforcer = deployment.getPolicyEnforcer();
AuthorizationContext context = policyEnforcer.enforce(createHttpFacade("/api/0", token));
assertTrue(context.isGranted());
}
private void initAuthorizationSettings(ClientResource clientResource) {

View file

@ -0,0 +1,19 @@
{
"realm": "authz-test",
"auth-server-url": "http://localhost:8180/auth",
"ssl-required": "external",
"resource": "resource-server-test",
"credentials": {
"secret": "secret"
},
"bearer-only": true,
"policy-enforcer": {
"lazy-load-paths": true,
"paths": [
{
"path": "/disabled",
"enforcement-mode": "DISABLED"
}
]
}
}