use of org.keycloak.admin.client.resource.AuthorizationResource in project keycloak by keycloak.
the class ConflictingScopePermissionTest method createScopePermission.
private void createScopePermission(String name, String resourceName, List<String> scopes, List<String> policies, ClientResource client) throws IOException {
AuthorizationResource authorization = client.authorization();
ScopePermissionRepresentation representation = new ScopePermissionRepresentation();
representation.setName(name);
if (resourceName != null) {
representation.addResource(resourceName);
}
representation.addScope(scopes.toArray(new String[scopes.size()]));
representation.addPolicy(policies.toArray(new String[policies.size()]));
authorization.permissions().scope().create(representation).close();
}
use of org.keycloak.admin.client.resource.AuthorizationResource in project keycloak by keycloak.
the class GroupNamePolicyTest method createResource.
private void createResource(String name) {
AuthorizationResource authorization = getClient().authorization();
ResourceRepresentation resource = new ResourceRepresentation(name);
authorization.resources().create(resource).close();
}
use of org.keycloak.admin.client.resource.AuthorizationResource in project keycloak by keycloak.
the class AuthorizationAPITest method configureAuthorization.
private void configureAuthorization(String clientId) throws Exception {
ClientResource client = getClient(getRealm(), clientId);
AuthorizationResource authorization = client.authorization();
ResourceRepresentation resource = new ResourceRepresentation("Resource A");
Response response = authorization.resources().create(resource);
response.close();
JSPolicyRepresentation policy = new JSPolicyRepresentation();
policy.setName("Default Policy");
policy.setCode("$evaluation.grant();");
response = authorization.policies().js().create(policy);
response.close();
ResourcePermissionRepresentation permission = new ResourcePermissionRepresentation();
permission.setName(resource.getName() + " Permission");
permission.addResource(resource.getName());
permission.addPolicy(policy.getName());
response = authorization.permissions().resource().create(permission);
response.close();
}
use of org.keycloak.admin.client.resource.AuthorizationResource in project keycloak by keycloak.
the class PartialImportTest method testAddClientsWithServiceAccountsAndAuthorization.
@EnableFeature(value = UPLOAD_SCRIPTS, skipRestart = true)
@Test
public void testAddClientsWithServiceAccountsAndAuthorization() throws IOException {
setFail();
addClients(true);
PartialImportResults results = doImport();
assertEquals(NUM_ENTITIES * 2, results.getAdded());
for (PartialImportResult result : results.getResults()) {
if (result.getResourceType().equals(ResourceType.CLIENT)) {
String id = result.getId();
ClientResource clientRsc = testRealmResource().clients().get(id);
ClientRepresentation client = clientRsc.toRepresentation();
assertTrue(client.getName().startsWith(CLIENT_PREFIX));
Assert.assertTrue(client.isServiceAccountsEnabled());
if (ProfileAssume.isFeatureEnabled(AUTHORIZATION)) {
Assert.assertTrue(client.getAuthorizationServicesEnabled());
AuthorizationResource authRsc = clientRsc.authorization();
ResourceServerRepresentation authRep = authRsc.exportSettings();
Assert.assertNotNull(authRep);
Assert.assertEquals(2, authRep.getResources().size());
Assert.assertEquals(3, authRep.getPolicies().size());
} else {
Assert.assertNull(client.getAuthorizationServicesEnabled());
}
} else {
UserResource userRsc = testRealmResource().users().get(result.getId());
Assert.assertTrue(userRsc.toRepresentation().getUsername().startsWith(ServiceAccountConstants.SERVICE_ACCOUNT_USER_PREFIX + CLIENT_PREFIX));
}
}
}
use of org.keycloak.admin.client.resource.AuthorizationResource in project keycloak by keycloak.
the class AuthorizationTest method configureAuthorization.
@Before
public void configureAuthorization() throws Exception {
ClientResource client = getClient();
AuthorizationResource authorization = client.authorization();
JSPolicyRepresentation policy = new JSPolicyRepresentation();
policy.setName("Grant Policy");
policy.setCode("$evaluation.grant();");
authorization.policies().js().create(policy).close();
policy = new JSPolicyRepresentation();
policy.setName("Deny Policy");
policy.setCode("$evaluation.deny();");
}
Aggregations