From 764b826063911a1c4ad81a231a3eb2c9f0d289d1 Mon Sep 17 00:00:00 2001 From: Nils Bandener Date: Thu, 20 Jun 2024 17:21:22 +0200 Subject: [PATCH] Fixes Signed-off-by: Nils Bandener --- .../security/privileges/PrivilegesEvaluator.java | 14 ++++++++------ .../impl/SecurityDynamicConfiguration.java | 13 ------------- .../security/privileges/ActionPrivilegesTest.java | 9 ++++----- .../SecurityIndexAccessEvaluatorTest.java | 3 ++- 4 files changed, 14 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java b/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java index 2c22bf2184..4d5cebe2ab 100644 --- a/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java +++ b/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java @@ -199,13 +199,15 @@ public PrivilegesEvaluator( SecurityDynamicConfiguration rolesConfiguration = configurationRepository.getConfiguration(CType.ROLES); if (rolesConfiguration != null) { - FlattenedActionGroups flattenedActionGroups = actionGroupsConfiguration != null - ? new FlattenedActionGroups( - (SecurityDynamicConfiguration) DynamicConfigFactory.addStatics( - actionGroupsConfiguration.deepClone() - ) + @SuppressWarnings("unchecked") + SecurityDynamicConfiguration actionGroupsWithStatics = actionGroupsConfiguration != null + ? (SecurityDynamicConfiguration) DynamicConfigFactory.addStatics( + actionGroupsConfiguration.deepClone() ) - : FlattenedActionGroups.EMPTY; + : (SecurityDynamicConfiguration) DynamicConfigFactory.addStatics( + SecurityDynamicConfiguration.empty() + ); + FlattenedActionGroups flattenedActionGroups = new FlattenedActionGroups(actionGroupsWithStatics); ActionPrivileges actionPrivileges = new ActionPrivileges( DynamicConfigFactory.addStatics(rolesConfiguration.deepClone()), flattenedActionGroups, diff --git a/src/main/java/org/opensearch/security/securityconf/impl/SecurityDynamicConfiguration.java b/src/main/java/org/opensearch/security/securityconf/impl/SecurityDynamicConfiguration.java index b6d13f32c1..403572c57c 100644 --- a/src/main/java/org/opensearch/security/securityconf/impl/SecurityDynamicConfiguration.java +++ b/src/main/java/org/opensearch/security/securityconf/impl/SecurityDynamicConfiguration.java @@ -172,19 +172,6 @@ public static SecurityDynamicConfiguration fromYaml(String yaml, CType ct return result; } - /** - * For testing only - */ - public static SecurityDynamicConfiguration fromMap(Map map, CType ctype) throws JsonProcessingException { - Class implementationClass = ctype.getImplementationClass().get(2); - SecurityDynamicConfiguration result = DefaultObjectMapper.objectMapper.convertValue( - map, - DefaultObjectMapper.getTypeFactory().constructParametricType(SecurityDynamicConfiguration.class, implementationClass) - ); - result.ctype = ctype; - return result; - } - // for Jackson private SecurityDynamicConfiguration() { super(); diff --git a/src/test/java/org/opensearch/security/privileges/ActionPrivilegesTest.java b/src/test/java/org/opensearch/security/privileges/ActionPrivilegesTest.java index dbaee6ba1d..7b835ccd25 100644 --- a/src/test/java/org/opensearch/security/privileges/ActionPrivilegesTest.java +++ b/src/test/java/org/opensearch/security/privileges/ActionPrivilegesTest.java @@ -515,17 +515,16 @@ SecurityDynamicConfiguration toRolesConfig(ActionSpec actionSpec) { try { return SecurityDynamicConfiguration.fromMap( ImmutableMap.of( - "test_role", // + "test_role", ImmutableMap.of( - // "index_permissions", Arrays.asList( - // ImmutableMap.of("index_patterns", this.givenIndexPrivs, "allowed_actions", actionSpec.givenPrivs) - )// + ) ) ), - CType.ROLES + CType.ROLES, + 2 ); } catch (JsonProcessingException e) { throw new RuntimeException(e); diff --git a/src/test/java/org/opensearch/security/privileges/SecurityIndexAccessEvaluatorTest.java b/src/test/java/org/opensearch/security/privileges/SecurityIndexAccessEvaluatorTest.java index 68c682c2fb..aa474c9ae9 100644 --- a/src/test/java/org/opensearch/security/privileges/SecurityIndexAccessEvaluatorTest.java +++ b/src/test/java/org/opensearch/security/privileges/SecurityIndexAccessEvaluatorTest.java @@ -125,7 +125,8 @@ public void setup( Arrays.asList("*") ) ), - CType.ROLES + CType.ROLES, + 2 ); this.actionPrivileges = new ActionPrivileges(rolesConfig, FlattenedActionGroups.EMPTY, () -> indexMetadata);