From 23297fa3b1f66d74325c8352cb8f5aae599a3090 Mon Sep 17 00:00:00 2001 From: antelder Date: Mon, 11 Aug 2008 07:29:53 +0000 Subject: Start branch for 1.3.1, the only changes in this commit are for the version git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@684661 13f79535-47bb-0310-9956-ffa450edef68 --- .../annotations/conversationattributes/pom.xml | 53 ++++++ .../conversationattributes/AService.java | 30 ++++ .../conversationattributes/B2Service.java | 32 ++++ .../conversationattributes/BService.java | 32 ++++ .../conversationattributes/CService.java | 30 ++++ .../conversationattributes/impl/AServiceImpl.java | 80 +++++++++ .../conversationattributes/impl/B2ServiceImpl.java | 42 +++++ .../conversationattributes/impl/BServiceImpl.java | 42 +++++ .../conversationattributes/impl/CServiceImpl.java | 37 +++++ .../security/ACallbackHandler.java | 50 ++++++ .../security/JaasLoginModule.java | 179 +++++++++++++++++++++ .../security/UserPrincipal.java | 66 ++++++++ .../src/main/resources/AJass.config | 3 + .../src/main/resources/conversation.composite | 46 ++++++ .../src/main/resources/definitions.xml | 34 ++++ .../src/main/resources/singleprincipal.composite | 38 +++++ .../ConversationAttributesAnnotationTestCase.java | 93 +++++++++++ .../SinglePricipalTestCase.java | 70 ++++++++ 18 files changed, 957 insertions(+) create mode 100644 branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/pom.xml create mode 100644 branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/AService.java create mode 100644 branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/B2Service.java create mode 100644 branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/BService.java create mode 100644 branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/CService.java create mode 100644 branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/impl/AServiceImpl.java create mode 100644 branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/impl/B2ServiceImpl.java create mode 100644 branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/impl/BServiceImpl.java create mode 100644 branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/impl/CServiceImpl.java create mode 100644 branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/security/ACallbackHandler.java create mode 100644 branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/security/JaasLoginModule.java create mode 100644 branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/security/UserPrincipal.java create mode 100644 branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/resources/AJass.config create mode 100644 branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/resources/conversation.composite create mode 100644 branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/resources/definitions.xml create mode 100644 branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/resources/singleprincipal.composite create mode 100644 branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/test/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/ConversationAttributesAnnotationTestCase.java create mode 100644 branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/test/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/SinglePricipalTestCase.java (limited to 'branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes') diff --git a/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/pom.xml b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/pom.xml new file mode 100644 index 0000000000..225a304699 --- /dev/null +++ b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/pom.xml @@ -0,0 +1,53 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + java-api-annotations + 1.3.1-SNAPSHOT + ../pom.xml + + vtest-java-api-annotations-conversationattributes + Apache Tuscany SCA Java APIs and Annotations Verification Tests - Annotations - @ConversationAttributes + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.3.1-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.3.1-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-policy-security + 1.3.1-SNAPSHOT + runtime + + + + diff --git a/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/AService.java b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/AService.java new file mode 100644 index 0000000000..a3f1f11826 --- /dev/null +++ b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/AService.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 org.apache.tuscany.sca.vtest.javaapi.annotations.conversationattributes; + +/** + * Simple Service + */ +public interface AService { + + public void testMaxAge() throws InterruptedException; + public void testMaxIdle() throws InterruptedException; + public void testSinglePrincipal(); + +} diff --git a/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/B2Service.java b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/B2Service.java new file mode 100644 index 0000000000..8a1ed23b9d --- /dev/null +++ b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/B2Service.java @@ -0,0 +1,32 @@ +/* + * 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.vtest.javaapi.annotations.conversationattributes; + +import org.osoa.sca.annotations.Conversational; + +/** + * Simple Service + */ +@Conversational +public interface B2Service { + + public void setState(String someState); + public String getState(); + +} diff --git a/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/BService.java b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/BService.java new file mode 100644 index 0000000000..1d215100f7 --- /dev/null +++ b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/BService.java @@ -0,0 +1,32 @@ +/* + * 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.vtest.javaapi.annotations.conversationattributes; + +import org.osoa.sca.annotations.Conversational; + +/** + * Simple Service + */ +@Conversational +public interface BService { + + public void setState(String someState); + public String getState(); + +} diff --git a/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/CService.java b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/CService.java new file mode 100644 index 0000000000..cd4f29ea5b --- /dev/null +++ b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/CService.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 org.apache.tuscany.sca.vtest.javaapi.annotations.conversationattributes; + +import org.osoa.sca.ServiceReference; + +/** + * Simple Service + */ +public interface CService { + + public void testSinglePricipal(ServiceReference bReference); + +} diff --git a/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/impl/AServiceImpl.java b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/impl/AServiceImpl.java new file mode 100644 index 0000000000..64b99c9f98 --- /dev/null +++ b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/impl/AServiceImpl.java @@ -0,0 +1,80 @@ +/* + * 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.vtest.javaapi.annotations.conversationattributes.impl; + +import org.apache.tuscany.sca.vtest.javaapi.annotations.conversationattributes.AService; +import org.apache.tuscany.sca.vtest.javaapi.annotations.conversationattributes.B2Service; +import org.apache.tuscany.sca.vtest.javaapi.annotations.conversationattributes.BService; +import org.apache.tuscany.sca.vtest.javaapi.annotations.conversationattributes.CService; +import org.osoa.sca.ComponentContext; +import org.osoa.sca.annotations.Context; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +@Service(AService.class) +public class AServiceImpl implements AService { + + @Reference + protected BService b; + + @Reference + protected B2Service b2; + + @Reference + protected CService c; + + @Context + protected ComponentContext context; + + private void delayForSeconds(int numSeconds) { + try { + Thread.sleep(numSeconds * 1000);// millisecs + } catch (InterruptedException ex) { + throw new Error(ex); + } + } + + public void testMaxAge() { + + String someState = "someState"; + b.setState(someState); + delayForSeconds(2); + b.setState(someState); + + } + + public void testMaxIdle() { + + String someState = "someState"; + b2.setState(someState); + delayForSeconds(2); + b2.setState(someState); + + } + + public void testSinglePrincipal() { + + b.setState("Some state"); + System.out.println("Calling c and passing reference to b"); + c.testSinglePricipal(context.getServiceReference(BService.class, "b")); + + } + +} diff --git a/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/impl/B2ServiceImpl.java b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/impl/B2ServiceImpl.java new file mode 100644 index 0000000000..0d34b802e1 --- /dev/null +++ b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/impl/B2ServiceImpl.java @@ -0,0 +1,42 @@ +/* + * 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.vtest.javaapi.annotations.conversationattributes.impl; + +import org.apache.tuscany.sca.vtest.javaapi.annotations.conversationattributes.BService; +import org.osoa.sca.annotations.ConversationAttributes; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +@Service(BService.class) +@Scope("CONVERSATION") +@ConversationAttributes(maxIdleTime="1 seconds") +public class B2ServiceImpl implements BService { + + String someState; + + public void setState(String someState) { + this.someState = someState; + } + + public String getState() { + return someState; + } + +} diff --git a/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/impl/BServiceImpl.java b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/impl/BServiceImpl.java new file mode 100644 index 0000000000..762c9533d0 --- /dev/null +++ b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/impl/BServiceImpl.java @@ -0,0 +1,42 @@ +/* + * 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.vtest.javaapi.annotations.conversationattributes.impl; + +import org.apache.tuscany.sca.vtest.javaapi.annotations.conversationattributes.BService; +import org.osoa.sca.annotations.ConversationAttributes; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +@Service(BService.class) +@Scope("CONVERSATION") +@ConversationAttributes(maxAge="1 seconds", singlePrincipal=true) +public class BServiceImpl implements BService { + + String someState; + + public void setState(String someState) { + this.someState = someState; + } + + public String getState() { + return someState; + } + +} diff --git a/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/impl/CServiceImpl.java b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/impl/CServiceImpl.java new file mode 100644 index 0000000000..3ebf63ba54 --- /dev/null +++ b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/impl/CServiceImpl.java @@ -0,0 +1,37 @@ +/* + * 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.vtest.javaapi.annotations.conversationattributes.impl; + +import org.apache.tuscany.sca.vtest.javaapi.annotations.conversationattributes.BService; +import org.apache.tuscany.sca.vtest.javaapi.annotations.conversationattributes.CService; +import org.osoa.sca.ServiceReference; +import org.osoa.sca.annotations.Service; + +@Service(CService.class) +public class CServiceImpl implements CService { + + public void testSinglePricipal(ServiceReference bReference) { + + System.out.println("In C calling set state on passed reference to B"); + bReference.getService().setState("someState"); + + } + +} diff --git a/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/security/ACallbackHandler.java b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/security/ACallbackHandler.java new file mode 100644 index 0000000000..3820240ee2 --- /dev/null +++ b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/security/ACallbackHandler.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.vtest.javaapi.annotations.conversationattributes.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 ACallbackHandler 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("AUser"); + } else if (callbacks[i] instanceof PasswordCallback) { + PasswordCallback pc = (PasswordCallback)callbacks[i]; + pc.setPassword("AUserPasswd".toCharArray()); + } else { + throw new UnsupportedCallbackException + (callbacks[i], "Unsupported Callback!"); + } + } + } + +} diff --git a/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/security/JaasLoginModule.java b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/security/JaasLoginModule.java new file mode 100644 index 0000000000..75573b838d --- /dev/null +++ b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/security/JaasLoginModule.java @@ -0,0 +1,179 @@ +/* + * 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.vtest.javaapi.annotations.conversationattributes.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.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/security/UserPrincipal.java b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/security/UserPrincipal.java new file mode 100644 index 0000000000..8349e775c5 --- /dev/null +++ b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/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 org.apache.tuscany.sca.vtest.javaapi.annotations.conversationattributes.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.3.1/vtest/java-api/annotations/conversationattributes/src/main/resources/AJass.config b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/resources/AJass.config new file mode 100644 index 0000000000..9d5aec8ed5 --- /dev/null +++ b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/resources/AJass.config @@ -0,0 +1,3 @@ +AService { + org.apache.tuscany.sca.vtest.javaapi.annotations.conversationattributes.security.JaasLoginModule required debug=true; +}; diff --git a/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/resources/conversation.composite b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/resources/conversation.composite new file mode 100644 index 0000000000..49391b3353 --- /dev/null +++ b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/resources/conversation.composite @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/resources/definitions.xml b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/resources/definitions.xml new file mode 100644 index 0000000000..d3573176a3 --- /dev/null +++ b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/resources/definitions.xml @@ -0,0 +1,34 @@ + + + + + + + + AService + org.apache.tuscany.sca.vtest.javaapi.annotations.conversationattributes.security.ACallbackHandler + + + + \ No newline at end of file diff --git a/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/resources/singleprincipal.composite b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/resources/singleprincipal.composite new file mode 100644 index 0000000000..c10369c9bd --- /dev/null +++ b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/main/resources/singleprincipal.composite @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + diff --git a/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/test/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/ConversationAttributesAnnotationTestCase.java b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/test/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/ConversationAttributesAnnotationTestCase.java new file mode 100644 index 0000000000..b9d10732e7 --- /dev/null +++ b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/test/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/ConversationAttributesAnnotationTestCase.java @@ -0,0 +1,93 @@ +/* + * 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.vtest.javaapi.annotations.conversationattributes; + +import org.apache.tuscany.sca.vtest.utilities.ServiceFinder; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.osoa.sca.ConversationEndedException; + +/** + * This test class tests the Service annotation described in section 1.2.1 and + * 1.8.17 + */ +public class ConversationAttributesAnnotationTestCase { + + protected static String compositeName = "conversation.composite"; + protected static AService aService = null; + + @BeforeClass + public static void init() throws Exception { + try { + System.out.println("Setting up"); + ServiceFinder.init(compositeName); + aService = ServiceFinder.getService(AService.class, "AComponent"); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + @AfterClass + public static void destroy() throws Exception { + + System.out.println("Cleaning up"); + ServiceFinder.cleanup(); + + } + + /** + * Line 1665, 1666 + *

+ * maxIdleTime (optional) - The maximum time that can pass between + * operations within a single conversation. If more time than this passes, + * then the container may end the conversation. + */ + @Test(expected = ConversationEndedException.class) + public void maxIdle() throws Exception { + aService.testMaxIdle(); + } + + /** + * Line 1667, 1668 + *

+ * maxAge (optional) - The maximum time that the entire conversation can + * remain active. If more time than this passes, then the container may end + * the conversation. + */ + @Test(expected = ConversationEndedException.class) + public void maxAge() throws Exception { + aService.testMaxAge(); + } + + /** + * Line 1669, 1670 + *

+ * singlePrincipal (optional) – If true, only the principal (the user) that + * started the conversation has authority to continue the conversation. + * The default value is false. + */ + @Ignore + @Test(expected = Exception.class) + public void singlePrincipal() throws Exception { + aService.testSinglePrincipal(); + } +} diff --git a/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/test/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/SinglePricipalTestCase.java b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/test/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/SinglePricipalTestCase.java new file mode 100644 index 0000000000..4ebd667a00 --- /dev/null +++ b/branches/sca-java-1.3.1/vtest/java-api/annotations/conversationattributes/src/test/java/org/apache/tuscany/sca/vtest/javaapi/annotations/conversationattributes/SinglePricipalTestCase.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 org.apache.tuscany.sca.vtest.javaapi.annotations.conversationattributes; + +import javax.security.auth.login.Configuration; + +import org.apache.tuscany.sca.vtest.utilities.ServiceFinder; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * + */ +public class SinglePricipalTestCase { + + protected static String compositeName = "singleprincipal.composite"; + protected static AService aService = null; + + @Before + public void init() throws Exception { + try { + Configuration.getConfiguration(); + } catch (java.lang.SecurityException e) { + System.out.println("Caught SecurityException"); + System.setProperty("java.security.auth.login.config", this.getClass().getClassLoader() + .getResource("AJass.config").toString()); + } + System.out.println("Setting up"); + ServiceFinder.init(compositeName); + aService = ServiceFinder.getService(AService.class, "AComponent"); + } + + @After + public void destroy() throws Exception { + + System.out.println("Cleaning up"); + ServiceFinder.cleanup(); + + } + + /** + * Line 1669, 1670 + *

+ * singlePrincipal (optional) – If true, only the principal (the user) that + * started the conversation has authority to continue the conversation. The + * default value is false. + */ + @Test(expected = Exception.class) + public void singlePrincipal() throws Exception { + aService.testSinglePrincipal(); + } +} -- cgit v1.2.3