Search in sources :

Example 1 with AdapterConfig

use of org.keycloak.representations.adapters.config.AdapterConfig in project keycloak by keycloak.

the class KeycloakDeploymentTest method stripDefaultPorts.

@Test
public void stripDefaultPorts() {
    KeycloakDeployment keycloakDeployment = new KeycloakDeploymentMock();
    keycloakDeployment.setRealm("test");
    AdapterConfig config = new AdapterConfig();
    config.setAuthServerUrl("http://localhost:80/auth");
    keycloakDeployment.setAuthServerBaseUrl(config);
    assertEquals("http://localhost/auth", keycloakDeployment.getAuthServerBaseUrl());
    config.setAuthServerUrl("https://localhost:443/auth");
    keycloakDeployment.setAuthServerBaseUrl(config);
    assertEquals("https://localhost/auth", keycloakDeployment.getAuthServerBaseUrl());
}
Also used : AdapterConfig(org.keycloak.representations.adapters.config.AdapterConfig) Test(org.junit.Test)

Example 2 with AdapterConfig

use of org.keycloak.representations.adapters.config.AdapterConfig in project keycloak by keycloak.

the class KeycloakDeploymentBuilder method loadAdapterConfig.

public static AdapterConfig loadAdapterConfig(InputStream is) {
    ObjectMapper mapper = new ObjectMapper(new SystemPropertiesJsonParserFactory());
    mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
    AdapterConfig adapterConfig;
    try {
        adapterConfig = mapper.readValue(is, AdapterConfig.class);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return adapterConfig;
}
Also used : SystemPropertiesJsonParserFactory(org.keycloak.util.SystemPropertiesJsonParserFactory) AdapterConfig(org.keycloak.representations.adapters.config.AdapterConfig) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with AdapterConfig

use of org.keycloak.representations.adapters.config.AdapterConfig in project keycloak by keycloak.

the class SubsystemParsingTestCase method testJsonHttpClientAttributes.

@Test
public void testJsonHttpClientAttributes() {
    KeycloakAdapterConfigService service = KeycloakAdapterConfigService.getInstance();
    // add a secure deployment
    PathAddress addr = PathAddress.pathAddress(PathElement.pathElement("subsystem", "keycloak"), PathElement.pathElement("secure-deployment", "foo"));
    ModelNode deploymentOp = new ModelNode();
    deploymentOp.get(ModelDescriptionConstants.OP_ADDR).set(addr.toModelNode());
    ModelNode deployment = new ModelNode();
    deployment.get("realm").set("demo");
    deployment.get("resource").set("customer-portal");
    deployment.get(SharedAttributeDefinitons.SOCKET_TIMEOUT.getName()).set(3000L);
    deployment.get(SharedAttributeDefinitons.CONNECTION_TIMEOUT.getName()).set(5000L);
    deployment.get(SharedAttributeDefinitons.CONNECTION_TTL.getName()).set(1000L);
    service.addSecureDeployment(deploymentOp, deployment, false);
    // get the subsystem config as JSON
    String jsonConfig = service.getJSON("foo");
    // attempt to create an adapter config instance from the subsystem JSON config
    AdapterConfig config = KeycloakDeploymentBuilder.loadAdapterConfig(new ByteArrayInputStream(jsonConfig.getBytes()));
    assertThat(config, CoreMatchers.notNullValue());
    assertThat(config.getSocketTimeout(), CoreMatchers.notNullValue());
    assertThat(config.getSocketTimeout(), CoreMatchers.is(3000L));
    assertThat(config.getConnectionTimeout(), CoreMatchers.notNullValue());
    assertThat(config.getConnectionTimeout(), CoreMatchers.is(5000L));
    assertThat(config.getConnectionTTL(), CoreMatchers.notNullValue());
    assertThat(config.getConnectionTTL(), CoreMatchers.is(1000L));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PathAddress(org.jboss.as.controller.PathAddress) AdapterConfig(org.keycloak.representations.adapters.config.AdapterConfig) ModelNode(org.jboss.dmr.ModelNode) AbstractSubsystemBaseTest(org.jboss.as.subsystem.test.AbstractSubsystemBaseTest) Test(org.junit.Test)

Example 4 with AdapterConfig

use of org.keycloak.representations.adapters.config.AdapterConfig in project keycloak by keycloak.

the class JsonParserTest method testParsingSystemProps.

@Test
public void testParsingSystemProps() throws IOException {
    System.setProperty("my.host", "foo");
    System.setProperty("con.pool.size", "200");
    System.setProperty("allow.any.hostname", "true");
    System.setProperty("socket.timeout.millis", "6000");
    System.setProperty("connection.timeout.millis", "7000");
    System.setProperty("connection.ttl.millis", "500");
    InputStream is = getClass().getClassLoader().getResourceAsStream("keycloak.json");
    AdapterConfig config = JsonSerialization.readValue(is, AdapterConfig.class, true);
    Assert.assertEquals("http://foo:8080/auth", config.getAuthServerUrl());
    Assert.assertEquals("external", config.getSslRequired());
    Assert.assertEquals("angular-product${non.existing}", config.getResource());
    Assert.assertTrue(config.isPublicClient());
    Assert.assertTrue(config.isAllowAnyHostname());
    Assert.assertEquals(100, config.getCorsMaxAge());
    Assert.assertEquals(200, config.getConnectionPoolSize());
    Assert.assertEquals(6000L, config.getSocketTimeout());
    Assert.assertEquals(7000L, config.getConnectionTimeout());
    Assert.assertEquals(500L, config.getConnectionTTL());
}
Also used : InputStream(java.io.InputStream) AdapterConfig(org.keycloak.representations.adapters.config.AdapterConfig) Test(org.junit.Test)

Example 5 with AdapterConfig

use of org.keycloak.representations.adapters.config.AdapterConfig in project keycloak by keycloak.

the class AdapterInstallationConfigTest method getConfigWithRegistrationAccessToken.

@Test
public void getConfigWithRegistrationAccessToken() throws ClientRegistrationException {
    reg.auth(Auth.token(client.getRegistrationAccessToken()));
    AdapterConfig config = reg.getAdapterConfig(client.getClientId());
    assertNotNull(config);
}
Also used : AdapterConfig(org.keycloak.representations.adapters.config.AdapterConfig) Test(org.junit.Test)

Aggregations

AdapterConfig (org.keycloak.representations.adapters.config.AdapterConfig)13 Test (org.junit.Test)7 IOException (java.io.IOException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 PathAddress (org.jboss.as.controller.PathAddress)2 AbstractSubsystemBaseTest (org.jboss.as.subsystem.test.AbstractSubsystemBaseTest)2 ModelNode (org.jboss.dmr.ModelNode)2 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)2 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)2 KeycloakDeployment (org.keycloak.adapters.KeycloakDeployment)2 SecurityException (com.canoo.platform.server.security.SecurityException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 CacheLoader (com.google.common.cache.CacheLoader)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 KeycloakConfigResolver (org.keycloak.adapters.KeycloakConfigResolver)1 Request (org.keycloak.adapters.spi.HttpFacade.Request)1 AdapterDeploymentContextFactoryBean (org.keycloak.adapters.springsecurity.AdapterDeploymentContextFactoryBean)1