[CXF-6532] Preparing a module and test structure
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/e7e75c58 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/e7e75c58 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/e7e75c58 Branch: refs/heads/master-jaxrs-2.1 Commit: e7e75c58c283d0178c6929cf298a68f41f6a8459 Parents: b977123 Author: Sergey Beryozkin <[email protected]> Authored: Mon Aug 29 22:06:01 2016 +0100 Committer: Sergey Beryozkin <[email protected]> Committed: Mon Aug 29 22:06:01 2016 +0100 ---------------------------------------------------------------------- rt/rs/security/jcs-parent/jcs/pom.xml | 58 ++++++++++++++ .../cxf/rs/security/jcs/TempResource.java | 23 ++++++ .../cxf/rs/security/jcs/TempResource.java | 23 ++++++ rt/rs/security/jcs-parent/pom.xml | 35 +++++++++ .../jaxrs/security/jcs/BookJcsServer.java | 59 +++++++++++++++ .../systest/jaxrs/security/jcs/BookStore.java | 50 +++++++++++++ .../jaxrs/security/jcs/JAXRSJcsTest.java | 79 ++++++++++++++++++++ .../cxf/systest/jaxrs/security/jcs/client.xml | 38 ++++++++++ .../systest/jaxrs/security/jcs/jcs-server.xml | 48 ++++++++++++ 9 files changed, 413 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/e7e75c58/rt/rs/security/jcs-parent/jcs/pom.xml ---------------------------------------------------------------------- diff --git a/rt/rs/security/jcs-parent/jcs/pom.xml b/rt/rs/security/jcs-parent/jcs/pom.xml new file mode 100644 index 0000000..21c9e4c --- /dev/null +++ b/rt/rs/security/jcs-parent/jcs/pom.xml @@ -0,0 +1,58 @@ +<?xml version="1.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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <artifactId>cxf-rt-rs-security-jcs</artifactId> + <packaging>bundle</packaging> + <name>Apache CXF Runtime JSON Clear Signature Core</name> + <description>Apache CXF Runtime JSON Clear Signature Core</description> + <url>http://cxf.apache.org</url> + <parent> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-parent</artifactId> + <version>3.2.0-SNAPSHOT</version> + <relativePath>../../../../../parent/pom.xml</relativePath> + </parent> + <dependencies> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-core</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-security</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.bouncycastle</groupId> + <artifactId>bcprov-ext-jdk15on</artifactId> + <version>${cxf.bcprov.version}</version> + <scope>provided</scope> + <optional>true</optional> + </dependency> + <!--test dependencies--> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + </dependencies> +</project> http://git-wip-us.apache.org/repos/asf/cxf/blob/e7e75c58/rt/rs/security/jcs-parent/jcs/src/main/java/org/apache/cxf/rs/security/jcs/TempResource.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jcs-parent/jcs/src/main/java/org/apache/cxf/rs/security/jcs/TempResource.java b/rt/rs/security/jcs-parent/jcs/src/main/java/org/apache/cxf/rs/security/jcs/TempResource.java new file mode 100644 index 0000000..e0e1372 --- /dev/null +++ b/rt/rs/security/jcs-parent/jcs/src/main/java/org/apache/cxf/rs/security/jcs/TempResource.java @@ -0,0 +1,23 @@ +/** + * 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.cxf.rs.security.jcs; + +public class TempResource { +} http://git-wip-us.apache.org/repos/asf/cxf/blob/e7e75c58/rt/rs/security/jcs-parent/jcs/src/test/java/org/apache/cxf/rs/security/jcs/TempResource.java ---------------------------------------------------------------------- diff --git a/rt/rs/security/jcs-parent/jcs/src/test/java/org/apache/cxf/rs/security/jcs/TempResource.java b/rt/rs/security/jcs-parent/jcs/src/test/java/org/apache/cxf/rs/security/jcs/TempResource.java new file mode 100644 index 0000000..e0e1372 --- /dev/null +++ b/rt/rs/security/jcs-parent/jcs/src/test/java/org/apache/cxf/rs/security/jcs/TempResource.java @@ -0,0 +1,23 @@ +/** + * 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.cxf.rs.security.jcs; + +public class TempResource { +} http://git-wip-us.apache.org/repos/asf/cxf/blob/e7e75c58/rt/rs/security/jcs-parent/pom.xml ---------------------------------------------------------------------- diff --git a/rt/rs/security/jcs-parent/pom.xml b/rt/rs/security/jcs-parent/pom.xml new file mode 100644 index 0000000..05fb540 --- /dev/null +++ b/rt/rs/security/jcs-parent/pom.xml @@ -0,0 +1,35 @@ +<?xml version="1.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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <artifactId>cxf-rt-rs-security-jcs-parent</artifactId> + <packaging>pom</packaging> + <name>Apache CXF JSON Clear Signature parent</name> + <description>Apache CXF JSON Clear Signature parent</description> + <url>http://cxf.apache.org</url> + <parent> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-rs-security</artifactId> + <version>3.2.0-SNAPSHOT</version> + </parent> + <modules> + <module>jcs</module> + </modules> +</project> http://git-wip-us.apache.org/repos/asf/cxf/blob/e7e75c58/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jcs/BookJcsServer.java ---------------------------------------------------------------------- diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jcs/BookJcsServer.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jcs/BookJcsServer.java new file mode 100644 index 0000000..fe7b2c7 --- /dev/null +++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jcs/BookJcsServer.java @@ -0,0 +1,59 @@ +/** + * 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.cxf.systest.jaxrs.security.jcs; + +import java.net.URL; + +import org.apache.cxf.Bus; +import org.apache.cxf.BusFactory; +import org.apache.cxf.bus.spring.SpringBusFactory; +import org.apache.cxf.testutil.common.AbstractBusTestServerBase; +import org.apache.cxf.testutil.common.TestUtil; + +public class BookJcsServer extends AbstractBusTestServerBase { + public static final String PORT = TestUtil.getPortNumber("jaxrs-jcs-server"); + private static final URL SERVER_CONFIG_FILE = + BookJcsServer.class.getResource("jcs-server.xml"); + + protected void run() { + SpringBusFactory bf = new SpringBusFactory(); + Bus springBus = bf.createBus(SERVER_CONFIG_FILE); + BusFactory.setDefaultBus(springBus); + setBus(springBus); + + try { + new BookJcsServer(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static void main(String[] args) { + try { + BookJcsServer s = new BookJcsServer(); + s.start(); + } catch (Exception ex) { + ex.printStackTrace(); + System.exit(-1); + } finally { + System.out.println("done!"); + } + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/e7e75c58/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jcs/BookStore.java ---------------------------------------------------------------------- diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jcs/BookStore.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jcs/BookStore.java new file mode 100644 index 0000000..f1d6be7 --- /dev/null +++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jcs/BookStore.java @@ -0,0 +1,50 @@ +/** + * 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.cxf.systest.jaxrs.security.jcs; + + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +@Path("/bookstore") +public class BookStore { + + public BookStore() { + } + + @POST + @Path("/books") + @Produces("application/json") + @Consumes("application/json") + public String echoJcsText(String text) { + validateBookFromJcs(text); + return text; + } + + protected void validateBookFromJcs(String text) { + + } + + +} + + http://git-wip-us.apache.org/repos/asf/cxf/blob/e7e75c58/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jcs/JAXRSJcsTest.java ---------------------------------------------------------------------- diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jcs/JAXRSJcsTest.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jcs/JAXRSJcsTest.java new file mode 100644 index 0000000..148c193 --- /dev/null +++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/jcs/JAXRSJcsTest.java @@ -0,0 +1,79 @@ +/** + * 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.cxf.systest.jaxrs.security.jcs; + +import java.net.URL; +import java.security.Security; +import java.util.ArrayList; +import java.util.List; + +import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase; +import org.bouncycastle.jce.provider.BouncyCastleProvider; + +import org.junit.AfterClass; +import org.junit.BeforeClass; + +/** + * Some tests for JWT tokens. + */ +public class JAXRSJcsTest extends AbstractBusClientServerTestBase { + public static final String PORT = BookJcsServer.PORT; + + @BeforeClass + public static void startServers() throws Exception { + assertTrue("server did not launch correctly", + launchServer(BookJcsServer.class, true)); + registerBouncyCastleIfNeeded(); + } + + private static void registerBouncyCastleIfNeeded() throws Exception { + // Still need it for Oracle Java 7 and Java 8 + Security.addProvider(new BouncyCastleProvider()); + } + + @AfterClass + public static void unregisterBouncyCastleIfNeeded() throws Exception { + Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME); + } + + @org.junit.Test + public void testJcsString() throws Exception { + + WebClient client = createWebClient(); + + String jcs = "{}"; + String responseJcs = client.post(jcs, String.class); + assertEquals(responseJcs, jcs); + } + + private WebClient createWebClient() { + URL busFile = JAXRSJcsTest.class.getResource("client.xml"); + + List<Object> providers = new ArrayList<Object>(); + + String address = "https://localhost:" + PORT + "/jcs/bookstore/books"; + WebClient client = + WebClient.create(address, providers, busFile.toString()); + client.type("application/json").accept("application/json"); + return client; + } + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/e7e75c58/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/jcs/client.xml ---------------------------------------------------------------------- diff --git a/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/jcs/client.xml b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/jcs/client.xml new file mode 100644 index 0000000..d10dac6 --- /dev/null +++ b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/jcs/client.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:http="http://cxf.apache.org/transports/http/configuration" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:cxf="http://cxf.apache.org/core" xmlns:p="http://cxf.apache.org/policy" xmlns:sec="http://cxf.apache.org/configuration/security" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd http://cxf.apache.org/policy http://cxf.apache.org/schemas/poli cy.xsd"> + <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/> + <cxf:bus> + <cxf:features> + <cxf:logging/> + </cxf:features> + </cxf:bus> + <http:conduit name="https://localhost.*"> + <http:client ConnectionTimeout="3000000" ReceiveTimeout="3000000"/> + <http:tlsClientParameters disableCNCheck="true"> + <sec:keyManagers keyPassword="password"> + <sec:keyStore type="JKS" password="password" resource="keys/Morpit.jks"/> + </sec:keyManagers> + <sec:trustManagers> + <sec:keyStore type="JKS" password="password" resource="keys/Truststore.jks"/> + </sec:trustManagers> + </http:tlsClientParameters> + </http:conduit> +</beans> http://git-wip-us.apache.org/repos/asf/cxf/blob/e7e75c58/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/jcs/jcs-server.xml ---------------------------------------------------------------------- diff --git a/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/jcs/jcs-server.xml b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/jcs/jcs-server.xml new file mode 100644 index 0000000..a951c37 --- /dev/null +++ b/systests/rs-security/src/test/resources/org/apache/cxf/systest/jaxrs/security/jcs/jcs-server.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:http="http://cxf.apache.org/transports/http/configuration" xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration" xmlns:sec="http://cxf.apache.org/configuration/security" xmlns:cxf="http://cxf.apache.org/core" xmlns:jaxrs="http://cxf.apache.org/jaxrs" xsi:schemaLocation=" http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd http://cxf.apache.org/transports/http-jetty/configuration http://cxf.apache.org/schemas/configuration/http-jetty.xsd http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd "> + <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/> + <cxf:bus> + <cxf:features> + <cxf:logging/> + </cxf:features> + </cxf:bus> + <httpj:engine-factory id="port-9095-tls-config"> + <httpj:engine port="${testutil.ports.jaxrs-jcs-server}"> + <httpj:tlsServerParameters> + <sec:keyManagers keyPassword="password"> + <sec:keyStore type="JKS" password="password" resource="keys/Bethal.jks"/> + </sec:keyManagers> + <sec:trustManagers> + <sec:keyStore type="JKS" password="password" resource="keys/Truststore.jks"/> + </sec:trustManagers> + <sec:clientAuthentication want="true" required="true"/> + </httpj:tlsServerParameters> + </httpj:engine> + </httpj:engine-factory> + + <bean id="serviceBean" class="org.apache.cxf.systest.jaxrs.security.jcs.BookStore"/> + <jaxrs:server address="https://localhost:${testutil.ports.jaxrs-jcs-server}/jcs"> + <jaxrs:serviceBeans> + <ref bean="serviceBean"/> + </jaxrs:serviceBeans> + </jaxrs:server> + +</beans>
