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;
}
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();
}
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;
}
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;
});
}
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);
}
}
Aggregations