Search in sources :

Example 11 with GroupPolicyRepresentation

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

the class GroupPolicyManagementTest method testCreateWithoutGroupClaims.

@Test
public void testCreateWithoutGroupClaims() throws InterruptedException {
    authorizationPage.navigateTo();
    GroupPolicyRepresentation expected = new GroupPolicyRepresentation();
    expected.setName("Test Group Policy");
    expected.setDescription("description");
    expected.addGroupPath("/Group A", true);
    expected.addGroupPath("/Group A/Group B/Group D");
    expected.addGroupPath("Group F");
    createPolicy(expected);
}
Also used : GroupPolicyRepresentation(org.keycloak.representations.idm.authorization.GroupPolicyRepresentation) Test(org.junit.Test)

Example 12 with GroupPolicyRepresentation

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

the class GroupPolicyManagementTest method testDelete.

@Test
public void testDelete() throws InterruptedException {
    authorizationPage.navigateTo();
    GroupPolicyRepresentation expected = new GroupPolicyRepresentation();
    expected.setName("Test Delete Group Policy");
    expected.setDescription("description");
    expected.setGroupsClaim("groups");
    expected.addGroupPath("/Group A", true);
    expected.addGroupPath("/Group A/Group B/Group D");
    expected.addGroupPath("Group F");
    expected = createPolicy(expected);
    authorizationPage.navigateTo();
    authorizationPage.authorizationTabs().policies().delete(expected.getName());
    assertAlertSuccess();
    authorizationPage.navigateTo();
    assertNull(authorizationPage.authorizationTabs().policies().policies().findByName(expected.getName()));
}
Also used : GroupPolicyRepresentation(org.keycloak.representations.idm.authorization.GroupPolicyRepresentation) Test(org.junit.Test)

Example 13 with GroupPolicyRepresentation

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

the class GroupPolicyManagementTest method assertPolicy.

private GroupPolicyRepresentation assertPolicy(GroupPolicyRepresentation expected, GroupPolicy policy) {
    GroupPolicyRepresentation actual = policy.toRepresentation();
    assertEquals(expected.getName(), actual.getName());
    assertEquals(expected.getDescription(), actual.getDescription());
    assertEquals(expected.getLogic(), actual.getLogic());
    assertEquals(expected.getGroupsClaim(), actual.getGroupsClaim());
    assertNotNull(actual.getGroups());
    assertEquals(expected.getGroups().size(), actual.getGroups().size());
    assertEquals(0, actual.getGroups().stream().filter(actualDefinition -> !expected.getGroups().stream().filter(groupDefinition -> actualDefinition.getPath().contains(groupDefinition.getPath()) && actualDefinition.isExtendChildren() == groupDefinition.isExtendChildren()).findFirst().isPresent()).count());
    return actual;
}
Also used : GroupPolicyRepresentation(org.keycloak.representations.idm.authorization.GroupPolicyRepresentation)

Example 14 with GroupPolicyRepresentation

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

the class GroupPolicyForm method populate.

