Search in sources :

Example 31 with ResourcePermissionRepresentation

use of org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation in project keycloak by keycloak.

the class ResourcePermissionManagementTest method testUpdateResourceType.

@Test
public void testUpdateResourceType() throws InterruptedException {
    authorizationPage.navigateTo();
    ResourcePermissionRepresentation expected = new ResourcePermissionRepresentation();
    expected.setName("testUpdateResourceType Permission");
    expected.setDescription("description");
    expected.setResourceType("test-resource-type");
    expected.addPolicy("Policy A");
    expected.addPolicy("Policy B");
    expected.addPolicy("Policy C");
    expected = createPermission(expected);
    String previousName = expected.getName();
    expected.setName(expected.getName() + " Changed");
    expected.setDescription("Changed description");
    expected.setDecisionStrategy(DecisionStrategy.CONSENSUS);
    expected.setResourceType("changed-resource-type");
    expected.setPolicies(expected.getPolicies().stream().filter(policy -> !policy.equals("Policy B")).collect(Collectors.toSet()));
    authorizationPage.navigateTo();
    authorizationPage.authorizationTabs().permissions().update(previousName, expected);
    assertAlertSuccess();
    authorizationPage.navigateTo();
    ResourcePermission actual = authorizationPage.authorizationTabs().permissions().name(expected.getName());
    assertPolicy(expected, actual);
    expected.setResourceType(null);
    expected.addResource("Resource A");
    authorizationPage.navigateTo();
    authorizationPage.authorizationTabs().permissions().update(expected.getName(), expected);
    assertAlertSuccess();
    ResourcePermissionsResource resourcePermission = testRealmResource().clients().get(newClient.getId()).authorization().permissions().resource();
    ResourcePermissionRepresentation permission = resourcePermission.findByName(expected.getName());
    assertFalse(resourcePermission.findById(permission.getId()).resources().isEmpty());
    expected.setResourceType("test");
    authorizationPage.navigateTo();
    authorizationPage.authorizationTabs().permissions().update(expected.getName(), expected);
    assertAlertSuccess();
    assertTrue(resourcePermission.findById(permission.getId()).resources().isEmpty());
}
Also used : ResourcePermissionsResource(org.keycloak.admin.client.resource.ResourcePermissionsResource) ResourcePermission(org.keycloak.testsuite.console.page.clients.authorization.permission.ResourcePermission) ResourcePermissionRepresentation(org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation) Test(org.junit.Test)

Example 32 with ResourcePermissionRepresentation

use of org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation in project keycloak by keycloak.

the class ResourcePermissionForm method toRepresentation.

public ResourcePermissionRepresentation toRepresentation() {
    ResourcePermissionRepresentation representation = new ResourcePermissionRepresentation();
    representation.setName(UIUtils.getTextInputValue(name));
    representation.setDescription(UIUtils.getTextInputValue(description));
    representation.setDecisionStrategy(DecisionStrategy.valueOf(UIUtils.getTextFromElement(decisionStrategy.getFirstSelectedOption()).toUpperCase()));
    representation.setPolicies(policySelect.getSelected());
    String inputValue = UIUtils.getTextInputValue(resourceType);
    if (!"".equals(inputValue)) {
        representation.setResourceType(inputValue);
    }
    representation.setResources(resourceSelect.getSelected());
    return representation;
}
Also used : ResourcePermissionRepresentation(org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation)

Example 33 with ResourcePermissionRepresentation

use of org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation in project keycloak by keycloak.

the class GenericPolicyManagementTest method testQueryPolicyAllFields.

