Search in sources :

Example 21 with ClientScopeModel

use of org.keycloak.models.ClientScopeModel in project keycloak by keycloak.

the class ClientScopeEvaluateResource method toProtocolMapperEvaluationRepresentation.

private ProtocolMapperEvaluationRepresentation toProtocolMapperEvaluationRepresentation(ProtocolMapperModel mapper, ClientScopeModel mapperContainer) {
    ProtocolMapperEvaluationRepresentation rep = new ProtocolMapperEvaluationRepresentation();
    rep.setMapperId(mapper.getId());
    rep.setMapperName(mapper.getName());
    rep.setProtocolMapper(mapper.getProtocolMapper());
    if (mapperContainer.getId().equals(client.getId())) {
        // Must be this client
        rep.setContainerId(client.getId());
        rep.setContainerName("");
        rep.setContainerType("client");
    } else {
        ClientScopeModel clientScope = mapperContainer;
        rep.setContainerId(clientScope.getId());
        rep.setContainerName(clientScope.getName());
        rep.setContainerType("client-scope");
    }
    return rep;
}
Also used : ClientScopeModel(org.keycloak.models.ClientScopeModel)

Example 22 with ClientScopeModel

use of org.keycloak.models.ClientScopeModel in project keycloak by keycloak.

the class RealmAdminResource method addDefaultClientScope.

private void addDefaultClientScope(String clientScopeId, boolean defaultScope) {
    auth.clients().requireManageClientScopes();
    ClientScopeModel clientScope = realm.getClientScopeById(clientScopeId);
    if (clientScope == null) {
        throw new NotFoundException("Client scope not found");
    }
    realm.addDefaultClientScope(clientScope, defaultScope);
    adminEvent.operation(OperationType.CREATE).resource(ResourceType.CLIENT_SCOPE).resourcePath(session.getContext().getUri()).success();
}
Also used : NotFoundException(javax.ws.rs.NotFoundException) ClientScopeModel(org.keycloak.models.ClientScopeModel)

Example 23 with ClientScopeModel

use of org.keycloak.models.ClientScopeModel in project keycloak by keycloak.

the class ClientScopesResource method getClientScope.

/**
 * Base path for managing a specific client scope.
 *
 * @param id id of client scope (not name)
 * @return
 */
@Path("{id}")
@NoCache
public ClientScopeResource getClientScope(@PathParam("id") final String id) {
    auth.clients().requireListClientScopes();
    ClientScopeModel clientModel = realm.getClientScopeById(id);
    if (clientModel == null) {
        throw new NotFoundException("Could not find client scope");
    }
    ClientScopeResource clientResource = new ClientScopeResource(realm, auth, clientModel, session, adminEvent);
    ResteasyProviderFactory.getInstance().injectProperties(clientResource);
    return clientResource;
}
Also used : NotFoundException(javax.ws.rs.NotFoundException) ClientScopeModel(org.keycloak.models.ClientScopeModel) Path(javax.ws.rs.Path) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 24 with ClientScopeModel

use of org.keycloak.models.ClientScopeModel in project keycloak by keycloak.

the class ClientScopeStorageTest method testGetClientScopeById.

