Search in sources :

Example 6 with ClientPoliciesRepresentation

use of org.keycloak.representations.idm.ClientPoliciesRepresentation in project keycloak by keycloak.

the class MigrateTo14_0_0 method migrateRealm.

private void migrateRealm(KeycloakSession session, RealmModel realm) {
    try {
        session.clientPolicy().updateClientProfiles(realm, new ClientProfilesRepresentation());
        session.clientPolicy().updateClientPolicies(realm, new ClientPoliciesRepresentation());
    } catch (ClientPolicyException cpe) {
        throw new ModelException("Exception during migration client profiles or client policies", cpe);
    }
}
Also used : ModelException(org.keycloak.models.ModelException) ClientPoliciesRepresentation(org.keycloak.representations.idm.ClientPoliciesRepresentation) ClientProfilesRepresentation(org.keycloak.representations.idm.ClientProfilesRepresentation) ClientPolicyException(org.keycloak.services.clientpolicy.ClientPolicyException)

Example 7 with ClientPoliciesRepresentation

use of org.keycloak.representations.idm.ClientPoliciesRepresentation in project keycloak by keycloak.

the class DefaultClientPolicyManager method updateRealmModelFromRepresentation.

@Override
public void updateRealmModelFromRepresentation(RealmModel realm, RealmRepresentation rep) {
    logger.tracev("LOAD PROFILE POLICIES ON IMPORTED REALM :: realm = {0}", realm.getName());
    if (rep.getParsedClientProfiles() != null) {
        try {
            updateClientProfiles(realm, rep.getParsedClientProfiles());
        } catch (ClientPolicyException e) {
            logger.warnv("VALIDATE SERIALIZE IMPORTED REALM PROFILES FAILED :: error = {0}, error detail = {1}", e.getError(), e.getErrorDetail());
            throw new RuntimeException("Failed to update client profiles", e);
        }
    }
    ClientPoliciesRepresentation clientPolicies = rep.getParsedClientPolicies();
    if (clientPolicies != null) {
        try {
            updateClientPolicies(realm, clientPolicies);
        } catch (ClientPolicyException e) {
            logger.warnv("VALIDATE SERIALIZE IMPORTED REALM POLICIES FAILED :: error = {0}, error detail = {1}", e.getError(), e.getErrorDetail());
            throw new RuntimeException("Failed to update client policies", e);
        }
    } else {
        setupClientPoliciesOnCreatedRealm(realm);
    }
}
Also used : ClientPoliciesRepresentation(org.keycloak.representations.idm.ClientPoliciesRepresentation)

Example 8 with ClientPoliciesRepresentation

use of org.keycloak.representations.idm.ClientPoliciesRepresentation in project keycloak by keycloak.

the class DefaultClientPolicyManager method updateRealmRepresentationFromModel.

@Override
public void updateRealmRepresentationFromModel(RealmModel realm, RealmRepresentation rep) {
    try {
        // client profiles  that filter out global profiles..
        ClientProfilesRepresentation filteredOutProfiles = getClientProfiles(realm, false);
        rep.setParsedClientProfiles(filteredOutProfiles);
        ClientPoliciesRepresentation filteredOutPolicies = getClientPolicies(realm);
        rep.setParsedClientPolicies(filteredOutPolicies);
    } catch (ClientPolicyException cpe) {
        throw new IllegalStateException("Exception during export client profiles or client policies", cpe);
    }
}
Also used : ClientPoliciesRepresentation(org.keycloak.representations.idm.ClientPoliciesRepresentation) ClientProfilesRepresentation(org.keycloak.representations.idm.ClientProfilesRepresentation)

Example 9 with ClientPoliciesRepresentation

use of org.keycloak.representations.idm.ClientPoliciesRepresentation in project keycloak by keycloak.

the class JsonFileImport1301MigrationClientPoliciesTest method migration13_0_1_Test.

