diff --git a/auth/server/base/src/test/java/org/wildfly/security/authz/RoleMappingTest.java b/auth/server/base/src/test/java/org/wildfly/security/authz/RoleMappingTest.java index 7bf83335c08..22b526d1cb6 100644 --- a/auth/server/base/src/test/java/org/wildfly/security/authz/RoleMappingTest.java +++ b/auth/server/base/src/test/java/org/wildfly/security/authz/RoleMappingTest.java @@ -259,6 +259,41 @@ public void testDifferenceRoles() { assertEquals(1, count); } + @Test + public void testIntersectionMappedRoles() { + Roles roles = createRoles("foo", "joe"); + + Map> mappingMap1 = new HashMap<>(); + mappingMap1.put("foo", createSet("bar", "role")); + + RoleMapper mapper1 = new MappedRoleMapper.Builder() + .setRoleMap(mappingMap1).build(); + + Map> mappingMap2 = new HashMap<>(); + mappingMap2.put("foo", createSet("bar", "test")); + + RoleMapper mapper2 = new MappedRoleMapper.Builder() + .setRoleMap(mappingMap2).build(); + + RoleMapper mapper3 = mapper1.and(mapper2); + + Roles mappedRoles = mapper3.mapRoles(roles); + + assertTrue(mappedRoles.contains("bar")); + assertFalse(mappedRoles.contains("role")); + assertFalse(mappedRoles.contains("test")); + assertFalse(mappedRoles.contains("foo")); + assertFalse(mappedRoles.contains("joe")); + + Iterator iterator = mappedRoles.iterator(); + int count = 0; + while (iterator.hasNext()) { + iterator.next(); + count++; + } + assertEquals(1, count); + } + private Set createSet(String... values) { HashSet set = new HashSet<>(); for (String s : values) set.add(s);