From 8581886944f08c59ad88a0111be9e0f2ef7360e7 Mon Sep 17 00:00:00 2001 From: Stefan Guilhen Date: Fri, 18 Oct 2024 12:49:10 -0300 Subject: [PATCH] Add validation for role and time policies Closes #28978 Signed-off-by: Stefan Guilhen --- authz/policy/common/pom.xml | 5 +++ .../role/RolePolicyProviderFactory.java | 7 ++-- .../time/TimePolicyProviderFactory.java | 36 ++++++++++++++++--- .../util/PolicyValidationException.java | 29 +++++++++++++++ .../admin/messages/messages_en.properties | 2 +- 5 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 authz/policy/common/src/main/java/org/keycloak/authorization/policy/provider/util/PolicyValidationException.java diff --git a/authz/policy/common/pom.xml b/authz/policy/common/pom.xml index ec7c0f5ddc..eb1e18fbe7 100644 --- a/authz/policy/common/pom.xml +++ b/authz/policy/common/pom.xml @@ -51,6 +51,11 @@ keycloak-server-spi-private provided + + io.quarkus.resteasy.reactive + resteasy-reactive-common + provided + org.jboss.logging jboss-logging diff --git a/authz/policy/common/src/main/java/org/keycloak/authorization/policy/provider/role/RolePolicyProviderFactory.java b/authz/policy/common/src/main/java/org/keycloak/authorization/policy/provider/role/RolePolicyProviderFactory.java index 2ebc91ee5a..8b9e3c1c96 100644 --- a/authz/policy/common/src/main/java/org/keycloak/authorization/policy/provider/role/RolePolicyProviderFactory.java +++ b/authz/policy/common/src/main/java/org/keycloak/authorization/policy/provider/role/RolePolicyProviderFactory.java @@ -22,6 +22,7 @@ import org.keycloak.authorization.AuthorizationProvider; import org.keycloak.authorization.model.Policy; import org.keycloak.authorization.policy.provider.PolicyProvider; import org.keycloak.authorization.policy.provider.PolicyProviderFactory; +import org.keycloak.authorization.policy.provider.util.PolicyValidationException; import org.keycloak.models.ClientModel; import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSessionFactory; @@ -150,7 +151,7 @@ public class RolePolicyProviderFactory implements PolicyProviderFactory roles) { Set updatedRoles = new HashSet<>(); - + Set processedRoles = new HashSet<>(); if (roles != null) { RealmModel realm = authorization.getRealm(); for (RolePolicyRepresentation.RoleDefinition definition : roles) { @@ -159,8 +160,10 @@ public class RolePolicyProviderFactory implements PolicyProviderFactory config = new HashMap(policy.getConfig()); @@ -143,11 +160,20 @@ public class TimePolicyProviderFactory implements PolicyProviderFactory