use of org.keycloak.representations.idm.authorization.ClientScopePolicyRepresentation in project keycloak by keycloak.
the class ClientScopePolicyTest method createClientScopePolicy.
private void createClientScopePolicy(String name, String... clientScopes) {
ClientScopePolicyRepresentation policy = new ClientScopePolicyRepresentation();
policy.setName(name);
for (String clientScope : clientScopes) {
policy.addClientScope(clientScope);
}
getClient().authorization().policies().clientScope().create(policy).close();
}
use of org.keycloak.representations.idm.authorization.ClientScopePolicyRepresentation in project keycloak by keycloak.
the class ClientScopePolicyTest method testRemovePolicyWhenRemovingScope.
@Test
public void testRemovePolicyWhenRemovingScope() {
createClientScopePolicy("Client Scope To Remove Policy", "to-remove-a", "to-remove-b");
ClientScopesResource clientScopes = getRealm().clientScopes();
ClientScopeRepresentation scopeRep = clientScopes.findAll().stream().filter(r -> r.getName().equals("to-remove-a")).findAny().get();
getClient().removeDefaultClientScope(scopeRep.getId());
getRealm().clientScopes().get(scopeRep.getId()).remove();
ClientScopePolicyRepresentation policyRep = getClient().authorization().policies().clientScope().findByName("Client Scope To Remove Policy");
final String id = scopeRep.getId();
assertFalse(policyRep.getClientScopes().stream().anyMatch(def -> def.getId().equals(id)));
scopeRep = clientScopes.findAll().stream().filter(r -> r.getName().equals("to-remove-b")).findAny().get();
getClient().removeDefaultClientScope(scopeRep.getId());
getRealm().clientScopes().get(scopeRep.getId()).remove();
assertNull(getClient().authorization().policies().clientScope().findByName("Client Scope To Remove Policy"));
}
use of org.keycloak.representations.idm.authorization.ClientScopePolicyRepresentation in project keycloak by keycloak.
the class ClientScopePolicyTest method createClientScopePolicyAndLastOneRequired.
private void createClientScopePolicyAndLastOneRequired(String name, String... clientScopes) {
ClientScopePolicyRepresentation policy = new ClientScopePolicyRepresentation();
policy.setName(name);
for (int i = 0; i < clientScopes.length - 1; i++) {
policy.addClientScope(clientScopes[i]);
}
policy.addClientScope(clientScopes[clientScopes.length - 1], true);
getClient().authorization().policies().clientScope().create(policy).close();
}
Aggregations