From bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a Mon Sep 17 00:00:00 2001 From: dims Date: Tue, 17 Jun 2008 00:23:01 +0000 Subject: Move Tuscany from Incubator to top level. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68 --- .../samples/helloworld-ws-service-secure/README | 152 ++++++++++++++++++++ .../samples/helloworld-ws-service-secure/build.xml | 72 ++++++++++ .../helloworld-ws-service-secure.png | Bin 0 -> 158 bytes .../helloworld-ws-service-secure.svg | 149 ++++++++++++++++++++ .../samples/helloworld-ws-service-secure/pom.xml | 85 +++++++++++ .../src/main/java/helloworld/HelloWorldImpl.java | 33 +++++ .../src/main/java/helloworld/HelloWorldServer.java | 46 ++++++ .../main/java/helloworld/HelloWorldService.java | 31 ++++ .../main/java/helloworld/ServerPWCBHandler.java | 55 ++++++++ .../src/main/resources/definitions.xml | 156 +++++++++++++++++++++ .../src/main/resources/helloworldKeys.jks | Bin 0 -> 1366 bytes .../src/main/resources/helloworldws.composite | 40 ++++++ .../src/main/resources/wsdl/helloworld.wsdl | 79 +++++++++++ .../java/helloworld/HelloWorldServerTestCase.java | 62 ++++++++ 14 files changed, 960 insertions(+) create mode 100644 branches/sca-java-1.1/samples/helloworld-ws-service-secure/README create mode 100644 branches/sca-java-1.1/samples/helloworld-ws-service-secure/build.xml create mode 100644 branches/sca-java-1.1/samples/helloworld-ws-service-secure/helloworld-ws-service-secure.png create mode 100644 branches/sca-java-1.1/samples/helloworld-ws-service-secure/helloworld-ws-service-secure.svg create mode 100644 branches/sca-java-1.1/samples/helloworld-ws-service-secure/pom.xml create mode 100644 branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/java/helloworld/HelloWorldImpl.java create mode 100644 branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/java/helloworld/HelloWorldServer.java create mode 100644 branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/java/helloworld/HelloWorldService.java create mode 100644 branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/java/helloworld/ServerPWCBHandler.java create mode 100644 branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/resources/definitions.xml create mode 100644 branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/resources/helloworldKeys.jks create mode 100644 branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/resources/helloworldws.composite create mode 100644 branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/resources/wsdl/helloworld.wsdl create mode 100644 branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/test/java/helloworld/HelloWorldServerTestCase.java (limited to 'branches/sca-java-1.1/samples/helloworld-ws-service-secure') diff --git a/branches/sca-java-1.1/samples/helloworld-ws-service-secure/README b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/README new file mode 100644 index 0000000000..f32eb08b05 --- /dev/null +++ b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/README @@ -0,0 +1,152 @@ +Hello World Secure Web Service Service Sample +============================================= +This sample demonstrates an SCA service that uses a web service binding that is enabled for simple +authentication using UseridToken and PasswordText + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens open a command prompt, navigate +to this sample directory and do: + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-helloworld-ws-service-secure.jar helloworld.HelloWorldServer + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-helloworld-ws-service-secure.jar helloworld.HelloWorldServer + +Now the server is started you can use the helloworld-ws-reference-secure sample to +exercise it. + +Sample Overview +--------------- +The sample provides a single component that is wired to a service with a +web service binding. The service specifies a policy intent named 'authentication' +which is fulfilled by a suitable policyset that is defined for the SCA Domain. Over +the helloworld-ws-service sample, this sample demonstrate generally the use of policy +intents and policy sets in Tuscany taking the specific instance of a security policy. + +Note : +------ +The policies mentioned and supported are instances of Tuscany specified policies and +not instnaces of WS-Policy. + +helloworld-ws-service-secure/ + src/ + main/ + java/ + helloworld/ + HelloWorldService.java - interface description for + HelloWorldServiceComponent + HelloWorldImpl.java - component implementation + HelloWorldServer.java - starts the SCA Runtime and + deploys the helloworldws + .composite and then waits for the + service to be called via web services + ServerPWCBHandler.java - callback handler to authenticate client userid and password. + The handle(Callback[] callbacks) method of this class typically contains + code for accessing user registries and retrieving passwords + for user identifiers sent by the client and verifying them + against the password sent by the client. For example + here is where one could access LDAP registries to obtain or + compare user identities and passwords. + resources/ + wsdl/ + helloworld.wsdl - the service description that describes + the exposed service + helloworldws.composite - the SCA assembly for this sample + definitions.xml - the SCA Definitions file that contains intents and policysets + defined for the SCA Domain + + helloworld-ws-service-secure.png - a pictorial representation of the + sample .composite file + build.xml - the Ant build file + pom.xml - the Maven build file + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant using the +following commands + +cd helloworld-ws-service-secure +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] 14-Jan-2008 14:22:07 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:8085/HelloWorldService + [java] 14-Jan-2008 14:22:07 org.apache.tuscany.sca.http.jetty.JettyServer a +ddServletMapping + [java] INFO: Added Servlet mapping: http://L3AW203:8085/HelloWorldWsPolicyS +ervice + [java] HelloWorld server started (press enter to shutdown) + +As this point the SCA service is exposed as a web service by a web server +started automatically by the SCA runtime. The webservice requires clients to +have security headers that carry userid tonken and password text. + +To stop the server just press enter. + +To exercise the service run up the helloworld-ws-reference-secure sample. Take a look at +the README in that sample and you will see you need the following commands + +cd helloworld-ws-reference-secure +ant run + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. When using Maven you don't need to run the helloworld- +ws-reference-secure sample as Maven includes a simple ping test to make sure that the +service is available + +cd helloworld-ws-service-secure +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running helloworld.HelloWorldServerTestCase +14-Jan-2008 14:23:20 org.apache.catalina.core.StandardEngine start +INFO: Starting Servlet Engine: Apache Tomcat/6.0.10 +14-Jan-2008 14:23:20 org.apache.catalina.startup.ContextConfig defaultWebConfig +INFO: No default web.xml +14-Jan-2008 14:23:20 org.apache.catalina.startup.DigesterFactory register +WARNING: Could not get url for /javax/servlet/jsp/resources/jsp_2_0.xsd +14-Jan-2008 14:23:20 org.apache.catalina.startup.DigesterFactory register +WARNING: Could not get url for /javax/servlet/jsp/resources/web-jsptaglibrary_1_ +1.dtd +14-Jan-2008 14:23:20 org.apache.catalina.startup.DigesterFactory register +WARNING: Could not get url for /javax/servlet/jsp/resources/web-jsptaglibrary_1_ +2.dtd +14-Jan-2008 14:23:20 org.apache.catalina.startup.DigesterFactory register +WARNING: Could not get url for /javax/servlet/jsp/resources/web-jsptaglibrary_2_ +0.xsd +14-Jan-2008 14:23:20 org.apache.catalina.startup.DigesterFactory register +WARNING: Could not get url for /javax/servlet/resources/j2ee_web_services_1_1.xs +d +14-Jan-2008 14:23:21 org.apache.coyote.http11.Http11Protocol init +INFO: Initializing Coyote HTTP/1.1 on http-8085 +14-Jan-2008 14:23:21 org.apache.coyote.http11.Http11Protocol start +INFO: Starting Coyote HTTP/1.1 on http-8085 +14-Jan-2008 14:23:21 org.apache.tuscany.sca.http.tomcat.TomcatServer addServletM +apping +INFO: Added Servlet mapping: http://L3AW203:8085/HelloWorldService +14-Jan-2008 14:23:21 org.apache.tuscany.sca.http.tomcat.TomcatServer addServletM +apping +INFO: Added Servlet mapping: http://L3AW203:8085/HelloWorldWsPolicyService +14-Jan-2008 14:23:21 org.apache.coyote.http11.Http11Protocol destroy +INFO: Stopping Coyote HTTP/1.1 on http-8085 +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.734 sec + +This shows that the Junit test cases have run successfully. diff --git a/branches/sca-java-1.1/samples/helloworld-ws-service-secure/build.xml b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/build.xml new file mode 100644 index 0000000000..29bbae0173 --- /dev/null +++ b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/build.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-1.1/samples/helloworld-ws-service-secure/helloworld-ws-service-secure.png b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/helloworld-ws-service-secure.png new file mode 100644 index 0000000000..6f7d9dd450 Binary files /dev/null and b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/helloworld-ws-service-secure.png differ diff --git a/branches/sca-java-1.1/samples/helloworld-ws-service-secure/helloworld-ws-service-secure.svg b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/helloworld-ws-service-secure.svg new file mode 100644 index 0000000000..53eb552923 --- /dev/null +++ b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/helloworld-ws-service-secure.svg @@ -0,0 +1,149 @@ + + + + + + + + + + image/svg+xml + + + + + + + + helloworldws + + HelloWorldServiceComponent + + HelloWorldWebService + + diff --git a/branches/sca-java-1.1/samples/helloworld-ws-service-secure/pom.xml b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/pom.xml new file mode 100644 index 0000000000..2c9695b3b1 --- /dev/null +++ b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/pom.xml @@ -0,0 +1,85 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 1.1-incubating-SNAPSHOT + ../../pom.xml + + sample-helloworld-ws-service-secure + Apache Tuscany SCA HelloWorld Secure Web Service Sample + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.1-incubating-SNAPSHOT + + + + org.apache.ws.security + wss4j + 1.5.3 + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.1-incubating-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-binding-ws-axis2 + 1.1-incubating-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-host-tomcat + 1.1-incubating-SNAPSHOT + runtime + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + + diff --git a/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/java/helloworld/HelloWorldImpl.java b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/java/helloworld/HelloWorldImpl.java new file mode 100644 index 0000000000..4cdcc1fd0b --- /dev/null +++ b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/java/helloworld/HelloWorldImpl.java @@ -0,0 +1,33 @@ +/* + * 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 helloworld; + +import org.osoa.sca.annotations.Service; + +/** + * This class implements the HelloWorld service. + */ +@Service(HelloWorldService.class) +public class HelloWorldImpl implements HelloWorldService { + + public String getGreetings(String name) { + return "Hello " + name; + } + +} diff --git a/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/java/helloworld/HelloWorldServer.java b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/java/helloworld/HelloWorldServer.java new file mode 100644 index 0000000000..3d43290380 --- /dev/null +++ b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/java/helloworld/HelloWorldServer.java @@ -0,0 +1,46 @@ +/* + * 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 helloworld; + +import java.io.IOException; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * This server program shows how to create an SCA runtime, and start it which + * activates the helloworld Web service endpoint. + */ +public class HelloWorldServer { + + public static void main(String[] args) { + + SCADomain scaDomain = SCADomain.newInstance("helloworldws.composite"); + + try { + System.out.println("HelloWorld server started (press enter to shutdown)"); + System.in.read(); + } catch (IOException e) { + e.printStackTrace(); + } + + scaDomain.close(); + System.out.println("HelloWorld server stopped"); + } + +} diff --git a/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/java/helloworld/HelloWorldService.java b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/java/helloworld/HelloWorldService.java new file mode 100644 index 0000000000..4b019b21bf --- /dev/null +++ b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/java/helloworld/HelloWorldService.java @@ -0,0 +1,31 @@ +/* + * 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 helloworld; + +import org.osoa.sca.annotations.Remotable; + +/** + * This is the business interface of the HelloWorld greetings service. + */ +@Remotable +public interface HelloWorldService { + + public String getGreetings(String name); +} + diff --git a/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/java/helloworld/ServerPWCBHandler.java b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/java/helloworld/ServerPWCBHandler.java new file mode 100644 index 0000000000..ded02f09d6 --- /dev/null +++ b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/java/helloworld/ServerPWCBHandler.java @@ -0,0 +1,55 @@ +/* + * 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 helloworld; + +import java.io.IOException; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.UnsupportedCallbackException; + +import org.apache.ws.security.WSPasswordCallback; + +/** + * Sample userid passwd generation class + */ +public class ServerPWCBHandler implements CallbackHandler { + + public void handle(Callback[] callbacks) throws IOException, + UnsupportedCallbackException { + for (int i = 0; i < callbacks.length; i++) { + System.out.println("*** Calling Server User/Passwd Handler...."); + WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i]; + System.out.println("User Id = " + pwcb.getIdentifer()); + System.out.println("Password = " + pwcb.getPassword()); + + if ( pwcb.getUsage() == WSPasswordCallback.USERNAME_TOKEN ) { + if ( pwcb.getIdentifer().equals("TuscanyWsUser") && + pwcb.getPassword().equals("TuscanyWsUserPasswd") ){ + return; + } else { + throw new UnsupportedCallbackException(pwcb, "Authentication Failed : UserId - Password mismatch"); + } + } else if ( pwcb.getUsage() == WSPasswordCallback.SIGNATURE ) { + pwcb.setPassword("TuscanyWsUserPasswd"); + } + } + } + +} diff --git a/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/resources/definitions.xml b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/resources/definitions.xml new file mode 100644 index 0000000000..8077e294ed --- /dev/null +++ b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/resources/definitions.xml @@ -0,0 +1,156 @@ + + + + + + + Communitcation thro this binding requires SOAP + + + + + + Communitcation thro this binding requires SOAP 1.1 + + + + + + Communitcation thro this binding requires SOAP 1.2 + + + + + + Communitcation thro this binding required Authentication. + + + + + + Protect messages from unauthorized reading or modification + + + + + + Communitcation thro this binding must prevent + unauthorized users from reading the messages. + + + + + + + + + UsernameToken + helloworld.ServerPWCBHandler + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TuscanyWsUser + TuscanyWsUser + helloworld.ServerPWCBHandler + + + + JKS + helloworldKeys.jks + TuscanyWsUserPasswd + + + + + + + + + + \ No newline at end of file diff --git a/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/resources/helloworldKeys.jks b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/resources/helloworldKeys.jks new file mode 100644 index 0000000000..0b4f2399f0 Binary files /dev/null and b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/resources/helloworldKeys.jks differ diff --git a/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/resources/helloworldws.composite b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/resources/helloworldws.composite new file mode 100644 index 0000000000..65a3eaaf95 --- /dev/null +++ b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/resources/helloworldws.composite @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/resources/wsdl/helloworld.wsdl b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/resources/wsdl/helloworld.wsdl new file mode 100644 index 0000000000..068229be6f --- /dev/null +++ b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/main/resources/wsdl/helloworld.wsdl @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/test/java/helloworld/HelloWorldServerTestCase.java b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/test/java/helloworld/HelloWorldServerTestCase.java new file mode 100644 index 0000000000..4a14afcd9d --- /dev/null +++ b/branches/sca-java-1.1/samples/helloworld-ws-service-secure/src/test/java/helloworld/HelloWorldServerTestCase.java @@ -0,0 +1,62 @@ +/* + * 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 helloworld; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; + +import java.io.IOException; +import java.net.Socket; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Tests that the helloworld server is available + */ +public class HelloWorldServerTestCase{ + + private SCADomain scaDomain; + + @Before + public void startServer() throws Exception { + scaDomain = SCADomain.newInstance("helloworldws.composite"); + } + + @Test + public void testPing() throws IOException { + new Socket("127.0.0.1", 8085); + } + + @Test + public void testServiceCall() throws IOException { + HelloWorldService helloWorldService = scaDomain.getService(HelloWorldService.class, "HelloWorldServiceComponent/HelloWorldService"); + assertNotNull(helloWorldService); + + assertEquals("Hello Smith", helloWorldService.getGreetings("Smith")); + } + + @After + public void stopServer() throws Exception { + scaDomain.close(); + } + +} -- cgit v1.2.3