Search in sources :

Example 1 with ClientPolicyExecutorProvider

use of org.keycloak.services.clientpolicy.executor.ClientPolicyExecutorProvider in project keycloak by keycloak.

the class ClientPoliciesUtil method getExecutorProvider.

private static ClientPolicyExecutorProvider getExecutorProvider(KeycloakSession session, RealmModel realm, String providerId, JsonNode config) {
    ComponentModel componentModel = new JsonConfigComponentModel(ClientPolicyExecutorProvider.class, realm.getId(), providerId, config);
    ClientPolicyExecutorProvider executorProvider = session.getComponentProvider(ClientPolicyExecutorProvider.class, componentModel.getId(), sessionFactory -> componentModel);
    if (executorProvider == null) {
        // condition's provider not found. just skip it.
        throw new IllegalStateException("Executor with provider ID " + providerId + " not found");
    }
    ClientPolicyExecutorConfigurationRepresentation configuration = (ClientPolicyExecutorConfigurationRepresentation) JsonSerialization.mapper.convertValue(config, executorProvider.getExecutorConfigurationClass());
    executorProvider.setupConfiguration(configuration);
    return executorProvider;
}
Also used : ClientPolicyExecutorProvider(org.keycloak.services.clientpolicy.executor.ClientPolicyExecutorProvider) ComponentModel(org.keycloak.component.ComponentModel) JsonConfigComponentModel(org.keycloak.component.JsonConfigComponentModel) ClientPolicyExecutorConfigurationRepresentation(org.keycloak.representations.idm.ClientPolicyExecutorConfigurationRepresentation) JsonConfigComponentModel(org.keycloak.component.JsonConfigComponentModel)

Example 2 with ClientPolicyExecutorProvider

use of org.keycloak.services.clientpolicy.executor.ClientPolicyExecutorProvider in project keycloak by keycloak.

the class ClientPoliciesUtil method getClientProfileModel.

/**
 * Gets existing client profile of given name with resolved executor providers. It can be profile from realm or from global client profiles.
 */
static ClientProfile getClientProfileModel(KeycloakSession session, RealmModel realm, ClientProfilesRepresentation profilesRep, List<ClientProfileRepresentation> globalClientProfiles, String profileName) throws ClientPolicyException {
    // Obtain profiles from realm
    List<ClientProfileRepresentation> profiles = profilesRep.getProfiles();
    if (profiles == null) {
        profiles = new ArrayList<>();
    }
    // Add global profiles as well
    profiles.addAll(globalClientProfiles);
    ClientProfileRepresentation profileRep = profiles.stream().filter(clientProfile -> profileName.equals(clientProfile.getName())).findFirst().orElse(null);
    if (profileRep == null) {
        return null;
    }
    ClientProfile profileModel = new ClientProfile();
    profileModel.setName(profileRep.getName());
    profileModel.setDescription(profileRep.getDescription());
    if (profileRep.getExecutors() == null) {
        profileModel.setExecutors(new ArrayList<>());
        return profileModel;
    }
    List<ClientPolicyExecutorProvider> executors = new ArrayList<>();
    if (profileRep.getExecutors() != null) {
        for (ClientPolicyExecutorRepresentation executorRep : profileRep.getExecutors()) {
            ClientPolicyExecutorProvider provider = getExecutorProvider(session, realm, executorRep.getExecutorProviderId(), executorRep.getConfiguration());
            executors.add(provider);
        }
    }
    profileModel.setExecutors(executors);
    return profileModel;
}
Also used : ClientPolicyExecutorProvider(org.keycloak.services.clientpolicy.executor.ClientPolicyExecutorProvider) ClientProfileRepresentation(org.keycloak.representations.idm.ClientProfileRepresentation) ClientPolicyExecutorRepresentation(org.keycloak.representations.idm.ClientPolicyExecutorRepresentation) ArrayList(java.util.ArrayList)

Example 3 with ClientPolicyExecutorProvider

use of org.keycloak.services.clientpolicy.executor.ClientPolicyExecutorProvider in project keycloak by keycloak.

the class DefaultClientPolicyManager method triggerOnEvent.

@Override
public void triggerOnEvent(ClientPolicyContext context) throws ClientPolicyException {
    if (!Profile.isFeatureEnabled(Profile.Feature.CLIENT_POLICIES)) {
        return;
    }
    RealmModel realm = session.getContext().getRealm();
    logger.tracev("POLICY OPERATION :: context realm = {0}, event = {1}", realm.getName(), context.getEvent());
    doPolicyOperation((ClientPolicyConditionProvider condition) -> condition.applyPolicy(context), (ClientPolicyExecutorProvider executor) -> executor.executeOnEvent(context), realm);
}
Also used : RealmModel(org.keycloak.models.RealmModel) ClientPolicyConditionProvider(org.keycloak.services.clientpolicy.condition.ClientPolicyConditionProvider) ClientPolicyExecutorProvider(org.keycloak.services.clientpolicy.executor.ClientPolicyExecutorProvider)

Aggregations

ClientPolicyExecutorProvider (org.keycloak.services.clientpolicy.executor.ClientPolicyExecutorProvider)3 ArrayList (java.util.ArrayList)1 ComponentModel (org.keycloak.component.ComponentModel)1 JsonConfigComponentModel (org.keycloak.component.JsonConfigComponentModel)1 RealmModel (org.keycloak.models.RealmModel)1 ClientPolicyExecutorConfigurationRepresentation (org.keycloak.representations.idm.ClientPolicyExecutorConfigurationRepresentation)1 ClientPolicyExecutorRepresentation (org.keycloak.representations.idm.ClientPolicyExecutorRepresentation)1 ClientProfileRepresentation (org.keycloak.representations.idm.ClientProfileRepresentation)1 ClientPolicyConditionProvider (org.keycloak.services.clientpolicy.condition.ClientPolicyConditionProvider)1