Search in sources :

Example 11 with ResourcesResource

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

the class PermissionClaimTest method removeAuthorization.

@After
public void removeAuthorization() throws Exception {
    ClientResource client = getClient(getRealm());
    ClientRepresentation representation = client.toRepresentation();
    representation.setAuthorizationServicesEnabled(false);
    client.update(representation);
    representation.setAuthorizationServicesEnabled(true);
    client.update(representation);
    ResourcesResource resources = client.authorization().resources();
    List<ResourceRepresentation> defaultResource = resources.findByName("Default Resource");
    resources.resource(defaultResource.get(0).getId()).remove();
}
Also used : ClientResource(org.keycloak.admin.client.resource.ClientResource) ResourcesResource(org.keycloak.admin.client.resource.ResourcesResource) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) ResourceRepresentation(org.keycloak.representations.idm.authorization.ResourceRepresentation) After(org.junit.After)

Example 12 with ResourcesResource

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

the class ScopeManagementTest method testNotUpdateOnResourceUpdate.

@Test
public void testNotUpdateOnResourceUpdate() {
    ResourceScopeResource scopeResource = createDefaultScope();
    ScopeRepresentation scope = scopeResource.toRepresentation();
    scope.setName("changed");
    scope.setDisplayName("changed");
    scope.setIconUri("changed");
    scopeResource.update(scope);
    scope = scopeResource.toRepresentation();
    assertEquals("changed", scope.getName());
    assertEquals("changed", scope.getDisplayName());
    assertEquals("changed", scope.getIconUri());
    ResourcesResource resources = getClientResource().authorization().resources();
    ResourceRepresentation resource;
    try (Response response = resources.create(new ResourceRepresentation(UUID.randomUUID().toString(), scope.getName()))) {
        resource = response.readEntity(ResourceRepresentation.class);
    }
    resource.getScopes().iterator().next().setDisplayName(null);
    resources.resource(resource.getId()).update(resource);
    scope = scopeResource.toRepresentation();
    assertEquals("changed", scope.getName());
    assertEquals("changed", scope.getDisplayName());
    assertEquals("changed", scope.getIconUri());
}
Also used : ResourceScopeResource(org.keycloak.admin.client.resource.ResourceScopeResource) Response(javax.ws.rs.core.Response) ScopeRepresentation(org.keycloak.representations.idm.authorization.ScopeRepresentation) ResourcesResource(org.keycloak.admin.client.resource.ResourcesResource) ResourceRepresentation(org.keycloak.representations.idm.authorization.ResourceRepresentation) Test(org.junit.Test)

Example 13 with ResourcesResource

use of org.keycloak.admin.client.resource.ResourcesResource 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)

Aggregations

ResourcesResource (org.keycloak.admin.client.resource.ResourcesResource)13 ResourceRepresentation (org.keycloak.representations.idm.authorization.ResourceRepresentation)11 Test (org.junit.Test)5 Response (javax.ws.rs.core.Response)3 AuthorizationResource (org.keycloak.admin.client.resource.AuthorizationResource)3 ClientResource (org.keycloak.admin.client.resource.ClientResource)3 PoliciesResource (org.keycloak.admin.client.resource.PoliciesResource)3 RoleRepresentation (org.keycloak.representations.idm.RoleRepresentation)3 After (org.junit.After)2 Before (org.junit.Before)2 RolePoliciesResource (org.keycloak.admin.client.resource.RolePoliciesResource)2 RolesResource (org.keycloak.admin.client.resource.RolesResource)2 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)2 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1