Search in sources :

Example 51 with AuthorizationResource

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

the class GroupPolicyManagementTest method testCreateWithoutGroupsClaim.

@Test
public void testCreateWithoutGroupsClaim() {
    AuthorizationResource authorization = getClient().authorization();
    GroupPolicyRepresentation representation = new GroupPolicyRepresentation();
    representation.setName(KeycloakModelUtils.generateId());
    representation.setDescription("description");
    representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
    representation.setLogic(Logic.NEGATIVE);
    representation.addGroupPath("/Group A/Group B/Group C", true);
    representation.addGroupPath("Group F");
    assertCreated(authorization, representation);
}
Also used : GroupPolicyRepresentation(org.keycloak.representations.idm.authorization.GroupPolicyRepresentation) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) Test(org.junit.Test)

Example 52 with AuthorizationResource

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

the class JSPolicyManagementTest method testUpdate.

@Test
public void testUpdate() {
    AuthorizationResource authorization = getClient().authorization();
    JSPolicyRepresentation representation = new JSPolicyRepresentation();
    representation.setName("Update JS Policy");
    representation.setDescription("description");
    representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
    representation.setLogic(Logic.NEGATIVE);
    representation.setCode("$evaluation.grant();");
    assertCreated(authorization, representation);
    representation.setName("changed");
    representation.setDescription("changed");
    representation.setDecisionStrategy(DecisionStrategy.AFFIRMATIVE);
    representation.setLogic(Logic.POSITIVE);
    representation.setCode("$evaluation.deny()");
    JSPoliciesResource policies = authorization.policies().js();
    JSPolicyResource permission = policies.findById(representation.getId());
    permission.update(representation);
    assertRepresentation(representation, permission);
}
Also used : JSPoliciesResource(org.keycloak.admin.client.resource.JSPoliciesResource) JSPolicyRepresentation(org.keycloak.representations.idm.authorization.JSPolicyRepresentation) JSPolicyResource(org.keycloak.admin.client.resource.JSPolicyResource) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) Test(org.junit.Test)

Example 53 with AuthorizationResource

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

the class JSPolicyManagementTest method testDelete.

