Search in sources :

Example 1 with ResourcesResource

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

the class ResourceManagementTest method doUpdateResource.

protected ResourceRepresentation doUpdateResource(ResourceRepresentation resource) {
    ResourcesResource resources = getClientResource().authorization().resources();
    ResourceResource existing = resources.resource(resource.getId());
    existing.update(resource);
    return resources.resource(resource.getId()).toRepresentation();
}
Also used : ResourceResource(org.keycloak.admin.client.resource.ResourceResource) ResourcesResource(org.keycloak.admin.client.resource.ResourcesResource)

Example 2 with ResourcesResource

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

the class AbstractServletAuthzAdapterTest method testCanNotAccessWhenEnforcing.

@Test
public void testCanNotAccessWhenEnforcing() throws Exception {
    performTests(() -> {
        importResourceServerSettings();
        ResourcesResource resources = getAuthorizationResource().resources();
        ResourceRepresentation resource = resources.findByName("Protected Resource").get(0);
        resource.setUri("/index.jsp");
        resources.resource(resource.getId()).update(resource);
    }, () -> {
        login("jdoe", "jdoe");
        driver.navigate().to(getResourceServerUrl().toString() + "/enforcing/resource");
        assertWasDenied();
    });
}
Also used : ResourcesResource(org.keycloak.admin.client.resource.ResourcesResource) ResourceRepresentation(org.keycloak.representations.idm.authorization.ResourceRepresentation) Test(org.junit.Test)

Example 3 with ResourcesResource

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

the class AuthorizationTest method onAfter.

@After
public void onAfter() {
    ResourcesResource resources = getClient().authorization().resources();
    List<ResourceRepresentation> existingResources = resources.resources();
    for (ResourceRepresentation resource : existingResources) {
        resources.resource(resource.getId()).remove();
    }
}
Also used : ResourcesResource(org.keycloak.admin.client.resource.ResourcesResource) ResourceRepresentation(org.keycloak.representations.idm.authorization.ResourceRepresentation) After(org.junit.After)

Example 4 with ResourcesResource

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

the class ScopePermissionManagementTest 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();
    authorization.scopes().create(new ScopeRepresentation("Scope A"));
    authorization.scopes().create(new ScopeRepresentation("Scope B"));
    authorization.scopes().create(new ScopeRepresentation("Scope C"));
    ResourcesResource resources = authorization.resources();
    resources.create(new ResourceRepresentation("Resource A", "Scope A"));
    resources.create(new ResourceRepresentation("Resource B", "Scope B", "Scope C"));
}
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) ScopeRepresentation(org.keycloak.representations.idm.authorization.ScopeRepresentation) 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 5 with ResourcesResource

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

the class ResourceManagementTest method doRemoveResource.

protected void doRemoveResource(ResourceRepresentation resource) {
    ResourcesResource resources = getClientResource().authorization().resources();
    resources.resource(resource.getId()).remove();
}
Also used : ResourcesResource(org.keycloak.admin.client.resource.ResourcesResource)

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