Search in sources :

Example 16 with ScopePermissionRepresentation

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

the class ScopePermissionManagementTest method testUpdateScopeOnly.

@Test
public void testUpdateScopeOnly() {
    authorizationPage.navigateTo();
    ScopePermissionRepresentation expected = new ScopePermissionRepresentation();
    expected.setName("testUpdateScopeOnly Permission");
    expected.setDescription("description");
    expected.addScope("Scope C", "Scope A", "Scope B");
    expected.addPolicy("Policy C", "Policy A", "Policy B");
    expected = createPermission(expected);
    String previousName = expected.getName();
    expected.setName(previousName + "Changed");
    expected.setDescription("changed");
    expected.setDecisionStrategy(DecisionStrategy.CONSENSUS);
    expected.getScopes().clear();
    expected.addScope("Scope B");
    expected.getPolicies().clear();
    expected.addPolicy("Policy C");
    authorizationPage.navigateTo();
    authorizationPage.authorizationTabs().permissions().update(previousName, expected);
    assertAlertSuccess();
    authorizationPage.navigateTo();
    ScopePermission actual = authorizationPage.authorizationTabs().permissions().name(expected.getName());
    assertPolicy(expected, actual);
}
Also used : ScopePermission(org.keycloak.testsuite.console.page.clients.authorization.permission.ScopePermission) ScopePermissionRepresentation(org.keycloak.representations.idm.authorization.ScopePermissionRepresentation) Test(org.junit.Test)

Example 17 with ScopePermissionRepresentation

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

the class ScopePermissionManagementTest method testCreateUpdateWithChild.

@Test
public void testCreateUpdateWithChild() {
    ScopePermissionRepresentation expected = new ScopePermissionRepresentation();
    expected.setName(UUID.randomUUID().toString());
    expected.setDescription("description");
    expected.addScope("Scope C");
    expected.addPolicy("Policy C");
    ScopePermission policy = authorizationPage.authorizationTabs().permissions().create(expected, false);
    RolePolicyRepresentation childPolicy = new RolePolicyRepresentation();
    childPolicy.setName(UUID.randomUUID().toString());
    childPolicy.addRole("Role A");
    policy.createPolicy(childPolicy);
    policy.form().save();
    assertAlertSuccess();
    expected.addPolicy(childPolicy.getName());
    authorizationPage.navigateTo();
    ScopePermission actual = authorizationPage.authorizationTabs().permissions().name(expected.getName());
    assertPolicy(expected, actual);
    RolePolicyRepresentation childPolicy2 = new RolePolicyRepresentation();
    childPolicy2.setName(UUID.randomUUID().toString());
    childPolicy2.addRole("Role A");
    policy.createPolicy(childPolicy2);
    policy.form().save();
    assertAlertSuccess();
    expected.addPolicy(childPolicy2.getName());
    authorizationPage.navigateTo();
    actual = authorizationPage.authorizationTabs().permissions().name(expected.getName());
    assertPolicy(expected, actual);
    expected.addResource("Resource B");
    expected.getScopes().clear();
    expected.addScope("Scope B", "Scope C");
    expected.getScopes().remove("Policy C");
    RolePolicyRepresentation childPolicy3 = new RolePolicyRepresentation();
    childPolicy3.setName(UUID.randomUUID().toString());
    childPolicy3.addRole("Role A");
    policy.update(expected, false);
    policy.createPolicy(childPolicy3);
    policy.form().save();
    assertAlertSuccess();
    expected.addPolicy(childPolicy3.getName());
    authorizationPage.navigateTo();
    actual = authorizationPage.authorizationTabs().permissions().name(expected.getName());
    assertPolicy(expected, actual);
}
Also used : ScopePermission(org.keycloak.testsuite.console.page.clients.authorization.permission.ScopePermission) RolePolicyRepresentation(org.keycloak.representations.idm.authorization.RolePolicyRepresentation) ScopePermissionRepresentation(org.keycloak.representations.idm.authorization.ScopePermissionRepresentation) Test(org.junit.Test)

