Search in sources :

Example 6 with PolicyResource

use of org.keycloak.admin.client.resource.PolicyResource in project keycloak by keycloak.

the class RolePolicyManagementTest method testGenericConfig.

@Test
public void testGenericConfig() {
    AuthorizationResource authorization = getClient().authorization();
    RolePolicyRepresentation representation = new RolePolicyRepresentation();
    representation.setName("Test Generic Config  Permission");
    representation.addRole("Role A", false);
    RolePoliciesResource policies = authorization.policies().role();
    try (Response response = policies.create(representation)) {
        RolePolicyRepresentation created = response.readEntity(RolePolicyRepresentation.class);
        PolicyResource policy = authorization.policies().policy(created.getId());
        PolicyRepresentation genericConfig = policy.toRepresentation();
        assertNotNull(genericConfig.getConfig());
        assertNotNull(genericConfig.getConfig().get("roles"));
        RoleRepresentation role = getRealm().roles().get("Role A").toRepresentation();
        assertTrue(genericConfig.getConfig().get("roles").contains(role.getId()));
    }
}
Also used : Response(javax.ws.rs.core.Response) RolePolicyRepresentation(org.keycloak.representations.idm.authorization.RolePolicyRepresentation) PolicyRepresentation(org.keycloak.representations.idm.authorization.PolicyRepresentation) RoleRepresentation(org.keycloak.representations.idm.RoleRepresentation) RolePolicyRepresentation(org.keycloak.representations.idm.authorization.RolePolicyRepresentation) RolePolicyResource(org.keycloak.admin.client.resource.RolePolicyResource) PolicyResource(org.keycloak.admin.client.resource.PolicyResource) RolePoliciesResource(org.keycloak.admin.client.resource.RolePoliciesResource) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) Test(org.junit.Test)

Example 7 with PolicyResource

use of org.keycloak.admin.client.resource.PolicyResource in project keycloak by keycloak.

the class UserPolicyManagementTest method testGenericConfig.

@Test
public void testGenericConfig() {
    AuthorizationResource authorization = getClient().authorization();
    UserPolicyRepresentation representation = new UserPolicyRepresentation();
    representation.setName("Test Generic Config Permission");
    representation.addUser("User A");
    UserPoliciesResource policies = authorization.policies().user();
    try (Response response = policies.create(representation)) {
        UserPolicyRepresentation created = response.readEntity(UserPolicyRepresentation.class);
        PolicyResource policy = authorization.policies().policy(created.getId());
        PolicyRepresentation genericConfig = policy.toRepresentation();
        assertNotNull(genericConfig.getConfig());
        assertNotNull(genericConfig.getConfig().get("users"));
        UserRepresentation user = getRealm().users().search("User A").get(0);
        assertTrue(genericConfig.getConfig().get("users").contains(user.getId()));
    }
}
Also used : Response(javax.ws.rs.core.Response) PolicyRepresentation(org.keycloak.representations.idm.authorization.PolicyRepresentation) UserPolicyRepresentation(org.keycloak.representations.idm.authorization.UserPolicyRepresentation) PolicyResource(org.keycloak.admin.client.resource.PolicyResource) UserPolicyResource(org.keycloak.admin.client.resource.UserPolicyResource) UserPolicyRepresentation(org.keycloak.representations.idm.authorization.UserPolicyRepresentation) UserPoliciesResource(org.keycloak.admin.client.resource.UserPoliciesResource) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 PolicyResource (org.keycloak.admin.client.resource.PolicyResource)7 PolicyRepresentation (org.keycloak.representations.idm.authorization.PolicyRepresentation)7 Response (javax.ws.rs.core.Response)6 AuthorizationResource (org.keycloak.admin.client.resource.AuthorizationResource)6 ResourceRepresentation (org.keycloak.representations.idm.authorization.ResourceRepresentation)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertFalse (org.junit.Assert.assertFalse)2 Assert.assertNotNull (org.junit.Assert.assertNotNull)2 Assert.assertNull (org.junit.Assert.assertNull)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 PoliciesResource (org.keycloak.admin.client.resource.PoliciesResource)2