This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch camel-master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 9253684d8120518606e048c0a2315eab96dfb265 Author: JiriOndrusek <ondrusek.j...@gmail.com> AuthorDate: Wed Oct 7 08:46:23 2020 +0200 Shiro native support #1844 --- .../ROOT/pages/reference/extensions/shiro.adoc | 8 +- .../ROOT/partials/reference/others/shiro.adoc | 6 +- extensions-jvm/pom.xml | 1 - .../component/shiro/deployment/ShiroProcessor.java | 46 --------- .../quarkus/component/shiro/it/ShiroResource.java | 48 --------- extensions/pom.xml | 1 + .../shiro/deployment/pom.xml | 4 + .../component/shiro/deployment/ShiroProcessor.java | 75 ++++++++++++++ {extensions-jvm => extensions}/shiro/pom.xml | 1 - .../shiro/runtime/pom.xml | 20 ++++ .../shiro/ReflectionBuilderSubstitute.java | 24 ++--- .../main/resources/META-INF/quarkus-extension.yaml | 3 +- integration-tests/pom.xml | 1 + .../shiro}/pom.xml | 79 +++++++++++++- .../quarkus/component/shiro/it/ShiroResource.java | 113 +++++++++++++++++++++ .../component/shiro/it/ShiroRouteBuilder.java | 71 +++++++++++++ .../src/main/resources/application.properties | 18 ++++ .../src/main/resources/config/securityConfig.ini | 29 +++--- .../camel/quarkus/component/shiro/it/ShiroIT.java | 16 +-- .../quarkus/component/shiro/it/ShiroTest.java | 96 +++++++++++++++++ pom.xml | 1 + tooling/scripts/test-categories.yaml | 1 + 22 files changed, 512 insertions(+), 150 deletions(-) diff --git a/docs/modules/ROOT/pages/reference/extensions/shiro.adoc b/docs/modules/ROOT/pages/reference/extensions/shiro.adoc index 386b160..3f336f7 100644 --- a/docs/modules/ROOT/pages/reference/extensions/shiro.adoc +++ b/docs/modules/ROOT/pages/reference/extensions/shiro.adoc @@ -2,15 +2,15 @@ // This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page = Shiro :cq-artifact-id: camel-quarkus-shiro -:cq-native-supported: false -:cq-status: Preview +:cq-native-supported: true +:cq-status: Stable :cq-description: Security using Shiro :cq-deprecated: false :cq-jvm-since: 1.2.0 -:cq-native-since: n/a +:cq-native-since: 1.2.0 [.badges] -[.badge-key]##JVM since##[.badge-supported]##1.2.0## [.badge-key]##Native##[.badge-unsupported]##unsupported## +[.badge-key]##JVM since##[.badge-supported]##1.2.0## [.badge-key]##Native since##[.badge-supported]##1.2.0## Security using Shiro diff --git a/docs/modules/ROOT/partials/reference/others/shiro.adoc b/docs/modules/ROOT/partials/reference/others/shiro.adoc index 730a8a1..c13328e 100644 --- a/docs/modules/ROOT/partials/reference/others/shiro.adoc +++ b/docs/modules/ROOT/partials/reference/others/shiro.adoc @@ -2,11 +2,11 @@ // This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page :cq-artifact-id: camel-quarkus-shiro :cq-artifact-id-base: shiro -:cq-native-supported: false -:cq-status: Preview +:cq-native-supported: true +:cq-status: Stable :cq-deprecated: false :cq-jvm-since: 1.2.0 -:cq-native-since: n/a +:cq-native-since: 1.2.0 :cq-camel-part-name: shiro :cq-camel-part-title: Shiro :cq-camel-part-description: Security using Shiro diff --git a/extensions-jvm/pom.xml b/extensions-jvm/pom.xml index d86a722..b89062a 100644 --- a/extensions-jvm/pom.xml +++ b/extensions-jvm/pom.xml @@ -127,7 +127,6 @@ <module>saga</module> <module>saxon</module> <module>schematron</module> - <module>shiro</module> <module>sip</module> <module>smpp</module> <module>snmp</module> diff --git a/extensions-jvm/shiro/deployment/src/main/java/org/apache/camel/quarkus/component/shiro/deployment/ShiroProcessor.java b/extensions-jvm/shiro/deployment/src/main/java/org/apache/camel/quarkus/component/shiro/deployment/ShiroProcessor.java deleted file mode 100644 index 434e868..0000000 --- a/extensions-jvm/shiro/deployment/src/main/java/org/apache/camel/quarkus/component/shiro/deployment/ShiroProcessor.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.quarkus.component.shiro.deployment; - -import io.quarkus.deployment.annotations.BuildStep; -import io.quarkus.deployment.annotations.ExecutionTime; -import io.quarkus.deployment.annotations.Record; -import io.quarkus.deployment.builditem.FeatureBuildItem; -import io.quarkus.deployment.pkg.steps.NativeBuild; -import org.apache.camel.quarkus.core.JvmOnlyRecorder; -import org.jboss.logging.Logger; - -class ShiroProcessor { - - private static final Logger LOG = Logger.getLogger(ShiroProcessor.class); - private static final String FEATURE = "camel-shiro"; - - @BuildStep - FeatureBuildItem feature() { - return new FeatureBuildItem(FEATURE); - } - - /** - * Remove this once this extension starts supporting the native mode. - */ - @BuildStep(onlyIf = NativeBuild.class) - @Record(value = ExecutionTime.RUNTIME_INIT) - void warnJvmInNative(JvmOnlyRecorder recorder) { - JvmOnlyRecorder.warnJvmInNative(LOG, FEATURE); // warn at build time - recorder.warnJvmInNative(FEATURE); // warn at runtime - } -} diff --git a/extensions-jvm/shiro/integration-test/src/main/java/org/apache/camel/quarkus/component/shiro/it/ShiroResource.java b/extensions-jvm/shiro/integration-test/src/main/java/org/apache/camel/quarkus/component/shiro/it/ShiroResource.java deleted file mode 100644 index be8128c..0000000 --- a/extensions-jvm/shiro/integration-test/src/main/java/org/apache/camel/quarkus/component/shiro/it/ShiroResource.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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.quarkus.component.shiro.it; - -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Inject; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.apache.camel.CamelContext; -import org.jboss.logging.Logger; - -@Path("/shiro") -@ApplicationScoped -public class ShiroResource { - - private static final Logger LOG = Logger.getLogger(ShiroResource.class); - - private static final String OTHER_SHIRO = "shiro"; - @Inject - CamelContext context; - - @Path("/load/other/shiro") - @GET - @Produces(MediaType.TEXT_PLAIN) - public Response loadOtherShiro() throws Exception { - /* This is an autogenerated test */ - /* No way to test a Camel artifact of kind "other" */ - return Response.ok().build(); - } -} diff --git a/extensions/pom.xml b/extensions/pom.xml index 6dbc4ab..2a78709 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -173,6 +173,7 @@ <module>seda</module> <module>servicenow</module> <module>servlet</module> + <module>shiro</module> <module>sjms</module> <module>sjms2</module> <module>slack</module> diff --git a/extensions-jvm/shiro/deployment/pom.xml b/extensions/shiro/deployment/pom.xml similarity index 93% rename from extensions-jvm/shiro/deployment/pom.xml rename to extensions/shiro/deployment/pom.xml index 9bc2e07..d68ea16 100644 --- a/extensions-jvm/shiro/deployment/pom.xml +++ b/extensions/shiro/deployment/pom.xml @@ -38,6 +38,10 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-commons-logging-deployment</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-shiro</artifactId> </dependency> </dependencies> diff --git a/extensions/shiro/deployment/src/main/java/org/apache/camel/quarkus/component/shiro/deployment/ShiroProcessor.java b/extensions/shiro/deployment/src/main/java/org/apache/camel/quarkus/component/shiro/deployment/ShiroProcessor.java new file mode 100644 index 0000000..f7afa46 --- /dev/null +++ b/extensions/shiro/deployment/src/main/java/org/apache/camel/quarkus/component/shiro/deployment/ShiroProcessor.java @@ -0,0 +1,75 @@ +/* + * 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.quarkus.component.shiro.deployment; + +import java.sql.Time; +import java.sql.Timestamp; +import java.util.Calendar; +import java.util.List; +import java.util.stream.Collectors; + +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.CombinedIndexBuildItem; +import io.quarkus.deployment.builditem.EnableAllSecurityServicesBuildItem; +import io.quarkus.deployment.builditem.FeatureBuildItem; +import io.quarkus.deployment.builditem.IndexDependencyBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; +import org.apache.camel.CamelAuthorizationException; +import org.apache.shiro.ShiroException; +import org.jboss.jandex.DotName; + +class ShiroProcessor { + + private static final String FEATURE = "camel-shiro"; + + private static final DotName SHIRO_EXCEPTION_NAME = DotName.createSimple(ShiroException.class.getName()); + + @BuildStep + FeatureBuildItem feature() { + return new FeatureBuildItem(FEATURE); + } + + @BuildStep + EnableAllSecurityServicesBuildItem enableAllSecurity() { + return new EnableAllSecurityServicesBuildItem(); + } + + @BuildStep + ReflectiveClassBuildItem registerForReflection(CombinedIndexBuildItem combinedIndex) { + List<String> dtos = combinedIndex.getIndex() + .getAllKnownSubclasses(SHIRO_EXCEPTION_NAME) + .stream() + .map(c -> c.name().toString()) + .filter(n -> n.startsWith("org.apache.shiro.auth")) + .collect(Collectors.toList()); + + dtos.add(CamelAuthorizationException.class.getName()); + dtos.add(Float[].class.getName()); + dtos.add(java.util.Date[].class.getName()); + dtos.add(Calendar[].class.getName()); + dtos.add(java.sql.Date[].class.getName()); + dtos.add(Time[].class.getName()); + dtos.add(Timestamp[].class.getName()); + + return new ReflectiveClassBuildItem(false, false, dtos.toArray(new String[dtos.size()])); + } + + @BuildStep + IndexDependencyBuildItem registerDependencyForIndex() { + return new IndexDependencyBuildItem("org.apache.shiro", "shiro-core"); + } +} diff --git a/extensions-jvm/shiro/pom.xml b/extensions/shiro/pom.xml similarity index 97% rename from extensions-jvm/shiro/pom.xml rename to extensions/shiro/pom.xml index f3bb2d3..687d54f 100644 --- a/extensions-jvm/shiro/pom.xml +++ b/extensions/shiro/pom.xml @@ -35,6 +35,5 @@ <modules> <module>deployment</module> <module>runtime</module> - <module>integration-test</module> </modules> </project> diff --git a/extensions-jvm/shiro/runtime/pom.xml b/extensions/shiro/runtime/pom.xml similarity index 82% rename from extensions-jvm/shiro/runtime/pom.xml rename to extensions/shiro/runtime/pom.xml index 6e3f15c..3e56fdc 100644 --- a/extensions-jvm/shiro/runtime/pom.xml +++ b/extensions/shiro/runtime/pom.xml @@ -34,6 +34,7 @@ <properties> <camel.quarkus.jvmSince>1.2.0</camel.quarkus.jvmSince> + <camel.quarkus.nativeSince>1.2.0</camel.quarkus.nativeSince> </properties> <dependencyManagement> @@ -57,6 +58,25 @@ <groupId>org.apache.camel</groupId> <artifactId>camel-shiro</artifactId> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-commons-logging</artifactId> + </dependency> + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.graalvm.nativeimage</groupId> + <artifactId>svm</artifactId> + <scope>provided</scope> + </dependency> </dependencies> <build> diff --git a/extensions-jvm/shiro/integration-test/src/test/java/org/apache/camel/quarkus/component/shiro/it/ShiroTest.java b/extensions/shiro/runtime/src/main/java/org/apache/camel/quarkus/component/shiro/ReflectionBuilderSubstitute.java similarity index 62% copy from extensions-jvm/shiro/integration-test/src/test/java/org/apache/camel/quarkus/component/shiro/it/ShiroTest.java copy to extensions/shiro/runtime/src/main/java/org/apache/camel/quarkus/component/shiro/ReflectionBuilderSubstitute.java index b2dd9f8..10c7342 100644 --- a/extensions-jvm/shiro/integration-test/src/test/java/org/apache/camel/quarkus/component/shiro/it/ShiroTest.java +++ b/extensions/shiro/runtime/src/main/java/org/apache/camel/quarkus/component/shiro/ReflectionBuilderSubstitute.java @@ -14,21 +14,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.quarkus.component.shiro.it; +package org.apache.camel.quarkus.component.shiro; -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.RestAssured; -import org.junit.jupiter.api.Test; +import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.TargetClass; +import org.apache.shiro.config.DefaultInterpolator; +import org.apache.shiro.config.Interpolator; +import org.apache.shiro.config.ReflectionBuilder; -@QuarkusTest -class ShiroTest { +@TargetClass(value = ReflectionBuilder.class) +final class ReflectionBuilderSubstitute { - @Test - public void loadOtherShiro() { - /* A simple autogenerated test */ - RestAssured.get("/shiro/load/other/shiro") - .then() - .statusCode(200); + @Substitute + private Interpolator createInterpolator() { + return new DefaultInterpolator(); } - } diff --git a/extensions-jvm/shiro/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/shiro/runtime/src/main/resources/META-INF/quarkus-extension.yaml similarity index 97% copy from extensions-jvm/shiro/runtime/src/main/resources/META-INF/quarkus-extension.yaml copy to extensions/shiro/runtime/src/main/resources/META-INF/quarkus-extension.yaml index 474ba52..cd43d12 100644 --- a/extensions-jvm/shiro/runtime/src/main/resources/META-INF/quarkus-extension.yaml +++ b/extensions/shiro/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -24,9 +24,8 @@ name: "Camel Shiro" description: "Security using Shiro" metadata: - unlisted: true guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/shiro.html" categories: - "integration" status: - - "preview" + - "stable" diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 2b30730..eae1ed8 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -145,6 +145,7 @@ <module>send-dynamic-http</module> <module>servicenow</module> <module>servlet</module> + <module>shiro</module> <module>slack</module> <module>smallrye-reactive-messaging</module> <module>soap</module> diff --git a/extensions-jvm/shiro/integration-test/pom.xml b/integration-tests/shiro/pom.xml similarity index 55% rename from extensions-jvm/shiro/integration-test/pom.xml rename to integration-tests/shiro/pom.xml index c73bcea..1e4af45 100644 --- a/extensions-jvm/shiro/integration-test/pom.xml +++ b/integration-tests/shiro/pom.xml @@ -23,13 +23,13 @@ <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-build-parent-it</artifactId> + <artifactId>camel-quarkus-integration-tests</artifactId> <version>1.2.0-SNAPSHOT</version> - <relativePath>../../../poms/build-parent-it/pom.xml</relativePath> + <relativePath>../pom.xml</relativePath> </parent> - <artifactId>camel-quarkus-shiro-integration-test</artifactId> - <name>Camel Quarkus :: Shiro :: Integration Test</name> + <artifactId>camel-quarkus-integration-test-shiro</artifactId> + <name>Camel Quarkus :: Integration Tests :: Shiro</name> <description>Integration tests for Camel Quarkus Shiro extension</description> <dependencyManagement> @@ -53,6 +53,18 @@ <groupId>io.quarkus</groupId> <artifactId>quarkus-resteasy</artifactId> </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-resteasy-jackson</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-direct</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-mock</artifactId> + </dependency> <!-- test dependencies --> <dependency> @@ -69,6 +81,34 @@ <!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory --> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-direct-deployment</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-mock-deployment</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + + <!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory --> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-shiro-deployment</artifactId> <version>${project.version}</version> <type>pom</type> @@ -97,4 +137,35 @@ </plugin> </plugins> </build> + + <profiles> + <profile> + <id>native</id> + <activation> + <property> + <name>native</name> + </property> + </activation> + <properties> + <quarkus.package.type>native</quarkus.package.type> + </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> + </project> diff --git a/integration-tests/shiro/src/main/java/org/apache/camel/quarkus/component/shiro/it/ShiroResource.java b/integration-tests/shiro/src/main/java/org/apache/camel/quarkus/component/shiro/it/ShiroResource.java new file mode 100644 index 0000000..e875523 --- /dev/null +++ b/integration-tests/shiro/src/main/java/org/apache/camel/quarkus/component/shiro/it/ShiroResource.java @@ -0,0 +1,113 @@ +/* + * 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.quarkus.component.shiro.it; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +import org.apache.camel.CamelContext; +import org.apache.camel.Processor; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.component.shiro.security.ShiroSecurityConstants; +import org.apache.camel.component.shiro.security.ShiroSecurityToken; +import org.apache.camel.component.shiro.security.ShiroSecurityTokenInjector; +import org.jboss.logging.Logger; + +@Path("/shiro") +@ApplicationScoped +public class ShiroResource { + + private static final Logger LOG = Logger.getLogger(ShiroResource.class); + + public static byte[] passPhrase = { + (byte) 0x08, (byte) 0x09, (byte) 0x0A, (byte) 0x0B, + (byte) 0x0C, (byte) 0x0D, (byte) 0x0E, (byte) 0x0F, + (byte) 0x10, (byte) 0x11, (byte) 0x12, (byte) 0x13, + (byte) 0x14, (byte) 0x15, (byte) 0x16, (byte) 0x17 }; + + @Inject + ProducerTemplate producerTemplate; + + @Inject + CamelContext context; + + @Path("/headers") + @POST + @Consumes(MediaType.APPLICATION_JSON) + public void headers(ShiroSecurityToken shiroSecurityToken, @QueryParam("expectSuccess") boolean expectSuccess, + @QueryParam("path") String path) + throws Exception { + verifyMock(path, expectSuccess, exchange -> { + exchange.getIn().setHeader(ShiroSecurityConstants.SHIRO_SECURITY_USERNAME, shiroSecurityToken.getUsername()); + exchange.getIn().setHeader(ShiroSecurityConstants.SHIRO_SECURITY_PASSWORD, shiroSecurityToken.getPassword()); + }); + } + + @Path("/token") + @POST + @Consumes(MediaType.APPLICATION_JSON) + public void token(ShiroSecurityToken shiroSecurityToken, @QueryParam("expectSuccess") boolean expectSuccess, + @QueryParam("path") String path) + throws Exception { + + verifyMock(path, expectSuccess, + exchange -> exchange.getIn().setHeader(ShiroSecurityConstants.SHIRO_SECURITY_TOKEN, shiroSecurityToken)); + } + + @Path("/base64") + @POST + @Consumes(MediaType.APPLICATION_JSON) + public void base64(ShiroSecurityToken shiroSecurityToken, @QueryParam("expectSuccess") boolean expectSuccess, + @QueryParam("path") String path) + throws Exception { + ShiroSecurityTokenInjector shiroSecurityTokenInjector = new ShiroSecurityTokenInjector(shiroSecurityToken, + passPhrase); + shiroSecurityTokenInjector.setBase64(true); + + verifyMock(path, expectSuccess, shiroSecurityTokenInjector); + } + + public void verifyMock(String path, boolean expectSuccess, Processor processor) throws Exception { + + MockEndpoint mockEndpointSuccess = context.getEndpoint("mock:success", MockEndpoint.class); + MockEndpoint mockEndpointFailure = context.getEndpoint("mock:authenticationException", MockEndpoint.class); + + mockEndpointSuccess.reset(); + mockEndpointFailure.reset(); + + mockEndpointSuccess.expectedMessageCount(expectSuccess ? 1 : 0); + mockEndpointFailure.expectedMessageCount(expectSuccess ? 0 : 1); + + try { + producerTemplate.send(path, processor); + } catch (Exception e) { + if (expectSuccess) { + throw e; + } + } + + mockEndpointSuccess.assertIsSatisfied(); + mockEndpointFailure.assertIsSatisfied(); + } + +} diff --git a/integration-tests/shiro/src/main/java/org/apache/camel/quarkus/component/shiro/it/ShiroRouteBuilder.java b/integration-tests/shiro/src/main/java/org/apache/camel/quarkus/component/shiro/it/ShiroRouteBuilder.java new file mode 100644 index 0000000..f28abf7 --- /dev/null +++ b/integration-tests/shiro/src/main/java/org/apache/camel/quarkus/component/shiro/it/ShiroRouteBuilder.java @@ -0,0 +1,71 @@ +/* + * 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.quarkus.component.shiro.it; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.apache.camel.CamelAuthorizationException; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.shiro.security.ShiroSecurityPolicy; +import org.apache.shiro.authc.AuthenticationException; +import org.apache.shiro.authc.IncorrectCredentialsException; +import org.apache.shiro.authc.LockedAccountException; +import org.apache.shiro.authc.UnknownAccountException; +import org.apache.shiro.authz.Permission; +import org.apache.shiro.authz.permission.WildcardPermission; + +public class ShiroRouteBuilder extends RouteBuilder { + public static final String DIRECT_SECURE_ENDPOINT = "direct:secureEndpoint"; + public static final String DIRECT_SECURE_WITH_ROLES = "direct:secureWithRoles"; + public static final String DIRECT_SECURE_WITH_PERMISSIONS = "direct:secureWithPermissions"; + + @Override + public void configure() throws Exception { + String securityConfig = "classpath:config/securityConfig.ini"; + + onException(CamelAuthorizationException.class, UnknownAccountException.class, IncorrectCredentialsException.class, + LockedAccountException.class, AuthenticationException.class).to("mock:authenticationException"); + //policy ignores roles or permissions + final ShiroSecurityPolicy securityPolicy = new ShiroSecurityPolicy(securityConfig, ShiroResource.passPhrase); + securityPolicy.setBase64(true); + + from(DIRECT_SECURE_ENDPOINT).policy(securityPolicy).to("mock:success"); + + //policy respects roles + List<String> rolesList = new ArrayList<>(); + rolesList.add("sec-level2"); + rolesList.add("sec-level3"); + + final ShiroSecurityPolicy securityPolicyWithRoles = new ShiroSecurityPolicy(securityConfig, + ShiroResource.passPhrase, + true); + securityPolicyWithRoles.setRolesList(rolesList); + + from(DIRECT_SECURE_WITH_ROLES).policy(securityPolicyWithRoles).to("mock:success"); + + //policy respects permissions + List<Permission> permissionsList = Collections.singletonList(new WildcardPermission("earth1:writeonly:*")); + + final ShiroSecurityPolicy securityPolicyWithPermissions = new ShiroSecurityPolicy(securityConfig, + ShiroResource.passPhrase, true, permissionsList); + + from(DIRECT_SECURE_WITH_PERMISSIONS).policy(securityPolicyWithPermissions).to("mock:success"); + + } +} diff --git a/integration-tests/shiro/src/main/resources/application.properties b/integration-tests/shiro/src/main/resources/application.properties new file mode 100644 index 0000000..a2f7d33 --- /dev/null +++ b/integration-tests/shiro/src/main/resources/application.properties @@ -0,0 +1,18 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +quarkus.camel.native.resources.include-patterns = config/* diff --git a/extensions-jvm/shiro/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/integration-tests/shiro/src/main/resources/config/securityConfig.ini similarity index 66% rename from extensions-jvm/shiro/runtime/src/main/resources/META-INF/quarkus-extension.yaml rename to integration-tests/shiro/src/main/resources/config/securityConfig.ini index 474ba52..70d181d 100644 --- a/extensions-jvm/shiro/runtime/src/main/resources/META-INF/quarkus-extension.yaml +++ b/integration-tests/shiro/src/main/resources/config/securityConfig.ini @@ -15,18 +15,17 @@ # limitations under the License. # -# This is a generated file. Do not edit directly! -# To re-generate, run the following command from the top level directory: -# -# mvn -N cq:update-quarkus-metadata -# ---- -name: "Camel Shiro" -description: "Security using Shiro" -metadata: - unlisted: true - guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/shiro.html" - categories: - - "integration" - status: - - "preview" +[users] +sheldon = earth2, sec-level1 +irma = password, sec-level2 +fred = fred, sec-level3 + +[roles] +# 'sec-level3' role has all permissions, indicated by the wildcard '*' +sec-level3 = * + +# The 'sec-level2' role can do anything with access of permission readonly (*) to help +sec-level2 = earth1:* + +# The 'sec-level1' role can do anything with access of permission readonly +sec-level1 = earth1:readonly:* \ No newline at end of file diff --git a/extensions-jvm/shiro/integration-test/src/test/java/org/apache/camel/quarkus/component/shiro/it/ShiroTest.java b/integration-tests/shiro/src/test/java/org/apache/camel/quarkus/component/shiro/it/ShiroIT.java similarity index 71% rename from extensions-jvm/shiro/integration-test/src/test/java/org/apache/camel/quarkus/component/shiro/it/ShiroTest.java rename to integration-tests/shiro/src/test/java/org/apache/camel/quarkus/component/shiro/it/ShiroIT.java index b2dd9f8..613c45b 100644 --- a/extensions-jvm/shiro/integration-test/src/test/java/org/apache/camel/quarkus/component/shiro/it/ShiroTest.java +++ b/integration-tests/shiro/src/test/java/org/apache/camel/quarkus/component/shiro/it/ShiroIT.java @@ -16,19 +16,9 @@ */ package org.apache.camel.quarkus.component.shiro.it; -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.RestAssured; -import org.junit.jupiter.api.Test; +import io.quarkus.test.junit.NativeImageTest; -@QuarkusTest -class ShiroTest { - - @Test - public void loadOtherShiro() { - /* A simple autogenerated test */ - RestAssured.get("/shiro/load/other/shiro") - .then() - .statusCode(200); - } +@NativeImageTest +class ShiroIT extends ShiroTest { } diff --git a/integration-tests/shiro/src/test/java/org/apache/camel/quarkus/component/shiro/it/ShiroTest.java b/integration-tests/shiro/src/test/java/org/apache/camel/quarkus/component/shiro/it/ShiroTest.java new file mode 100644 index 0000000..a88ac31 --- /dev/null +++ b/integration-tests/shiro/src/test/java/org/apache/camel/quarkus/component/shiro/it/ShiroTest.java @@ -0,0 +1,96 @@ +/* + * 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.quarkus.component.shiro.it; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import io.restassured.http.ContentType; +import org.apache.camel.component.shiro.security.ShiroSecurityToken; +import org.junit.jupiter.api.Test; + +@QuarkusTest +class ShiroTest { + + enum AUTHORIZATION { + none(ShiroRouteBuilder.DIRECT_SECURE_ENDPOINT), + roles(ShiroRouteBuilder.DIRECT_SECURE_WITH_ROLES), + permissions(ShiroRouteBuilder.DIRECT_SECURE_WITH_PERMISSIONS); + + private String path; + + AUTHORIZATION(String path) { + this.path = path; + } + + public String getPath() { + return path; + } + } + + static ShiroSecurityToken SHELDON_TOKEN = new ShiroSecurityToken("sheldon", "earth2"); + private static ShiroSecurityToken IRMA_TOKEN = new ShiroSecurityToken("irma", "password"); + private static ShiroSecurityToken FRED_TOKEN = new ShiroSecurityToken("fred", "fred"); + private static ShiroSecurityToken SEC_LEVEL1 = SHELDON_TOKEN; + private static ShiroSecurityToken SEC_LEVEL2 = IRMA_TOKEN; + private static ShiroSecurityToken SEC_LEVEL3 = FRED_TOKEN; + private static ShiroSecurityToken WRONG_TOKEN = new ShiroSecurityToken("sheldon", "wrong"); + + @Test + public void testHeaders() { + test("headers", SHELDON_TOKEN, AUTHORIZATION.none, true); + test("headers", WRONG_TOKEN, AUTHORIZATION.none, false); + } + + @Test + public void testToken() { + test("token", IRMA_TOKEN, AUTHORIZATION.none, true); + test("token", WRONG_TOKEN, AUTHORIZATION.none, false); + } + + @Test + public void testBase64() { + test("base64", FRED_TOKEN, AUTHORIZATION.none, true); + test("base64", WRONG_TOKEN, AUTHORIZATION.none, false); + } + + @Test + public void testTokenWithRoles() { + test("headers", SEC_LEVEL1, AUTHORIZATION.roles, false); + test("token", SEC_LEVEL2, AUTHORIZATION.roles, true); + test("token", SEC_LEVEL3, AUTHORIZATION.roles, true); + } + + @Test + public void testTokenWithPermissions() { + test("token", SEC_LEVEL1, AUTHORIZATION.permissions, false); + test("headers", SEC_LEVEL2, AUTHORIZATION.permissions, true); + test("headers", SEC_LEVEL3, AUTHORIZATION.permissions, true); + } + + void test(String path, ShiroSecurityToken token, AUTHORIZATION authorization, boolean expectSuccess) { + + RestAssured.given() + .queryParam("expectSuccess", expectSuccess) + .queryParam("path", authorization.getPath()) + .contentType(ContentType.JSON) + .body(token) + .post("/shiro/" + path) + .then() + .statusCode(204); + } + +} diff --git a/pom.xml b/pom.xml index 723109b..09445f6 100644 --- a/pom.xml +++ b/pom.xml @@ -435,6 +435,7 @@ <Jenkinsfile.quarkus>SLASHSTAR_STYLE</Jenkinsfile.quarkus> <properties>CAMEL_PROPERTIES_STYLE</properties> <rnc>SCRIPT_STYLE</rnc> + <ini>SCRIPT_STYLE</ini> <rng>XML_STYLE</rng> <spring.factories>CAMEL_PROPERTIES_STYLE</spring.factories> <spring.provides>CAMEL_PROPERTIES_STYLE</spring.provides> diff --git a/tooling/scripts/test-categories.yaml b/tooling/scripts/test-categories.yaml index db2d809..5fbeecc 100644 --- a/tooling/scripts/test-categories.yaml +++ b/tooling/scripts/test-categories.yaml @@ -104,6 +104,7 @@ misc: - mustache - pdf - qute + - shiro - stringtemplate - tika - velocity