@Test
public void testGetClientScopeById() {
    getParameters(ClientScopeStorageProviderModel.class).forEach(fs -> inComittedTransaction(fs, (session, federatedStorage) -> {
        Assume.assumeThat("Cannot handle more than 1 client scope federation provider", clientScopeFederationId, Matchers.nullValue());
        RealmModel realm = session.realms().getRealm(realmId);
        federatedStorage.setParentId(realmId);
        federatedStorage.setEnabled(true);
        federatedStorage.getConfig().putSingle(HardcodedClientScopeStorageProviderFactory.SCOPE_NAME, HardcodedClientScopeStorageProviderFactory.SCOPE_NAME);
        ComponentModel res = realm.addComponentModel(federatedStorage);
        clientScopeFederationId = res.getId();
        log.infof("Added %s client scope federation provider: %s", federatedStorage.getName(), clientScopeFederationId);
        return null;
    }));
    inComittedTransaction(1, (session, i) -> {
        final RealmModel realm = session.realms().getRealm(realmId);
        StorageId storageId = new StorageId(clientScopeFederationId, "scope_name");
        ClientScopeModel hardcoded = session.clientScopes().getClientScopeById(realm, storageId.getId());
        Assert.assertNotNull(hardcoded);
        return null;
    });
}
Also used : ClientScopeStorageProviderModel(org.keycloak.storage.clientscope.ClientScopeStorageProviderModel) HardcodedClientScopeStorageProviderFactory(org.keycloak.testsuite.federation.HardcodedClientScopeStorageProviderFactory) ClientScopeModel(org.keycloak.models.ClientScopeModel) RealmModel(org.keycloak.models.RealmModel) Constants(org.keycloak.models.Constants) Matchers(org.hamcrest.Matchers) KeycloakSession(org.keycloak.models.KeycloakSession) Test(org.junit.Test) StorageId(org.keycloak.storage.StorageId) ClientScopeStorageProviderModel(org.keycloak.storage.clientscope.ClientScopeStorageProviderModel) RealmProvider(org.keycloak.models.RealmProvider) ComponentModel(org.keycloak.component.ComponentModel) Assume(org.junit.Assume) Assert(org.junit.Assert) ClientScopeStorageProvider(org.keycloak.storage.clientscope.ClientScopeStorageProvider) RealmModel(org.keycloak.models.RealmModel) ComponentModel(org.keycloak.component.ComponentModel) ClientScopeModel(org.keycloak.models.ClientScopeModel) StorageId(org.keycloak.storage.StorageId) Test(org.junit.Test)

Example 25 with ClientScopeModel

use of org.keycloak.models.ClientScopeModel in project keycloak by keycloak.

the class ClientScopePolicyProviderFactory method updateClientScopes.

private void updateClientScopes(Policy policy, AuthorizationProvider authorization, Set<ClientScopeDefinition> clientScopes) {
    RealmModel realm = authorization.getRealm();
    Set<ClientScopePolicyRepresentation.ClientScopeDefinition> updatedClientScopes = new HashSet<>();
    if (clientScopes != null) {
        for (ClientScopePolicyRepresentation.ClientScopeDefinition definition : clientScopes) {
            String clientScopeName = definition.getId();
            ClientScopeModel clientScope = realm.getClientScopesStream().filter(scope -> scope.getName().equals(clientScopeName)).findAny().orElse(null);
            if (clientScope == null) {
                clientScope = realm.getClientScopeById(clientScopeName);
            }
            if (clientScope == null) {
                throw new RuntimeException("Error while updating policy [" + policy.getName() + "]. Client Scope [" + "] could not be found.");
            }
            definition.setId(clientScope.getId());
            updatedClientScopes.add(definition);
        }
    }
    try {
        policy.putConfig("clientScopes", JsonSerialization.writeValueAsString(updatedClientScopes));
    } catch (IOException e) {
        throw new RuntimeException("Failed to serialize client scopes", e);
    }
}
Also used : RealmModel(org.keycloak.models.RealmModel) ClientScopeDefinition(org.keycloak.representations.idm.authorization.ClientScopePolicyRepresentation.ClientScopeDefinition) ClientScopeDefinition(org.keycloak.representations.idm.authorization.ClientScopePolicyRepresentation.ClientScopeDefinition) ClientScopePolicyRepresentation(org.keycloak.representations.idm.authorization.ClientScopePolicyRepresentation) ClientScopeModel(org.keycloak.models.ClientScopeModel) IOException(java.io.IOException) HashSet(java.util.HashSet)

Aggregations

ClientScopeModel (org.keycloak.models.ClientScopeModel)58 ClientModel (org.keycloak.models.ClientModel)22 RealmModel (org.keycloak.models.RealmModel)18 KeycloakSession (org.keycloak.models.KeycloakSession)17 UserConsentModel (org.keycloak.models.UserConsentModel)14 HashMap (java.util.HashMap)11 Map (java.util.Map)9 UserModel (org.keycloak.models.UserModel)9 HashSet (java.util.HashSet)8 Test (org.junit.Test)8 RoleModel (org.keycloak.models.RoleModel)8 MultivaluedHashMap (org.keycloak.common.util.MultivaluedHashMap)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 NotFoundException (javax.ws.rs.NotFoundException)6 ArtifactBindingUtils.computeArtifactBindingIdentifierString (org.keycloak.protocol.saml.util.ArtifactBindingUtils.computeArtifactBindingIdentifierString)6 ModelTest (org.keycloak.testsuite.arquillian.annotation.ModelTest)6 IOException (java.io.IOException)5 Path (javax.ws.rs.Path)5 NoCache (org.jboss.resteasy.annotations.cache.NoCache)5