Search in sources :

Example 11 with ClientProfilesRepresentation

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());
}
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 12 with ClientProfilesRepresentation

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);
    });
}
Also used : ClientPolicyRepresentation(org.keycloak.representations.idm.ClientPolicyRepresentation) ClientProfileRepresentation(org.keycloak.representations.idm.ClientProfileRepresentation) ClientPoliciesRepresentation(org.keycloak.representations.idm.ClientPoliciesRepresentation) ClientProfilesBuilder(org.keycloak.testsuite.util.ClientPoliciesUtil.ClientProfilesBuilder) ClientPoliciesBuilder(org.keycloak.testsuite.util.ClientPoliciesUtil.ClientPoliciesBuilder) ClientProfilesRepresentation(org.keycloak.representations.idm.ClientProfilesRepresentation) Test(org.junit.Test)

Example 13 with ClientProfilesRepresentation

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;
}
Also used : ClientProfilesRepresentation(org.keycloak.representations.idm.ClientProfilesRepresentation)

Example 14 with ClientProfilesRepresentation

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;
    }
}
Also used : ClientProfileRepresentation(org.keycloak.representations.idm.ClientProfileRepresentation) ClientProfilesRepresentation(org.keycloak.representations.idm.ClientProfilesRepresentation)

Example 15 with ClientProfilesRepresentation

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());
    }
}
Also used : BadRequestException(javax.ws.rs.BadRequestException) ClientProfilesRepresentation(org.keycloak.representations.idm.ClientProfilesRepresentation) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) IOException(java.io.IOException) ClientPolicyException(org.keycloak.services.clientpolicy.ClientPolicyException) URISyntaxException(java.net.URISyntaxException) OAuthErrorException(org.keycloak.OAuthErrorException) BadRequestException(javax.ws.rs.BadRequestException) ClientRegistrationException(org.keycloak.client.registration.ClientRegistrationException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) NoSuchProviderException(java.security.NoSuchProviderException) ClientPolicyException(org.keycloak.services.clientpolicy.ClientPolicyException)

Aggregations

ClientProfilesRepresentation (org.keycloak.representations.idm.ClientProfilesRepresentation)20 ClientPoliciesRepresentation (org.keycloak.representations.idm.ClientPoliciesRepresentation)11 ClientProfileRepresentation (org.keycloak.representations.idm.ClientProfileRepresentation)9 Test (org.junit.Test)6 ClientPolicyRepresentation (org.keycloak.representations.idm.ClientPolicyRepresentation)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 Logger (org.jboss.logging.Logger)3 Profile (org.keycloak.common.Profile)3 ComponentModel (org.keycloak.component.ComponentModel)3 JsonConfigComponentModel (org.keycloak.component.JsonConfigComponentModel)3 Constants (org.keycloak.models.Constants)3 KeycloakSession (org.keycloak.models.KeycloakSession)3