Search in sources :

Example 6 with PoliciesResource

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

the class ResourcePermissionManagementTest method configureTest.

@Before
public void configureTest() {
    super.configureTest();
    RolesResource realmRoles = testRealmResource().roles();
    realmRoles.create(new RoleRepresentation("Role A", "", false));
    realmRoles.create(new RoleRepresentation("Role B", "", false));
    RolePolicyRepresentation policyA = new RolePolicyRepresentation();
    policyA.setName("Policy A");
    policyA.addRole("Role A");
    AuthorizationResource authorization = testRealmResource().clients().get(newClient.getId()).authorization();
    PoliciesResource policies = authorization.policies();
    RolePoliciesResource roles = policies.role();
    roles.create(policyA);
    RolePolicyRepresentation policyB = new RolePolicyRepresentation();
    policyB.setName("Policy B");
    policyB.addRole("Role B");
    roles.create(policyB);
    UserPolicyRepresentation policyC = new UserPolicyRepresentation();
    policyC.setName("Policy C");
    policyC.addUser("test");
    policies.user().create(policyC).close();
    ResourcesResource resources = authorization.resources();
    resources.create(new ResourceRepresentation("Resource A"));
    resources.create(new ResourceRepresentation("Resource B"));
}
Also used : RoleRepresentation(org.keycloak.representations.idm.RoleRepresentation) RolePolicyRepresentation(org.keycloak.representations.idm.authorization.RolePolicyRepresentation) UserPolicyRepresentation(org.keycloak.representations.idm.authorization.UserPolicyRepresentation) RolePoliciesResource(org.keycloak.admin.client.resource.RolePoliciesResource) PoliciesResource(org.keycloak.admin.client.resource.PoliciesResource) RolePoliciesResource(org.keycloak.admin.client.resource.RolePoliciesResource) RolesResource(org.keycloak.admin.client.resource.RolesResource) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) ResourcesResource(org.keycloak.admin.client.resource.ResourcesResource) ResourceRepresentation(org.keycloak.representations.idm.authorization.ResourceRepresentation) Before(org.junit.Before)

Example 7 with PoliciesResource

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

the class AggregatePolicyManagementTest method configureTest.

@Before
public void configureTest() {
    super.configureTest();
    RealmResource realmResource = testRealmResource();
    RolesResource realmRoles = realmResource.roles();
    realmRoles.create(new RoleRepresentation("Role A", "", false));
    realmRoles.create(new RoleRepresentation("Role B", "", false));
    UsersResource users = realmResource.users();
    users.create(UserBuilder.create().username("user a").build());
    ClientsResource clients = realmResource.clients();
    clients.create(ClientBuilder.create().clientId("client a").build());
    realmResource.groups().add(GroupBuilder.create().name("Group A").build());
    RolePolicyRepresentation policyA = new RolePolicyRepresentation();
    policyA.setName("Policy A");
    policyA.addRole("Role A");
    AuthorizationResource authorization = realmResource.clients().get(newClient.getId()).authorization();
    PoliciesResource policies = authorization.policies();
    RolePoliciesResource roles = policies.role();
    roles.create(policyA);
    RolePolicyRepresentation policyB = new RolePolicyRepresentation();
    policyB.setName("Policy B");
    policyB.addRole("Role B");
    roles.create(policyB);
    UserPolicyRepresentation policyC = new UserPolicyRepresentation();
    policyC.setName("Policy C");
    policyC.addUser("test");
    policies.user().create(policyC).close();
}
Also used : RoleRepresentation(org.keycloak.representations.idm.RoleRepresentation) RolePolicyRepresentation(org.keycloak.representations.idm.authorization.RolePolicyRepresentation) RealmResource(org.keycloak.admin.client.resource.RealmResource) UserPolicyRepresentation(org.keycloak.representations.idm.authorization.UserPolicyRepresentation) UsersResource(org.keycloak.admin.client.resource.UsersResource) ClientsResource(org.keycloak.admin.client.resource.ClientsResource) RolePoliciesResource(org.keycloak.admin.client.resource.RolePoliciesResource) PoliciesResource(org.keycloak.admin.client.resource.PoliciesResource) RolePoliciesResource(org.keycloak.admin.client.resource.RolePoliciesResource) RolesResource(org.keycloak.admin.client.resource.RolesResource) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) Before(org.junit.Before)

Aggregations

PoliciesResource (org.keycloak.admin.client.resource.PoliciesResource)7 AuthorizationResource (org.keycloak.admin.client.resource.AuthorizationResource)4 RoleRepresentation (org.keycloak.representations.idm.RoleRepresentation)4 PolicyRepresentation (org.keycloak.representations.idm.authorization.PolicyRepresentation)4 Before (org.junit.Before)3 Test (org.junit.Test)3 ResourcesResource (org.keycloak.admin.client.resource.ResourcesResource)3 RolePoliciesResource (org.keycloak.admin.client.resource.RolePoliciesResource)3 RolesResource (org.keycloak.admin.client.resource.RolesResource)3 ResourceRepresentation (org.keycloak.representations.idm.authorization.ResourceRepresentation)3 RolePolicyRepresentation (org.keycloak.representations.idm.authorization.RolePolicyRepresentation)3 UserPolicyRepresentation (org.keycloak.representations.idm.authorization.UserPolicyRepresentation)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Response (javax.ws.rs.core.Response)2 ScopeRepresentation (org.keycloak.representations.idm.authorization.ScopeRepresentation)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Set (java.util.Set)1