public void populate(GroupPolicyRepresentation expected, boolean save) {
    UIUtils.setTextInputValue(name, expected.getName());
    UIUtils.setTextInputValue(description, expected.getDescription());
    UIUtils.setTextInputValue(groupsClaim, expected.getGroupsClaim());
    logic.selectByValue(expected.getLogic().name());
    for (GroupPolicyRepresentation.GroupDefinition definition : toRepresentation().getGroups()) {
        boolean isExpected = false;
        for (GroupPolicyRepresentation.GroupDefinition expectedDef : expected.getGroups()) {
            if (definition.getPath().equals(expectedDef.getPath())) {
                isExpected = true;
                break;
            }
        }
        if (!isExpected) {
            unselect(definition.getPath());
        }
    }
    for (GroupPolicyRepresentation.GroupDefinition definition : expected.getGroups()) {
        String path = definition.getPath();
        String groupName = path.substring(path.lastIndexOf('/') + 1);
        WebElement element = driver.findElement(By.xpath("//span[text()='" + groupName + "']"));
        element.click();
        waitUntilElement(selectGroupButton).is().enabled();
        selectGroupButton.click();
        driver.findElements(By.xpath("(//table[@id='selected-groups'])/tbody/tr")).stream().filter(webElement -> webElement.findElements(tagName("td")).size() > 1).map(webElement -> webElement.findElements(tagName("td"))).filter(tds -> UIUtils.getTextFromElement(tds.get(0)).equals(definition.getPath())).forEach(tds -> {
            if (!tds.get(1).findElement(By.tagName("input")).isSelected()) {
                if (definition.isExtendChildren()) {
                    tds.get(1).findElement(By.tagName("input")).click();
                }
            } else {
                if (!definition.isExtendChildren() && tds.get(1).findElement(By.tagName("input")).isSelected()) {
                    tds.get(1).findElement(By.tagName("input")).click();
                }
            }
        });
    }
    if (save) {
        save();
    }
}
Also used : WaitUtils.waitUntilElement(org.keycloak.testsuite.util.WaitUtils.waitUntilElement) Form(org.keycloak.testsuite.page.Form) GroupPolicyRepresentation(org.keycloak.representations.idm.authorization.GroupPolicyRepresentation) By(org.openqa.selenium.By) WebDriver(org.openqa.selenium.WebDriver) UIUtils(org.keycloak.testsuite.util.UIUtils) WebElement(org.openqa.selenium.WebElement) Page(org.jboss.arquillian.graphene.page.Page) HashSet(java.util.HashSet) List(java.util.List) ModalDialog(org.keycloak.testsuite.console.page.fragment.ModalDialog) Drone(org.jboss.arquillian.drone.api.annotation.Drone) Logic(org.keycloak.representations.idm.authorization.Logic) Select(org.openqa.selenium.support.ui.Select) UIUtils.getTextFromElement(org.keycloak.testsuite.util.UIUtils.getTextFromElement) By.tagName(org.openqa.selenium.By.tagName) FindBy(org.openqa.selenium.support.FindBy) GroupPolicyRepresentation(org.keycloak.representations.idm.authorization.GroupPolicyRepresentation) WebElement(org.openqa.selenium.WebElement)

Example 15 with GroupPolicyRepresentation

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

the class GroupPolicyProviderFactory method onExport.

@Override
public void onExport(Policy policy, PolicyRepresentation representation, AuthorizationProvider authorization) {
    Map<String, String> config = new HashMap<>();
    GroupPolicyRepresentation groupPolicy = toRepresentation(policy, authorization);
    Set<GroupPolicyRepresentation.GroupDefinition> groups = groupPolicy.getGroups();
    for (GroupPolicyRepresentation.GroupDefinition definition : groups) {
        GroupModel group = authorization.getRealm().getGroupById(definition.getId());
        definition.setId(null);
        definition.setPath(ModelToRepresentation.buildGroupPath(group));
    }
    try {
        String groupsClaim = groupPolicy.getGroupsClaim();
        if (groupsClaim != null) {
            config.put("groupsClaim", groupsClaim);
        }
        config.put("groups", JsonSerialization.writeValueAsString(groups));
    } catch (IOException cause) {
        throw new RuntimeException("Failed to export group policy [" + policy.getName() + "]", cause);
    }
    representation.setConfig(config);
}
Also used : HashMap(java.util.HashMap) GroupModel(org.keycloak.models.GroupModel) IOException(java.io.IOException) GroupPolicyRepresentation(org.keycloak.representations.idm.authorization.GroupPolicyRepresentation)

Aggregations

GroupPolicyRepresentation (org.keycloak.representations.idm.authorization.GroupPolicyRepresentation)28 Test (org.junit.Test)13 AuthorizationResource (org.keycloak.admin.client.resource.AuthorizationResource)6 GroupPoliciesResource (org.keycloak.admin.client.resource.GroupPoliciesResource)4 GroupPolicyResource (org.keycloak.admin.client.resource.GroupPolicyResource)4 Policy (org.keycloak.authorization.model.Policy)4 ClientPolicyRepresentation (org.keycloak.representations.idm.authorization.ClientPolicyRepresentation)4 JSPolicyRepresentation (org.keycloak.representations.idm.authorization.JSPolicyRepresentation)4 RolePolicyRepresentation (org.keycloak.representations.idm.authorization.RolePolicyRepresentation)4 UserPolicyRepresentation (org.keycloak.representations.idm.authorization.UserPolicyRepresentation)4 HashSet (java.util.HashSet)3 Response (javax.ws.rs.core.Response)3 GroupModel (org.keycloak.models.GroupModel)3 AbstractPolicyRepresentation (org.keycloak.representations.idm.authorization.AbstractPolicyRepresentation)3 WebElement (org.openqa.selenium.WebElement)3 IOException (java.io.IOException)2 List (java.util.List)2 NotFoundException (javax.ws.rs.NotFoundException)2 Drone (org.jboss.arquillian.drone.api.annotation.Drone)2 Page (org.jboss.arquillian.graphene.page.Page)2