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