Search in sources :

Example 1 with ClientScopePolicyRepresentation

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();
}
Also used : ClientScopePolicyRepresentation(org.keycloak.representations.idm.authorization.ClientScopePolicyRepresentation)

Example 2 with ClientScopePolicyRepresentation

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"));
}
Also used : ResourceRepresentation(org.keycloak.representations.idm.authorization.ResourceRepresentation) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) AuthzClient(org.keycloak.authorization.client.AuthzClient) RealmBuilder(org.keycloak.testsuite.util.RealmBuilder) ClientsResource(org.keycloak.admin.client.resource.ClientsResource) AuthorizationDeniedException(org.keycloak.authorization.client.AuthorizationDeniedException) UserBuilder(org.keycloak.testsuite.util.UserBuilder) ResourcePermissionRepresentation(org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation) Assert.fail(org.junit.Assert.fail) AuthServer(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude.AuthServer) ClientResource(org.keycloak.admin.client.resource.ClientResource) Before(org.junit.Before) ClientScopesResource(org.keycloak.admin.client.resource.ClientScopesResource) Assert.assertNotNull(org.junit.Assert.assertNotNull) RealmResource(org.keycloak.admin.client.resource.RealmResource) ClientScopeRepresentation(org.keycloak.representations.idm.ClientScopeRepresentation) AuthorizationRequest(org.keycloak.representations.idm.authorization.AuthorizationRequest) Test(org.junit.Test) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) AuthorizationResponse(org.keycloak.representations.idm.authorization.AuthorizationResponse) PermissionRequest(org.keycloak.representations.idm.authorization.PermissionRequest) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) ClientBuilder(org.keycloak.testsuite.util.ClientBuilder) ClientScopeBuilder(org.keycloak.testsuite.util.ClientScopeBuilder) ClientScopePolicyRepresentation(org.keycloak.representations.idm.authorization.ClientScopePolicyRepresentation) ClientScopePolicyRepresentation(org.keycloak.representations.idm.authorization.ClientScopePolicyRepresentation) ClientScopeRepresentation(org.keycloak.representations.idm.ClientScopeRepresentation) ClientScopesResource(org.keycloak.admin.client.resource.ClientScopesResource) Test(org.junit.Test)

Example 3 with ClientScopePolicyRepresentation

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();
}
Also used : ClientScopePolicyRepresentation(org.keycloak.representations.idm.authorization.ClientScopePolicyRepresentation)

Aggregations

ClientScopePolicyRepresentation (org.keycloak.representations.idm.authorization.ClientScopePolicyRepresentation)3 List (java.util.List)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Assert.assertNull (org.junit.Assert.assertNull)1 Assert.fail (org.junit.Assert.fail)1 Before (org.junit.Before)1 Test (org.junit.Test)1 AuthorizationResource (org.keycloak.admin.client.resource.AuthorizationResource)1 ClientResource (org.keycloak.admin.client.resource.ClientResource)1 ClientScopesResource (org.keycloak.admin.client.resource.ClientScopesResource)1 ClientsResource (org.keycloak.admin.client.resource.ClientsResource)1 RealmResource (org.keycloak.admin.client.resource.RealmResource)1 AuthorizationDeniedException (org.keycloak.authorization.client.AuthorizationDeniedException)1 AuthzClient (org.keycloak.authorization.client.AuthzClient)1 ClientScopeRepresentation (org.keycloak.representations.idm.ClientScopeRepresentation)1 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)1 AuthorizationRequest (org.keycloak.representations.idm.authorization.AuthorizationRequest)1 AuthorizationResponse (org.keycloak.representations.idm.authorization.AuthorizationResponse)1 PermissionRequest (org.keycloak.representations.idm.authorization.PermissionRequest)1