From c7b50e47dd1dd51a4c1c83f92cd28845853bef90 Mon Sep 17 00:00:00 2001 From: lresende Date: Sat, 31 Jan 2009 08:59:12 +0000 Subject: Moving iTests that are not part of the main build to contrib git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@739528 13f79535-47bb-0310-9956-ffa450edef68 --- .../itest/policy-security-basicauth/pom.xml | 113 ++++++++++++++++++++ .../main/java/helloworld/HelloWorldClientImpl.java | 40 ++++++++ .../main/java/helloworld/HelloWorldService.java | 30 ++++++ .../java/helloworld/HelloWorldServiceImpl.java | 46 +++++++++ .../src/main/resources/definitions.xml | 44 ++++++++ .../src/main/resources/helloworld.composite | 46 +++++++++ .../tuscany/sca/itest/BasicAuthTestCase.java | 114 +++++++++++++++++++++ 7 files changed, 433 insertions(+) create mode 100644 java/sca/contrib/itest/policy-security-basicauth/pom.xml create mode 100644 java/sca/contrib/itest/policy-security-basicauth/src/main/java/helloworld/HelloWorldClientImpl.java create mode 100644 java/sca/contrib/itest/policy-security-basicauth/src/main/java/helloworld/HelloWorldService.java create mode 100644 java/sca/contrib/itest/policy-security-basicauth/src/main/java/helloworld/HelloWorldServiceImpl.java create mode 100644 java/sca/contrib/itest/policy-security-basicauth/src/main/resources/definitions.xml create mode 100644 java/sca/contrib/itest/policy-security-basicauth/src/main/resources/helloworld.composite create mode 100644 java/sca/contrib/itest/policy-security-basicauth/src/test/java/org/apache/tuscany/sca/itest/BasicAuthTestCase.java (limited to 'java/sca/contrib/itest/policy-security-basicauth') diff --git a/java/sca/contrib/itest/policy-security-basicauth/pom.xml b/java/sca/contrib/itest/policy-security-basicauth/pom.xml new file mode 100644 index 0000000000..f3b3b28c1f --- /dev/null +++ b/java/sca/contrib/itest/policy-security-basicauth/pom.xml @@ -0,0 +1,113 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-itest + 2.0-SNAPSHOT + ../pom.xml + + itest-policy-security-basicauth + Apache Tuscany SCA Policy Basic Authentication Integration Tests + + + + org.apache.tuscany.sca + tuscany-node-api + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-node-impl + 2.0-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 2.0-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-binding-ws-axis2 + 2.0-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-binding-ws-axis2-policy + 2.0-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-host-jetty + 2.0-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-binding-jms-runtime + 2.0-SNAPSHOT + + + + org.apache.activemq + activemq-core + 4.1.1 + runtime + + + + org.apache.geronimo.specs + geronimo-jms_1.1_spec + 1.1 + provided + + + org.apache.geronimo.specs + geronimo-jms_1.1_spec + + + + + + junit + junit + 4.5 + + + + httpunit + httpunit + 1.6.1 + test + + + + diff --git a/java/sca/contrib/itest/policy-security-basicauth/src/main/java/helloworld/HelloWorldClientImpl.java b/java/sca/contrib/itest/policy-security-basicauth/src/main/java/helloworld/HelloWorldClientImpl.java new file mode 100644 index 0000000000..a7e60e7e09 --- /dev/null +++ b/java/sca/contrib/itest/policy-security-basicauth/src/main/java/helloworld/HelloWorldClientImpl.java @@ -0,0 +1,40 @@ +/* + * 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.oasisopen.sca.annotation.Reference; +import org.oasisopen.sca.annotation.Service; + +/** + * This class implements the HelloWorld service. + */ +@Service(HelloWorldService.class) +public class HelloWorldClientImpl implements HelloWorldService { + + @Reference + protected HelloWorldService helloworldWS; + + + + public String getGreetings(String name) { + return "Hello " + + helloworldWS.getGreetings(name); + } + +} diff --git a/java/sca/contrib/itest/policy-security-basicauth/src/main/java/helloworld/HelloWorldService.java b/java/sca/contrib/itest/policy-security-basicauth/src/main/java/helloworld/HelloWorldService.java new file mode 100644 index 0000000000..18f74b083f --- /dev/null +++ b/java/sca/contrib/itest/policy-security-basicauth/src/main/java/helloworld/HelloWorldService.java @@ -0,0 +1,30 @@ +/* + * 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.oasisopen.sca.annotation.Remotable; + +/** + * This is the business interface of the HelloWorld greetings service. + */ +@Remotable +public interface HelloWorldService { + + public String getGreetings(String name); +} diff --git a/java/sca/contrib/itest/policy-security-basicauth/src/main/java/helloworld/HelloWorldServiceImpl.java b/java/sca/contrib/itest/policy-security-basicauth/src/main/java/helloworld/HelloWorldServiceImpl.java new file mode 100644 index 0000000000..e9787bfac3 --- /dev/null +++ b/java/sca/contrib/itest/policy-security-basicauth/src/main/java/helloworld/HelloWorldServiceImpl.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 javax.security.auth.Subject; + +import org.oasisopen.sca.RequestContext; +import org.oasisopen.sca.annotation.Context; +import org.oasisopen.sca.annotation.Service; + +/** + * This class implements the HelloWorld service. + */ +@Service(HelloWorldService.class) +public class HelloWorldServiceImpl implements HelloWorldService { + + @Context + protected RequestContext requestContext; + + public String getGreetings(String name) { + Subject subject = requestContext.getSecuritySubject(); + + if (subject == null){ + return "Hello " + name + " null subject"; + } else { + return "Hello " + name + " " + subject.toString(); + } + } + +} diff --git a/java/sca/contrib/itest/policy-security-basicauth/src/main/resources/definitions.xml b/java/sca/contrib/itest/policy-security-basicauth/src/main/resources/definitions.xml new file mode 100644 index 0000000000..dbdf0cd263 --- /dev/null +++ b/java/sca/contrib/itest/policy-security-basicauth/src/main/resources/definitions.xml @@ -0,0 +1,44 @@ + + + + + + + + myname + mypassword + + + + + + + + + + \ No newline at end of file diff --git a/java/sca/contrib/itest/policy-security-basicauth/src/main/resources/helloworld.composite b/java/sca/contrib/itest/policy-security-basicauth/src/main/resources/helloworld.composite new file mode 100644 index 0000000000..f883629180 --- /dev/null +++ b/java/sca/contrib/itest/policy-security-basicauth/src/main/resources/helloworld.composite @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/sca/contrib/itest/policy-security-basicauth/src/test/java/org/apache/tuscany/sca/itest/BasicAuthTestCase.java b/java/sca/contrib/itest/policy-security-basicauth/src/test/java/org/apache/tuscany/sca/itest/BasicAuthTestCase.java new file mode 100644 index 0000000000..10fbac4e20 --- /dev/null +++ b/java/sca/contrib/itest/policy-security-basicauth/src/test/java/org/apache/tuscany/sca/itest/BasicAuthTestCase.java @@ -0,0 +1,114 @@ +/* + * 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.tuscany.sca.itest; + +import java.io.ByteArrayInputStream; + +import junit.framework.Assert; +import helloworld.HelloWorldService; + +import org.apache.tuscany.sca.node.Client; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.apache.ws.security.util.Base64; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +import com.meterware.httpunit.PostMethodWebRequest; +import com.meterware.httpunit.WebConversation; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; + +public class BasicAuthTestCase { + private static Node node; + private static HelloWorldService service; + + @BeforeClass + public static void init() throws Exception { + try { + NodeFactory factory = NodeFactory.newInstance(); + node = factory.createSCANodeFromClassLoader("helloworld.composite", + BasicAuthTestCase.class.getClassLoader()); + node.start(); + + service = ((Client)node).getService(HelloWorldService.class, "HelloWorldClientComponent"); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + @AfterClass + public static void destroy() throws Exception { + node.stop(); + } + + @Test + //@Ignore + public void testViaSCAClient() { + String greetings = service.getGreetings("Simon"); + System.out.println(">>>" + greetings); + } + + @Test + @Ignore + public void testWSViaNonSCAClient() { + + try { + String token ="MyToken"; + String encToken = Base64.encode(token.getBytes()); + + String response = callService("http://L3AW203:8085/HelloWorldServiceWSComponent", + "" + + "" + + "" + + "" + encToken + "" + + "" + + "" + + "" + + "Simon" + + "" + + "" + + "" ); + System.out.println(">>>" + response); + } catch(Exception ex) { + System.out.println(ex.toString()); + } + } + + @Test + public void testJMSViaNonSCAClient() { + // TODO + } + + public String callService(String url, String requestString) throws Exception { + System.out.println("Request = " + requestString); + WebConversation wc = new WebConversation(); + wc.setAuthorization("Me", "MyPasswd"); + WebRequest request = new PostMethodWebRequest( url, + new ByteArrayInputStream(requestString.getBytes("UTF-8")),"text/xml"); + request.setHeaderField("SOAPAction", ""); + WebResponse response = wc.getResource(request); + System.out.println("Response= " + response.getText()); + Assert.assertEquals(200, response.getResponseCode()); + return response.getText(); + } +} -- cgit v1.2.3