summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'branches/sca-java-1.1/samples/calculator-implementation-policies/src/main')
-rw-r--r--branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/AddService.java28
-rw-r--r--branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/AddServiceImpl.java35
-rw-r--r--branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/CalculatorClient.java69
-rw-r--r--branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/CalculatorService.java35
-rw-r--r--branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/CalculatorServiceImpl.java70
-rw-r--r--branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/DivideService.java28
-rw-r--r--branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/DivideServiceImpl.java35
-rw-r--r--branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/MultiplyService.java28
-rw-r--r--branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/MultiplyServiceImpl.java35
-rw-r--r--branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/SubtractService.java28
-rw-r--r--branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/SubtractServiceImpl.java35
-rw-r--r--branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/security/CalculatorCallbackHandler.java50
-rw-r--r--branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/security/JaasLoginModule.java84
-rw-r--r--branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/resources/Calculator.composite61
-rw-r--r--branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/resources/CalculatorJass.config3
-rw-r--r--branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/resources/CalculatorLogMessages.properties18
-rw-r--r--branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/resources/definitions.xml61
17 files changed, 703 insertions, 0 deletions
diff --git a/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/AddService.java b/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/AddService.java
new file mode 100644
index 0000000000..5a1e7a638a
--- /dev/null
+++ b/branches/sca-java-1.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.1/samples/calculator-implementation-policies/src/main/java/calculator/AddServiceImpl.java b/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/AddServiceImpl.java
new file mode 100644
index 0000000000..caf4d358df
--- /dev/null
+++ b/branches/sca-java-1.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.1/samples/calculator-implementation-policies/src/main/java/calculator/CalculatorClient.java b/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/CalculatorClient.java
new file mode 100644
index 0000000000..c1f79888cb
--- /dev/null
+++ b/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/CalculatorClient.java
@@ -0,0 +1,69 @@
+/*
+ * 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", "target/classes/CalculatorJass.config");
+ } 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.1/samples/calculator-implementation-policies/src/main/java/calculator/CalculatorService.java b/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/CalculatorService.java
new file mode 100644
index 0000000000..ad87375529
--- /dev/null
+++ b/branches/sca-java-1.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.1/samples/calculator-implementation-policies/src/main/java/calculator/CalculatorServiceImpl.java b/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/CalculatorServiceImpl.java
new file mode 100644
index 0000000000..ae4ed12b7b
--- /dev/null
+++ b/branches/sca-java-1.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.1/samples/calculator-implementation-policies/src/main/java/calculator/DivideService.java b/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/DivideService.java
new file mode 100644
index 0000000000..ef6a8b375b
--- /dev/null
+++ b/branches/sca-java-1.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.1/samples/calculator-implementation-policies/src/main/java/calculator/DivideServiceImpl.java b/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/DivideServiceImpl.java
new file mode 100644
index 0000000000..cd91935f08
--- /dev/null
+++ b/branches/sca-java-1.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.1/samples/calculator-implementation-policies/src/main/java/calculator/MultiplyService.java b/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/MultiplyService.java
new file mode 100644
index 0000000000..db568cc762
--- /dev/null
+++ b/branches/sca-java-1.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.1/samples/calculator-implementation-policies/src/main/java/calculator/MultiplyServiceImpl.java b/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/MultiplyServiceImpl.java
new file mode 100644
index 0000000000..c85357fcd8
--- /dev/null
+++ b/branches/sca-java-1.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.1/samples/calculator-implementation-policies/src/main/java/calculator/SubtractService.java b/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/SubtractService.java
new file mode 100644
index 0000000000..56ee372fc4
--- /dev/null
+++ b/branches/sca-java-1.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.1/samples/calculator-implementation-policies/src/main/java/calculator/SubtractServiceImpl.java b/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/SubtractServiceImpl.java
new file mode 100644
index 0000000000..1b669084d9
--- /dev/null
+++ b/branches/sca-java-1.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.1/samples/calculator-implementation-policies/src/main/java/calculator/security/CalculatorCallbackHandler.java b/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/security/CalculatorCallbackHandler.java
new file mode 100644
index 0000000000..b48fb90148
--- /dev/null
+++ b/branches/sca-java-1.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.1/samples/calculator-implementation-policies/src/main/java/calculator/security/JaasLoginModule.java b/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/security/JaasLoginModule.java
new file mode 100644
index 0000000000..a9461f65de
--- /dev/null
+++ b/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/java/calculator/security/JaasLoginModule.java
@@ -0,0 +1,84 @@
+/*
+ * 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.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 = null;
+ private Subject subject = null;
+
+ public boolean abort() throws LoginException {
+ return true;
+ }
+
+
+ public boolean commit() throws LoginException {
+ return true;
+ }
+
+ public void initialize(Subject subject,
+ CallbackHandler callbackHandler,
+ Map<String, ?> sharedState,
+ Map<String, ?> 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);
+ String userId = ((NameCallback)callbacks[0]).getName();
+ String password = new String(((PasswordCallback)callbacks[1]).getPassword());
+
+ if ( userId.equals("CalculatorUser") && password.equals("CalculatorUserPasswd")) {
+ System.out.println("Successfully AUTHENTICATED!!");
+ return true;
+ } else {
+ System.out.println("Incorrect userId / password! AUTHENTICATION FAILED!!");
+ return false;
+ }
+ } catch ( Exception e ) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ public boolean logout() throws LoginException {
+ return true;
+ }
+
+}
diff --git a/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/resources/Calculator.composite b/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/resources/Calculator.composite
new file mode 100644
index 0000000000..d91bf88d96
--- /dev/null
+++ b/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/resources/Calculator.composite
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ targetNamespace="http://sample"
+ xmlns:sample="http://sample"
+ name="Calculator"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0">
+
+ <component name="CalculatorServiceComponent">
+ <implementation.java class="calculator.CalculatorServiceImpl">
+ <operation name="divide" requires="tuscany:logging"/>
+ <operation name="subtract" requires="tuscany:logging"/>
+ </implementation.java>
+ <reference name="addService" target="AddServiceComponent" />
+ <reference name="subtractService" target="SubtractServiceComponent" />
+ <reference name="multiplyService" target="MultiplyServiceComponent" />
+ <reference name="divideService" target="DivideServiceComponent" />
+ </component>
+
+ <component name="AddServiceComponent">
+ <implementation.java class="calculator.AddServiceImpl" requires="tuscany:logging"/>
+ </component>
+
+ <component name="SubtractServiceComponent">
+ <implementation.java class="calculator.SubtractServiceImpl"/>
+ </component>
+
+ <component name="MultiplyServiceComponent">
+ <implementation.java class="calculator.MultiplyServiceImpl" requires="tuscany:jaasAuthentication"/>
+ </component>
+
+ <component name="DivideServiceComponent">
+ <implementation.java class="calculator.DivideServiceImpl"/>
+ </component>
+
+ <component name="AnotherCalculatorServiceComponent">
+ <implementation.java class="calculator.CalculatorServiceImpl" requires="tuscany:logging"/>
+ <reference name="addService" target="AddServiceComponent" />
+ <reference name="subtractService" target="SubtractServiceComponent" />
+ <reference name="multiplyService" target="MultiplyServiceComponent" />
+ <reference name="divideService" target="DivideServiceComponent" />
+ </component>
+
+</composite>
diff --git a/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/resources/CalculatorJass.config b/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/resources/CalculatorJass.config
new file mode 100644
index 0000000000..0e7cb86633
--- /dev/null
+++ b/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/resources/CalculatorJass.config
@@ -0,0 +1,3 @@
+Calculator {
+ calculator.security.JaasLoginModule required debug=true;
+};
diff --git a/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/resources/CalculatorLogMessages.properties b/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/resources/CalculatorLogMessages.properties
new file mode 100644
index 0000000000..f62125eaa9
--- /dev/null
+++ b/branches/sca-java-1.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.1/samples/calculator-implementation-policies/src/main/resources/definitions.xml b/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/resources/definitions.xml
new file mode 100644
index 0000000000..f6ed3573b3
--- /dev/null
+++ b/branches/sca-java-1.1/samples/calculator-implementation-policies/src/main/resources/definitions.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ * 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.
+-->
+<definitions xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ targetNamespace="http://test"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:calc="http://calculator">
+
+<!-- Policy Intents -->
+<intent name="tuscany:logging"
+ constrains="sca:implementation.java">
+ <description>
+ All messages to and from this implementation must be logged
+ </description>
+</intent>
+
+<intent name="tuscany:jaasAuthentication"
+ constrains="sca:implementation.java">
+ <description>
+ All invocations to be authenticated
+ </description>
+</intent>
+
+<!-- PolicySets -->
+<policySet name="tuscany:JaasPolicy"
+ provides="tuscany:jaasAuthentication"
+ appliesTo="sca:implementation.java"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0">
+ <tuscany:jaasAuthentication>
+ <tuscany:callbackHandler>calculator.security.CalculatorCallbackHandler</tuscany:callbackHandler>
+ </tuscany:jaasAuthentication>
+</policySet>
+
+<!-- PolicySets -->
+<policySet name="tuscany:JDKLoggingPolicy"
+ provides="tuscany:logging"
+ appliesTo="sca:implementation.java"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0">
+ <tuscany:jdkLogger xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0" name="calculator">
+ <logLevel>FINER</logLevel>
+ </tuscany:jdkLogger>
+</policySet>
+
+</definitions> \ No newline at end of file