@Test
public void testDelete() {
    AuthorizationResource authorization = getClient().authorization();
    JSPolicyRepresentation representation = new JSPolicyRepresentation();
    representation.setName("Test Delete Policy");
    representation.setCode("$evaluation.grant()");
    JSPoliciesResource policies = authorization.policies().js();
    try (Response response = policies.create(representation)) {
        JSPolicyRepresentation created = response.readEntity(JSPolicyRepresentation.class);
        policies.findById(created.getId()).remove();
        JSPolicyResource removed = policies.findById(created.getId());
        try {
            removed.toRepresentation();
            fail("Permission not removed");
        } catch (NotFoundException ignore) {
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) JSPoliciesResource(org.keycloak.admin.client.resource.JSPoliciesResource) JSPolicyRepresentation(org.keycloak.representations.idm.authorization.JSPolicyRepresentation) JSPolicyResource(org.keycloak.admin.client.resource.JSPolicyResource) NotFoundException(javax.ws.rs.NotFoundException) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) Test(org.junit.Test)

Example 54 with AuthorizationResource

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

the class ClientPolicyManagementTest method testDeleteClient.

@Test
public void testDeleteClient() {
    AuthorizationResource authorization = getClient().authorization();
    ClientPolicyRepresentation representation = new ClientPolicyRepresentation();
    representation.setName("Update Test Client Policy");
    representation.setDescription("description");
    representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
    representation.setLogic(Logic.NEGATIVE);
    representation.addClient("Client D");
    representation.addClient("Client E");
    representation.addClient("Client F");
    assertCreated(authorization, representation);
    ClientsResource clients = getRealm().clients();
    ClientRepresentation client = clients.findByClientId("Client D").get(0);
    clients.get(client.getId()).remove();
    representation = authorization.policies().client().findById(representation.getId()).toRepresentation();
    Assert.assertEquals(2, representation.getClients().size());
    Assert.assertFalse(representation.getClients().contains(client.getId()));
    client = clients.findByClientId("Client E").get(0);
    clients.get(client.getId()).remove();
    representation = authorization.policies().client().findById(representation.getId()).toRepresentation();
    Assert.assertEquals(1, representation.getClients().size());
    Assert.assertFalse(representation.getClients().contains(client.getId()));
    client = clients.findByClientId("Client F").get(0);
    clients.get(client.getId()).remove();
    try {
        authorization.policies().client().findById(representation.getId()).toRepresentation();
        fail("Client policy should be removed");
    } catch (NotFoundException nfe) {
    // ignore
    }
}
Also used : ClientPolicyRepresentation(org.keycloak.representations.idm.authorization.ClientPolicyRepresentation) ClientsResource(org.keycloak.admin.client.resource.ClientsResource) NotFoundException(javax.ws.rs.NotFoundException) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Test(org.junit.Test)

Example 55 with AuthorizationResource

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

the class ClientPolicyManagementTest method testDelete.

@Test
public void testDelete() {
    AuthorizationResource authorization = getClient().authorization();
    ClientPolicyRepresentation representation = new ClientPolicyRepresentation();
    representation.setName("Test Delete Permission");
    representation.addClient("Client A");
    ClientPoliciesResource policies = authorization.policies().client();
    try (Response response = policies.create(representation)) {
        ClientPolicyRepresentation created = response.readEntity(ClientPolicyRepresentation.class);
        policies.findById(created.getId()).remove();
        ClientPolicyResource removed = policies.findById(created.getId());
        try {
            removed.toRepresentation();
            fail("Permission not removed");
        } catch (NotFoundException ignore) {
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) ClientPolicyRepresentation(org.keycloak.representations.idm.authorization.ClientPolicyRepresentation) ClientPoliciesResource(org.keycloak.admin.client.resource.ClientPoliciesResource) ClientPolicyResource(org.keycloak.admin.client.resource.ClientPolicyResource) NotFoundException(javax.ws.rs.NotFoundException) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) Test(org.junit.Test)

Aggregations

AuthorizationResource (org.keycloak.admin.client.resource.AuthorizationResource)110 Test (org.junit.Test)87 ResourceRepresentation (org.keycloak.representations.idm.authorization.ResourceRepresentation)46 ClientResource (org.keycloak.admin.client.resource.ClientResource)43 Response (javax.ws.rs.core.Response)41 JSPolicyRepresentation (org.keycloak.representations.idm.authorization.JSPolicyRepresentation)30 AuthorizationResponse (org.keycloak.representations.idm.authorization.AuthorizationResponse)28 ResourcePermissionRepresentation (org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation)28 AuthzClient (org.keycloak.authorization.client.AuthzClient)27 AuthorizationRequest (org.keycloak.representations.idm.authorization.AuthorizationRequest)25 ScopePermissionRepresentation (org.keycloak.representations.idm.authorization.ScopePermissionRepresentation)23 Permission (org.keycloak.representations.idm.authorization.Permission)22 PermissionResponse (org.keycloak.representations.idm.authorization.PermissionResponse)19 OAuthClient (org.keycloak.testsuite.util.OAuthClient)19 TokenIntrospectionResponse (org.keycloak.authorization.client.representation.TokenIntrospectionResponse)16 AccessTokenResponse (org.keycloak.representations.AccessTokenResponse)16 PolicyRepresentation (org.keycloak.representations.idm.authorization.PolicyRepresentation)16 ResourceServerRepresentation (org.keycloak.representations.idm.authorization.ResourceServerRepresentation)15 ArrayList (java.util.ArrayList)14 HttpResponseException (org.keycloak.authorization.client.util.HttpResponseException)13