use of org.keycloak.representations.idm.authorization.GroupPolicyRepresentation in project keycloak by keycloak.
the class GroupPolicyManagementTest method assertRepresentation.
private void assertRepresentation(GroupPolicyRepresentation representation, GroupPolicyResource permission) {
GroupPolicyRepresentation actual = permission.toRepresentation();
assertRepresentation(representation, actual, () -> permission.resources(), () -> Collections.emptyList(), () -> permission.associatedPolicies());
assertEquals(representation.getGroups().size(), actual.getGroups().size());
assertEquals(0, actual.getGroups().stream().filter(actualDefinition -> !representation.getGroups().stream().filter(groupDefinition -> getGroupPath(actualDefinition.getId()).equals(getCanonicalGroupPath(groupDefinition.getPath())) && actualDefinition.isExtendChildren() == groupDefinition.isExtendChildren()).findFirst().isPresent()).count());
}
use of org.keycloak.representations.idm.authorization.GroupPolicyRepresentation in project keycloak by keycloak.
the class GroupPolicyManagementTest method testRemoveWithoutPath.
@Test
public void testRemoveWithoutPath() {
GroupPolicyRepresentation representation = new GroupPolicyRepresentation();
representation.setName("Delete Group Path Policy");
representation.setGroupsClaim("groups");
representation.addGroup("Group A");
representation.removeGroup("Group A");
assertTrue(representation.getGroups().isEmpty());
}
use of org.keycloak.representations.idm.authorization.GroupPolicyRepresentation in project keycloak by keycloak.
the class GroupSynchronizer method synchronize.
@Override
public void synchronize(GroupModel.GroupRemovedEvent event, KeycloakSessionFactory factory) {
ProviderFactory<AuthorizationProvider> providerFactory = factory.getProviderFactory(AuthorizationProvider.class);
AuthorizationProvider authorizationProvider = providerFactory.create(event.getKeycloakSession());
StoreFactory storeFactory = authorizationProvider.getStoreFactory();
PolicyStore policyStore = storeFactory.getPolicyStore();
GroupModel group = event.getGroup();
Map<Policy.FilterOption, String[]> attributes = new EnumMap<>(Policy.FilterOption.class);
attributes.put(Policy.FilterOption.TYPE, new String[] { "group" });
attributes.put(Policy.FilterOption.CONFIG, new String[] { "groups", group.getId() });
attributes.put(Policy.FilterOption.ANY_OWNER, Policy.FilterOption.EMPTY_FILTER);
List<Policy> search = policyStore.findByResourceServer(attributes, null, -1, -1);
for (Policy policy : search) {
PolicyProviderFactory policyFactory = authorizationProvider.getProviderFactory(policy.getType());
GroupPolicyRepresentation representation = GroupPolicyRepresentation.class.cast(policyFactory.toRepresentation(policy, authorizationProvider));
Set<GroupPolicyRepresentation.GroupDefinition> groups = representation.getGroups();
groups.removeIf(groupDefinition -> groupDefinition.getId().equals(group.getId()));
if (groups.isEmpty()) {
policyFactory.onRemove(policy, authorizationProvider);
policyStore.delete(policy.getId());
} else {
policyFactory.onUpdate(policy, representation, authorizationProvider);
}
}
}
use of org.keycloak.representations.idm.authorization.GroupPolicyRepresentation in project keycloak by keycloak.
the class AggregatePolicyManagementTest method testCreateWithChildAndSelectedPolicy.
@Test
public void testCreateWithChildAndSelectedPolicy() {
refreshPageAndWaitForLoad();
AggregatePolicyRepresentation expected = new AggregatePolicyRepresentation();
expected.setName("Test Child Create And Select Aggregate Policy");
expected.setDescription("description");
expected.addPolicy("Policy C");
AggregatePolicy policy = authorizationPage.authorizationTabs().policies().create(expected, false);
RolePolicyRepresentation childRolePolicy = new RolePolicyRepresentation();
childRolePolicy.setName(UUID.randomUUID().toString());
childRolePolicy.addRole("Role A");
policy.createPolicy(childRolePolicy);
expected.addPolicy(childRolePolicy.getName());
UserPolicyRepresentation childUserPolicy = new UserPolicyRepresentation();
childUserPolicy.setName(UUID.randomUUID().toString());
childUserPolicy.setDescription("description");
childUserPolicy.addUser("user a");
policy.createPolicy(childUserPolicy);
expected.addPolicy(childUserPolicy.getName());
ClientPolicyRepresentation childClientPolicy = new ClientPolicyRepresentation();
childClientPolicy.setName(UUID.randomUUID().toString());
childClientPolicy.setDescription("description");
childClientPolicy.addClient("client a");
policy.createPolicy(childClientPolicy);
expected.addPolicy(childClientPolicy.getName());
JSPolicyRepresentation childJSPolicy = new JSPolicyRepresentation();
childJSPolicy.setName(UUID.randomUUID().toString());
childJSPolicy.setDescription("description");
childJSPolicy.setCode("$evaluation.grant();");
policy.createPolicy(childJSPolicy);
expected.addPolicy(childJSPolicy.getName());
TimePolicyRepresentation childTimePolicy = new TimePolicyRepresentation();
childTimePolicy.setName(UUID.randomUUID().toString());
childTimePolicy.setDescription("description");
childTimePolicy.setNotBefore("2017-01-01 00:00:00");
childTimePolicy.setNotBefore("2018-01-01 00:00:00");
policy.createPolicy(childTimePolicy);
expected.addPolicy(childTimePolicy.getName());
GroupPolicyRepresentation childGroupPolicy = new GroupPolicyRepresentation();
childGroupPolicy.setName(UUID.randomUUID().toString());
childGroupPolicy.setDescription("description");
childGroupPolicy.setGroupsClaim("groups");
childGroupPolicy.addGroupPath("/Group A", true);
policy.createPolicy(childGroupPolicy);
expected.addPolicy(childGroupPolicy.getName());
policy.form().save();
assertAlertSuccess();
authorizationPage.navigateTo();
AggregatePolicy actual = authorizationPage.authorizationTabs().policies().name(expected.getName());
assertPolicy(expected, actual);
}
use of org.keycloak.representations.idm.authorization.GroupPolicyRepresentation in project keycloak by keycloak.
the class GroupPolicyManagementTest method testDeleteFromList.
@Test
public void testDeleteFromList() throws InterruptedException {
authorizationPage.navigateTo();
GroupPolicyRepresentation expected = new GroupPolicyRepresentation();
expected.setName("Test Delete Group Policy");
expected.setDescription("description");
expected.setGroupsClaim("groups");
expected.addGroupPath("/Group A", true);
expected.addGroupPath("/Group A/Group B/Group D");
expected.addGroupPath("Group F");
expected = createPolicy(expected);
authorizationPage.navigateTo();
authorizationPage.authorizationTabs().policies().deleteFromList(expected.getName());
authorizationPage.navigateTo();
assertNull(authorizationPage.authorizationTabs().policies().policies().findByName(expected.getName()));
}
Aggregations