@Test
public void migration13_0_1_Test() throws Exception {
    RealmRepresentation testRealm = adminClient.realms().realm("test").toRepresentation();
    // Stick to null for now. No support for proper migration from Keycloak 13 as client policies was preview and JSON format was changed significantly
    Assert.assertTrue(testRealm.getParsedClientProfiles().getProfiles().isEmpty());
    Assert.assertTrue(testRealm.getParsedClientPolicies().getPolicies().isEmpty());
    ClientProfilesRepresentation clientProfiles = adminClient.realms().realm("test").clientPoliciesProfilesResource().getProfiles(false);
    Assert.assertTrue(clientProfiles.getProfiles().isEmpty());
    ClientPoliciesRepresentation clientPolicies = adminClient.realms().realm("test").clientPoliciesPoliciesResource().getPolicies();
    Assert.assertTrue(clientPolicies.getPolicies().isEmpty());
}
Also used : ClientPoliciesRepresentation(org.keycloak.representations.idm.ClientPoliciesRepresentation) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) ClientProfilesRepresentation(org.keycloak.representations.idm.ClientProfilesRepresentation) Test(org.junit.Test)

Example 10 with ClientPoliciesRepresentation

use of org.keycloak.representations.idm.ClientPoliciesRepresentation in project keycloak by keycloak.

the class ClientPoliciesFeatureTest method checkIfFeatureWorks.

// Check if the feature really works
private void checkIfFeatureWorks(boolean shouldWork) {
    try {
        ClientPoliciesRepresentation clientPolicies = testRealm().clientPoliciesPoliciesResource().getPolicies();
        Assert.assertTrue(clientPolicies.getPolicies().isEmpty());
        if (!shouldWork)
            fail("Feature is available, but at this moment should be disabled");
    } catch (Exception e) {
        if (shouldWork) {
            e.printStackTrace();
            fail("Feature is not available");
        }
    }
    ServerInfoRepresentation serverInfo = adminClient.serverInfo().getInfo();
    Set<String> executorProviderIds = serverInfo.getProviders().get(ClientPolicyExecutorSpi.SPI_NAME).getProviders().keySet();
    Set<String> conditionProviderIds = serverInfo.getProviders().get(ClientPolicyConditionSpi.SPI_NAME).getProviders().keySet();
    if (shouldWork) {
        Assert.assertTrue(executorProviderIds.contains(SecureResponseTypeExecutorFactory.PROVIDER_ID));
        Assert.assertTrue(conditionProviderIds.contains(ClientUpdaterContextConditionFactory.PROVIDER_ID));
    } else {
        Assert.assertFalse(executorProviderIds.contains(SecureResponseTypeExecutorFactory.PROVIDER_ID));
        Assert.assertFalse(conditionProviderIds.contains(ClientUpdaterContextConditionFactory.PROVIDER_ID));
    }
}
Also used : ClientPoliciesRepresentation(org.keycloak.representations.idm.ClientPoliciesRepresentation) ServerInfoRepresentation(org.keycloak.representations.info.ServerInfoRepresentation)

Aggregations

ClientPoliciesRepresentation (org.keycloak.representations.idm.ClientPoliciesRepresentation)21 ClientPolicyRepresentation (org.keycloak.representations.idm.ClientPolicyRepresentation)9 ClientProfilesRepresentation (org.keycloak.representations.idm.ClientProfilesRepresentation)9 Test (org.junit.Test)6 ClientProfileRepresentation (org.keycloak.representations.idm.ClientProfileRepresentation)4 ClientPolicyConditionRepresentation (org.keycloak.representations.idm.ClientPolicyConditionRepresentation)3 ClientPoliciesBuilder (org.keycloak.testsuite.util.ClientPoliciesUtil.ClientPoliciesBuilder)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 ClientPolicyConditionConfigurationRepresentation (org.keycloak.representations.idm.ClientPolicyConditionConfigurationRepresentation)2 ClientPolicyException (org.keycloak.services.clientpolicy.ClientPolicyException)2 ClientPolicyConditionProvider (org.keycloak.services.clientpolicy.condition.ClientPolicyConditionProvider)2 ClientPolicyBuilder (org.keycloak.testsuite.util.ClientPoliciesUtil.ClientPolicyBuilder)2 ClientProfilesBuilder (org.keycloak.testsuite.util.ClientPoliciesUtil.ClientProfilesBuilder)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Collections (java.util.Collections)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Set (java.util.Set)1