use of org.keycloak.representations.idm.authorization.ScopeRepresentation in project keycloak by keycloak.
the class ResourceManagementTest method createResourceWithDefaultScopes.
private ResourceRepresentation createResourceWithDefaultScopes() {
ResourceRepresentation resource = createResource();
assertEquals(0, resource.getScopes().size());
HashSet<ScopeRepresentation> scopes = new HashSet<>();
scopes.add(createScope("Scope A", "").toRepresentation());
scopes.add(createScope("Scope B", "").toRepresentation());
scopes.add(createScope("Scope C", "").toRepresentation());
resource.setScopes(scopes);
return doUpdateResource(resource);
}
use of org.keycloak.representations.idm.authorization.ScopeRepresentation in project keycloak by keycloak.
the class GenericPolicyManagementTest method testUpdate.
@Test
public void testUpdate() {
PolicyResource policyResource = createTestingPolicy();
PolicyRepresentation policy = policyResource.toRepresentation();
policy.setName("changed");
policy.setLogic(Logic.NEGATIVE);
policy.setDecisionStrategy(DecisionStrategy.AFFIRMATIVE);
policy.getConfig().put("configA", "changed configuration for A");
policy.getConfig().remove("configB");
policy.getConfig().put("configC", "changed configuration for C");
policyResource.update(policy);
policy = policyResource.toRepresentation();
assertEquals("changed", policy.getName());
assertEquals(Logic.NEGATIVE, policy.getLogic());
assertEquals(DecisionStrategy.AFFIRMATIVE, policy.getDecisionStrategy());
assertEquals("changed configuration for A", policy.getConfig().get("configA"));
assertNull(policy.getConfig().get("configB"));
assertEquals("changed configuration for C", policy.getConfig().get("configC"));
Map<String, String> config = policy.getConfig();
config.put("applyPolicies", buildConfigOption(findPolicyByName("Test Associated C").getId()));
config.put("resources", buildConfigOption(findResourceByName("Test Resource B").getId()));
config.put("scopes", buildConfigOption(findScopeByName("Test Scope A").getId()));
policyResource.update(policy);
policy = policyResource.toRepresentation();
config = policy.getConfig();
assertAssociatedPolicy("Test Associated C", policy);
List<PolicyRepresentation> associatedPolicies = getClientResource().authorization().policies().policy(policy.getId()).associatedPolicies();
assertFalse(associatedPolicies.stream().filter(associated -> associated.getId().equals(findPolicyByName("Test Associated A").getId())).findFirst().isPresent());
assertFalse(associatedPolicies.stream().filter(associated -> associated.getId().equals(findPolicyByName("Test Associated B").getId())).findFirst().isPresent());
assertAssociatedResource("Test Resource B", policy);
List<ResourceRepresentation> resources = policyResource.resources();
assertFalse(resources.contains(findResourceByName("Test Resource A")));
assertFalse(resources.contains(findResourceByName("Test Resource C")));
assertAssociatedScope("Test Scope A", policy);
List<ScopeRepresentation> scopes = getClientResource().authorization().policies().policy(policy.getId()).scopes();
assertFalse(scopes.contains(findScopeByName("Test Scope B").getId()));
assertFalse(scopes.contains(findScopeByName("Test Scope C").getId()));
}
use of org.keycloak.representations.idm.authorization.ScopeRepresentation in project keycloak by keycloak.
the class GenericPolicyManagementTest method createScope.
private ResourceScopeResource createScope(String name) {
ScopeRepresentation newScope = new ScopeRepresentation();
newScope.setName(name);
ResourceScopesResource scopes = getClientResource().authorization().scopes();
try (Response response = scopes.create(newScope)) {
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
ScopeRepresentation stored = response.readEntity(ScopeRepresentation.class);
return scopes.scope(stored.getId());
}
}
use of org.keycloak.representations.idm.authorization.ScopeRepresentation in project keycloak by keycloak.
the class AbstractAuthorizationTest method createScope.
protected ResourceScopeResource createScope(String name, String iconUri) {
ScopeRepresentation newScope = new ScopeRepresentation();
newScope.setName(name);
newScope.setIconUri(iconUri);
ResourceScopesResource resources = getClientResource().authorization().scopes();
try (Response response = resources.create(newScope)) {
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
ScopeRepresentation stored = response.readEntity(ScopeRepresentation.class);
return resources.scope(stored.getId());
}
}
use of org.keycloak.representations.idm.authorization.ScopeRepresentation in project keycloak by keycloak.
the class ScopesTable method toRepresentation.
public ScopeRepresentation toRepresentation(WebElement row) {
ScopeRepresentation representation = null;
List<WebElement> tds = row.findElements(tagName("td"));
if (!(tds.isEmpty() || getTextFromElement(tds.get(1)).isEmpty())) {
representation = new ScopeRepresentation();
representation.setName(getTextFromElement(tds.get(1)));
}
return representation;
}
Aggregations