Example 18 with ScopePermissionRepresentation

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

the class ScopePermissionManagementTest method testDeleteFromList.

@Test
public void testDeleteFromList() {
    authorizationPage.navigateTo();
    ScopePermissionRepresentation expected = new ScopePermissionRepresentation();
    expected.setName("testDeleteFromList Permission");
    expected.setDescription("description");
    expected.addScope("Scope C");
    expected.addPolicy("Policy C");
    expected = createPermission(expected);
    authorizationPage.navigateTo();
    authorizationPage.authorizationTabs().permissions().deleteFromList(expected.getName());
    authorizationPage.navigateTo();
    assertNull(authorizationPage.authorizationTabs().permissions().permissions().findByName(expected.getName()));
}
Also used : ScopePermissionRepresentation(org.keycloak.representations.idm.authorization.ScopePermissionRepresentation) Test(org.junit.Test)

Example 19 with ScopePermissionRepresentation

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

the class ScopePermissionForm method toRepresentation.

public ScopePermissionRepresentation toRepresentation() {
    ScopePermissionRepresentation representation = new ScopePermissionRepresentation();
    representation.setName(UIUtils.getTextInputValue(name));
    representation.setDescription(UIUtils.getTextInputValue(description));
    representation.setDecisionStrategy(DecisionStrategy.valueOf(UIUtils.getTextFromElement(decisionStrategy.getFirstSelectedOption()).toUpperCase()));
    representation.setPolicies(policySelect.getSelected());
    representation.setResources(resourceSelect.getSelected());
    representation.setScopes(scopeSelect.getSelected());
    representation.getScopes().addAll(resourceScopeSelect.getSelected());
    return representation;
}
Also used : ScopePermissionRepresentation(org.keycloak.representations.idm.authorization.ScopePermissionRepresentation)

Example 20 with ScopePermissionRepresentation

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

the class ScopePolicyProviderFactory method toRepresentation.

@Override
public ScopePermissionRepresentation toRepresentation(Policy policy, AuthorizationProvider authorization) {
    ScopePermissionRepresentation representation = new ScopePermissionRepresentation();
    representation.setResourceType(policy.getConfig().get("defaultResourceType"));
    return representation;
}
Also used : ScopePermissionRepresentation(org.keycloak.representations.idm.authorization.ScopePermissionRepresentation)

Aggregations

ScopePermissionRepresentation (org.keycloak.representations.idm.authorization.ScopePermissionRepresentation)43 Test (org.junit.Test)32 AuthorizationResource (org.keycloak.admin.client.resource.AuthorizationResource)23 AuthorizationResponse (org.keycloak.representations.idm.authorization.AuthorizationResponse)17 AuthzClient (org.keycloak.authorization.client.AuthzClient)16 JSPolicyRepresentation (org.keycloak.representations.idm.authorization.JSPolicyRepresentation)16 ResourceRepresentation (org.keycloak.representations.idm.authorization.ResourceRepresentation)16 ClientResource (org.keycloak.admin.client.resource.ClientResource)15 AuthorizationRequest (org.keycloak.representations.idm.authorization.AuthorizationRequest)15 Permission (org.keycloak.representations.idm.authorization.Permission)14 Response (javax.ws.rs.core.Response)13 OAuthClient (org.keycloak.testsuite.util.OAuthClient)13 PermissionResponse (org.keycloak.representations.idm.authorization.PermissionResponse)11 TokenIntrospectionResponse (org.keycloak.authorization.client.representation.TokenIntrospectionResponse)10 AccessTokenResponse (org.keycloak.representations.AccessTokenResponse)10 HttpResponseException (org.keycloak.authorization.client.util.HttpResponseException)7 ResourcePermissionRepresentation (org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation)7 ScopePermissionsResource (org.keycloak.admin.client.resource.ScopePermissionsResource)6 ScopePermission (org.keycloak.testsuite.console.page.clients.authorization.permission.ScopePermission)5 ArrayList (java.util.ArrayList)4