@Test
public void testQueryPolicyAllFields() {
    AuthorizationResource authorization = getClientResource().authorization();
    authorization.resources().create(new ResourceRepresentation("Resource A"));
    ResourcePermissionRepresentation permission = new ResourcePermissionRepresentation();
    permission.setName("Permission A");
    permission.addResource("Resource A");
    authorization.permissions().resource().create(permission);
    List<PolicyRepresentation> policies = authorization.policies().policies(null, "Permission A", null, null, null, true, null, "*", -1, -1);
    assertEquals(1, policies.size());
    assertEquals(1, policies.get(0).getResourcesData().size());
    policies = authorization.policies().policies(null, "Permission A", null, null, null, true, null, null, -1, -1);
    assertEquals(1, policies.size());
    assertNull(policies.get(0).getResourcesData());
}
Also used : PolicyRepresentation(org.keycloak.representations.idm.authorization.PolicyRepresentation) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) ResourceRepresentation(org.keycloak.representations.idm.authorization.ResourceRepresentation) ResourcePermissionRepresentation(org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation) Test(org.junit.Test)

Example 34 with ResourcePermissionRepresentation

use of org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation in project keycloak by keycloak.

the class ResourcePermissionManagementTest method testCreateResourceType.

@Test
public void testCreateResourceType() {
    AuthorizationResource authorization = getClient().authorization();
    ResourcePermissionRepresentation representation = new ResourcePermissionRepresentation();
    representation.setName("Resource A Type Permission");
    representation.setDescription("description");
    representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
    representation.setLogic(Logic.NEGATIVE);
    representation.setResourceType("test-resource");
    representation.addPolicy("Only Marta Policy");
    assertCreated(authorization, representation);
}
Also used : AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) ResourcePermissionRepresentation(org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation) Test(org.junit.Test)

Example 35 with ResourcePermissionRepresentation

use of org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation in project keycloak by keycloak.

the class ResourcePermissionManagementTest method testCreateResourcePermission.

@Test
public void testCreateResourcePermission() {
    AuthorizationResource authorization = getClient().authorization();
    ResourcePermissionRepresentation representation = new ResourcePermissionRepresentation();
    representation.setName("Resource A Permission");
    representation.setDescription("description");
    representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
    representation.setLogic(Logic.NEGATIVE);
    representation.addResource("Resource A");
    representation.addPolicy("Only Marta Policy", "Only Kolo Policy");
    assertCreated(authorization, representation);
}
Also used : AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) ResourcePermissionRepresentation(org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation) Test(org.junit.Test)

Aggregations

ResourcePermissionRepresentation (org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation)65 Test (org.junit.Test)46 ResourceRepresentation (org.keycloak.representations.idm.authorization.ResourceRepresentation)32 AuthorizationResource (org.keycloak.admin.client.resource.AuthorizationResource)28 AuthorizationResponse (org.keycloak.representations.idm.authorization.AuthorizationResponse)28 ClientResource (org.keycloak.admin.client.resource.ClientResource)25 Response (javax.ws.rs.core.Response)20 JSPolicyRepresentation (org.keycloak.representations.idm.authorization.JSPolicyRepresentation)19 Permission (org.keycloak.representations.idm.authorization.Permission)19 AuthorizationRequest (org.keycloak.representations.idm.authorization.AuthorizationRequest)18 AuthzClient (org.keycloak.authorization.client.AuthzClient)16 OAuthClient (org.keycloak.testsuite.util.OAuthClient)16 AccessToken (org.keycloak.representations.AccessToken)14 TokenIntrospectionResponse (org.keycloak.authorization.client.representation.TokenIntrospectionResponse)12 AccessTokenResponse (org.keycloak.representations.AccessTokenResponse)12 PermissionResponse (org.keycloak.representations.idm.authorization.PermissionResponse)12 AuthorizationDeniedException (org.keycloak.authorization.client.AuthorizationDeniedException)11 HttpResponseException (org.keycloak.authorization.client.util.HttpResponseException)9 PermissionTicketRepresentation (org.keycloak.representations.idm.authorization.PermissionTicketRepresentation)7 ScopePermissionRepresentation (org.keycloak.representations.idm.authorization.ScopePermissionRepresentation)7