Search in sources :

Example 1 with ClientPolicyConditionConfigurationRepresentation

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

the class JsonParserTest method testReadClientPolicy.

@Test
public void testReadClientPolicy() throws Exception {
    InputStream is = getClass().getClassLoader().getResourceAsStream("sample-client-policy.json");
    ClientPoliciesRepresentation clientPolicies = JsonSerialization.readValue(is, ClientPoliciesRepresentation.class);
    Assert.assertEquals(clientPolicies.getPolicies().size(), 1);
    ClientPolicyRepresentation clientPolicy = clientPolicies.getPolicies().get(0);
    Assert.assertEquals("some-policy", clientPolicy.getName());
    List<ClientPolicyConditionRepresentation> conditions = clientPolicy.getConditions();
    Assert.assertEquals(conditions.size(), 1);
    ClientPolicyConditionRepresentation condition = conditions.get(0);
    Assert.assertEquals("some-condition", condition.getConditionProviderId());
    ClientPolicyConditionConfigurationRepresentation configRep = JsonSerialization.mapper.convertValue(condition.getConfiguration(), ClientPolicyConditionConfigurationRepresentation.class);
    Assert.assertEquals(true, configRep.isNegativeLogic());
    Assert.assertEquals("val1", configRep.getConfigAsMap().get("string-option"));
    Assert.assertEquals(14, configRep.getConfigAsMap().get("int-option"));
    Assert.assertEquals(true, configRep.getConfigAsMap().get("bool-option"));
    Assert.assertNull(configRep.getConfigAsMap().get("not-existing-option"));
}
Also used : ClientPolicyRepresentation(org.keycloak.representations.idm.ClientPolicyRepresentation) ClientPolicyConditionConfigurationRepresentation(org.keycloak.representations.idm.ClientPolicyConditionConfigurationRepresentation) InputStream(java.io.InputStream) ClientPoliciesRepresentation(org.keycloak.representations.idm.ClientPoliciesRepresentation) ClientPolicyConditionRepresentation(org.keycloak.representations.idm.ClientPolicyConditionRepresentation) Test(org.junit.Test)

Example 2 with ClientPolicyConditionConfigurationRepresentation

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

the class ClientPoliciesUtil method getConditionProvider.

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

Example 3 with ClientPolicyConditionConfigurationRepresentation

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

the class ClientPoliciesUtil method createAnyClientConditionConfig.

public static ClientPolicyConditionConfigurationRepresentation createAnyClientConditionConfig(Boolean isNegativeLogic) {
    ClientPolicyConditionConfigurationRepresentation config = new ClientPolicyConditionConfigurationRepresentation();
    config.setNegativeLogic(isNegativeLogic);
    return config;
}
Also used : ClientPolicyConditionConfigurationRepresentation(org.keycloak.representations.idm.ClientPolicyConditionConfigurationRepresentation)

Example 4 with ClientPolicyConditionConfigurationRepresentation

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

the class AbstractClientPoliciesTest method assertExpectedAnyClientCondition.

protected void assertExpectedAnyClientCondition(ClientPolicyRepresentation policyRep) {
    ClientPolicyConditionConfigurationRepresentation config = getConfigAsExpectedType(policyRep, AnyClientConditionFactory.PROVIDER_ID, ClientPolicyConditionConfigurationRepresentation.class);
    Assert.assertTrue("Expected empty configuration for provider " + AnyClientConditionFactory.PROVIDER_ID, config.getConfigAsMap().isEmpty());
}
Also used : ClientPolicyConditionConfigurationRepresentation(org.keycloak.representations.idm.ClientPolicyConditionConfigurationRepresentation)

Aggregations

ClientPolicyConditionConfigurationRepresentation (org.keycloak.representations.idm.ClientPolicyConditionConfigurationRepresentation)4 InputStream (java.io.InputStream)1 Test (org.junit.Test)1 ComponentModel (org.keycloak.component.ComponentModel)1 JsonConfigComponentModel (org.keycloak.component.JsonConfigComponentModel)1 ClientPoliciesRepresentation (org.keycloak.representations.idm.ClientPoliciesRepresentation)1 ClientPolicyConditionRepresentation (org.keycloak.representations.idm.ClientPolicyConditionRepresentation)1 ClientPolicyRepresentation (org.keycloak.representations.idm.ClientPolicyRepresentation)1 ClientPolicyConditionProvider (org.keycloak.services.clientpolicy.condition.ClientPolicyConditionProvider)1