use of org.keycloak.representations.idm.ClientProfilesRepresentation 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.ClientProfilesRepresentation in project keycloak by keycloak.
the class ClientPoliciesLoadUpdateTest method testUpdateValidProfilesAndPolicies.
@Test
public void testUpdateValidProfilesAndPolicies() throws Exception {
setupValidProfilesAndPolicies();
assertExpectedLoadedProfiles((ClientProfilesRepresentation reps) -> {
ClientProfileRepresentation rep = getProfileRepresentation(reps, "ordinal-test-profile", false);
assertExpectedProfile(rep, "ordinal-test-profile", "The profile that can be loaded.");
});
assertExpectedLoadedPolicies((ClientPoliciesRepresentation reps) -> {
ClientPolicyRepresentation rep = getPolicyRepresentation(reps, "new-policy");
assertExpectedPolicy("new-policy", "duplicated profiles are ignored.", true, Arrays.asList("ordinal-test-profile", "lack-of-builtin-field-test-profile"), rep);
});
// update existing profiles
String modifiedProfileDescription = "The profile has been updated.";
ClientProfilesRepresentation actualProfilesRep = getProfilesWithoutGlobals();
ClientProfilesBuilder profilesBuilder = new ClientProfilesBuilder();
actualProfilesRep.getProfiles().stream().forEach(i -> {
if (i.getName().equals("ordinal-test-profile")) {
i.setDescription(modifiedProfileDescription);
}
profilesBuilder.addProfile(i);
});
updateProfiles(profilesBuilder.toString());
assertExpectedLoadedProfiles((ClientProfilesRepresentation reps) -> {
ClientProfileRepresentation rep = getProfileRepresentation(reps, "ordinal-test-profile", false);
assertExpectedProfile(rep, "ordinal-test-profile", modifiedProfileDescription);
});
// update existing policies
String modifiedPolicyDescription = "The policy has also been updated.";
ClientPoliciesRepresentation actualPoliciesRep = getPolicies();
ClientPoliciesBuilder policiesBuilder = new ClientPoliciesBuilder();
actualPoliciesRep.getPolicies().stream().forEach(i -> {
if (i.getName().equals("new-policy")) {
i.setDescription(modifiedPolicyDescription);
i.setEnabled(null);
}
policiesBuilder.addPolicy(i);
});
updatePolicies(policiesBuilder.toString());
assertExpectedLoadedPolicies((ClientPoliciesRepresentation reps) -> {
ClientPolicyRepresentation rep = getPolicyRepresentation(reps, "new-policy");
assertExpectedPolicy("new-policy", modifiedPolicyDescription, false, Arrays.asList("ordinal-test-profile", "lack-of-builtin-field-test-profile"), rep);
});
}
use of org.keycloak.representations.idm.ClientProfilesRepresentation in project keycloak by keycloak.
the class AbstractClientPoliciesTest method addProfile.
protected void addProfile(ClientProfileRepresentation profileRep) throws ClientPolicyException {
ClientProfilesRepresentation reps = getProfilesWithoutGlobals();
if (reps == null || reps.getProfiles() == null)
return;
reps.getProfiles().add(profileRep);
updateProfiles(convertToProfilesJson(reps));
return;
}
use of org.keycloak.representations.idm.ClientProfilesRepresentation in project keycloak by keycloak.
the class AbstractClientPoliciesTest method updateProfile.
protected void updateProfile(ClientProfileRepresentation profileRep) throws ClientPolicyException {
if (profileRep == null || profileRep.getName() == null)
return;
String profileName = profileRep.getName();
ClientProfilesRepresentation reps = getProfilesWithoutGlobals();
if (reps.getProfiles().stream().anyMatch(i -> profileName.equals(i.getName()))) {
ClientProfileRepresentation rep = reps.getProfiles().stream().filter(i -> profileName.equals(i.getName())).collect(Collectors.toList()).get(0);
reps.getProfiles().remove(rep);
reps.getProfiles().add(profileRep);
updateProfiles(convertToProfilesJson(reps));
} else {
return;
}
}
use of org.keycloak.representations.idm.ClientProfilesRepresentation in project keycloak by keycloak.
the class AbstractClientPoliciesTest method updateProfiles.
// TODO: Possibly change this to accept ClientProfilesRepresentation instead of String to have more type-safety.
protected void updateProfiles(String json) throws ClientPolicyException {
try {
ClientProfilesRepresentation clientProfiles = JsonSerialization.readValue(json, ClientProfilesRepresentation.class);
adminClient.realm(REALM_NAME).clientPoliciesProfilesResource().updateProfiles(clientProfiles);
} catch (BadRequestException e) {
throw new ClientPolicyException("update profiles failed", e.getResponse().getStatusInfo().toString());
} catch (Exception e) {
throw new ClientPolicyException("update profiles failed", e.getMessage());
}
}
Aggregations