diff --git a/adapters/oidc/fuse7/camel-undertow/pom.xml b/adapters/oidc/fuse7/camel-undertow/pom.xml index 95363c3954..a05406d1b2 100644 --- a/adapters/oidc/fuse7/camel-undertow/pom.xml +++ b/adapters/oidc/fuse7/camel-undertow/pom.xml @@ -87,12 +87,12 @@ org.apache.camel camel-undertow - 2.21.0 + 2.21.2 org.apache.camel camel-core - 2.21.0 + 2.21.2 diff --git a/adapters/oidc/fuse7/camel-undertow/src/main/java/org/keycloak/adapters/camel/undertow/UndertowKeycloakComponent.java b/adapters/oidc/fuse7/camel-undertow/src/main/java/org/keycloak/adapters/camel/undertow/UndertowKeycloakComponent.java index 9b9219b8ea..8592112660 100644 --- a/adapters/oidc/fuse7/camel-undertow/src/main/java/org/keycloak/adapters/camel/undertow/UndertowKeycloakComponent.java +++ b/adapters/oidc/fuse7/camel-undertow/src/main/java/org/keycloak/adapters/camel/undertow/UndertowKeycloakComponent.java @@ -19,20 +19,9 @@ package org.keycloak.adapters.camel.undertow; import java.net.URI; import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; import org.apache.camel.CamelContext; -import org.apache.camel.Consumer; -import org.apache.camel.Processor; -import org.apache.camel.component.undertow.RestUndertowHttpBinding; import org.apache.camel.component.undertow.UndertowComponent; import org.apache.camel.component.undertow.UndertowEndpoint; -import org.apache.camel.spi.RestConfiguration; -import org.apache.camel.util.FileUtil; -import org.apache.camel.util.HostUtils; -import org.apache.camel.util.ObjectHelper; -import org.apache.camel.util.URISupport; /** * @@ -52,136 +41,8 @@ public class UndertowKeycloakComponent extends UndertowComponent { return new UndertowKeycloakEndpoint(endpointUri.toString(), component); } - // TODO: uncomment line below after backport of https://issues.apache.org/jira/browse/CAMEL-12514 into fuse -// @Override + @Override protected String getComponentName() { return "undertow-keycloak"; } - - // TODO: remove all below this line after backport of https://issues.apache.org/jira/browse/CAMEL-12514 into fuse - @Override - public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String basePath, String uriTemplate, - String consumes, String produces, RestConfiguration configuration, Map parameters) throws Exception { - return doCreateConsumer(camelContext, processor, verb, basePath, uriTemplate, consumes, produces, configuration, parameters, false); - } - - @Override - public Consumer createApiConsumer(CamelContext camelContext, Processor processor, String contextPath, - RestConfiguration configuration, Map parameters) throws Exception { - // reuse the createConsumer method we already have. The api need to use GET and match on uri prefix - return doCreateConsumer(camelContext, processor, "GET", contextPath, null, null, null, configuration, parameters, true); - } - - Consumer doCreateConsumer(CamelContext camelContext, Processor processor, String verb, String basePath, String uriTemplate, - String consumes, String produces, RestConfiguration configuration, Map parameters, boolean api) throws Exception { - String path = basePath; - if (uriTemplate != null) { - // make sure to avoid double slashes - if (uriTemplate.startsWith("/")) { - path = path + uriTemplate; - } else { - path = path + "/" + uriTemplate; - } - } - path = FileUtil.stripLeadingSeparator(path); - String scheme = "http"; - String host = ""; - int port = 0; - - RestConfiguration config = configuration; - if (config == null) { - config = camelContext.getRestConfiguration(getComponentName(), true); - } - if (config.getScheme() != null) { - scheme = config.getScheme(); - } - if (config.getHost() != null) { - host = config.getHost(); - } - int num = config.getPort(); - if (num > 0) { - port = num; - } - - // prefix path with context-path if configured in rest-dsl configuration - String contextPath = config.getContextPath(); - if (ObjectHelper.isNotEmpty(contextPath)) { - contextPath = FileUtil.stripTrailingSeparator(contextPath); - contextPath = FileUtil.stripLeadingSeparator(contextPath); - if (ObjectHelper.isNotEmpty(contextPath)) { - path = contextPath + "/" + path; - } - } - - // if no explicit hostname set then resolve the hostname - if (ObjectHelper.isEmpty(host)) { - if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.allLocalIp) { - host = "0.0.0.0"; - } else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) { - host = HostUtils.getLocalHostName(); - } else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localIp) { - host = HostUtils.getLocalIp(); - } - } - - Map map = new HashMap(); - // build query string, and append any endpoint configuration properties - if (config.getComponent() == null || config.getComponent().equals(getComponentName())) { - // setup endpoint options - if (config.getEndpointProperties() != null && !config.getEndpointProperties().isEmpty()) { - map.putAll(config.getEndpointProperties()); - } - } - - boolean explicitOptions = true; - // must use upper case for restrict - String restrict = verb.toUpperCase(Locale.US); - // allow OPTIONS in rest-dsl to allow clients to call the API and have responses with ALLOW headers - if (!restrict.contains("OPTIONS")) { - restrict += ",OPTIONS"; - // this is not an explicit OPTIONS path in the rest-dsl - explicitOptions = false; - } - - boolean cors = config.isEnableCORS(); - if (cors) { - // allow HTTP Options as we want to handle CORS in rest-dsl - map.put("optionsEnabled", "true"); - } else if (explicitOptions) { - // the rest-dsl is using OPTIONS - map.put("optionsEnabled", "true"); - } - - String query = URISupport.createQueryString(map); - - String url; - if (api) { - url = getComponentName() + ":%s://%s:%s/%s?matchOnUriPrefix=true&httpMethodRestrict=%s"; - } else { - url = getComponentName() + ":%s://%s:%s/%s?matchOnUriPrefix=false&httpMethodRestrict=%s"; - } - - // get the endpoint - url = String.format(url, scheme, host, port, path, restrict); - - if (!query.isEmpty()) { - url = url + "&" + query; - } - - UndertowEndpoint endpoint = camelContext.getEndpoint(url, UndertowEndpoint.class); - setProperties(camelContext, endpoint, parameters); - - if (!map.containsKey("undertowHttpBinding")) { - // use the rest binding, if not using a custom http binding - endpoint.setUndertowHttpBinding(new RestUndertowHttpBinding()); - } - - // configure consumer properties - Consumer consumer = endpoint.createConsumer(processor); - if (config.getConsumerProperties() != null && !config.getConsumerProperties().isEmpty()) { - setProperties(camelContext, consumer, config.getConsumerProperties()); - } - - return consumer; - } }