Search in sources :

Example 1 with ResourceScopeResource

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

the class ScopeManagementTest method testUpdate.

@Test
public void testUpdate() {
    ResourceScopeResource scopeResource = createDefaultScope();
    ScopeRepresentation scope = scopeResource.toRepresentation();
    scope.setName("changed");
    scope.setIconUri("changed");
    scopeResource.update(scope);
    scope = scopeResource.toRepresentation();
    assertEquals("changed", scope.getName());
    assertEquals("changed", scope.getIconUri());
}
Also used : ResourceScopeResource(org.keycloak.admin.client.resource.ResourceScopeResource) ScopeRepresentation(org.keycloak.representations.idm.authorization.ScopeRepresentation) Test(org.junit.Test)

Example 2 with ResourceScopeResource

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

the class ScopeManagementTest method testDeleteAndPolicyUpdate.

@Test(expected = NotFoundException.class)
public void testDeleteAndPolicyUpdate() {
    ResourceScopeResource scopeResource = createDefaultScope();
    ScopeRepresentation scopeRepresentation = scopeResource.toRepresentation();
    ScopePermissionRepresentation representation = new ScopePermissionRepresentation();
    representation.setName(scopeRepresentation.getName());
    representation.addScope(scopeRepresentation.getId());
    getClientResource().authorization().permissions().scope().create(representation);
    ScopePermissionRepresentation permissionRepresentation = getClientResource().authorization().permissions().scope().findByName(scopeRepresentation.getName());
    List<ScopeRepresentation> scopes = getClientResource().authorization().policies().policy(permissionRepresentation.getId()).scopes();
    assertEquals(1, scopes.size());
    scopeResource.remove();
    assertTrue(getClientResource().authorization().policies().policy(permissionRepresentation.getId()).scopes().isEmpty());
}
Also used : ResourceScopeResource(org.keycloak.admin.client.resource.ResourceScopeResource) ScopeRepresentation(org.keycloak.representations.idm.authorization.ScopeRepresentation) ScopePermissionRepresentation(org.keycloak.representations.idm.authorization.ScopePermissionRepresentation) Test(org.junit.Test)

Example 3 with ResourceScopeResource

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

the class ScopeManagementTest method testDelete.

@Test(expected = NotFoundException.class)
public void testDelete() {
    ResourceScopeResource scopeResource = createDefaultScope();
    scopeResource.remove();
    scopeResource.toRepresentation();
}
Also used : ResourceScopeResource(org.keycloak.admin.client.resource.ResourceScopeResource) Test(org.junit.Test)

Example 4 with ResourceScopeResource

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

Aggregations

Test (org.junit.Test)4 ResourceScopeResource (org.keycloak.admin.client.resource.ResourceScopeResource)4 ScopeRepresentation (org.keycloak.representations.idm.authorization.ScopeRepresentation)3 Response (javax.ws.rs.core.Response)1 ResourcesResource (org.keycloak.admin.client.resource.ResourcesResource)1 ResourceRepresentation (org.keycloak.representations.idm.authorization.ResourceRepresentation)1 ScopePermissionRepresentation (org.keycloak.representations.idm.authorization.ScopePermissionRepresentation)1