This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit b0ab9e2f640a1dfb6b57f222dad593b372b4c4e9 Author: sramamoorthy <[email protected]> AuthorDate: Fri May 14 15:49:34 2021 -0700 CAMEL-16609 rest dsl - Add more security models for JWT bearer tokens etc Added security scheme types mutualTLS (no parameters) and openIdConnect with required parameter "openIdConnectUrl". Security scheme type oauth2: - former flow "application" is now "clientCredentials", and "accessCode" is now "authorizationCode". We accept old and new names for both flows and set the flow appropriately based on the version at schema generation. - added parameter "refreshUrl", applicable to all flows. Security scheme type apiKey: added "in" option "cookie". Security scheme type http: added scheme "bearer" with optional parameter "bearerFormat". --- .../apache/camel/openapi/RestOpenApiReader.java | 118 ++++++++++--- .../openapi/RestOpenApiV2SecuritySchemesTest.java | 104 ++++++++++++ .../openapi/RestOpenApiV3SecuritySchemesTest.java | 134 +++++++++++++++ .../services/org/apache/camel/model.properties | 3 + .../org/apache/camel/model/rest/apiKey.json | 1 + .../org/apache/camel/model/rest/bearerToken.json | 18 ++ .../org/apache/camel/model/rest/jaxb.index | 3 + .../org/apache/camel/model/rest/mutualTLS.json | 17 ++ .../org/apache/camel/model/rest/oauth2.json | 3 +- .../org/apache/camel/model/rest/openIdConnect.json | 18 ++ .../camel/model/rest/securityDefinitions.json | 2 +- .../camel/model/rest/RestSecuritiesDefinition.java | 43 ++++- .../camel/model/rest/RestSecurityApiKey.java | 25 +++ .../camel/model/rest/RestSecurityBearerToken.java | 54 ++++++ .../camel/model/rest/RestSecurityMutualTLS.java | 39 +++++ .../camel/model/rest/RestSecurityOAuth2.java | 44 ++++- .../model/rest/RestSecurityOpenIdConnect.java | 54 ++++++ .../java/org/apache/camel/xml/in/ModelParser.java | 27 +++ .../dsl/yaml/deserializers/ModelDeserializers.java | 185 ++++++++++++++++++++- .../deserializers/ModelDeserializersResolver.java | 6 + .../src/generated/resources/camel-yaml-dsl.json | 57 +++++++ 21 files changed, 925 insertions(+), 30 deletions(-) diff --git a/components/camel-openapi-java/src/main/java/org/apache/camel/openapi/RestOpenApiReader.java b/components/camel-openapi-java/src/main/java/org/apache/camel/openapi/RestOpenApiReader.java index 11ed7be..afbf394 100644 --- a/components/camel-openapi-java/src/main/java/org/apache/camel/openapi/RestOpenApiReader.java +++ b/components/camel-openapi-java/src/main/java/org/apache/camel/openapi/RestOpenApiReader.java @@ -40,8 +40,10 @@ import io.apicurio.datamodels.core.models.ExtensibleNode; import io.apicurio.datamodels.core.models.Extension; import io.apicurio.datamodels.core.models.Node; import io.apicurio.datamodels.core.models.common.AuthorizationCodeOAuthFlow; +import io.apicurio.datamodels.core.models.common.ClientCredentialsOAuthFlow; import io.apicurio.datamodels.core.models.common.ImplicitOAuthFlow; import io.apicurio.datamodels.core.models.common.OAuthFlow; +import io.apicurio.datamodels.core.models.common.PasswordOAuthFlow; import io.apicurio.datamodels.core.models.common.SecurityRequirement; import io.apicurio.datamodels.core.models.common.Tag; import io.apicurio.datamodels.core.visitors.TraverserDirection; @@ -82,8 +84,11 @@ import org.apache.camel.model.rest.RestSecuritiesDefinition; import org.apache.camel.model.rest.RestSecuritiesRequirement; import org.apache.camel.model.rest.RestSecurityApiKey; import org.apache.camel.model.rest.RestSecurityBasicAuth; +import org.apache.camel.model.rest.RestSecurityBearerToken; import org.apache.camel.model.rest.RestSecurityDefinition; +import org.apache.camel.model.rest.RestSecurityMutualTLS; import org.apache.camel.model.rest.RestSecurityOAuth2; +import org.apache.camel.model.rest.RestSecurityOpenIdConnect; import org.apache.camel.model.rest.SecurityDefinition; import org.apache.camel.model.rest.VerbDefinition; import org.apache.camel.spi.ClassResolver; @@ -294,7 +299,14 @@ public class RestOpenApiReader { auth.type = "http"; auth.scheme = "basic"; auth.description = def.getDescription(); - openApi.components.addSecurityScheme("BasicAuth", auth); + openApi.components.addSecurityScheme(def.getKey(), auth); + } else if (def instanceof RestSecurityBearerToken) { + Oas30SecurityScheme auth = openApi.components.createSecurityScheme(def.getKey()); + auth.type = "http"; + auth.scheme = "bearer"; + auth.description = def.getDescription(); + auth.bearerFormat = ((RestSecurityBearerToken) def).getFormat(); + openApi.components.addSecurityScheme(def.getKey(), auth); } else if (def instanceof RestSecurityApiKey) { RestSecurityApiKey rs = (RestSecurityApiKey) def; Oas30SecurityScheme auth = openApi.components @@ -304,8 +316,12 @@ public class RestOpenApiReader { auth.name = rs.getName(); if (rs.getInHeader() != null && Boolean.parseBoolean(rs.getInHeader())) { auth.in = "header"; - } else { + } else if (rs.getInQuery() != null && Boolean.parseBoolean(rs.getInQuery())) { auth.in = "query"; + } else if (rs.getInCookie() != null && Boolean.parseBoolean(rs.getInCookie())) { + auth.in = "cookie"; + } else { + throw new IllegalStateException("No API Key location specified."); } openApi.components.addSecurityScheme(def.getKey(), auth); } else if (def instanceof RestSecurityOAuth2) { @@ -317,30 +333,57 @@ public class RestOpenApiReader { auth.description = rs.getDescription(); String flow = rs.getFlow(); if (flow == null) { - if (rs.getAuthorizationUrl() != null && rs.getTokenUrl() != null) { - flow = "accessCode"; - } else if (rs.getTokenUrl() == null && rs.getAuthorizationUrl() != null) { - flow = "implicit"; - } + flow = inferOauthFlow(rs); } - OAuthFlow oauthFlow = null; + OAuthFlow oauthFlow; if (auth.flows == null) { auth.flows = auth.createOAuthFlows(); } - if (flow.equals("accessCode")) { - oauthFlow = auth.flows.createAuthorizationCodeOAuthFlow(); - auth.flows.authorizationCode = (AuthorizationCodeOAuthFlow) oauthFlow; - } else if (flow.equals("implicit")) { - oauthFlow = auth.flows.createImplicitOAuthFlow(); - auth.flows.implicit = (ImplicitOAuthFlow) oauthFlow; + switch (flow) { + case "authorizationCode": + case "accessCode": + AuthorizationCodeOAuthFlow authorizationCodeOAuthFlow + = auth.flows.createAuthorizationCodeOAuthFlow(); + oauthFlow = authorizationCodeOAuthFlow; + auth.flows.authorizationCode = authorizationCodeOAuthFlow; + break; + case "implicit": + ImplicitOAuthFlow implicitOAuthFlow = auth.flows.createImplicitOAuthFlow(); + oauthFlow = implicitOAuthFlow; + auth.flows.implicit = implicitOAuthFlow; + break; + case "clientCredentials": + case "application": + ClientCredentialsOAuthFlow clientCredentialsOAuthFlow + = auth.flows.createClientCredentialsOAuthFlow(); + oauthFlow = clientCredentialsOAuthFlow; + auth.flows.clientCredentials = clientCredentialsOAuthFlow; + break; + case "password": + PasswordOAuthFlow passwordOAuthFlow = auth.flows.createPasswordOAuthFlow(); + oauthFlow = passwordOAuthFlow; + auth.flows.password = passwordOAuthFlow; + break; + default: + throw new IllegalStateException("Invalid OAuth flow '" + flow + "' specified"); } oauthFlow.authorizationUrl = rs.getAuthorizationUrl(); oauthFlow.tokenUrl = rs.getTokenUrl(); + oauthFlow.refreshUrl = rs.getRefreshUrl(); for (RestPropertyDefinition scope : rs.getScopes()) { oauthFlow.addScope(scope.getKey(), scope.getValue()); } openApi.components.addSecurityScheme(def.getKey(), auth); + } else if (def instanceof RestSecurityMutualTLS) { + Oas30SecurityScheme auth = openApi.components.createSecurityScheme(def.getKey()); + auth.type = "mutualTLS"; + openApi.components.addSecurityScheme(def.getKey(), auth); + } else if (def instanceof RestSecurityOpenIdConnect) { + Oas30SecurityScheme auth = openApi.components.createSecurityScheme(def.getKey()); + auth.type = "openIdConnect"; + auth.openIdConnectUrl = ((RestSecurityOpenIdConnect) def).getUrl(); + openApi.components.addSecurityScheme(def.getKey(), auth); } } } @@ -366,7 +409,9 @@ public class RestOpenApiReader { = openApi.securityDefinitions.createSecurityScheme(getValue(camelContext, def.getKey())); auth.type = "basicAuth"; auth.description = getValue(camelContext, def.getDescription()); - openApi.securityDefinitions.addSecurityScheme("BasicAuth", auth); + openApi.securityDefinitions.addSecurityScheme(getValue(camelContext, def.getKey()), auth); + } else if (def instanceof RestSecurityBearerToken) { + throw new IllegalStateException("OpenAPI 2.0 does not support bearer token security schemes."); } else if (def instanceof RestSecurityApiKey) { RestSecurityApiKey rs = (RestSecurityApiKey) def; Oas20SecurityScheme auth @@ -376,8 +421,10 @@ public class RestOpenApiReader { auth.name = getValue(camelContext, rs.getName()); if (rs.getInHeader() != null && CamelContextHelper.parseBoolean(camelContext, rs.getInHeader())) { auth.in = "header"; - } else { + } else if (rs.getInQuery() != null && CamelContextHelper.parseBoolean(camelContext, rs.getInQuery())) { auth.in = "query"; + } else { + throw new IllegalStateException("Invalid 'in' value for API Key security scheme"); } openApi.securityDefinitions.addSecurityScheme(getValue(camelContext, def.getKey()), auth); } else if (def instanceof RestSecurityOAuth2) { @@ -388,13 +435,24 @@ public class RestOpenApiReader { auth.description = getValue(camelContext, rs.getDescription()); String flow = rs.getFlow(); if (flow == null) { - if (rs.getAuthorizationUrl() != null && rs.getTokenUrl() != null) { - flow = "accessCode"; - } else if (rs.getTokenUrl() == null && rs.getAuthorizationUrl() != null) { - flow = "implicit"; - } + flow = inferOauthFlow(rs); + } + switch (flow) { + case "accessCode": + case "authorizationCode": + auth.flow = "accessCode"; + break; + case "application": + case "clientCredentials": + auth.flow = "application"; + break; + case "password": + case "implicit": + auth.flow = flow; + break; + default: + throw new IllegalStateException("Invalid OAuth flow `" + flow + "'"); } - auth.flow = flow; auth.authorizationUrl = getValue(camelContext, rs.getAuthorizationUrl()); auth.tokenUrl = getValue(camelContext, rs.getTokenUrl()); if (!rs.getScopes().isEmpty() && auth.scopes == null) { @@ -407,6 +465,10 @@ public class RestOpenApiReader { openApi.securityDefinitions = openApi.createSecurityDefinitions(); } openApi.securityDefinitions.addSecurityScheme(getValue(camelContext, def.getKey()), auth); + } else if (def instanceof RestSecurityMutualTLS) { + throw new IllegalStateException("Mutual TLS security scheme is not supported"); + } else if (def instanceof RestSecurityOpenIdConnect) { + throw new IllegalStateException("OpenId Connect security scheme is not supported"); } } } @@ -1504,4 +1566,16 @@ public class RestOpenApiReader { return name == null ? ref : name; } + private String inferOauthFlow(RestSecurityOAuth2 rs) { + String flow; + if (rs.getAuthorizationUrl() != null && rs.getTokenUrl() != null) { + flow = "authorizationCode"; + } else if (rs.getTokenUrl() == null && rs.getAuthorizationUrl() != null) { + flow = "implicit"; + } else { + throw new IllegalStateException("Error inferring OAuth flow"); + } + return flow; + } + } diff --git a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiV2SecuritySchemesTest.java b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiV2SecuritySchemesTest.java new file mode 100644 index 0000000..c8d991a --- /dev/null +++ b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiV2SecuritySchemesTest.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.openapi; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import io.apicurio.datamodels.Library; +import io.apicurio.datamodels.openapi.models.OasDocument; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.impl.engine.DefaultClassResolver; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class RestOpenApiV2SecuritySchemesTest extends CamelTestSupport { + + private final Logger log = LoggerFactory.getLogger(getClass()); + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() { + rest() + .securityDefinitions() + .oauth2("petstore_auth_implicit")// OAuth implicit + .authorizationUrl("https://petstore.swagger.io/oauth/dialog") + .end() + .oauth2("oauth_password") + .flow("password") + .tokenUrl("https://petstore.swagger.io/oauth/token") + .end() + .oauth2("oauth2_accessCode")// OAuth access/authorization code + .authorizationUrl("https://petstore.swagger.io/oauth/dialog") + .tokenUrl("https://petstore.swagger.io/oauth/token") + .end() + .apiKey("api_key_header") + .withHeader("myHeader") + .end() + .apiKey("api_key_query") + .withQuery("myQuery") + .end() + .end(); + } + }; + } + + @Test + public void testSecuritySchemesV2() throws Exception { + BeanConfig config = new BeanConfig(); + config.setHost("localhost:8080"); + config.setSchemes(new String[] { "http" }); + config.setBasePath("/api"); + config.setTitle("Camel User store"); + config.setLicense("Apache 2.0"); + config.setLicenseUrl("https://www.apache.org/licenses/LICENSE-2.0.html"); + config.setVersion("2.0"); + + RestOpenApiReader reader = new RestOpenApiReader(); + OasDocument openApi = reader.read(context, context.getRestDefinitions(), null, config, context.getName(), + new DefaultClassResolver()); + assertNotNull(openApi); + + ObjectMapper mapper = new ObjectMapper(); + mapper.enable(SerializationFeature.INDENT_OUTPUT); + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + Object dump = Library.writeNode(openApi); + String json = mapper.writeValueAsString(dump); + + log.info(json); + + json = json.replace("\n", " ").replaceAll("\\s+", " "); + + assertTrue(json.contains("\"petstore_auth_implicit\" : { \"flow\" : \"implicit\", \"authorizationUrl\" : " + + "\"https://petstore.swagger.io/oauth/dialog\", \"type\" : \"oauth2\" }")); + assertTrue(json.contains("\"oauth_password\" : { \"flow\" : \"password\", \"tokenUrl\" : " + + "\"https://petstore.swagger.io/oauth/token\", \"type\" : \"oauth2\" }")); + assertTrue(json.contains("\"oauth2_accessCode\" : { \"flow\" : \"accessCode\", \"authorizationUrl\" : " + + "\"https://petstore.swagger.io/oauth/dialog\", \"tokenUrl\" : " + + "\"https://petstore.swagger.io/oauth/token\", \"type\" : \"oauth2\" }")); + assertTrue( + json.contains("\"api_key_header\" : { \"type\" : \"apiKey\", \"name\" : \"myHeader\", \"in\" : \"header\" }")); + assertTrue(json.contains("\"api_key_query\" : { \"type\" : \"apiKey\", \"name\" : \"myQuery\", \"in\" : \"query\" }")); + } +} diff --git a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiV3SecuritySchemesTest.java b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiV3SecuritySchemesTest.java new file mode 100644 index 0000000..05d0475 --- /dev/null +++ b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiV3SecuritySchemesTest.java @@ -0,0 +1,134 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.openapi; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import io.apicurio.datamodels.Library; +import io.apicurio.datamodels.openapi.models.OasDocument; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.impl.engine.DefaultClassResolver; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class RestOpenApiV3SecuritySchemesTest extends CamelTestSupport { + + private final Logger log = LoggerFactory.getLogger(getClass()); + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() { + rest() + .securityDefinitions() + .oauth2("petstore_auth_implicit")// OAuth implicit + .authorizationUrl("https://petstore.swagger.io/oauth/dialog") + .refreshUrl("https://petstore.swagger.io/oauth/refresh") + .end() + .oauth2("oauth_password") + .flow("password") + .tokenUrl("https://petstore.swagger.io/oauth/token") + .end() + .oauth2("oauth2_accessCode")// OAuth access code + .authorizationUrl("https://petstore.swagger.io/oauth/dialog") + .tokenUrl("https://petstore.swagger.io/oauth/token") + .end() + .apiKey("api_key_header") + .withHeader("myHeader") + .end() + .apiKey("api_key_query") + .withQuery("myQuery") + .end() + .apiKey("api_key_cookie", "API Key using cookie") + .withCookie("myCookie") + .end() + .openIdConnect("openIdConnect_auth", "https://petstore.swagger.io/openidconnect") + .mutualTLS("mutualTLS_auth") + .end(); + } + }; + } + + @Test + public void testSecuritySchemesV3() throws Exception { + BeanConfig config = new BeanConfig(); + config.setHost("localhost:8080"); + config.setSchemes(new String[] { "http" }); + config.setBasePath("/api"); + config.setTitle("Camel User store"); + config.setLicense("Apache 2.0"); + config.setLicenseUrl("https://www.apache.org/licenses/LICENSE-2.0.html"); + + RestOpenApiReader reader = new RestOpenApiReader(); + OasDocument openApi = reader.read(context, context.getRestDefinitions(), null, config, context.getName(), + new DefaultClassResolver()); + assertNotNull(openApi); + + ObjectMapper mapper = new ObjectMapper(); + mapper.enable(SerializationFeature.INDENT_OUTPUT); + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + Object dump = Library.writeNode(openApi); + String json = mapper.writeValueAsString(dump); + + log.info(json); + + json = json.replace("\n", " ").replaceAll("\\s+", " "); + + assertTrue(json.contains("\"petstore_auth_implicit\" : { \"flows\" : { \"implicit\" : { \"authorizationUrl\" : " + + "\"https://petstore.swagger.io/oauth/dialog\", \"refreshUrl\" : " + + "\"https://petstore.swagger.io/oauth/refresh\" } }, \"type\" : \"oauth2\" }")); + assertTrue(json.contains("\"oauth_password\" : { \"flows\" : { \"password\" : { \"tokenUrl\" : " + + "\"https://petstore.swagger.io/oauth/token\" } }, \"type\" : \"oauth2\" }")); + assertTrue(json.contains("\"oauth2_accessCode\" : { \"flows\" : { \"authorizationCode\" : { \"authorizationUrl\" : " + + "\"https://petstore.swagger.io/oauth/dialog\", \"tokenUrl\" : " + + "\"https://petstore.swagger.io/oauth/token\" } }, \"type\" : \"oauth2\" }")); + assertTrue( + json.contains("\"api_key_header\" : { \"type\" : \"apiKey\", \"name\" : \"myHeader\", \"in\" : \"header\" }")); + assertTrue(json.contains("\"api_key_query\" : { \"type\" : \"apiKey\", \"name\" : \"myQuery\", \"in\" : \"query\" }")); + assertTrue(json.contains("\"api_key_cookie\" : { \"type\" : \"apiKey\", \"description\" : \"API Key using cookie\", " + + "\"name\" : \"myCookie\", \"in\" : \"cookie\" }")); + assertTrue( + json.contains("\"openIdConnect_auth\" : { \"openIdConnectUrl\" : " + + "\"https://petstore.swagger.io/openidconnect\", \"type\" : \"openIdConnect\" }")); + assertTrue(json.contains("\"mutualTLS_auth\" : { \"type\" : \"mutualTLS\" }")); + } + + @Test + public void testSecuritySchemesV2() throws Exception { + BeanConfig config = new BeanConfig(); + config.setHost("localhost:8080"); + config.setSchemes(new String[] { "http" }); + config.setBasePath("/api"); + config.setTitle("Camel User store"); + config.setLicense("Apache 2.0"); + config.setLicenseUrl("https://www.apache.org/licenses/LICENSE-2.0.html"); + config.setVersion("2.0"); + + RestOpenApiReader reader = new RestOpenApiReader(); + assertThrows(IllegalStateException.class, + () -> reader.read(context, context.getRestDefinitions(), null, config, context.getName(), + new DefaultClassResolver())); + } +} diff --git a/core/camel-core-model/src/generated/resources/META-INF/services/org/apache/camel/model.properties b/core/camel-core-model/src/generated/resources/META-INF/services/org/apache/camel/model.properties index 19029a3..2b03f53 100644 --- a/core/camel-core-model/src/generated/resources/META-INF/services/org/apache/camel/model.properties +++ b/core/camel-core-model/src/generated/resources/META-INF/services/org/apache/camel/model.properties @@ -10,6 +10,7 @@ basicAuth batch-config bean beanio +bearerToken bindy blacklistServiceFilter cachingServiceDiscovery @@ -89,12 +90,14 @@ marshal method mime-multipart multicast +mutualTLS mvel oauth2 ognl onCompletion onException onFallback +openIdConnect optimisticLockRetryPolicy otherwise outputType diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/apiKey.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/apiKey.json index 3f9b203..10e78ce 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/apiKey.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/apiKey.json @@ -14,6 +14,7 @@ "name": { "kind": "attribute", "displayName": "Name", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The name of the header or query parameter to be used." }, "inHeader": { "kind": "attribute", "displayName": "In Header", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To use header as the location of the API key." }, "inQuery": { "kind": "attribute", "displayName": "In Query", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To use query parameter as the location of the API key." }, + "inCookie": { "kind": "attribute", "displayName": "In Cookie", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To use a cookie as the location of the API key." }, "key": { "kind": "attribute", "displayName": "Key", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Key used to refer to this security definition" }, "description": { "kind": "attribute", "displayName": "Description", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "A short description for security scheme." } } diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/bearerToken.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/bearerToken.json new file mode 100644 index 0000000..d0f1b12 --- /dev/null +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/bearerToken.json @@ -0,0 +1,18 @@ +{ + "model": { + "kind": "model", + "name": "bearerToken", + "title": "Bearer Token", + "description": "Rest security bearer token authentication definition", + "deprecated": false, + "label": "rest,security", + "javaType": "org.apache.camel.model.rest.RestSecurityBearerToken", + "input": false, + "output": false + }, + "properties": { + "format": { "kind": "attribute", "displayName": "Format", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "A hint to the client to identify how the bearer token is formatted." }, + "key": { "kind": "attribute", "displayName": "Key", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Key used to refer to this security definition" }, + "description": { "kind": "attribute", "displayName": "Description", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "A short description for security scheme." } + } +} diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/jaxb.index b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/jaxb.index index 402f653..41cacf5 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/jaxb.index +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/jaxb.index @@ -20,7 +20,10 @@ RestSecuritiesDefinition RestSecuritiesRequirement RestSecurityApiKey RestSecurityBasicAuth +RestSecurityBearerToken +RestSecurityMutualTLS RestSecurityOAuth2 +RestSecurityOpenIdConnect RestsDefinition SecurityDefinition VerbDefinition diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/mutualTLS.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/mutualTLS.json new file mode 100644 index 0000000..64bd471 --- /dev/null +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/mutualTLS.json @@ -0,0 +1,17 @@ +{ + "model": { + "kind": "model", + "name": "mutualTLS", + "title": "Mutual TLS", + "description": "Rest security mutual TLS authentication definition", + "deprecated": false, + "label": "rest,security", + "javaType": "org.apache.camel.model.rest.RestSecurityMutualTLS", + "input": false, + "output": false + }, + "properties": { + "key": { "kind": "attribute", "displayName": "Key", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Key used to refer to this security definition" }, + "description": { "kind": "attribute", "displayName": "Description", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "A short description for security scheme." } + } +} diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/oauth2.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/oauth2.json index 17a24a9..af933c1 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/oauth2.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/oauth2.json @@ -13,7 +13,8 @@ "properties": { "authorizationUrl": { "kind": "attribute", "displayName": "Authorization Url", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The authorization URL to be used for this flow. This SHOULD be in the form of a URL. Required for implicit and access code flows" }, "tokenUrl": { "kind": "attribute", "displayName": "Token Url", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The token URL to be used for this flow. This SHOULD be in the form of a URL. Required for password, application, and access code flows." }, - "flow": { "kind": "attribute", "displayName": "Flow", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "accessCode", "application", "implicit", "password" ], "deprecated": false, "autowired": false, "secret": false, "description": "The flow used by the OAuth2 security scheme. Valid values are implicit, password, application or accessCode." }, + "refreshUrl": { "kind": "attribute", "displayName": "Refresh Url", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The URL to be used for obtaining refresh tokens. This MUST be in the form of a URL." }, + "flow": { "kind": "attribute", "displayName": "Flow", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "accessCode", "application", "authorizationCode", "clientCredentials", "implicit", "password" ], "deprecated": false, "autowired": false, "secret": false, "description": "The flow used by the OAuth2 security scheme. Valid values are implicit, password, application or accessCode." }, "scopes": { "kind": "element", "displayName": "Scopes", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.rest.RestPropertyDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "The available scopes for an OAuth2 security scheme" }, "key": { "kind": "attribute", "displayName": "Key", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Key used to refer to this security definition" }, "description": { "kind": "attribute", "displayName": "Description", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "A short description for security scheme." } diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/openIdConnect.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/openIdConnect.json new file mode 100644 index 0000000..9418595 --- /dev/null +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/openIdConnect.json @@ -0,0 +1,18 @@ +{ + "model": { + "kind": "model", + "name": "openIdConnect", + "title": "Open Id Connect", + "description": "Rest security OpenID Connect definition", + "deprecated": false, + "label": "rest,security", + "javaType": "org.apache.camel.model.rest.RestSecurityOpenIdConnect", + "input": false, + "output": false + }, + "properties": { + "url": { "kind": "attribute", "displayName": "Url", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "OpenId Connect URL to discover OAuth2 configuration values." }, + "key": { "kind": "attribute", "displayName": "Key", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Key used to refer to this security definition" }, + "description": { "kind": "attribute", "displayName": "Description", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "A short description for security scheme." } + } +} diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/securityDefinitions.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/securityDefinitions.json index 6ab871b..e43059c 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/securityDefinitions.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/rest/securityDefinitions.json @@ -11,6 +11,6 @@ "output": false }, "properties": { - "securityDefinitions": { "kind": "element", "displayName": "Security Definitions", "required": true, "type": "array", "javaType": "java.util.List<org.apache.camel.model.rest.RestSecurityDefinition>", "oneOf": [ "apiKey", "basicAuth", "oauth2" ], "deprecated": false, "autowired": false, "secret": false, "description": "Security definitions" } + "securityDefinitions": { "kind": "element", "displayName": "Security Definitions", "required": true, "type": "array", "javaType": "java.util.List<org.apache.camel.model.rest.RestSecurityDefinition>", "oneOf": [ "apiKey", "basicAuth", "bearer", "mutualTLS", "oauth2", "openIdConnect" ], "deprecated": false, "autowired": false, "secret": false, "description": "Security definitions" } } } diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestSecuritiesDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestSecuritiesDefinition.java index 0130b89..148e5b7 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestSecuritiesDefinition.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestSecuritiesDefinition.java @@ -42,7 +42,10 @@ public class RestSecuritiesDefinition { @XmlElements({ @XmlElement(name = "apiKey", type = RestSecurityApiKey.class), @XmlElement(name = "basicAuth", type = RestSecurityBasicAuth.class), - @XmlElement(name = "oauth2", type = RestSecurityOAuth2.class) }) + @XmlElement(name = "bearer", type = RestSecurityBearerToken.class), + @XmlElement(name = "oauth2", type = RestSecurityOAuth2.class), + @XmlElement(name = "openIdConnect", type = RestSecurityOpenIdConnect.class), + @XmlElement(name = "mutualTLS", type = RestSecurityMutualTLS.class) }) private List<RestSecurityDefinition> securityDefinitions = new ArrayList<>(); public RestSecuritiesDefinition() { @@ -87,6 +90,44 @@ public class RestSecuritiesDefinition { return this; } + public RestSecuritiesDefinition bearerToken(String key, String bearerFormat) { + return bearerToken(key, null, bearerFormat); + } + + public RestSecuritiesDefinition bearerToken(String key, String description, String bearerFormat) { + RestSecurityBearerToken auth = new RestSecurityBearerToken(rest); + securityDefinitions.add(auth); + auth.setKey(key); + auth.setDescription(description); + auth.setFormat(bearerFormat); + return this; + } + + public RestSecuritiesDefinition mutualTLS(String key) { + return mutualTLS(key, null); + } + + public RestSecuritiesDefinition mutualTLS(String key, String description) { + RestSecurityMutualTLS auth = new RestSecurityMutualTLS(rest); + securityDefinitions.add(auth); + auth.setKey(key); + auth.setDescription(description); + return this; + } + + public RestSecuritiesDefinition openIdConnect(String key, String url) { + return openIdConnect(key, null, url); + } + + public RestSecuritiesDefinition openIdConnect(String key, String description, String url) { + RestSecurityOpenIdConnect auth = new RestSecurityOpenIdConnect(rest); + securityDefinitions.add(auth); + auth.setKey(key); + auth.setDescription(description); + auth.setUrl(url); + return this; + } + public RestSecurityOAuth2 oauth2(String key) { return oauth2(key, null); } diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestSecurityApiKey.java b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestSecurityApiKey.java index ceabd61..b1958a7 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestSecurityApiKey.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestSecurityApiKey.java @@ -43,6 +43,10 @@ public class RestSecurityApiKey extends RestSecurityDefinition { @Metadata(javaType = "java.lang.Boolean") private String inQuery; + @XmlAttribute(name = "inCookie") + @Metadata(javaType = "java.lang.Boolean") + private String inCookie; + public RestSecurityApiKey() { } @@ -83,10 +87,22 @@ public class RestSecurityApiKey extends RestSecurityDefinition { this.inQuery = inQuery; } + public String getInCookie() { + return inCookie; + } + + /** + * To use a cookie as the location of the API key. + */ + public void setInCookie(String inCookie) { + this.inCookie = inCookie; + } + public RestSecurityApiKey withHeader(String name) { setName(name); setInHeader(Boolean.toString(true)); setInQuery(Boolean.toString(false)); + setInCookie(Boolean.toString(false)); return this; } @@ -94,6 +110,15 @@ public class RestSecurityApiKey extends RestSecurityDefinition { setName(name); setInQuery(Boolean.toString(true)); setInHeader(Boolean.toString(false)); + setInCookie(Boolean.toString(false)); + return this; + } + + public RestSecurityApiKey withCookie(String name) { + setName(name); + setInCookie(Boolean.toString(true)); + setInHeader(Boolean.toString(false)); + setInQuery(Boolean.toString(false)); return this; } diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestSecurityBearerToken.java b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestSecurityBearerToken.java new file mode 100644 index 0000000..47b7680 --- /dev/null +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestSecurityBearerToken.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.model.rest; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; + +import org.apache.camel.spi.Metadata; + +/** + * Rest security bearer token authentication definition + */ +@Metadata(label = "rest,security") +@XmlRootElement(name = "bearerToken") +@XmlAccessorType(XmlAccessType.FIELD) +public class RestSecurityBearerToken extends RestSecurityDefinition { + @XmlAttribute + private String format; + + @SuppressWarnings("unused") + public RestSecurityBearerToken() { + } + + public RestSecurityBearerToken(RestDefinition rest) { + super(rest); + } + + public String getFormat() { + return format; + } + + /** + * A hint to the client to identify how the bearer token is formatted. + */ + public void setFormat(String format) { + this.format = format; + } +} diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestSecurityMutualTLS.java b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestSecurityMutualTLS.java new file mode 100644 index 0000000..0c6c28f --- /dev/null +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestSecurityMutualTLS.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.model.rest; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +import org.apache.camel.spi.Metadata; + +/** + * Rest security mutual TLS authentication definition + */ +@Metadata(label = "rest,security") +@XmlRootElement(name = "mutualTLS") +@XmlAccessorType(XmlAccessType.FIELD) +public class RestSecurityMutualTLS extends RestSecurityDefinition { + @SuppressWarnings("unused") + public RestSecurityMutualTLS() { + } + + public RestSecurityMutualTLS(RestDefinition rest) { + super(rest); + } +} diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestSecurityOAuth2.java b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestSecurityOAuth2.java index b657938..9baf25c 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestSecurityOAuth2.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestSecurityOAuth2.java @@ -42,7 +42,10 @@ public class RestSecurityOAuth2 extends RestSecurityDefinition { private String tokenUrl; @XmlAttribute - @Metadata(enums = "implicit,password,application,accessCode") + private String refreshUrl; + + @XmlAttribute + @Metadata(enums = "implicit,password,application,clientCredentials,accessCode,authorizationCode") private String flow; @XmlElement(name = "scopes") @@ -79,6 +82,17 @@ public class RestSecurityOAuth2 extends RestSecurityDefinition { this.tokenUrl = tokenUrl; } + public String getRefreshUrl() { + return refreshUrl; + } + + /** + * The URL to be used for obtaining refresh tokens. This MUST be in the form of a URL. + */ + public void setRefreshUrl(String refreshUrl) { + this.refreshUrl = refreshUrl; + } + public String getFlow() { return flow; } @@ -102,9 +116,23 @@ public class RestSecurityOAuth2 extends RestSecurityDefinition { this.scopes = scopes; } + public RestSecurityOAuth2 flow(String flow) { + setFlow(flow); + return this; + } + public RestSecurityOAuth2 authorizationUrl(String authorizationUrl) { setAuthorizationUrl(authorizationUrl); - setFlow("implicit"); + return this; + } + + public RestSecurityOAuth2 tokenUrl(String tokenUrl) { + setTokenUrl(tokenUrl); + return this; + } + + public RestSecurityOAuth2 refreshUrl(String refreshUrl) { + setRefreshUrl(refreshUrl); return this; } @@ -115,15 +143,23 @@ public class RestSecurityOAuth2 extends RestSecurityDefinition { } public RestSecurityOAuth2 application(String tokenUrl) { + return clientCredentials(tokenUrl); + } + + public RestSecurityOAuth2 clientCredentials(String tokenUrl) { setTokenUrl(tokenUrl); - setFlow("application"); + setFlow("clientCredentials"); return this; } public RestSecurityOAuth2 accessCode(String authorizationUrl, String tokenUrl) { + return authorizationCode(authorizationUrl, tokenUrl); + } + + public RestSecurityOAuth2 authorizationCode(String authorizationUrl, String tokenUrl) { setAuthorizationUrl(authorizationUrl); setTokenUrl(tokenUrl); - setFlow("accessCode"); + setFlow("authorizationCode"); return this; } diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestSecurityOpenIdConnect.java b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestSecurityOpenIdConnect.java new file mode 100644 index 0000000..1240c57 --- /dev/null +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestSecurityOpenIdConnect.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.model.rest; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; + +import org.apache.camel.spi.Metadata; + +/** + * Rest security OpenID Connect definition + */ +@Metadata(label = "rest,security") +@XmlRootElement(name = "openIdConnect") +@XmlAccessorType(XmlAccessType.FIELD) +public class RestSecurityOpenIdConnect extends RestSecurityDefinition { + @XmlAttribute(required = true) + private String url; + + @SuppressWarnings("unused") + public RestSecurityOpenIdConnect() { + } + + public RestSecurityOpenIdConnect(RestDefinition rest) { + super(rest); + } + + public String getUrl() { + return url; + } + + /** + * OpenId Connect URL to discover OAuth2 configuration values. + */ + public void setUrl(String url) { + this.url = url; + } +} diff --git a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java index 8398ad6..076fa12 100644 --- a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java +++ b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java @@ -2795,7 +2795,10 @@ public class ModelParser extends BaseParser { switch (key) { case "apiKey": doAdd(doParseRestSecurityApiKey(), def.getSecurityDefinitions(), def::setSecurityDefinitions); break; case "basicAuth": doAdd(doParseRestSecurityBasicAuth(), def.getSecurityDefinitions(), def::setSecurityDefinitions); break; + case "bearer": doAdd(doParseRestSecurityBearerToken(), def.getSecurityDefinitions(), def::setSecurityDefinitions); break; case "oauth2": doAdd(doParseRestSecurityOAuth2(), def.getSecurityDefinitions(), def::setSecurityDefinitions); break; + case "openIdConnect": doAdd(doParseRestSecurityOpenIdConnect(), def.getSecurityDefinitions(), def::setSecurityDefinitions); break; + case "mutualTLS": doAdd(doParseRestSecurityMutualTLS(), def.getSecurityDefinitions(), def::setSecurityDefinitions); break; default: return false; } return true; @@ -2845,6 +2848,7 @@ public class ModelParser extends BaseParser { protected RestSecurityApiKey doParseRestSecurityApiKey() throws IOException, XmlPullParserException { return doParse(new RestSecurityApiKey(), (def, key, val) -> { switch (key) { + case "inCookie": def.setInCookie(val); break; case "inHeader": def.setInHeader(val); break; case "inQuery": def.setInQuery(val); break; case "name": def.setName(val); break; @@ -2857,11 +2861,25 @@ public class ModelParser extends BaseParser { return doParse(new RestSecurityBasicAuth(), restSecurityDefinitionAttributeHandler(), noElementHandler(), noValueHandler()); } + protected RestSecurityBearerToken doParseRestSecurityBearerToken() throws IOException, XmlPullParserException { + return doParse(new RestSecurityBearerToken(), (def, key, val) -> { + if ("format".equals(key)) { + def.setFormat(val); + return true; + } + return restSecurityDefinitionAttributeHandler().accept(def, key, val); + }, noElementHandler(), noValueHandler()); + } + protected RestSecurityMutualTLS doParseRestSecurityMutualTLS() throws IOException, XmlPullParserException { + return doParse(new RestSecurityMutualTLS(), + restSecurityDefinitionAttributeHandler(), noElementHandler(), noValueHandler()); + } protected RestSecurityOAuth2 doParseRestSecurityOAuth2() throws IOException, XmlPullParserException { return doParse(new RestSecurityOAuth2(), (def, key, val) -> { switch (key) { case "authorizationUrl": def.setAuthorizationUrl(val); break; case "flow": def.setFlow(val); break; + case "refreshUrl": def.setRefreshUrl(val); break; case "tokenUrl": def.setTokenUrl(val); break; default: return restSecurityDefinitionAttributeHandler().accept(def, key, val); } @@ -2874,6 +2892,15 @@ public class ModelParser extends BaseParser { return false; }, noValueHandler()); } + protected RestSecurityOpenIdConnect doParseRestSecurityOpenIdConnect() throws IOException, XmlPullParserException { + return doParse(new RestSecurityOpenIdConnect(), (def, key, val) -> { + if ("url".equals(key)) { + def.setUrl(val); + return true; + } + return restSecurityDefinitionAttributeHandler().accept(def, key, val); + }, noElementHandler(), noValueHandler()); + } public Optional<RestsDefinition> parseRestsDefinition() throws IOException, XmlPullParserException { return hasTag("rests") ? Optional.of(doParseRestsDefinition()) : Optional.empty(); diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java index 7f5e529..224868e 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java @@ -215,7 +215,10 @@ import org.apache.camel.model.rest.RestSecuritiesDefinition; import org.apache.camel.model.rest.RestSecuritiesRequirement; import org.apache.camel.model.rest.RestSecurityApiKey; import org.apache.camel.model.rest.RestSecurityBasicAuth; +import org.apache.camel.model.rest.RestSecurityBearerToken; +import org.apache.camel.model.rest.RestSecurityMutualTLS; import org.apache.camel.model.rest.RestSecurityOAuth2; +import org.apache.camel.model.rest.RestSecurityOpenIdConnect; import org.apache.camel.model.rest.RestsDefinition; import org.apache.camel.model.rest.SecurityDefinition; import org.apache.camel.model.rest.VerbDefinition; @@ -11432,7 +11435,10 @@ public final class ModelDeserializers extends YamlDeserializerSupport { properties = { @YamlProperty(name = "api-key", type = "object:org.apache.camel.model.rest.RestSecurityApiKey"), @YamlProperty(name = "basic-auth", type = "object:org.apache.camel.model.rest.RestSecurityBasicAuth"), - @YamlProperty(name = "oauth2", type = "object:org.apache.camel.model.rest.RestSecurityOAuth2") + @YamlProperty(name = "bearer", type = "object:org.apache.camel.model.rest.RestSecurityBearerToken"), + @YamlProperty(name = "oauth2", type = "object:org.apache.camel.model.rest.RestSecurityOAuth2"), + @YamlProperty(name = "open-id-connect", type = "object:org.apache.camel.model.rest.RestSecurityOpenIdConnect"), + @YamlProperty(name = "mutual-tls", type = "object:org.apache.camel.model.rest.RestSecurityMutualTLS") } ) public static class RestSecuritiesDefinitionDeserializer extends YamlDeserializerBase<RestSecuritiesDefinition> { @@ -11474,6 +11480,16 @@ public final class ModelDeserializers extends YamlDeserializerSupport { target.setSecurityDefinitions(existing); break; } + case "bearer": { + org.apache.camel.model.rest.RestSecurityBearerToken val = asType(node, org.apache.camel.model.rest.RestSecurityBearerToken.class); + java.util.List<org.apache.camel.model.rest.RestSecurityDefinition> existing = target.getSecurityDefinitions(); + if (existing == null) { + existing = new java.util.ArrayList<>(); + } + existing.add(val); + target.setSecurityDefinitions(existing); + break; + } case "oauth2": { org.apache.camel.model.rest.RestSecurityOAuth2 val = asType(node, org.apache.camel.model.rest.RestSecurityOAuth2.class); java.util.List<org.apache.camel.model.rest.RestSecurityDefinition> existing = target.getSecurityDefinitions(); @@ -11484,6 +11500,26 @@ public final class ModelDeserializers extends YamlDeserializerSupport { target.setSecurityDefinitions(existing); break; } + case "open-id-connect": { + org.apache.camel.model.rest.RestSecurityOpenIdConnect val = asType(node, org.apache.camel.model.rest.RestSecurityOpenIdConnect.class); + java.util.List<org.apache.camel.model.rest.RestSecurityDefinition> existing = target.getSecurityDefinitions(); + if (existing == null) { + existing = new java.util.ArrayList<>(); + } + existing.add(val); + target.setSecurityDefinitions(existing); + break; + } + case "mutual-tls": { + org.apache.camel.model.rest.RestSecurityMutualTLS val = asType(node, org.apache.camel.model.rest.RestSecurityMutualTLS.class); + java.util.List<org.apache.camel.model.rest.RestSecurityDefinition> existing = target.getSecurityDefinitions(); + if (existing == null) { + existing = new java.util.ArrayList<>(); + } + existing.add(val); + target.setSecurityDefinitions(existing); + break; + } default: { return false; } @@ -11536,6 +11572,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { nodes = "api-key", properties = { @YamlProperty(name = "description", type = "string"), + @YamlProperty(name = "in-cookie", type = "boolean"), @YamlProperty(name = "in-header", type = "boolean"), @YamlProperty(name = "in-query", type = "boolean"), @YamlProperty(name = "key", type = "string", required = true), @@ -11561,6 +11598,11 @@ public final class ModelDeserializers extends YamlDeserializerSupport { target.setDescription(val); break; } + case "in-cookie": { + String val = asText(node); + target.setInCookie(val); + break; + } case "in-header": { String val = asText(node); target.setInHeader(val); @@ -11631,6 +11673,94 @@ public final class ModelDeserializers extends YamlDeserializerSupport { } @YamlType( + types = org.apache.camel.model.rest.RestSecurityBearerToken.class, + order = org.apache.camel.dsl.yaml.common.YamlDeserializerResolver.ORDER_LOWEST - 1, + nodes = "bearer-token", + properties = { + @YamlProperty(name = "description", type = "string"), + @YamlProperty(name = "format", type = "string"), + @YamlProperty(name = "key", type = "string", required = true) + } + ) + public static class RestSecurityBearerTokenDeserializer extends YamlDeserializerBase<RestSecurityBearerToken> { + public RestSecurityBearerTokenDeserializer() { + super(RestSecurityBearerToken.class); + } + + @Override + protected RestSecurityBearerToken newInstance() { + return new RestSecurityBearerToken(); + } + + @Override + protected boolean setProperty(RestSecurityBearerToken target, String propertyKey, + String propertyName, Node node) { + switch(propertyKey) { + case "description": { + String val = asText(node); + target.setDescription(val); + break; + } + case "format": { + String val = asText(node); + target.setFormat(val); + break; + } + case "key": { + String val = asText(node); + target.setKey(val); + break; + } + default: { + return false; + } + } + return true; + } + } + + @YamlType( + types = org.apache.camel.model.rest.RestSecurityMutualTLS.class, + order = org.apache.camel.dsl.yaml.common.YamlDeserializerResolver.ORDER_LOWEST - 1, + nodes = "mutual-tls", + properties = { + @YamlProperty(name = "description", type = "string"), + @YamlProperty(name = "key", type = "string", required = true) + } + ) + public static class RestSecurityMutualTLSDeserializer extends YamlDeserializerBase<RestSecurityMutualTLS> { + public RestSecurityMutualTLSDeserializer() { + super(RestSecurityMutualTLS.class); + } + + @Override + protected RestSecurityMutualTLS newInstance() { + return new RestSecurityMutualTLS(); + } + + @Override + protected boolean setProperty(RestSecurityMutualTLS target, String propertyKey, + String propertyName, Node node) { + switch(propertyKey) { + case "description": { + String val = asText(node); + target.setDescription(val); + break; + } + case "key": { + String val = asText(node); + target.setKey(val); + break; + } + default: { + return false; + } + } + return true; + } + } + + @YamlType( types = org.apache.camel.model.rest.RestSecurityOAuth2.class, order = org.apache.camel.dsl.yaml.common.YamlDeserializerResolver.ORDER_LOWEST - 1, nodes = "oauth2", @@ -11639,6 +11769,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "description", type = "string"), @YamlProperty(name = "flow", type = "string"), @YamlProperty(name = "key", type = "string", required = true), + @YamlProperty(name = "refresh-url", type = "string"), @YamlProperty(name = "scopes", type = "array:org.apache.camel.model.rest.RestPropertyDefinition"), @YamlProperty(name = "token-url", type = "string") } @@ -11677,6 +11808,11 @@ public final class ModelDeserializers extends YamlDeserializerSupport { target.setKey(val); break; } + case "refresh-url": { + String val = asText(node); + target.setRefreshUrl(val); + break; + } case "scopes": { java.util.List<org.apache.camel.model.rest.RestPropertyDefinition> val = asFlatList(node, org.apache.camel.model.rest.RestPropertyDefinition.class); target.setScopes(val); @@ -11696,6 +11832,53 @@ public final class ModelDeserializers extends YamlDeserializerSupport { } @YamlType( + types = org.apache.camel.model.rest.RestSecurityOpenIdConnect.class, + order = org.apache.camel.dsl.yaml.common.YamlDeserializerResolver.ORDER_LOWEST - 1, + nodes = "open-id-connect", + properties = { + @YamlProperty(name = "description", type = "string"), + @YamlProperty(name = "key", type = "string", required = true), + @YamlProperty(name = "url", type = "string", required = true) + } + ) + public static class RestSecurityOpenIdConnectDeserializer extends YamlDeserializerBase<RestSecurityOpenIdConnect> { + public RestSecurityOpenIdConnectDeserializer() { + super(RestSecurityOpenIdConnect.class); + } + + @Override + protected RestSecurityOpenIdConnect newInstance() { + return new RestSecurityOpenIdConnect(); + } + + @Override + protected boolean setProperty(RestSecurityOpenIdConnect target, String propertyKey, + String propertyName, Node node) { + switch(propertyKey) { + case "description": { + String val = asText(node); + target.setDescription(val); + break; + } + case "key": { + String val = asText(node); + target.setKey(val); + break; + } + case "url": { + String val = asText(node); + target.setUrl(val); + break; + } + default: { + return false; + } + } + return true; + } + } + + @YamlType( types = org.apache.camel.model.rest.RestsDefinition.class, order = org.apache.camel.dsl.yaml.common.YamlDeserializerResolver.ORDER_LOWEST - 1, nodes = "rests", diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializersResolver.java b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializersResolver.java index 737c084..eae4520 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializersResolver.java +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializersResolver.java @@ -278,8 +278,14 @@ public final class ModelDeserializersResolver implements YamlDeserializerResolve case "org.apache.camel.model.rest.RestSecurityApiKey": return new ModelDeserializers.RestSecurityApiKeyDeserializer(); case "basic-auth": return new ModelDeserializers.RestSecurityBasicAuthDeserializer(); case "org.apache.camel.model.rest.RestSecurityBasicAuth": return new ModelDeserializers.RestSecurityBasicAuthDeserializer(); + case "bearer-token": return new ModelDeserializers.RestSecurityBearerTokenDeserializer(); + case "org.apache.camel.model.rest.RestSecurityBearerToken": return new ModelDeserializers.RestSecurityBearerTokenDeserializer(); + case "mutual-tls": return new ModelDeserializers.RestSecurityMutualTLSDeserializer(); + case "org.apache.camel.model.rest.RestSecurityMutualTLS": return new ModelDeserializers.RestSecurityMutualTLSDeserializer(); case "oauth2": return new ModelDeserializers.RestSecurityOAuth2Deserializer(); case "org.apache.camel.model.rest.RestSecurityOAuth2": return new ModelDeserializers.RestSecurityOAuth2Deserializer(); + case "open-id-connect": return new ModelDeserializers.RestSecurityOpenIdConnectDeserializer(); + case "org.apache.camel.model.rest.RestSecurityOpenIdConnect": return new ModelDeserializers.RestSecurityOpenIdConnectDeserializer(); case "rests": return new ModelDeserializers.RestsDefinitionDeserializer(); case "org.apache.camel.model.rest.RestsDefinition": return new ModelDeserializers.RestsDefinitionDeserializer(); case "ribbon-load-balancer": return new ModelDeserializers.RibbonServiceCallServiceLoadBalancerConfigurationDeserializer(); diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/camel-yaml-dsl.json b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/camel-yaml-dsl.json index 5f3b639..39388e3 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/camel-yaml-dsl.json +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/camel-yaml-dsl.json @@ -6653,8 +6653,17 @@ "basic-auth" : { "$ref" : "#/items/definitions/org.apache.camel.model.rest.RestSecurityBasicAuth" }, + "bearer" : { + "$ref" : "#/items/definitions/org.apache.camel.model.rest.RestSecurityBearerToken" + }, + "mutual-tls" : { + "$ref" : "#/items/definitions/org.apache.camel.model.rest.RestSecurityMutualTLS" + }, "oauth2" : { "$ref" : "#/items/definitions/org.apache.camel.model.rest.RestSecurityOAuth2" + }, + "open-id-connect" : { + "$ref" : "#/items/definitions/org.apache.camel.model.rest.RestSecurityOpenIdConnect" } } }, @@ -6672,6 +6681,9 @@ "description" : { "type" : "string" }, + "in-cookie" : { + "type" : "boolean" + }, "in-header" : { "type" : "boolean" }, @@ -6699,6 +6711,33 @@ }, "required" : [ "key" ] }, + "org.apache.camel.model.rest.RestSecurityBearerToken" : { + "type" : "object", + "properties" : { + "description" : { + "type" : "string" + }, + "format" : { + "type" : "string" + }, + "key" : { + "type" : "string" + } + }, + "required" : [ "key" ] + }, + "org.apache.camel.model.rest.RestSecurityMutualTLS" : { + "type" : "object", + "properties" : { + "description" : { + "type" : "string" + }, + "key" : { + "type" : "string" + } + }, + "required" : [ "key" ] + }, "org.apache.camel.model.rest.RestSecurityOAuth2" : { "type" : "object", "properties" : { @@ -6714,6 +6753,9 @@ "key" : { "type" : "string" }, + "refresh-url" : { + "type" : "string" + }, "scopes" : { "type" : "array", "items" : { @@ -6726,6 +6768,21 @@ }, "required" : [ "key" ] }, + "org.apache.camel.model.rest.RestSecurityOpenIdConnect" : { + "type" : "object", + "properties" : { + "description" : { + "type" : "string" + }, + "key" : { + "type" : "string" + }, + "url" : { + "type" : "string" + } + }, + "required" : [ "key", "url" ] + }, "org.apache.camel.model.rest.RestsDefinition" : { "type" : "object", "properties" : {
