use of org.keycloak.representations.idm.authorization.ScopeRepresentation in project keycloak by keycloak.
the class Scopes method update.
public void update(String name, ScopeRepresentation representation) {
for (WebElement row : scopes().rows()) {
ScopeRepresentation actual = scopes().toRepresentation(row);
if (actual.getName().equalsIgnoreCase(name)) {
clickLink(row.findElements(tagName("a")).get(0));
scope.form().populate(representation);
}
}
}
use of org.keycloak.representations.idm.authorization.ScopeRepresentation in project keycloak by keycloak.
the class Scopes method delete.
public void delete(String name) {
for (WebElement row : scopes().rows()) {
ScopeRepresentation actual = scopes().toRepresentation(row);
if (actual.getName().equalsIgnoreCase(name)) {
clickLink(row.findElements(tagName("a")).get(0));
scope.form().delete();
}
}
}
use of org.keycloak.representations.idm.authorization.ScopeRepresentation in project keycloak by keycloak.
the class ExportUtils method exportAuthorizationSettings.
public static ResourceServerRepresentation exportAuthorizationSettings(KeycloakSession session, ClientModel client) {
AuthorizationProviderFactory providerFactory = (AuthorizationProviderFactory) session.getKeycloakSessionFactory().getProviderFactory(AuthorizationProvider.class);
AuthorizationProvider authorization = providerFactory.create(session, client.getRealm());
StoreFactory storeFactory = authorization.getStoreFactory();
ResourceServer settingsModel = authorization.getStoreFactory().getResourceServerStore().findByClient(client);
if (settingsModel == null) {
return null;
}
ResourceServerRepresentation representation = toRepresentation(settingsModel, client);
representation.setId(null);
representation.setName(null);
representation.setClientId(null);
List<ResourceRepresentation> resources = storeFactory.getResourceStore().findByResourceServer(settingsModel.getId()).stream().map(resource -> {
ResourceRepresentation rep = toRepresentation(resource, settingsModel.getId(), authorization);
if (rep.getOwner().getId().equals(settingsModel.getId())) {
rep.setOwner((ResourceOwnerRepresentation) null);
} else {
rep.getOwner().setId(null);
}
rep.getScopes().forEach(scopeRepresentation -> {
scopeRepresentation.setId(null);
scopeRepresentation.setIconUri(null);
});
return rep;
}).collect(Collectors.toList());
representation.setResources(resources);
List<PolicyRepresentation> policies = new ArrayList<>();
PolicyStore policyStore = storeFactory.getPolicyStore();
policies.addAll(policyStore.findByResourceServer(settingsModel.getId()).stream().filter(policy -> !policy.getType().equals("resource") && !policy.getType().equals("scope") && policy.getOwner() == null).map(policy -> createPolicyRepresentation(authorization, policy)).collect(Collectors.toList()));
policies.addAll(policyStore.findByResourceServer(settingsModel.getId()).stream().filter(policy -> (policy.getType().equals("resource") || policy.getType().equals("scope") && policy.getOwner() == null)).map(policy -> createPolicyRepresentation(authorization, policy)).collect(Collectors.toList()));
representation.setPolicies(policies);
List<ScopeRepresentation> scopes = storeFactory.getScopeStore().findByResourceServer(settingsModel.getId()).stream().map(scope -> {
ScopeRepresentation rep = toRepresentation(scope);
rep.setPolicies(null);
rep.setResources(null);
return rep;
}).collect(Collectors.toList());
representation.setScopes(scopes);
return representation;
}
use of org.keycloak.representations.idm.authorization.ScopeRepresentation in project keycloak by keycloak.
the class PolicyEnforcerClaimsTest method createResource.
private ResourceRepresentation createResource(ClientResource clientResource, String name, String uri, String... scopes) {
ResourceRepresentation representation = new ResourceRepresentation();
representation.setName(name);
representation.setUri(uri);
representation.setScopes(Arrays.asList(scopes).stream().map(ScopeRepresentation::new).collect(Collectors.toSet()));
try (javax.ws.rs.core.Response response = clientResource.authorization().resources().create(representation)) {
representation.setId(response.readEntity(ResourceRepresentation.class).getId());
return representation;
}
}
use of org.keycloak.representations.idm.authorization.ScopeRepresentation in project keycloak by keycloak.
the class ResourceManagementTest method testUpdateScopes.
@Test
public void testUpdateScopes() {
ResourceRepresentation resource = createResourceWithDefaultScopes();
Set<ScopeRepresentation> scopes = new HashSet<>(resource.getScopes());
assertEquals(3, scopes.size());
assertTrue(scopes.removeIf(scopeRepresentation -> scopeRepresentation.getName().equals("Scope B")));
resource.setScopes(scopes);
ResourceRepresentation updated = doUpdateResource(resource);
assertEquals(2, resource.getScopes().size());
assertFalse(containsScope("Scope B", updated));
assertTrue(containsScope("Scope A", updated));
assertTrue(containsScope("Scope C", updated));
scopes = new HashSet<>(updated.getScopes());
assertTrue(scopes.removeIf(scopeRepresentation -> scopeRepresentation.getName().equals("Scope A")));
assertTrue(scopes.removeIf(scopeRepresentation -> scopeRepresentation.getName().equals("Scope C")));
updated.setScopes(scopes);
updated = doUpdateResource(updated);
assertEquals(0, updated.getScopes().size());
}
Aggregations