use of org.keycloak.representations.adapters.config.AdapterConfig in project keycloak by keycloak.
the class AdapterInstallationConfigTest method getConfigPublicClient.
@Test
public void getConfigPublicClient() throws ClientRegistrationException {
reg.auth(null);
AdapterConfig config = reg.getAdapterConfig(clientPublic.getClientId());
assertNotNull(config);
assertEquals("test", config.getRealm());
assertEquals(0, config.getCredentials().size());
assertEquals(clientPublic.getClientId(), config.getResource());
if (AUTH_SERVER_SSL_REQUIRED)
assertEquals(SslRequired.EXTERNAL.name().toLowerCase(), config.getSslRequired());
}
use of org.keycloak.representations.adapters.config.AdapterConfig in project dolphin-platform by canoo.
the class DolphinKeycloakConfigResolver method resolve.
public KeycloakDeployment resolve(final HttpFacade.Request request) {
Assert.requireNonNull(request, "request");
final String realmName = Optional.ofNullable(request.getHeader(REALM_NAME_HEADER)).orElse(configuration.getRealmName());
final String applicationName = Optional.ofNullable(request.getHeader(APPLICATION_NAME_HEADER)).orElse(configuration.getApplicationName());
final String authEndPoint = configuration.getAuthEndpoint();
final boolean cors = configuration.isCors();
Optional.ofNullable(realmName).orElseThrow(() -> new SecurityException("Realm name for security check is not configured!"));
Optional.ofNullable(applicationName).orElseThrow(() -> new SecurityException("Application name for security check is not configured!"));
Optional.ofNullable(authEndPoint).orElseThrow(() -> new SecurityException("Auth endpoint for security check is not configured!"));
LOG.debug("Defined Keycloak AdapterConfig for request against realm '" + realmName + "' and app '" + applicationName + "'");
final AdapterConfig adapterConfig = new AdapterConfig();
LOG.debug("Checking if realm '" + realmName + "' is allowed");
if (isRealmAllowed(realmName)) {
adapterConfig.setRealm(realmName);
} else {
if (LOG.isDebugEnabled()) {
final String allowedRealms = configuration.getRealmNames().stream().reduce("", (a, b) -> a + "," + b);
LOG.debug("Realm '" + realmName + "' is not allowed! Allowed realms are {}", allowedRealms);
}
throw new SecurityException("Access Denied! The given realm is not in the allowed realms.");
}
adapterConfig.setResource(applicationName);
adapterConfig.setAuthServerUrl(authEndPoint);
adapterConfig.setCors(cors);
Optional.ofNullable(request.getHeader(BEARER_ONLY_HEADER)).ifPresent(v -> adapterConfig.setBearerOnly(true));
return KeycloakDeploymentBuilder.build(adapterConfig);
}
use of org.keycloak.representations.adapters.config.AdapterConfig in project openremote by openremote.
the class KeycloakIdentityProvider method createKeycloakDeploymentCache.
protected LoadingCache<KeycloakRealmClient, KeycloakDeployment> createKeycloakDeploymentCache() {
CacheLoader<KeycloakRealmClient, KeycloakDeployment> loader = new CacheLoader<KeycloakRealmClient, KeycloakDeployment>() {
public KeycloakDeployment load(KeycloakRealmClient keycloakRealmClient) {
LOG.fine("Loading adapter config for client '" + keycloakRealmClient.clientId + "' in realm '" + keycloakRealmClient.realm + "'");
// KeycloakResource keycloak = getKeycloak();
KeycloakResource keycloak = getTarget(httpClient, keycloakServiceUri.build(), null, null, null).proxy(KeycloakResource.class);
// Can't get adapter for client in another realm
AdapterConfig adapterConfig = keycloak.getAdapterConfig(// keycloakRealmClient.clientId
keycloakRealmClient.realm, // keycloakRealmClient.clientId
KEYCLOAK_CLIENT_ID);
// The auth-server-url in the adapter config must be reachable by this manager it will be the frontend URL by default
adapterConfig.setAuthServerUrl(keycloakServiceUri.clone().build().toString());
return KeycloakDeploymentBuilder.build(adapterConfig);
}
};
// TODO configurable? Or replace all of this with Observable.cache()?
return CacheBuilder.newBuilder().maximumSize(500).expireAfterWrite(10, MINUTES).build(loader);
}
use of org.keycloak.representations.adapters.config.AdapterConfig in project keycloak by keycloak.
the class SubsystemParsingTestCase method testJsonFromRedirectRewriteRuleConfiguration.
/**
* Tests a subsystem configuration that contains a {@code redirect-rewrite-rule}, checking that the resulting JSON
* can be properly used to create an {@link AdapterConfig}.
*
* Added as part of the fix for {@code KEYCLOAK-18302}.
*/
@Test
public void testJsonFromRedirectRewriteRuleConfiguration() {
KeycloakAdapterConfigService service = KeycloakAdapterConfigService.getInstance();
// add a secure deployment with a redirect-rewrite-rule
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");
service.addSecureDeployment(deploymentOp, deployment, false);
this.addRedirectRewriteRule(addr, service, "^/wsmaster/api/(.*)$", "api/$1");
// 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()));
Assert.assertNotNull(config);
// assert that the config has the configured rule
Map<String, String> redirectRewriteRules = config.getRedirectRewriteRules();
Assert.assertNotNull(redirectRewriteRules);
Map.Entry<String, String> entry = redirectRewriteRules.entrySet().iterator().next();
Assert.assertEquals("^/wsmaster/api/(.*)$", entry.getKey());
Assert.assertEquals("api/$1", entry.getValue());
}
use of org.keycloak.representations.adapters.config.AdapterConfig in project shinyproxy by openanalytics.
the class KeycloakAuthenticationBackend method adapterDeploymentContext.
@Bean
@ConditionalOnProperty(name = "shiny.proxy.authentication", havingValue = "keycloak")
protected AdapterDeploymentContext adapterDeploymentContext() throws Exception {
AdapterConfig cfg = new AdapterConfig();
cfg.setRealm(environment.getProperty("shiny.proxy.keycloak.realm"));
cfg.setAuthServerUrl(environment.getProperty("shiny.proxy.keycloak.auth-server-url"));
cfg.setResource(environment.getProperty("shiny.proxy.keycloak.resource"));
Map<String, Object> credentials = new HashMap<>();
credentials.put("secret", environment.getProperty("shiny.proxy.keycloak.credentials-secret"));
cfg.setCredentials(credentials);
KeycloakDeployment dep = KeycloakDeploymentBuilder.build(cfg);
AdapterDeploymentContextFactoryBean factoryBean = new AdapterDeploymentContextFactoryBean(new KeycloakConfigResolver() {
@Override
public KeycloakDeployment resolve(Request facade) {
return dep;
}
});
factoryBean.afterPropertiesSet();
return factoryBean.getObject();
}
Aggregations