Search in sources :

Example 46 with ScopeRepresentation

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

the class ResourceManagementTest method testUpdate.

@Test
public void testUpdate() {
    ResourceRepresentation expected = createResource();
    String previousName = expected.getName();
    expected.setName("changed");
    expected.setDisplayName("changed");
    expected.setType("changed");
    expected.setUri("changed");
    expected.setScopes(Arrays.asList("Scope A", "Scope B", "Scope C").stream().map(name -> new ScopeRepresentation(name)).collect(Collectors.toSet()));
    authorizationPage.navigateTo();
    Resource resource = authorizationPage.authorizationTabs().resources().name(previousName);
    resource.update(expected);
    assertAlertSuccess();
    assertResource(expected);
    expected.setScopes(expected.getScopes().stream().filter(scope -> scope.getName().equals("Scope C")).collect(Collectors.toSet()));
    authorizationPage.navigateTo();
    authorizationPage.authorizationTabs().resources().update(expected.getName(), expected);
    assertAlertSuccess();
    assertResource(expected);
}
Also used : Resource(org.keycloak.testsuite.console.page.clients.authorization.resource.Resource) ScopeRepresentation(org.keycloak.representations.idm.authorization.ScopeRepresentation) ResourceRepresentation(org.keycloak.representations.idm.authorization.ResourceRepresentation) Test(org.junit.Test)

Example 47 with ScopeRepresentation

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

the class ResourceManagementTest method configureTest.

@Before
@Override
public void configureTest() {
    super.configureTest();
    for (String scopeName : Arrays.asList("Scope A", "Scope B", "Scope C")) {
        authorizationPage.navigateTo();
        authorizationPage.authorizationTabs().scopes().create(new ScopeRepresentation(scopeName));
    }
    authorizationPage.navigateTo();
}
Also used : ScopeRepresentation(org.keycloak.representations.idm.authorization.ScopeRepresentation) Before(org.junit.Before)

Example 48 with ScopeRepresentation

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

the class ResourceManagementTest method assertResource.

private void assertResource(ResourceRepresentation expected) {
    authorizationPage.navigateTo();
    ResourceRepresentation actual = authorizationPage.authorizationTabs().resources().resources().findByName(expected.getName());
    assertEquals(expected.getName(), actual.getName());
    assertEquals(expected.getType(), actual.getType());
    assertEquals(expected.getUri(), actual.getUri());
    assertEquals(expected.getIconUri(), actual.getIconUri());
    ResourceRepresentation resource = authorizationPage.authorizationTabs().resources().name(expected.getName()).toRepresentation();
    assertEquals(expected.getDisplayName(), resource.getDisplayName());
    Set<ScopeRepresentation> associatedScopes = resource.getScopes();
    if (expected.getScopes() != null) {
        assertNotNull(associatedScopes);
        assertEquals(expected.getScopes().size(), associatedScopes.size());
        assertEquals(0, resource.getScopes().stream().filter(actualScope -> !expected.getScopes().stream().filter(expectedScope -> actualScope.getName().equals(expectedScope.getName())).findFirst().isPresent()).count());
    } else {
        assertTrue(associatedScopes.isEmpty());
    }
}
Also used : ScopeRepresentation(org.keycloak.representations.idm.authorization.ScopeRepresentation) ResourceRepresentation(org.keycloak.representations.idm.authorization.ResourceRepresentation)

Aggregations

ScopeRepresentation (org.keycloak.representations.idm.authorization.ScopeRepresentation)48 ResourceRepresentation (org.keycloak.representations.idm.authorization.ResourceRepresentation)27 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)14 List (java.util.List)12 Response (javax.ws.rs.core.Response)11 HashSet (java.util.HashSet)10 AuthorizationResource (org.keycloak.admin.client.resource.AuthorizationResource)10 HashMap (java.util.HashMap)8 Map (java.util.Map)8 Set (java.util.Set)8 AuthzClient (org.keycloak.authorization.client.AuthzClient)8 Arrays (java.util.Arrays)7 AuthorizationRequest (org.keycloak.representations.idm.authorization.AuthorizationRequest)7 PolicyRepresentation (org.keycloak.representations.idm.authorization.PolicyRepresentation)7 Collection (java.util.Collection)6 Collectors (java.util.stream.Collectors)6 ResourceScopesResource (org.keycloak.admin.client.resource.ResourceScopesResource)5 HttpResponseException (org.keycloak.authorization.client.util.HttpResponseException)5 WebElement (org.openqa.selenium.WebElement)5