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 --- .../calculator-implementation-policies/README | 266 +++++++++++++++++ .../calculator-implementation-policies/build.xml | 72 +++++ .../calculator.png | Bin 0 -> 20552 bytes .../calculator.svg | 329 +++++++++++++++++++++ .../calculator-implementation-policies/pom.xml | 64 ++++ .../src/main/java/calculator/AddService.java | 28 ++ .../src/main/java/calculator/AddServiceImpl.java | 35 +++ .../src/main/java/calculator/CalculatorClient.java | 70 +++++ .../main/java/calculator/CalculatorService.java | 35 +++ .../java/calculator/CalculatorServiceImpl.java | 70 +++++ .../src/main/java/calculator/DivideService.java | 28 ++ .../main/java/calculator/DivideServiceImpl.java | 35 +++ .../src/main/java/calculator/MultiplyService.java | 28 ++ .../main/java/calculator/MultiplyServiceImpl.java | 35 +++ .../src/main/java/calculator/SubtractService.java | 28 ++ .../main/java/calculator/SubtractServiceImpl.java | 35 +++ .../security/CalculatorCallbackHandler.java | 50 ++++ .../java/calculator/security/JaasLoginModule.java | 178 +++++++++++ .../java/calculator/security/UserPrincipal.java | 66 +++++ .../src/main/resources/Calculator.composite | 61 ++++ .../src/main/resources/CalculatorJass.config | 21 ++ .../resources/CalculatorLogMessages.properties | 18 ++ .../src/main/resources/definitions.xml | 49 +++ .../test/java/calculator/CalculatorTestCase.java | 74 +++++ 24 files changed, 1675 insertions(+) create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/README create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/build.xml create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/calculator.png create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/calculator.svg create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/pom.xml create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/AddService.java create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/AddServiceImpl.java create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/CalculatorClient.java create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/CalculatorService.java create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/DivideService.java create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/DivideServiceImpl.java create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/MultiplyService.java create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/MultiplyServiceImpl.java create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/SubtractService.java create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/SubtractServiceImpl.java create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/security/CalculatorCallbackHandler.java create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/security/JaasLoginModule.java create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/security/UserPrincipal.java create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/resources/Calculator.composite create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/resources/CalculatorJass.config create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/resources/CalculatorLogMessages.properties create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/resources/definitions.xml create mode 100644 branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/test/java/calculator/CalculatorTestCase.java (limited to 'branches/sca-java-1.2.1/samples/calculator-implementation-policies') diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/README b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/README new file mode 100644 index 0000000000..b69c6873a6 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/README @@ -0,0 +1,266 @@ +Calculator Implementation Policies Sample +========================================= +This sample builds over simple calculator sample to demonstrate how Implementation Policies can +be use in Tuscany SCA Java. + +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 the sample 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-calculator.jar calculator.CalculatorClient + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-calculator.jar calculator.CalculatorClient + + +Sample Overview +--------------- +The sample provides the calculator service with a default SCA (java) binding. The 'logging' policy +which is handled by the Tuscany SCA java policy-logging module is used in this calculator +composite to specify the need for 'logging'. The MultiplyService Component specifies for 'jassAuthentication' +which is one way of implemention login authentication, using the Java Authentication and Authorization Service. + +The logging intent and policyset that is to be used by this calculator application must be +defined in the definitions.xml file. Here we use the policyset structure already defined in +Tuscany for logging under the policy-logging and hence there is no need to specify the policyset processors +and policy handler classes as part of this application. + +Similarly the jaasAuthentication intent and policyset also is defined in the definitions.xml file +of this sample. This sample uses the calculator.security.JaasLoginModule class for handling the +authentication functions. Right now there is a simply matching of userid and passwords that happens in this +class. Applications could implement their own sophisticated authentication mechanisms. For more information +on how to do this please look up Java Authentication and Authorization Service documentation. The sample +also use the calculator.security.CalculatorCallbackHandler to fetch the userid and password to be use for the +login authentication. This handler presently uses hardcoded userids and passwords. Applications could +typically use this handler to prompt for userid and passwords. + +There are two components that provide the calculator service namely 'CalculatorServiceComponent' +and 'AnotherCalculatorServiceComponent'. The logging intent is specified for the 'subtract' and 'divide' +operations of the 'CalculatorServiceCompnent' implementation, and on the entire implementation +(i.e. all operations) for the AddServiceComponent and AnotherCalculatorServiceComponent. + +The CalculatorClient first exercises the CalculatorServiceComponent calling add, +subtract, multiply and divide operations. This results in logging messages appearing on the +console for 'add', 'subtract' and 'divide' operations. The CalculatorClient then exercises the +AnotherCalculatorServiceComponent calling all the service methods. This will result in logging messages +printed on the console for all the operations. For the 'add' operation there will be two sets of messages +printed - one that has resulted from specifying the 'logging' intent on the implementation element of the +'AnotherCalculatorServiceComponent' and another from specifying the 'logging' intent on the +'AddServiceComponent' + +The jaasAuthentication intent is specified for the 'MultiplyServiceComponent'. So everytime this component +is invoke an authentication is attempted and only if it succeeds, is the multiply function is invoked. The +console prints messages that denote if the authentication has succeeded or failed. + +Thus this sample demonstrates how intents could be applied to either implementations as a whole or to some +selective operations on an implementation. + + +calculator/ + src/ + main/ + java/ + calculator/ + CalculatorService.java - the first component, calls +-/* as + appropriate + CalculatorServiceImpl.java + AddService.java - adds two numbers + AddServiceImpl.java + SubtractService.java - subtracts one number from another + SubtractServiceImpl.java + MultiplyService.java - multiplies two numbers + MultiplyServiceImpl.java + DivideService.java - divides one number by another + DivideServiceImpl.java + CalculatorClient.java - starts the SCA Runtime and + deploys the Calculator.composite. + It then calls the deployed Calculator + Components services + calculator/security + JaasLoginModule.java JaasLoginModule implementation for this sample + CalculatorCallbackHandler.java JAAS callbackhandler for fetching userid and password + + + resources/ + Calculator.composite - the SCA assembly for this sample + definitions.xml - sca definitions file that defines the 'logging' intent + and policyset + used by this application + CalculatorLogMessages.properties - A resource bundle contain the log messages to be + used. + CalculatorJaas.config - JAAS Login Configuration file + + test/ + java/ + calculator/ + CalculatorTestCase.java - JUnit test case + calculator.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 as +follows + +cd calculator-implementation-policies +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] Calling CalculatorServiceComponent configured with 'logging' policy for subtract and divide operations... + [java] Nov 23, 2007 1:06:10 PM + [java] INFO: Invoking operation - add + [java] Nov 23, 2007 1:06:10 PM + [java] INFO: Returned from operation - add + [java] 3 + 2=5.0 + [java] 3 - 2=1.0 + [java] 3 * 2=6.0 + [java] 3 / 2=1.5 + [java] Calling CalculatorServiceComponent configured with 'logging' for all operations in the implementation... + [java] Nov 23, 2007 1:06:10 PM + [java] INFO: Invoking operation - subtract + [java] Nov 23, 2007 1:06:10 PM + [java] INFO: Returned from operation - subtract + [java] Nov 23, 2007 1:06:10 PM + [java] INFO: Invoking operation - divide + [java] Nov 23, 2007 1:06:10 PM + [java] INFO: Returned from operation - divide + [java] Nov 23, 2007 1:06:10 PM + [java] 3 + 2=5.0 + [java] 3 - 2=1.0 + [java] 3 * 2=6.0 + [java] INFO: Invoking operation - add + [java] 3 / 2=1.5 + [java] Nov 23, 2007 1:06:10 PM + [java] INFO: Invoking operation - add + [java] Nov 23, 2007 1:06:10 PM + [java] INFO: Returned from operation - add + [java] Nov 23, 2007 1:06:10 PM + [java] INFO: Returned from operation - add + [java] Nov 23, 2007 1:06:10 PM + [java] INFO: Invoking operation - subtract + [java] Nov 23, 2007 1:06:10 PM + [java] INFO: Returned from operation - subtract + [java] Nov 23, 2007 1:06:10 PM + [java] INFO: Invoking operation - multiply + [java] Nov 23, 2007 1:06:10 PM + [java] INFO: Returned from operation - multiply + [java] Nov 23, 2007 1:06:10 PM + [java] INFO: Invoking operation - divide + [java] Nov 23, 2007 1:06:10 PM + [java] INFO: Returned from operation - divide + +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. + +cd calculator +mvn + +You should see the following output from the test phase. Notice the log messages. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running calculator.CalculatorTestCase +Dec 18, 2007 12:05:06 PM org.apache.tuscany.sca.contribution.processor.ValidatingXMLStreamReader$1 error +WARNING: XMLSchema validation problem in: file:/F:/LatestTrunk/sca/samples/calculator-implementation-policies/target/ +classes/Calculator.composite, line: 28, column: 4 +cvc-complex-type.2.4.a: Invalid content was found starting with element 'operation'. One of '{WC[##other:"http://www. +osoa.org/xmlns/sca/1.0"]}' is expected. +Dec 18, 2007 12:05:06 PM +INFO: Invoking operation - add +Dec 18, 2007 12:05:06 PM +FINER: Inovoking operation add with arguments 3.0, 2.0, +Dec 18, 2007 12:05:06 PM +INFO: Returned from operation - add +Dec 18, 2007 12:05:06 PM +FINER: Returning from operation add with return value 5 +Dec 18, 2007 12:05:06 PM +INFO: Invoking operation - subtract +Dec 18, 2007 12:05:06 PM +FINER: Inovoking operation subtract with arguments 3.0, 2.0, +Dec 18, 2007 12:05:06 PM +INFO: Returned from operation - subtract +Dec 18, 2007 12:05:06 PM +FINER: Returning from operation subtract with return value 1 +Successfully AUTHENTICATED!! +Dec 18, 2007 12:05:06 PM +INFO: Invoking operation - divide +Dec 18, 2007 12:05:06 PM +FINER: Inovoking operation divide with arguments 3.0, 2.0, +Dec 18, 2007 12:05:06 PM +INFO: Returned from operation - divide +Dec 18, 2007 12:05:06 PM +FINER: Returning from operation divide with return value 1.5 +Dec 18, 2007 12:05:06 PM org.apache.tuscany.sca.contribution.processor.ValidatingXMLStreamReader$1 error +WARNING: XMLSchema validation problem in: file:/F:/LatestTrunk/sca/samples/calculator-implementation-policies/target/ +classes/Calculator.composite, line: 28, column: 4 +cvc-complex-type.2.4.a: Invalid content was found starting with element 'operation'. One of '{WC[##other:"http://www. +osoa.org/xmlns/sca/1.0"]}' is expected. +Dec 18, 2007 12:05:06 PM +INFO: Invoking operation - add +Dec 18, 2007 12:05:06 PM +FINER: Inovoking operation add with arguments 3.0, 2.0, +Dec 18, 2007 12:05:06 PM +INFO: Invoking operation - add +Dec 18, 2007 12:05:06 PM +FINER: Inovoking operation add with arguments 3.0, 2.0, +Dec 18, 2007 12:05:06 PM +INFO: Returned from operation - add +Dec 18, 2007 12:05:06 PM +FINER: Returning from operation add with return value 5 +Dec 18, 2007 12:05:06 PM +INFO: Returned from operation - add +Dec 18, 2007 12:05:06 PM +FINER: Returning from operation add with return value 5 +Dec 18, 2007 12:05:06 PM +INFO: Invoking operation - subtract +Dec 18, 2007 12:05:06 PM +FINER: Inovoking operation subtract with arguments 3.0, 2.0, +Dec 18, 2007 12:05:06 PM +INFO: Returned from operation - subtract +Dec 18, 2007 12:05:06 PM +FINER: Returning from operation subtract with return value 1 +Dec 18, 2007 12:05:06 PM +INFO: Invoking operation - multiply +Dec 18, 2007 12:05:06 PM +FINER: Inovoking operation multiply with arguments 3.0, 2.0, +Successfully AUTHENTICATED!! +Dec 18, 2007 12:05:06 PM +INFO: Returned from operation - multiply +Dec 18, 2007 12:05:06 PM +FINER: Returning from operation multiply with return value 6 +Dec 18, 2007 12:05:06 PM +INFO: Invoking operation - divide +Dec 18, 2007 12:05:06 PM +FINER: Inovoking operation divide with arguments 3.0, 2.0, +Dec 18, 2007 12:05:06 PM +INFO: Returned from operation - divide +Dec 18, 2007 12:05:06 PM +FINER: Returning from operation divide with return value 1.5 +Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.823 sec + +Results : + +Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 + +Results : + +Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 +This shows that the Junit test cases have run successfully. diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/build.xml b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/build.xml new file mode 100644 index 0000000000..3d65356a06 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/build.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/calculator.png b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/calculator.png new file mode 100644 index 0000000000..995a57b1fd Binary files /dev/null and b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/calculator.png differ diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/calculator.svg b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/calculator.svg new file mode 100644 index 0000000000..af34f07e04 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/calculator.svg @@ -0,0 +1,329 @@ + + + + + + + + + + image/svg+xml + + + + + + + + Calculator + + CalculatorServiceComponent + + + CalculatorService + AddServiceComponent + + SubtractServiceComponent + + MultiplyServiceComponent + + DivideServiceComponent + addService + subtractService + multiplyService + divideService + + + + + + diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/pom.xml b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/pom.xml new file mode 100644 index 0000000000..1ebe9a82d2 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/pom.xml @@ -0,0 +1,64 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 1.2.1-incubating-SNAPSHOT + ../../pom.xml + + sample-calculator-impl-policies + Apache Tuscany SCA Calculator Sample using Implementation Policies + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.2.1-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.2.1-incubating-SNAPSHOT + runtime + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/AddService.java b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..188451ebac --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/AddService.java @@ -0,0 +1,28 @@ +/* + * 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 calculator; + +/** + * The Add service interface + */ +public interface AddService { + + double add(double n1, double n2); + +} diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/AddServiceImpl.java b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..7ca8fb04b5 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/AddServiceImpl.java @@ -0,0 +1,35 @@ +/* + * 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 calculator; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * An implementation of the Add service + */ +public class AddServiceImpl implements AddService { + + public double add(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.FINEST, "Adding " + n1 + " and " + n2); + return n1 + n2; + } + +} diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/CalculatorClient.java b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..57bbc39d89 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/CalculatorClient.java @@ -0,0 +1,70 @@ +/* + * 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 calculator; + +import javax.security.auth.login.Configuration; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * This client program shows how to create an SCA runtime, start it, + * and locate and invoke a SCA component + */ +public class CalculatorClient { + public static void main(String[] args) throws Exception { + try { + Configuration secConf = Configuration.getConfiguration(); + } catch ( java.lang.SecurityException e ) { + if ( e.getMessage().equals("Unable to locate a login configuration") ) { + System.setProperty("java.security.auth.login.config", + CalculatorClient.class.getClassLoader().getResource("CalculatorJass.config").toString()); + } else { + throw e; + } + } + + SCADomain scaDomain = SCADomain.newInstance("Calculator.composite"); + + CalculatorService calculatorService = + scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent"); + + // Calculate + System.out.println("Calling CalculatorServiceComponent configured with 'logging' " + + "policy for subtract and divide operations..."); + System.out.println("3 + 2=" + calculatorService.add(3, 2)); + System.out.println("3 - 2=" + calculatorService.subtract(3, 2)); + System.out.println("3 * 2=" + calculatorService.multiply(3, 2)); + System.out.println("3 / 2=" + calculatorService.divide(3, 2)); + + calculatorService = + scaDomain.getService(CalculatorService.class, "AnotherCalculatorServiceComponent"); + + // Calculate + System.out.println("Calling CalculatorServiceComponent configured with 'logging' " + + "for all operations in the implementation..."); + System.out.println("3 + 2=" + calculatorService.add(3, 2)); + System.out.println("3 - 2=" + calculatorService.subtract(3, 2)); + System.out.println("3 * 2=" + calculatorService.multiply(3, 2)); + System.out.println("3 / 2=" + calculatorService.divide(3, 2)); + + scaDomain.close(); + } + +} diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/CalculatorService.java b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..031fa8b912 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/CalculatorService.java @@ -0,0 +1,35 @@ +/* + * 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 calculator; + + +/** + * The Calculator service interface. + */ +public interface CalculatorService { + + double add(double n1, double n2); + + double subtract(double n1, double n2); + + double multiply(double n1, double n2); + + double divide(double n1, double n2); + +} diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/CalculatorServiceImpl.java b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..3d861f2018 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/CalculatorServiceImpl.java @@ -0,0 +1,70 @@ +/* + * 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 calculator; + +import org.osoa.sca.annotations.Reference; + + +/** + * An implementation of the Calculator service. + */ +public class CalculatorServiceImpl implements CalculatorService { + + private AddService addService; + private SubtractService subtractService; + private MultiplyService multiplyService; + private DivideService divideService; + + @Reference + public void setAddService(AddService addService) { + this.addService = addService; + } + + @Reference + public void setSubtractService(SubtractService subtractService) { + this.subtractService = subtractService; + } + + @Reference + public void setDivideService(DivideService divideService) { + this.divideService = divideService; + } + + @Reference + public void setMultiplyService(MultiplyService multiplyService) { + this.multiplyService = multiplyService; + } + + public double add(double n1, double n2) { + return addService.add(n1, n2); + } + + public double subtract(double n1, double n2) { + return subtractService.subtract(n1, n2); + } + + public double multiply(double n1, double n2) { + return multiplyService.multiply(n1, n2); + } + + public double divide(double n1, double n2) { + return divideService.divide(n1, n2); + } + +} diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/DivideService.java b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..30d248208b --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/DivideService.java @@ -0,0 +1,28 @@ +/* + * 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 calculator; + +/** + * The divide service interface + */ +public interface DivideService { + + double divide(double n1, double n2); + +} diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/DivideServiceImpl.java b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..1323edf55a --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/DivideServiceImpl.java @@ -0,0 +1,35 @@ +/* + * 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 calculator; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * An implementation of the Divide service. + */ +public class DivideServiceImpl implements DivideService { + + public double divide(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.FINEST, "Dividing " + n1 + " with " + n2); + return n1 / n2; + } + +} diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/MultiplyService.java b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..5290605938 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/MultiplyService.java @@ -0,0 +1,28 @@ +/* + * 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 calculator; + +/** + * The interface for the multiply service + */ +public interface MultiplyService { + + double multiply(double n1, double n2); + +} diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/MultiplyServiceImpl.java b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..91b803bc9e --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/MultiplyServiceImpl.java @@ -0,0 +1,35 @@ +/* + * 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 calculator; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * An implementation of the Multiply service. + */ +public class MultiplyServiceImpl implements MultiplyService { + + public double multiply(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.FINEST, "Multiplying " + n1 + " with " + n2); + return n1 * n2; + } + +} diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/SubtractService.java b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..bf0d1882b6 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/SubtractService.java @@ -0,0 +1,28 @@ +/* + * 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 calculator; + +/** + * The interface for the multiply service + */ +public interface SubtractService { + + double subtract(double n1, double n2); + +} diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/SubtractServiceImpl.java b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..58cc4a3547 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/SubtractServiceImpl.java @@ -0,0 +1,35 @@ +/* + * 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 calculator; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * An implementation of the subtract service. + */ +public class SubtractServiceImpl implements SubtractService { + + public double subtract(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.FINEST, "Subtracting " + n1 + " from " + n2); + return n1 - n2; + } + +} diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/security/CalculatorCallbackHandler.java b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/security/CalculatorCallbackHandler.java new file mode 100644 index 0000000000..4f063993a3 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/security/CalculatorCallbackHandler.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 calculator.security; + +import java.io.IOException; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.NameCallback; +import javax.security.auth.callback.PasswordCallback; +import javax.security.auth.callback.UnsupportedCallbackException; + +/** + * @version $Rev$ $Date$ + */ +public class CalculatorCallbackHandler implements CallbackHandler { + + public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { + for (int i = 0; i < callbacks.length; i++) { + if (callbacks[i] instanceof NameCallback) { + NameCallback nc = (NameCallback)callbacks[i]; + nc.setName("CalculatorUser"); + } else if (callbacks[i] instanceof PasswordCallback) { + PasswordCallback pc = (PasswordCallback)callbacks[i]; + pc.setPassword("CalculatorUserPasswd".toCharArray()); + } else { + throw new UnsupportedCallbackException + (callbacks[i], "Unsupported Callback!"); + } + } + } + +} diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/security/JaasLoginModule.java b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/security/JaasLoginModule.java new file mode 100644 index 0000000000..b3ef6e7312 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/security/JaasLoginModule.java @@ -0,0 +1,178 @@ +/* + * 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 calculator.security; + +import java.security.Principal; +import java.util.Map; + +import javax.security.auth.Subject; +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.NameCallback; +import javax.security.auth.callback.PasswordCallback; +import javax.security.auth.login.LoginException; +import javax.security.auth.spi.LoginModule; + +/** + * @version $Rev$ $Date$ + */ +public class JaasLoginModule implements LoginModule { + + private CallbackHandler callbackHandler; + private Subject subject; + private Principal userPrincipal; + private String userId; + private String password; + private boolean succeeded; + private boolean commitSucceeded; + + public void initialize(Subject subject, + CallbackHandler callbackHandler, + Map sharedState, + Map options) { + this.callbackHandler = callbackHandler; + this.subject = subject; + } + + public boolean login() throws LoginException { + Callback[] callbacks = new Callback[2]; + callbacks[0] = new NameCallback("UserId:"); + callbacks[1] = new PasswordCallback("Password:", false); + + try { + callbackHandler.handle(callbacks); + userId = ((NameCallback)callbacks[0]).getName(); + password = new String(((PasswordCallback)callbacks[1]).getPassword()); + + if (userId.equals("CalculatorUser") && password.equals("CalculatorUserPasswd")) { + System.out.println("Successfully AUTHENTICATED!!"); + succeeded = true; + return true; + } else { + System.out.println("Incorrect userId / password! AUTHENTICATION FAILED!!"); + return false; + } + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + *

This method is called if the LoginContext's + * overall authentication succeeded + * (the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL LoginModules + * succeeded). + * + *

If this LoginModule's own authentication attempt + * succeeded (checked by retrieving the private state saved by the + * login method), then this method associates a + * UserPrincipal + * with the Subject located in the + * LoginModule. If this LoginModule's own + * authentication attempted failed, then this method removes + * any state that was originally saved. + * + *

+ * + * @exception LoginException if the commit fails. + * + * @return true if this LoginModule's own login and commit + * attempts succeeded, or false otherwise. + */ + public boolean commit() throws LoginException { + if (succeeded == false) { + return false; + } else { + // add a Principal (authenticated identity) to the Subject + + // assume the user we authenticated is the UserPrincipal + userPrincipal = new UserPrincipal(userId); + if (!subject.getPrincipals().contains(userPrincipal)) + subject.getPrincipals().add(userPrincipal); + + // in any case, clean out state + userId = null; + password = null; + commitSucceeded = true; + return true; + } + } + + /** + *

This method is called if the LoginContext's + * overall authentication failed. + * (the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL LoginModules + * did not succeed). + * + *

If this LoginModule's own authentication attempt + * succeeded (checked by retrieving the private state saved by the + * login and commit methods), + * then this method cleans up any state that was originally saved. + * + *

+ * + * @exception LoginException if the abort fails. + * + * @return false if this LoginModule's own login and/or commit attempts + * failed, and true otherwise. + */ + public boolean abort() throws LoginException { + if (succeeded == false) { + return false; + } else if (succeeded == true && commitSucceeded == false) { + // login succeeded but overall authentication failed + succeeded = false; + userId = null; + password = null; + userPrincipal = null; + } else { + // overall authentication succeeded and commit succeeded, + // but someone else's commit failed + logout(); + } + return true; + } + + /** + * Logout the user. + * + *

This method removes the SimplePrincipal + * that was added by the commit method. + * + *

+ * + * @exception LoginException if the logout fails. + * + * @return true in all cases since this LoginModule + * should not be ignored. + */ + public boolean logout() throws LoginException { + subject.getPrincipals().remove(userPrincipal); + succeeded = false; + succeeded = commitSucceeded; + userId = null; + if (password != null) + password = null; + userPrincipal = null; + return true; + } + +} diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/security/UserPrincipal.java b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/security/UserPrincipal.java new file mode 100644 index 0000000000..595626e672 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/java/calculator/security/UserPrincipal.java @@ -0,0 +1,66 @@ +/** + * 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 calculator.security; + +import java.security.Principal; + +/** + * @version $Rev$ $Date$ + */ +public class UserPrincipal implements Principal { + + private final String name; + + public UserPrincipal(String name) { + if (name == null) + throw new IllegalArgumentException("name cannot be null"); + this.name = name; + } + + public String getName() { + return name; + } + + public String toString() { + return name; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final UserPrincipal other = (UserPrincipal)obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } +} diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/resources/Calculator.composite b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/resources/Calculator.composite new file mode 100644 index 0000000000..d91bf88d96 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/resources/Calculator.composite @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/resources/CalculatorJass.config b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/resources/CalculatorJass.config new file mode 100644 index 0000000000..c3adb904b2 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/resources/CalculatorJass.config @@ -0,0 +1,21 @@ +/* + * 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. + */ +Calculator { + calculator.security.JaasLoginModule required debug=true; +}; diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/resources/CalculatorLogMessages.properties b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/resources/CalculatorLogMessages.properties new file mode 100644 index 0000000000..0238f0b013 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/resources/CalculatorLogMessages.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. +CALLING_OPERATION=Inovoking operation {0} with arguments {1} +OPERATION_RETURNED=Returning from operation {0} with return value {1} \ No newline at end of file diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/resources/definitions.xml b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/resources/definitions.xml new file mode 100644 index 0000000000..b9f0feb145 --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/main/resources/definitions.xml @@ -0,0 +1,49 @@ + + + + + + + All messages to and from this implementation must be logged + + + + All invocations to be authenticated + + + + + + Calculator + calculator.security.CalculatorCallbackHandler + + + + + + + FINER + + + \ No newline at end of file diff --git a/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/test/java/calculator/CalculatorTestCase.java b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/test/java/calculator/CalculatorTestCase.java new file mode 100644 index 0000000000..d44e86775b --- /dev/null +++ b/branches/sca-java-1.2.1/samples/calculator-implementation-policies/src/test/java/calculator/CalculatorTestCase.java @@ -0,0 +1,74 @@ +/* + * 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 calculator; + +import javax.security.auth.login.Configuration; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * This shows how to test the Calculator service component. + */ +public class CalculatorTestCase extends TestCase { + + private CalculatorService calculatorService; + private CalculatorService anotherCalculatorService; + private SCADomain scaDomain; + + @Override + protected void setUp() throws Exception { + try { + Configuration secConf = Configuration.getConfiguration(); + } catch ( java.lang.SecurityException e ) { + //FIXME: We should not compare exception strings as they are localized in various languages + //if ( e.getMessage().equals("Unable to locate a login configuration") ) { + System.setProperty("java.security.auth.login.config", + this.getClass().getClassLoader().getResource("CalculatorJass.config").toString()); + //} else { + // throw e; + //} + } + scaDomain = SCADomain.newInstance("Calculator.composite"); + calculatorService = scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent"); + anotherCalculatorService = scaDomain.getService(CalculatorService.class, "AnotherCalculatorServiceComponent"); + } + + @Override + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testCalculator() throws Exception { + // Calculate + assertEquals(calculatorService.add(3, 2), 5.0); + assertEquals(calculatorService.subtract(3, 2), 1.0); + assertEquals(calculatorService.multiply(3, 2), 6.0); + assertEquals(calculatorService.divide(3, 2), 1.5); + } + + public void testAnotherCalculator() throws Exception { + // Calculate + assertEquals(anotherCalculatorService.add(3, 2), 5.0); + assertEquals(anotherCalculatorService.subtract(3, 2), 1.0); + assertEquals(anotherCalculatorService.multiply(3, 2), 6.0); + assertEquals(anotherCalculatorService.divide(3, 2), 1.5); + } +} -- cgit v1.2.3