diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-20 09:41:17 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-20 09:41:17 +0000 |
commit | ecaed8ff741ea67c33c93cf571557db0837fa689 (patch) | |
tree | 35ded6f9b2ea3340fa8328f91539e9f648594d8f /sandbox/ant/sca/branches/tb7/modules/policy | |
parent | e7b8cc1fba20b8e530c8ba89d67a6f094a2cb523 (diff) |
[maven-release-plugin] copy for branch tb7
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@756391 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
96 files changed, 8787 insertions, 0 deletions
diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/LICENSE b/sandbox/ant/sca/branches/tb7/modules/policy-security/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/LICENSE @@ -0,0 +1,205 @@ +
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
+
+
+
diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/META-INF/MANIFEST.MF b/sandbox/ant/sca/branches/tb7/modules/policy-security/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..593060a130 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/META-INF/MANIFEST.MF @@ -0,0 +1,64 @@ +Manifest-Version: 1.0
+Export-Package: org.apache.tuscany.sca.policy.authorization;uses:="jav
+ ax.xml.stream,org.apache.tuscany.sca.contribution.resolver,org.apache
+ .tuscany.sca.contribution.processor,org.apache.tuscany.sca.core,org.a
+ pache.tuscany.sca.monitor,org.apache.tuscany.sca.policy,javax.xml.nam
+ espace";version="2.0.0",org.apache.tuscany.sca.policy.security.jaas;use
+ s:="javax.security.auth.callback,org.apache.tuscany.sca.runtime,org.a
+ pache.tuscany.sca.assembly,org.apache.tuscany.sca.provider,javax.secu
+ rity.auth.login,org.apache.tuscany.sca.core,org.apache.tuscany.sca.mo
+ nitor,org.apache.tuscany.sca.policy,org.apache.tuscany.sca.interfaced
+ ef,javax.xml.namespace,org.apache.tuscany.sca.invocation,javax.xml.st
+ ream,org.apache.tuscany.sca.contribution.resolver,org.apache.tuscany.
+ sca.policy.util,org.apache.tuscany.sca.contribution.processor,org.oasisopen
+ .sca";version="2.0.0",org.apache.tuscany.sca.policy.authentication.bas
+ ic;uses:="org.apache.tuscany.sca.runtime,org.apache.tuscany.sca.assem
+ bly,org.apache.tuscany.sca.provider,org.apache.tuscany.sca.core,org.a
+ pache.tuscany.sca.policy,org.apache.tuscany.sca.monitor,org.apache.tu
+ scany.sca.interfacedef,javax.xml.namespace,org.apache.tuscany.sca.inv
+ ocation,javax.xml.stream,org.apache.tuscany.sca.contribution.resolver
+ ,org.apache.tuscany.sca.contribution.processor";version="2.0.0",org.apa
+ che.tuscany.sca.policy.security;uses:="org.apache.tuscany.sca.definit
+ ions.util,org.apache.tuscany.sca.provider,org.apache.tuscany.sca.defi
+ nitions,org.apache.tuscany.sca.contribution.processor,org.apache.tusc
+ any.sca.core";version="2.0.0",org.apache.tuscany.sca.policy.identity;us
+ es:="javax.xml.stream,org.apache.tuscany.sca.contribution.resolver,or
+ g.apache.tuscany.sca.contribution.processor,org.apache.tuscany.sca.co
+ re,org.apache.tuscany.sca.monitor,org.apache.tuscany.sca.policy,javax
+ .xml.namespace";version="2.0.0",org.apache.tuscany.sca.policy.authentic
+ ation.token;version="2.0.0"
+Tool: Bnd-0.0.255
+Bundle-Name: Apache Tuscany Security Policy Model
+Created-By: 1.6.0_07 (Sun Microsystems Inc.)
+Bundle-Vendor: The Apache Software Foundation
+Bundle-Version: 2.0.0
+Bnd-LastModified: 1225397295515
+Bundle-ManifestVersion: 2
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Bundle-Description: Apache Tuscany Security Policy Model
+Import-Package: javax.security.auth.callback,
+ javax.security.auth.login,
+ javax.xml.namespace,
+ javax.xml.stream,
+ org.apache.tuscany.sca.assembly;version="2.0.0",
+ org.apache.tuscany.sca.contribution.processor;version="2.0.0",
+ org.apache.tuscany.sca.contribution.resolver;version="2.0.0",
+ org.apache.tuscany.sca.core;version="2.0.0",
+ org.apache.tuscany.sca.definitions;version="2.0.0",
+ org.apache.tuscany.sca.definitions.util;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef;version="2.0.0",
+ org.apache.tuscany.sca.invocation;version="2.0.0",
+ org.apache.tuscany.sca.monitor;version="2.0.0",
+ org.apache.tuscany.sca.policy;version="2.0.0",
+ org.apache.tuscany.sca.policy.authentication.basic;version="2.0.0",
+ org.apache.tuscany.sca.policy.authorization;version="2.0.0",
+ org.apache.tuscany.sca.policy.identity;version="2.0.0",
+ org.apache.tuscany.sca.policy.security;version="2.0.0",
+ org.apache.tuscany.sca.policy.security.jaas;version="2.0.0",
+ org.apache.tuscany.sca.policy.util;version="2.0.0",
+ org.apache.tuscany.sca.provider;version="2.0.0",
+ org.apache.tuscany.sca.runtime;version="2.0.0",
+ org.oasisopen.sca;version="2.0.0"
+Bundle-SymbolicName: org.apache.tuscany.sca.policy.security
+Bundle-DocURL: http://www.apache.org/
+
diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/NOTICE b/sandbox/ant/sca/branches/tb7/modules/policy-security/NOTICE new file mode 100644 index 0000000000..51042eab05 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/NOTICE @@ -0,0 +1,6 @@ +${pom.name}
+Copyright (c) 2005 - 2009 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/pom.xml b/sandbox/ant/sca/branches/tb7/modules/policy-security/pom.xml new file mode 100644 index 0000000000..fcd8803f7a --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/pom.xml @@ -0,0 +1,45 @@ +<?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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>2.0-TB3-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-policy-security</artifactId>
+ <name>Apache Tuscany SCA Policy Security Model</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution</artifactId>
+ <version>2.0-TB3-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly-xml</artifactId>
+ <version>2.0-TB3-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPolicy.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPolicy.java new file mode 100644 index 0000000000..c735f63b7d --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPolicy.java @@ -0,0 +1,65 @@ +/* + * 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.policy.authentication.basic; + +import javax.xml.namespace.QName; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev$ $Date$ + */ +public class BasicAuthenticationPolicy { + private static final String SCA10_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1"; + + public static final QName BASIC_AUTHENTICATION_POLICY_QNAME = new QName(SCA10_TUSCANY_NS, "basicAuthentication"); + public static final String BASIC_AUTHENTICATION_USERNAME = "userName"; + public static final String BASIC_AUTHENTICATION_PASSWORD = "password"; + + private String userName; + private String password; + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public QName getSchemaName() { + return BASIC_AUTHENTICATION_POLICY_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPolicyProcessor.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPolicyProcessor.java new file mode 100644 index 0000000000..99a8508ba4 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPolicyProcessor.java @@ -0,0 +1,123 @@ +/* + * 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.policy.authentication.basic; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * + * @version $Rev$ $Date$ + */ +public class BasicAuthenticationPolicyProcessor implements StAXArtifactProcessor<BasicAuthenticationPolicy> { + private static final String SCA10_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1"; + + public QName getArtifactType() { + return BasicAuthenticationPolicy.BASIC_AUTHENTICATION_POLICY_QNAME; + } + + public BasicAuthenticationPolicyProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + } + + + public BasicAuthenticationPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + BasicAuthenticationPolicy policy = new BasicAuthenticationPolicy(); + int event = reader.getEventType(); + QName name = null; + + while (reader.hasNext()) { + event = reader.getEventType(); + switch (event) { + case START_ELEMENT : { + name = reader.getName(); + if ( name.equals(getArtifactType()) ) { + // no attributes at the moment + } else if ( BasicAuthenticationPolicy.BASIC_AUTHENTICATION_USERNAME.equals(name.getLocalPart()) ) { + policy.setUserName(reader.getElementText()); + } else if ( BasicAuthenticationPolicy.BASIC_AUTHENTICATION_PASSWORD.equals(name.getLocalPart()) ) { + policy.setPassword(reader.getElementText()); + } + break; + } + } + + if ( event == END_ELEMENT ) { + if ( getArtifactType().equals(reader.getName()) ) { + break; + } + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + + return policy; + } + + public void write(BasicAuthenticationPolicy policy, XMLStreamWriter writer) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", SCA10_TUSCANY_NS); + + if ( policy.getUserName() != null ) { + writer.writeStartElement(prefix, + BasicAuthenticationPolicy.BASIC_AUTHENTICATION_USERNAME, + getArtifactType().getNamespaceURI()); + writer.writeCharacters(policy.getUserName()); + writer.writeEndElement(); + } + + if ( policy.getPassword() != null ) { + writer.writeStartElement(prefix, + BasicAuthenticationPolicy.BASIC_AUTHENTICATION_PASSWORD, + getArtifactType().getNamespaceURI()); + writer.writeCharacters(policy.getPassword()); + writer.writeEndElement(); + } + + writer.writeEndElement(); + } + + public Class<BasicAuthenticationPolicy> getModelType() { + return BasicAuthenticationPolicy.class; + } + + public void resolve(BasicAuthenticationPolicy arg0, ModelResolver arg1) throws ContributionResolveException { + + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPolicyProviderFactory.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPolicyProviderFactory.java new file mode 100644 index 0000000000..348934bd6c --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPolicyProviderFactory.java @@ -0,0 +1,75 @@ +/* + * 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.policy.authentication.basic; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.PolicyProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class BasicAuthenticationPolicyProviderFactory implements PolicyProviderFactory<BasicAuthenticationPolicy> { + private ExtensionPointRegistry registry; + + public BasicAuthenticationPolicyProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createImplementationPolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.assembly.Implementation) + */ + public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component, Implementation implementation) { + return null;//new BasicAuthenticationImplementationPolicyProvider(component, implementation); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createReferencePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentReference, org.apache.tuscany.sca.assembly.Binding) + */ + public PolicyProvider createReferencePolicyProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + return new BasicAuthenticationReferencePolicyProvider(component, reference, binding); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createServicePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentService, org.apache.tuscany.sca.assembly.Binding) + */ + public PolicyProvider createServicePolicyProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + return new BasicAuthenticationServicePolicyProvider(component, service, binding); + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPrincipal.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPrincipal.java new file mode 100644 index 0000000000..3ab9cb656d --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPrincipal.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.policy.authentication.basic; + +import java.security.Principal; + + +/** + * + * @version $Rev$ $Date$ + */ +public class BasicAuthenticationPrincipal implements Principal { + + private String name; + private String password; + + public BasicAuthenticationPrincipal(String name, String password){ + if (name == null) { + throw new IllegalArgumentException("name cannot be null"); + } + + this.name = name; + this.password = password; + } + + public String getName() { + return name; + } + + public String getPassword() { + return password; + } + + @Override + public int hashCode() { + return name.hashCode(); + } + + @Override + public String toString() { + return name; + } + + + @Override + public boolean equals(Object principal) { + if (principal == null) + return false; + if (this == principal) + return true; + if (getClass() != principal.getClass()) + return false; + final BasicAuthenticationPrincipal other = (BasicAuthenticationPrincipal)principal; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)){ + return false; + } + + return true; + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationReferencePolicyInterceptor.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationReferencePolicyInterceptor.java new file mode 100644 index 0000000000..ef1e66b7de --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationReferencePolicyInterceptor.java @@ -0,0 +1,96 @@ +/* + * 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.policy.authentication.basic; + +import javax.security.auth.Subject; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.security.SecurityUtil; + +/** + * + * @version $Rev$ $Date$ + */ +public class BasicAuthenticationReferencePolicyInterceptor implements Interceptor { + private static final String SCA10_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1"; + public static final QName policySetQName = new QName(SCA10_TUSCANY_NS, "wsBasicAuthentication"); + + private Invoker next; + private Operation operation; + private PolicySet policySet = null; + private String context; + private BasicAuthenticationPolicy policy; + + public BasicAuthenticationReferencePolicyInterceptor(String context, Operation operation, PolicySet policySet) { + super(); + this.operation = operation; + this.policySet = policySet; + this.context = context; + init(); + } + + private void init() { + if (policySet != null) { + for (Object policyObject : policySet.getPolicies()){ + if (policyObject instanceof BasicAuthenticationPolicy){ + policy = (BasicAuthenticationPolicy)policyObject; + break; + } + } + } + } + + public Message invoke(Message msg) { + + // get the security context + Subject subject = SecurityUtil.getSubject(msg); + BasicAuthenticationPrincipal principal = SecurityUtil.getPrincipal(subject, + BasicAuthenticationPrincipal.class); + + // if no credentials propogated from the reference then use + // the ones from the policy + if (principal == null && + policy.getUserName() != null && + !policy.getUserName().equals("")) { + principal = new BasicAuthenticationPrincipal(policy.getUserName(), + policy.getPassword()); + subject.getPrincipals().add(principal); + } + + if (principal == null){ + // alternatively we could call out here to some 3rd party system to get credentials + // or convert from some other security principal + } + + return getNext().invoke(msg); + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationReferencePolicyProvider.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationReferencePolicyProvider.java new file mode 100644 index 0000000000..c5352e1f57 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationReferencePolicyProvider.java @@ -0,0 +1,89 @@ +/* + * 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.policy.authentication.basic; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySubject; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * @version $Rev$ $Date$ + */ +public class BasicAuthenticationReferencePolicyProvider implements PolicyProvider { + private RuntimeComponent component; + private RuntimeComponentReference reference; + private Binding binding; + + public BasicAuthenticationReferencePolicyProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + super(); + this.component = component; + this.reference = reference; + this.binding = binding; + } + + private PolicySet findPolicySet() { + if (binding instanceof PolicySubject) { + List<PolicySet> policySets = ((PolicySubject)binding).getPolicySets(); + for (PolicySet ps : policySets) { + for (Object p : ps.getPolicies()) { + if (BasicAuthenticationPolicy.class.isInstance(p)) { + return ps; + } + } + } + } + return null; + } + + private String getContext() { + return "component.reference: " + component.getURI() + + "#" + + reference.getName() + + "(" + + binding.getClass().getName() + + ")"; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#createInterceptor(org.apache.tuscany.sca.interfacedef.Operation) + */ + public Interceptor createInterceptor(Operation operation) { + PolicySet ps = findPolicySet(); + return ps == null ? null : new BasicAuthenticationReferencePolicyInterceptor(getContext(), operation, ps); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#getPhase() + */ + public String getPhase() { + return Phase.REFERENCE_POLICY; + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationServicePolicyInterceptor.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationServicePolicyInterceptor.java new file mode 100644 index 0000000000..da4d31a11a --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationServicePolicyInterceptor.java @@ -0,0 +1,96 @@ +/* + * 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.policy.authentication.basic; + + +import javax.security.auth.Subject; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.security.SecurityUtil; + + +/** + * Policy handler to handle PolicySet related to Logging with the QName + * {http://tuscany.apache.org/xmlns/sca/1.1/impl/java}LoggingPolicy + * + * @version $Rev$ $Date$ + */ +public class BasicAuthenticationServicePolicyInterceptor implements Interceptor { + private static final String SCA10_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1"; + public static final QName policySetQName = new QName(SCA10_TUSCANY_NS, "wsBasicAuthentication"); + + private Invoker next; + private Operation operation; + private PolicySet policySet = null; + private String context; + private BasicAuthenticationPolicy policy; + + public BasicAuthenticationServicePolicyInterceptor(String context, Operation operation, PolicySet policySet) { + super(); + this.operation = operation; + this.policySet = policySet; + this.context = context; + init(); + } + + private void init() { + if (policySet != null) { + for (Object policyObject : policySet.getPolicies()){ + if (policyObject instanceof BasicAuthenticationPolicy){ + policy = (BasicAuthenticationPolicy)policyObject; + break; + } + } + } + } + + public Message invoke(Message msg) { + + Subject subject = SecurityUtil.getSubject(msg); + BasicAuthenticationPrincipal principal = SecurityUtil.getPrincipal(subject, + BasicAuthenticationPrincipal.class); + + if (principal != null){ + + System.out.println("Username: " + + principal.getName() + + " Password: " + + principal.getPassword()); + + // could call out here to some 3rd party system to do whatever you + // need to do do with username and password + + } + + return getNext().invoke(msg); + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationServicePolicyProvider.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationServicePolicyProvider.java new file mode 100644 index 0000000000..b8684e29c0 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationServicePolicyProvider.java @@ -0,0 +1,87 @@ +/* + * 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.policy.authentication.basic; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySubject; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class BasicAuthenticationServicePolicyProvider implements PolicyProvider { + private RuntimeComponent component; + private RuntimeComponentService service; + private Binding binding; + + public BasicAuthenticationServicePolicyProvider(RuntimeComponent component, RuntimeComponentService service, Binding binding) { + super(); + this.component = component; + this.service = service; + this.binding = binding; + } + + private PolicySet findPolicySet() { + if (binding instanceof PolicySubject) { + List<PolicySet> policySets = ((PolicySubject)binding).getPolicySets(); + for (PolicySet ps : policySets) { + for (Object p : ps.getPolicies()) { + if (BasicAuthenticationPolicy.class.isInstance(p)) { + return ps; + } + } + } + } + return null; + } + + private String getContext() { + return "component.service: " + component.getURI() + + "#" + + service.getName() + + "(" + + binding.getClass().getName() + + ")"; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#createInterceptor(org.apache.tuscany.sca.interfacedef.Operation) + */ + public Interceptor createInterceptor(Operation operation) { + PolicySet ps = findPolicySet(); + return ps == null ? null : new BasicAuthenticationServicePolicyInterceptor(getContext(), operation, ps); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProvider#getPhase() + */ + public String getPhase() { + return Phase.SERVICE_POLICY; + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/token/TokenPrincipal.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/token/TokenPrincipal.java new file mode 100644 index 0000000000..147b863c01 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/token/TokenPrincipal.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 org.apache.tuscany.sca.policy.authentication.token; + +import java.security.Principal; + + +/** + * + * @version $Rev$ $Date$ + */ +public class TokenPrincipal implements Principal { + + private String name; + + public TokenPrincipal(String name){ + if (name == null) { + throw new IllegalArgumentException("name cannot be null"); + } + + this.name = name; + } + + public String getName() { + return name; + } + + @Override + public int hashCode() { + return name.hashCode(); + } + + @Override + public String toString() { + return name; + } + + + @Override + public boolean equals(Object principal) { + if (principal == null) + return false; + if (this == principal) + return true; + if (getClass() != principal.getClass()) + return false; + final TokenPrincipal other = (TokenPrincipal)principal; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)){ + return false; + } + + return true; + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authorization/AuthorizationPolicy.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authorization/AuthorizationPolicy.java new file mode 100644 index 0000000000..8b0bbd54ff --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authorization/AuthorizationPolicy.java @@ -0,0 +1,83 @@ +/* + * 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.policy.authorization; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +/** + * Models the SCA Implementation Security Policy Assertion for Authorization. + * + * @version $Rev$ $Date$ + */ +public class AuthorizationPolicy { + private final static String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; + // private final static String SCA10_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1"; + public static final QName NAME = new QName(SCA11_NS, "authorization"); + + public static enum AcessControl { + permitAll, denyAll, allow + }; + + private List<String> roleNames = new ArrayList<String>(); + + public AuthorizationPolicy() { + } + + private AcessControl accessControl; + + public AcessControl getAccessControl() { + return accessControl; + } + + public void setAccessControl(AcessControl accessControl) { + this.accessControl = accessControl; + } + + public List<String> getRoleNames() { + if (accessControl == AcessControl.allow) { + return roleNames; + } else { + throw new IllegalArgumentException("Role names are only available for 'allow'"); + } + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + + public QName getSchemaName() { + return NAME; + } + + @Override + public String toString() { + if (accessControl == AcessControl.allow) { + return accessControl.name() + " " + roleNames; + } + return accessControl.name(); + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authorization/AuthorizationPolicyProcessor.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authorization/AuthorizationPolicyProcessor.java new file mode 100644 index 0000000000..d78c0fc2e3 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authorization/AuthorizationPolicyProcessor.java @@ -0,0 +1,151 @@ +/* + * 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.policy.authorization; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import java.util.StringTokenizer; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; + +/** + * + * @version $Rev$ $Date$ + */ +public class AuthorizationPolicyProcessor implements StAXArtifactProcessor<AuthorizationPolicy> { + private static final String ROLES = "roles"; + private Monitor monitor; + + public QName getArtifactType() { + return AuthorizationPolicy.NAME; + } + + public AuthorizationPolicyProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + this.monitor = monitor; + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = monitor.createProblem(this.getClass().getName(), "policy-security-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + public AuthorizationPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + AuthorizationPolicy policy = new AuthorizationPolicy(); + int event = reader.getEventType(); + QName start = reader.getName(); + while (true) { + switch (event) { + case START_ELEMENT: + String ac = reader.getName().getLocalPart(); + if ("allow".equals(ac)) { + policy.setAccessControl(AuthorizationPolicy.AcessControl.allow); + String roleNames = reader.getAttributeValue(null, ROLES); + if (roleNames == null) { + error("RequiredAttributeRolesMissing", reader); + //throw new IllegalArgumentException("Required attribute 'roles' is missing."); + } else { + StringTokenizer st = new StringTokenizer(roleNames); + while (st.hasMoreTokens()) { + policy.getRoleNames().add(st.nextToken()); + } + } + } else if ("permitAll".equals(ac)) { + policy.setAccessControl(AuthorizationPolicy.AcessControl.permitAll); + } else if ("denyAll".endsWith(ac)) { + policy.setAccessControl(AuthorizationPolicy.AcessControl.denyAll); + } + break; + case END_ELEMENT: + if (start.equals(reader.getName())) { + if (reader.hasNext()) { + reader.next(); + } + return policy; + } + + } + if (reader.hasNext()) { + event = reader.next(); + } else { + return policy; + } + } + } + + public void write(AuthorizationPolicy policy, XMLStreamWriter writer) throws ContributionWriteException, + XMLStreamException { + writer.writeStartElement(AuthorizationPolicy.NAME.getLocalPart()); + + writer.writeStartElement(policy.getAccessControl().name()); + + if (policy.getAccessControl() == AuthorizationPolicy.AcessControl.allow) { + StringBuffer sb = new StringBuffer(); + for (String role : policy.getRoleNames()) { + sb.append(role); + } + + if (sb.length() > 0) { + writer.writeAttribute(ROLES, sb.toString()); + } + } + + writer.writeEndElement(); + writer.writeEndElement(); + } + + public Class<AuthorizationPolicy> getModelType() { + return AuthorizationPolicy.class; + } + + public void resolve(AuthorizationPolicy policy, ModelResolver resolver) throws ContributionResolveException { + + if ((policy.getAccessControl() == AuthorizationPolicy.AcessControl.allow) && + (policy.getRoleNames().isEmpty())){ + // role names are required so leave policy unresolved + return; + } + + //right now nothing to resolve + policy.setUnresolved(false); + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityImplementationPolicyInterceptor.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityImplementationPolicyInterceptor.java new file mode 100644 index 0000000000..1f48b3b30a --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityImplementationPolicyInterceptor.java @@ -0,0 +1,77 @@ +/* + * 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.policy.identity; + +import java.util.List; + +import javax.security.auth.Subject; + +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.policy.security.SecurityUtil; +import org.oasisopen.sca.ServiceRuntimeException; + +/** + * @version $Rev$ $Date$ + */ +public class SecurityIdentityImplementationPolicyInterceptor implements Interceptor { + private List<SecurityIdentityPolicy> securityIdentityPolicies; + private Invoker next; + + public SecurityIdentityImplementationPolicyInterceptor(List<SecurityIdentityPolicy> securityIdentityPolicies) { + super(); + this.securityIdentityPolicies = securityIdentityPolicies; + } + + /** + * @see org.apache.tuscany.sca.invocation.Interceptor#getNext() + */ + public Invoker getNext() { + return next; + } + + /** + * @see org.apache.tuscany.sca.invocation.Interceptor#setNext(org.apache.tuscany.sca.invocation.Invoker) + */ + public void setNext(Invoker next) { + this.next = next; + } + + /** + * @see org.apache.tuscany.sca.invocation.Invoker#invoke(org.apache.tuscany.sca.invocation.Message) + */ + public Message invoke(Message msg) { + try { + + Subject subject = SecurityUtil.getSubject(msg); + + // May do some selection here based on runAs settings. + // by default though there is nothing to do as the implementation + // assumes the callers user credentials + + + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + return getNext().invoke(msg); + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityImplementationPolicyProvider.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityImplementationPolicyProvider.java new file mode 100644 index 0000000000..38feea21b5 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityImplementationPolicyProvider.java @@ -0,0 +1,88 @@ +/* + * 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.policy.identity; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * @version $Rev$ $Date$ + */ +public class SecurityIdentityImplementationPolicyProvider implements PolicyProvider { + private RuntimeComponent component; + private Implementation implementation; + + public SecurityIdentityImplementationPolicyProvider(RuntimeComponent component, Implementation implementation) { + super(); + this.component = component; + this.implementation = implementation; + } + + private List<SecurityIdentityPolicy> findPolicies(Operation op) { + List<SecurityIdentityPolicy> polices = new ArrayList<SecurityIdentityPolicy>(); + /* + // FIXME: How do we get a list of effective policySets for a given operation? + if (implementation instanceof OperationsConfigurator) { + OperationsConfigurator operationsConfigurator = (OperationsConfigurator)implementation; + for (ConfiguredOperation cop : operationsConfigurator.getConfiguredOperations()) { + if (cop.getName().equals(op.getName())) { + for (PolicySet ps : cop.getPolicySets()) { + for (Object p : ps.getPolicies()) { + if (SecurityIdentityPolicy.class.isInstance(p)) { + polices.add((SecurityIdentityPolicy)p); + } + } + } + } + } + } + */ + + List<PolicySet> policySets = component.getPolicySets(); + for (PolicySet ps : policySets) { + for (Object p : ps.getPolicies()) { + if (SecurityIdentityPolicy.class.isInstance(p)) { + polices.add((SecurityIdentityPolicy)p); + } + } + } + return polices; + } + + public Interceptor createInterceptor(Operation operation) { + List<SecurityIdentityPolicy> policies = findPolicies(operation); + if (policies == null || policies.isEmpty()) { + return null; + } else { + return new SecurityIdentityImplementationPolicyInterceptor(findPolicies(operation)); + } + } + + public String getPhase() { + return Phase.IMPLEMENTATION_POLICY; + } +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityPolicy.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityPolicy.java new file mode 100644 index 0000000000..28ffcaf348 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityPolicy.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 org.apache.tuscany.sca.policy.identity; + +import javax.xml.namespace.QName; + +/** + * Models the SCA Implementation Security Policy Assertion for Security Identity. + * + * @version $Rev$ $Date$ + */ +public class SecurityIdentityPolicy { + private final static String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; + public static final QName NAME = new QName(SCA11_NS, "securityIdentity"); + + private boolean useCallerIdentity; + + private String runAsRole; + + public SecurityIdentityPolicy() { + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + + public QName getSchemaName() { + return NAME; + } + + public boolean isUseCallerIdentity() { + return useCallerIdentity; + } + + public void setUseCallerIdentity(boolean useCallerIdentity) { + this.useCallerIdentity = useCallerIdentity; + } + + public String getRunAsRole() { + return runAsRole; + } + + public void setRunAsRole(String runAsRole) { + this.runAsRole = runAsRole; + } + + @Override + public String toString() { + if (useCallerIdentity) { + return "useCallerIdentity"; + } + return "runAs " + runAsRole; + } +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityPolicyProcessor.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityPolicyProcessor.java new file mode 100644 index 0000000000..0ccda91364 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityPolicyProcessor.java @@ -0,0 +1,132 @@ +/* + * 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.policy.identity; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; + +/** + * + * @version $Rev$ $Date$ + */ +public class SecurityIdentityPolicyProcessor implements StAXArtifactProcessor<SecurityIdentityPolicy> { + private static final String ROLE = "role"; + private Monitor monitor; + + public QName getArtifactType() { + return SecurityIdentityPolicy.NAME; + } + + public SecurityIdentityPolicyProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + this.monitor = monitor; + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = monitor.createProblem(this.getClass().getName(), "policy-security-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + public SecurityIdentityPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + SecurityIdentityPolicy policy = new SecurityIdentityPolicy(); + int event = reader.getEventType(); + QName start = reader.getName(); + while (true) { + switch (event) { + case START_ELEMENT: + String ac = reader.getName().getLocalPart(); + if ("runAs".equals(ac)) { + String roleName = reader.getAttributeValue(null, ROLE); + if (roleName == null) { + error("RequiredAttributeRolesMissing", reader); + //throw new IllegalArgumentException("Required attribute 'roles' is missing."); + } else { + policy.setRunAsRole(roleName); + } + } else if ("useCallerIdentity".equals(ac)) { + policy.setUseCallerIdentity(true); + } + break; + case END_ELEMENT: + if (start.equals(reader.getName())) { + if (reader.hasNext()) { + reader.next(); + } + return policy; + } + + } + if (reader.hasNext()) { + event = reader.next(); + } else { + return policy; + } + } + } + + public void write(SecurityIdentityPolicy policy, XMLStreamWriter writer) throws ContributionWriteException, + XMLStreamException { + writer.writeStartElement(SecurityIdentityPolicy.NAME.getLocalPart()); + + String child = policy.isUseCallerIdentity() ? "useCallerIdentity" : "runAs"; + writer.writeStartElement(child); + + if (!policy.isUseCallerIdentity()) { + writer.writeAttribute(ROLE, policy.getRunAsRole()); + } + + writer.writeEndElement(); + writer.writeEndElement(); + } + + public Class<SecurityIdentityPolicy> getModelType() { + return SecurityIdentityPolicy.class; + } + + public void resolve(SecurityIdentityPolicy policy, ModelResolver resolver) throws ContributionResolveException { + + if (policy.getRunAsRole() != null) + //right now nothing to resolve + policy.setUnresolved(false); + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityPolicyProviderFactory.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityPolicyProviderFactory.java new file mode 100644 index 0000000000..a20f314a2a --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityPolicyProviderFactory.java @@ -0,0 +1,75 @@ +/* + * 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.policy.identity; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.PolicyProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class SecurityIdentityPolicyProviderFactory implements PolicyProviderFactory<SecurityIdentityPolicy> { + private ExtensionPointRegistry registry; + + public SecurityIdentityPolicyProviderFactory(ExtensionPointRegistry registry) { + super(); + this.registry = registry; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createImplementationPolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.assembly.Implementation) + */ + public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component, Implementation implementation) { + return new SecurityIdentityImplementationPolicyProvider(component, implementation); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createReferencePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentReference, org.apache.tuscany.sca.assembly.Binding) + */ + public PolicyProvider createReferencePolicyProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + return null; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createServicePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentService, org.apache.tuscany.sca.assembly.Binding) + */ + public PolicyProvider createServicePolicyProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + return null; + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class getModelType() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/SecurityPolicyDefinitionsProvider.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/SecurityPolicyDefinitionsProvider.java new file mode 100644 index 0000000000..b58b9bb874 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/SecurityPolicyDefinitionsProvider.java @@ -0,0 +1,86 @@ +/* + * 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.policy.security; + +import java.net.URI; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; + +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.definitions.Definitions; +import org.apache.tuscany.sca.definitions.util.DefinitionsUtil; +import org.apache.tuscany.sca.provider.DefinitionsProvider; +import org.apache.tuscany.sca.provider.DefinitionsProviderException; + +/** + * Provider for Policy Intents and PolicySet definitions related to security + * + * @version $Rev$ $Date$ + */ +public class SecurityPolicyDefinitionsProvider implements DefinitionsProvider { + private static final String tuscanyDefinitionsFile = "org/apache/tuscany/sca/policy/security/tuscany_definitions.xml"; + private String definitionsFile = "org/apache/tuscany/sca/policy/security/definitions.xml"; + URLArtifactProcessor urlArtifactProcessor = null; + + public SecurityPolicyDefinitionsProvider(ExtensionPointRegistry registry) { + URLArtifactProcessorExtensionPoint documentProcessors = registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + urlArtifactProcessor = (URLArtifactProcessor)documentProcessors.getProcessor(Definitions.class); + } + + public Definitions getDefinitions() throws DefinitionsProviderException { + Definitions scaDefns = null; + Definitions tuscanyDefns = null; + try { + // Allow privileged access to load resource. Requires RuntimePermssion in security policy. + URL definitionsFileUrl = AccessController.doPrivileged(new PrivilegedAction<URL>() { + public URL run() { + return getClass().getClassLoader().getResource(definitionsFile); + } + }); + + URI uri = new URI(definitionsFile); + + scaDefns = (Definitions)urlArtifactProcessor.read(null, + uri, + definitionsFileUrl); + + definitionsFileUrl = AccessController.doPrivileged(new PrivilegedAction<URL>() { + public URL run() { + return getClass().getClassLoader().getResource(tuscanyDefinitionsFile); + } + }); + + uri = new URI(definitionsFile); + tuscanyDefns = (Definitions)urlArtifactProcessor.read(null, + uri, + definitionsFileUrl); + + DefinitionsUtil.aggregate(tuscanyDefns, scaDefns); + return scaDefns; + + } catch ( Exception e ) { + throw new DefinitionsProviderException(e); + } + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/SecurityUtil.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/SecurityUtil.java new file mode 100644 index 0000000000..1297b44b93 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/SecurityUtil.java @@ -0,0 +1,76 @@ +/* + * 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.policy.security; + +import java.security.Principal; + +import javax.security.auth.Subject; + +import org.apache.tuscany.sca.invocation.Message; + + +/** + * + * @version $Rev$ $Date$ + */ +public class SecurityUtil { + + public static Subject getSubject(Message msg){ + + Subject subject = null; + + for (Object header : msg.getHeaders()){ + if (header instanceof Subject){ + subject = (Subject)header; + break; + } + } + + if (subject == null){ + subject = new Subject(); + msg.getHeaders().add(subject); + } + + return subject; + } + + public static <T> T getPrincipal(Subject subject, Class<T> clazz){ + for (Principal msgPrincipal : subject.getPrincipals() ){ + if (clazz.isInstance(msgPrincipal)){ + return clazz.cast(msgPrincipal); + } + } + + return null; + } + + public static Principal getPrincipal(Message msg){ + + Principal principal = null; + + for (Object header : msg.getHeaders()){ + if (header instanceof Principal){ + principal = (Principal)header; + break; + } + } + + return principal; + } +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationImplementationPolicyProvider.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationImplementationPolicyProvider.java new file mode 100644 index 0000000000..203d9ca0ab --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationImplementationPolicyProvider.java @@ -0,0 +1,90 @@ +/* + * 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.policy.security.jaas; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * Policy handler to handle PolicySet containing JaasAuthenticationPolicy instances + * + * @version $Rev$ $Date$ + */ +public class JaasAuthenticationImplementationPolicyProvider implements PolicyProvider { + private RuntimeComponent component; + private Implementation implementation; + + public JaasAuthenticationImplementationPolicyProvider(RuntimeComponent component, Implementation implementation) { + super(); + this.component = component; + this.implementation = implementation; + } + + private List<JaasAuthenticationPolicy> findPolicies(Operation op) { + List<JaasAuthenticationPolicy> polices = new ArrayList<JaasAuthenticationPolicy>(); + /* + // FIXME: How do we get a list of effective policySets for a given operation? + if (implementation instanceof OperationsConfigurator) { + OperationsConfigurator operationsConfigurator = (OperationsConfigurator)implementation; + for (ConfiguredOperation cop : operationsConfigurator.getConfiguredOperations()) { + if (cop.getName().equals(op.getName())) { + for (PolicySet ps : cop.getPolicySets()) { + for (Object p : ps.getPolicies()) { + if (JaasAuthenticationPolicy.class.isInstance(p)) { + polices.add((JaasAuthenticationPolicy)p); + } + } + } + } + } + } + */ + + List<PolicySet> policySets = component.getPolicySets(); + for (PolicySet ps : policySets) { + for (Object p : ps.getPolicies()) { + if (JaasAuthenticationPolicy.class.isInstance(p)) { + polices.add((JaasAuthenticationPolicy)p); + } + } + } + return polices; + } + + public Interceptor createInterceptor(Operation operation) { + List<JaasAuthenticationPolicy> policies = findPolicies(operation); + if (policies == null || policies.isEmpty()) { + return null; + } else { + return new JaasAuthenticationInterceptor(findPolicies(operation)); + } + } + + public String getPhase() { + return Phase.IMPLEMENTATION_POLICY; + } +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationInterceptor.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationInterceptor.java new file mode 100644 index 0000000000..41a7b62772 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationInterceptor.java @@ -0,0 +1,76 @@ +/* + * 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.policy.security.jaas; + +import java.util.List; + +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.login.LoginContext; + +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.oasisopen.sca.ServiceRuntimeException; + +/** + * @version $Rev$ $Date$ + */ +public class JaasAuthenticationInterceptor implements Interceptor { + private List<JaasAuthenticationPolicy> authenticationPolicies; + private Invoker next; + + public JaasAuthenticationInterceptor(List<JaasAuthenticationPolicy> authenticationPolicies) { + super(); + this.authenticationPolicies = authenticationPolicies; + } + + /** + * @see org.apache.tuscany.sca.invocation.Interceptor#getNext() + */ + public Invoker getNext() { + return next; + } + + /** + * @see org.apache.tuscany.sca.invocation.Interceptor#setNext(org.apache.tuscany.sca.invocation.Invoker) + */ + public void setNext(Invoker next) { + this.next = next; + } + + /** + * @see org.apache.tuscany.sca.invocation.Invoker#invoke(org.apache.tuscany.sca.invocation.Message) + */ + public Message invoke(Message msg) { + try { + for (JaasAuthenticationPolicy policy : authenticationPolicies) { + CallbackHandler callbackHandler = + (CallbackHandler)policy.getCallbackHandlerClass().newInstance(); + LoginContext lc = new LoginContext(policy.getConfigurationName(), callbackHandler); + lc.login(); + // Subject subject = lc.getSubject(); + } + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + return getNext().invoke(msg); + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicy.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicy.java new file mode 100644 index 0000000000..179fd0700f --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicy.java @@ -0,0 +1,71 @@ +/*
+ * 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.policy.security.jaas;
+
+import javax.xml.namespace.QName;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class JaasAuthenticationPolicy {
+ private static final String SCA10_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1";
+ public static final QName NAME = new QName(SCA10_TUSCANY_NS, "jaasAuthentication");
+
+ private String configurationName = "other";
+ private String callbackHandlerClassName;
+ private Class<?> callbackHandlerClass;
+
+ public String getCallbackHandlerClassName() {
+ return callbackHandlerClassName;
+ }
+
+ public void setCallbackHandlerClassName(String callbackHandlerClassName) {
+ this.callbackHandlerClassName = callbackHandlerClassName;
+ }
+
+ public Class<?> getCallbackHandlerClass() {
+ return callbackHandlerClass;
+ }
+
+ public void setCallbackHandlerClass(Class<?> callbackHandlerClass) {
+ this.callbackHandlerClass = callbackHandlerClass;
+ }
+
+ public QName getSchemaName() {
+ return NAME;
+ }
+
+ public boolean isUnresolved() {
+ return false;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ }
+
+ public String getConfigurationName() {
+ return configurationName;
+ }
+
+ public void setConfigurationName(String configurationName) {
+ this.configurationName = configurationName;
+ }
+
+}
diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicyHandler.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicyHandler.java new file mode 100644 index 0000000000..a45ac9b250 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicyHandler.java @@ -0,0 +1,71 @@ +/*
+ * 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.policy.security.jaas;
+
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.login.LoginContext;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/**
+ * Policy handler to handle PolicySet containing JaasAuthenticationPolicy instances
+ *
+ * @version $Rev$ $Date$
+ */
+public class JaasAuthenticationPolicyHandler {
+ private static final String jaasPolicy = "JaasPolicy";
+ private static final String SCA10_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1";
+ public static final QName policySetQName = new QName(SCA10_TUSCANY_NS, jaasPolicy);
+ private PolicySet applicablePolicySet = null;
+
+ public void setUp(Object... context) {
+ if (applicablePolicySet != null) {
+ }
+ }
+
+ public void cleanUp(Object... context) {
+ }
+
+ public void beforeInvoke(Object... context) {
+ try {
+ JaasAuthenticationPolicy policy = (JaasAuthenticationPolicy)applicablePolicySet.getPolicies().get(0);
+ CallbackHandler callbackHandler =
+ (CallbackHandler)policy.getCallbackHandlerClass().newInstance();
+ LoginContext lc = new LoginContext(policy.getConfigurationName(), callbackHandler);
+ lc.login();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ public void afterInvoke(Object... context) {
+
+ }
+
+ public PolicySet getApplicablePolicySet() {
+ return applicablePolicySet;
+ }
+
+ public void setApplicablePolicySet(PolicySet applicablePolicySet) {
+ this.applicablePolicySet = applicablePolicySet;
+ }
+}
diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicyProcessor.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicyProcessor.java new file mode 100644 index 0000000000..615e8bf5a3 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicyProcessor.java @@ -0,0 +1,148 @@ +/* + * 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.policy.security.jaas; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; + +/** + * + * @version $Rev$ $Date$ + */ +public class JaasAuthenticationPolicyProcessor implements StAXArtifactProcessor<JaasAuthenticationPolicy> { + private static final QName JAAS_AUTHENTICATION_POLICY_QNAME = JaasAuthenticationPolicy.NAME; + private static final String callbackHandler = "callbackHandler"; + private static final String SCA10_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1"; + public static final QName CALLBACK_HANDLER_QNAME = new QName(SCA10_TUSCANY_NS, callbackHandler); + public static final QName CONFIGURATION_QNAME = new QName(SCA10_TUSCANY_NS, "configurationName"); + private Monitor monitor; + + public QName getArtifactType() { + return JAAS_AUTHENTICATION_POLICY_QNAME; + } + + public JaasAuthenticationPolicyProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + this.monitor = monitor; + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = monitor.createProblem(this.getClass().getName(), "policy-security-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + public JaasAuthenticationPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + JaasAuthenticationPolicy policy = new JaasAuthenticationPolicy(); + int event = reader.getEventType(); + QName name = null; + + while (reader.hasNext()) { + event = reader.getEventType(); + switch (event) { + case START_ELEMENT : { + name = reader.getName(); + if (name.equals(CALLBACK_HANDLER_QNAME)) { + String callbackHandlerClassName = reader.getElementText(); + if (callbackHandlerClassName != null) { + policy.setCallbackHandlerClassName(callbackHandlerClassName.trim()); + } + } + if (name.equals(CONFIGURATION_QNAME)) { + String configurationName = reader.getElementText(); + if (configurationName != null) { + policy.setConfigurationName(configurationName.trim()); + } + } + + break; + } + } + + if ( event == END_ELEMENT ) { + if ( JAAS_AUTHENTICATION_POLICY_QNAME.equals(reader.getName()) ) { + break; + } + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + + return policy; + } + + public void write(JaasAuthenticationPolicy policy, XMLStreamWriter writer) throws ContributionWriteException, + XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + JAAS_AUTHENTICATION_POLICY_QNAME.getLocalPart(), + JAAS_AUTHENTICATION_POLICY_QNAME.getNamespaceURI()); + writer.writeNamespace("tuscany", SCA10_TUSCANY_NS); + + + writer.writeEndElement(); + } + + public Class<JaasAuthenticationPolicy> getModelType() { + return JaasAuthenticationPolicy.class; + } + + public void resolve(JaasAuthenticationPolicy policy, ModelResolver resolver) throws ContributionResolveException { + + if (policy.getCallbackHandlerClassName() != null) { + ClassReference classReference = new ClassReference(policy.getCallbackHandlerClassName()); + classReference = resolver.resolveModel(ClassReference.class, classReference); + Class<?> callbackClass = classReference.getJavaClass(); + if (callbackClass == null) { + error("ClassNotFoundException", resolver, policy.getCallbackHandlerClassName()); + //throw new ContributionResolveException(new ClassNotFoundException(policy.getCallbackHandlerClassName())); + } else { + policy.setCallbackHandlerClass(callbackClass); + policy.setUnresolved(false); + } + } + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicyProviderFactory.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicyProviderFactory.java new file mode 100644 index 0000000000..48a42eb711 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicyProviderFactory.java @@ -0,0 +1,72 @@ +/* + * 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.policy.security.jaas; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.PolicyProvider; +import org.apache.tuscany.sca.provider.PolicyProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class JaasAuthenticationPolicyProviderFactory implements PolicyProviderFactory<JaasAuthenticationPolicy> { + + public JaasAuthenticationPolicyProviderFactory(ExtensionPointRegistry registry) { + super(); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createImplementationPolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.assembly.Implementation) + */ + public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component, Implementation implementation) { + return new JaasAuthenticationImplementationPolicyProvider(component, implementation); + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createReferencePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentReference, org.apache.tuscany.sca.assembly.Binding) + */ + public PolicyProvider createReferencePolicyProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + return null; + } + + /** + * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createServicePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentService, org.apache.tuscany.sca.assembly.Binding) + */ + public PolicyProvider createServicePolicyProvider(RuntimeComponent component, + RuntimeComponentService service, + Binding binding) { + return null; + } + + /** + * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType() + */ + public Class<JaasAuthenticationPolicy> getModelType() { + return JaasAuthenticationPolicy.class; + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..24b1e5841d --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,27 @@ +# 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.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.policy.authorization.AuthorizationPolicyProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200903#authorization,model=org.apache.tuscany.sca.policy.authorization.AuthorizationPolicy
+org.apache.tuscany.sca.policy.authorization.AuthorizationPolicyProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200903#allow,model=org.apache.tuscany.sca.policy.authorization.AuthorizationPolicy
+org.apache.tuscany.sca.policy.authorization.AuthorizationPolicyProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200903#permitAll,model=org.apache.tuscany.sca.policy.authorization.AuthorizationPolicy
+org.apache.tuscany.sca.policy.authorization.AuthorizationPolicyProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200903#denyAll,model=org.apache.tuscany.sca.policy.authorization.AuthorizationPolicy
+org.apache.tuscany.sca.policy.identity.SecurityIdentityPolicyProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200903#runAs,model=org.apache.tuscany.sca.policy.identity.SecurityIdentityPolicy
+org.apache.tuscany.sca.policy.identity.SecurityIdentityPolicyProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200903#securityIdentity,model=org.apache.tuscany.sca.policy.identity.SecurityIdentityPolicy
+org.apache.tuscany.sca.policy.identity.SecurityIdentityPolicyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#securityIdentity,model=org.apache.tuscany.sca.policy.identity.SecurityIdentityPolicy
+org.apache.tuscany.sca.policy.security.jaas.JaasAuthenticationPolicyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#jaasAuthentication,model=org.apache.tuscany.sca.policy.security.jaas.JaasAuthenticationPolicy
+org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#basicAuthentication,model=org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicy
diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.DefinitionsProvider b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.DefinitionsProvider new file mode 100644 index 0000000000..790424df6b --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.DefinitionsProvider @@ -0,0 +1,19 @@ +# 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. + +# Implementation class for SCA Definitions Providers +org.apache.tuscany.sca.policy.security.SecurityPolicyDefinitionsProvider
\ No newline at end of file diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory new file mode 100644 index 0000000000..0363fbd981 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory @@ -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.
+
+# Implementation class for the policy extension
+org.apache.tuscany.sca.policy.security.jaas.JaasAuthenticationPolicyProviderFactory;model=org.apache.tuscany.sca.policy.security.jaas.JaasAuthenticationPolicy
+org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicyProviderFactory;model=org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicy
+org.apache.tuscany.sca.policy.identity.SecurityIdentityPolicyProviderFactory;model=org.apache.tuscany.sca.policy.identity.SecurityIdentityPolicy
diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/resources/org/apache/tuscany/sca/policy/security/definitions.xml b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/resources/org/apache/tuscany/sca/policy/security/definitions.xml new file mode 100644 index 0000000000..84ff597e15 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/resources/org/apache/tuscany/sca/policy/security/definitions.xml @@ -0,0 +1,55 @@ +<?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://docs.oasis-open.org/ns/opencsa/sca/200903" + targetNamespace="http://docs.oasis-open.org/ns/opencsa/sca/200903" + xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200903" + xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"> + + <!-- POLICY SETS --> + <policySet name="runAs" appliesTo="sca:implementation.java"/> + <policySet name="allow" appliesTo="sca:implementation.java"/> + <policySet name="rolesAllowed" appliesTo="sca:implementation.java"/> + <policySet name="permitAll" appliesTo="sca:implementation.java"/> + <policySet name="denyAll" appliesTo="sca:implementation.java"/> + + <!-- Policy Intents Defined by the SCA Runtime --> + <intent name="authentication" + constrains="sca:binding"> + <description> + Specifying this intent on references requires necessary authentication information + to be sent along with outgoing messages. Specifying this intent on service requires + incoming messages to be authenticated + </description> + </intent> + + <intent name="confidentiality" + constrains="sca:binding"> + <description> + Specifying this intent requires message exchanged to be encrypted + </description> + </intent> + + <intent name="integrity" + constrains="sca:binding"> + <description> + Specifying this intent requires message exchanged to be signed + </description> + </intent> +</definitions> diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/resources/org/apache/tuscany/sca/policy/security/tuscany_definitions.xml b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/resources/org/apache/tuscany/sca/policy/security/tuscany_definitions.xml new file mode 100644 index 0000000000..2881a5a56d --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/resources/org/apache/tuscany/sca/policy/security/tuscany_definitions.xml @@ -0,0 +1,32 @@ +<?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://docs.oasis-open.org/ns/opencsa/sca/200903" targetNamespace="http://tuscany.apache.org/xmlns/sca/1.1" + xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200903" xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"> + + <intent name="identity" constrains="sca:implementation.java + sca:implementation.spring"> + <description>All invocations are must have an identity set</description> + </intent> + + <intent name="jaasAuthentication" constrains="sca:implementation.java + sca:implementation.spring"> + <description>All invocations to be authenticated</description> + </intent> +</definitions>
\ No newline at end of file diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/resources/policy-security-validation-messages.properties b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/resources/policy-security-validation-messages.properties new file mode 100644 index 0000000000..ebb47f2b60 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/main/resources/policy-security-validation-messages.properties @@ -0,0 +1,22 @@ +# +# +# 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. +# +# +RequiredAttributeRolesMissing = Required attribute 'roles' is missing. +ClassNotFoundException = Class Not Found Exception: {0}
\ No newline at end of file diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/test/java/org/apache/tuscany/sca/policy/security/PolicyProcessorTestCase.java b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/test/java/org/apache/tuscany/sca/policy/security/PolicyProcessorTestCase.java new file mode 100644 index 0000000000..a1b790dbb4 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/test/java/org/apache/tuscany/sca/policy/security/PolicyProcessorTestCase.java @@ -0,0 +1,87 @@ +/* + * 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.policy.security; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.policy.authorization.AuthorizationPolicy; +import org.apache.tuscany.sca.policy.authorization.AuthorizationPolicyProcessor; +import org.apache.tuscany.sca.policy.identity.SecurityIdentityPolicy; +import org.apache.tuscany.sca.policy.identity.SecurityIdentityPolicyProcessor; +import org.junit.Assert; +import org.junit.Test; + +/** + * @version $Rev$ $Date$ + */ +public class PolicyProcessorTestCase { + private final static String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; + private final static List<String> SEQ = + Arrays.asList("permitAll", + "allow [r1, r2]", + "denyAll", + "runAs admin", + "useCallerIdentity", + "permitAll", + "allow [r1, r2]", + "denyAll", + "runAs admin"); + + @Test + public void testRead() throws Exception { + List<String> results = new ArrayList<String>(); + Map<QName, StAXArtifactProcessor> processors = new HashMap<QName, StAXArtifactProcessor>(); + processors.put(AuthorizationPolicy.NAME, new AuthorizationPolicyProcessor(null,null)); + processors.put(SecurityIdentityPolicy.NAME, new SecurityIdentityPolicyProcessor(null,null)); + processors.put(new QName(SCA11_NS, "allow"), new AuthorizationPolicyProcessor(null,null)); + processors.put(new QName(SCA11_NS, "permitAll"), new AuthorizationPolicyProcessor(null,null)); + processors.put(new QName(SCA11_NS, "denyAll"), new AuthorizationPolicyProcessor(null,null)); + processors.put(new QName(SCA11_NS, "runAs"), new SecurityIdentityPolicyProcessor(null,null)); + InputStream is = getClass().getResourceAsStream("mock_policy_definitions.xml"); + XMLInputFactory factory = XMLInputFactory.newInstance(); + XMLStreamReader reader = factory.createXMLStreamReader(is); + while (true) { + int event = reader.getEventType(); + if (event == XMLStreamConstants.START_ELEMENT) { + if ("policySet".equals(reader.getName().getLocalPart())) { + reader.nextTag(); + results.add(processors.get(reader.getName()).read(reader).toString()); + } + } + if (reader.hasNext()) { + reader.next(); + } else { + break; + } + } + Assert.assertEquals(SEQ, results); + } +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-security/src/test/resources/org/apache/tuscany/sca/policy/security/mock_policy_definitions.xml b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/test/resources/org/apache/tuscany/sca/policy/security/mock_policy_definitions.xml new file mode 100644 index 0000000000..acb47de243 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-security/src/test/resources/org/apache/tuscany/sca/policy/security/mock_policy_definitions.xml @@ -0,0 +1,78 @@ +<?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://docs.oasis-open.org/ns/opencsa/sca/200903" targetNamespace="http://tuscany.apache.org/xmlns/sca/1.1" + xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200903"> + + <!-- POLICY SETS --> + <policySet name="ps1" provides="authorization" appliesTo="sca:implementation"> + <authorization> + <permitAll /> + </authorization> + </policySet> + + <!-- POLICY SETS --> + <policySet name="ps2" provides="authorization" appliesTo="sca:implementation"> + <authorization> + <allow roles="r1 r2" /> + </authorization> + </policySet> + + <!-- POLICY SETS --> + <policySet name="ps3" provides="authorization" appliesTo="sca:implementation"> + <authorization> + <denyAll /> + </authorization> + </policySet> + + <!-- POLICY SETS --> + <policySet name="ps4" provides="securityIdentity" appliesTo="sca:implementation"> + <securityIdentity> + <runAs role="admin" /> + </securityIdentity> + </policySet> + + <!-- POLICY SETS --> + <policySet name="ps5" provides="securityIdentity" appliesTo="sca:implementation"> + <securityIdentity> + <useCallerIdentity /> + </securityIdentity> + </policySet> + + <!-- POLICY SETS --> + <policySet name="ps6" provides="authorization" appliesTo="sca:implementation"> + <permitAll /> + </policySet> + + <!-- POLICY SETS --> + <policySet name="ps7" provides="authorization" appliesTo="sca:implementation"> + <allow roles="r1 r2" /> + </policySet> + + <!-- POLICY SETS --> + <policySet name="ps8" provides="authorization" appliesTo="sca:implementation"> + <denyAll /> + </policySet> + + <!-- POLICY SETS --> + <policySet name="ps9" provides="securityIdentity" appliesTo="sca:implementation"> + <runAs role="admin" /> + </policySet> + +</definitions>
\ No newline at end of file diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/LICENSE b/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. + + + diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/META-INF/MANIFEST.MF b/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..d11dc08764 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/META-INF/MANIFEST.MF @@ -0,0 +1,31 @@ +Manifest-Version: 1.0
+Private-Package: org.apache.tuscany.sca.policy.xml.ws;version="2.0.0"
+Tool: Bnd-0.0.255
+Bundle-Name: Apache Tuscany SCA Policy XML WS Model
+Created-By: 1.6.0_07 (Sun Microsystems Inc.)
+Bundle-Vendor: The Apache Software Foundation
+Bundle-Version: 2.0.0
+Bnd-LastModified: 1225397120421
+Bundle-ManifestVersion: 2
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Bundle-Description: Apache Tuscany SCA Policy XML WS Model
+Import-Package: javax.xml.namespace,
+ javax.xml.stream,
+ org.apache.axiom.om,
+ org.apache.neethi,
+ org.apache.tuscany.sca.contribution.processor;version="2.0.0",
+ org.apache.tuscany.sca.contribution.resolver;version="2.0.0",
+ org.apache.tuscany.sca.core;version="2.0.0",
+ org.apache.tuscany.sca.monitor;version="2.0.0",
+ org.apache.tuscany.sca.policy;version="2.0.0";resolution:=optional,
+ org.apache.tuscany.sca.policy.xml;version="2.0.0";resolution:=optional
+Bundle-SymbolicName: org.apache.tuscany.sca.policy.xml.ws
+Bundle-DocURL: http://www.apache.org/
+Export-Package: org.apache.tuscany.sca.policy.xml.ws;version="2.0.0";
+ uses:="javax.xml.stream,
+ junit.framework,
+ org.apache.tuscany.sca.contribution.resolver,
+ org.apache.tuscany.sca.contribution.processor,
+ org.apache.tuscany.sca.policy,
+ javax.xml.namespace"
+
diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/NOTICE b/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/pom.xml b/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/pom.xml new file mode 100644 index 0000000000..5f86760f6e --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/pom.xml @@ -0,0 +1,130 @@ +<?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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-modules</artifactId> + <version>2.0-TB3-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>tuscany-policy-xml-ws</artifactId> + <name>Apache Tuscany SCA Policy XML WS Model</name> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-policy</artifactId> + <version>2.0-TB3-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-policy-xml</artifactId> + <version>2.0-TB3-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-contribution</artifactId> + <version>2.0-TB3-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.ws.commons.axiom</groupId> + <artifactId>axiom-api</artifactId> + <version>1.2.7</version> + <exclusions> + <exclusion> + <groupId>xerces</groupId> + <artifactId>xercesImpl</artifactId> + </exclusion> + <exclusion> + <groupId>javax.mail</groupId> + <artifactId>mail</artifactId> + </exclusion> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>xml-apis</groupId> + <artifactId>xml-apis</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>org.apache.neethi</groupId> + <artifactId>neethi</artifactId> + <version>2.0.4</version> + <exclusions> + <exclusion> + <groupId>wsdl4j</groupId> + <artifactId>wsdl4j</artifactId> + </exclusion> + <exclusion> + <groupId>org.codehaus.woodstox</groupId> + <artifactId>wstx-asl</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>org.apache.ws.commons.axiom</groupId> + <artifactId>axiom-impl</artifactId> + <version>1.2.7</version> + <scope>runtime</scope> + <exclusions> + <exclusion> + <groupId>javax.mail</groupId> + <artifactId>mail</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>org.codehaus.woodstox</groupId> + <artifactId>wstx-asl</artifactId> + <version>3.2.4</version> + <scope>runtime</scope> + <exclusions> + <exclusion> + <groupId>stax</groupId> + <artifactId>stax-api</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + <version>1.1.1</version> + <scope>runtime</scope> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + +</project> diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/src/main/java/org/apache/tuscany/sca/policy/xml/ws/WSPolicyProcessor.java b/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/src/main/java/org/apache/tuscany/sca/policy/xml/ws/WSPolicyProcessor.java new file mode 100644 index 0000000000..1b0813a0d8 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/src/main/java/org/apache/tuscany/sca/policy/xml/ws/WSPolicyProcessor.java @@ -0,0 +1,160 @@ +/* + * 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.policy.xml.ws; + +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.neethi.PolicyEngine; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; + + +/** + * Processor for handling xml models of PolicySet definitions + * + * @version $Rev$ $Date$ + */ +public class WSPolicyProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<org.apache.neethi.Policy> { + public final static String WS_POLICY_NS = "http://schemas.xmlsoap.org/ws/2004/09/policy"; + public final static String WS_POLICY = "Policy"; + + public final static QName WS_POLICY_QNAME =new QName(WS_POLICY_NS, WS_POLICY); + + public WSPolicyProcessor() { + System.out.println(">>>Initializing WSPolicyProcessor"); + } + + public WSPolicyProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + System.out.println(">>>Initializing WSPolicyProcessor"); + } + + public QName getArtifactType() { + return WS_POLICY_QNAME; + } + + public Class<org.apache.neethi.Policy> getModelType() { + return org.apache.neethi.Policy.class; + } + + public org.apache.neethi.Policy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + org.apache.neethi.Policy wsPolicy = null; + + int event = reader.getEventType(); + if (event == START_ELEMENT) { + QName name = reader.getName(); + if (WS_POLICY_QNAME.equals(name)) { + OMElement policyElement = loadElement(reader); + wsPolicy = PolicyEngine.getPolicy(policyElement); + } + } + return wsPolicy; + } + + public void write(org.apache.neethi.Policy wsPolicy, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + // Write an <sca:policySet> + writer.writeStartElement(WS_POLICY_NS, WS_POLICY); + + //FIXME write proper ws-policy stuff here + + writer.writeEndElement(); + } + + public void resolve(org.apache.neethi.Policy wsPolicy, ModelResolver resolver) throws ContributionResolveException { + + } + + + private OMElement loadElement(XMLStreamReader reader) throws XMLStreamException { + OMFactory fac = OMAbstractFactory.getOMFactory(); + OMElement head = fac.createOMElement(reader.getName()); + OMElement current = head; + + while (true) { + switch (reader.next()) { + case XMLStreamConstants.START_ELEMENT: + QName name = reader.getName(); + OMElement child = fac.createOMElement(name, current); + + int count = reader.getNamespaceCount(); + for (int i = 0; i < count; i++) { + String prefix = reader.getNamespacePrefix(i); + String ns = reader.getNamespaceURI(i); + child.declareNamespace(ns, prefix); + } + + if(!"".equals(name.getNamespaceURI())) { + child.declareNamespace(name.getNamespaceURI(), name.getPrefix()); + } + + // add the attributes for this element + count = reader.getAttributeCount(); + for (int i = 0; i < count; i++) { + OMNamespace omNs = null; + String ns = reader.getAttributeNamespace(i); + String prefix = reader.getAttributePrefix(i); + String qname = reader.getAttributeLocalName(i); + String value = reader.getAttributeValue(i); + + if ( ns != null ) { + omNs = fac.createOMNamespace(ns, prefix); + } + + child.addAttribute(qname, value, omNs); + if (ns != null) { + child.declareNamespace(ns, prefix); + } + } + current = child; + break; + case XMLStreamConstants.CDATA: + fac.createOMText(current, reader.getText()); + break; + case XMLStreamConstants.CHARACTERS: + fac.createOMText(current, reader.getText()); + break; + case XMLStreamConstants.END_ELEMENT: + if ( current == head ) { + return head; + } else { + current = (OMElement)current.getParent(); + } + } + } + } + + + } diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..2e11e31fec --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# 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. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.policy.xml.ws.WSPolicyProcessor;qname=http://schemas.xmlsoap.org/ws/2004/09/policy#Policy,model=org.apache.neethi.Policy diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/ws/TestModelResolver.java b/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/ws/TestModelResolver.java new file mode 100644 index 0000000000..57e3fe8d3a --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/ws/TestModelResolver.java @@ -0,0 +1,63 @@ +/* + * 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.policy.xml.ws; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + + +/** + * A default implementation of an artifact resolver, based on a map. + * + * @version $Rev$ $Date$ + */ +public class TestModelResolver implements ModelResolver { + private static final long serialVersionUID = -7826976465762296634L; + + private Map<Object, Object> map = new HashMap<Object, Object>(); + + public TestModelResolver() { + } + + public <T> T resolveModel(Class<T> modelClass, T unresolved) { + Object resolved = map.get(unresolved); + if (resolved != null) { + + // Return the resolved object + return modelClass.cast(resolved); + + } else { + + // Return the unresolved object + return unresolved; + } + } + + public void addModel(Object resolved) { + map.put(resolved, resolved); + } + + public Object removeModel(Object resolved) { + return map.remove(resolved); + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/ws/TestPolicyProcessor.java b/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/ws/TestPolicyProcessor.java new file mode 100644 index 0000000000..12a90f5c37 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/ws/TestPolicyProcessor.java @@ -0,0 +1,73 @@ +/* + * 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.policy.xml.ws; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * + * @version $Rev$ $Date$ + */ +public class TestPolicyProcessor implements StAXArtifactProcessor<Object> { + + public QName getArtifactType() { + return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment"); + } + + public Object read(XMLStreamReader arg0) throws ContributionReadException, XMLStreamException { + return new MockPolicyImplOne(); + } + + public void write(Object arg0, XMLStreamWriter arg1) throws ContributionWriteException, + XMLStreamException { + } + + public Class<Object> getModelType() { + // TODO Auto-generated method stub + return Object.class; + } + + public void resolve(Object arg0, ModelResolver arg1) throws ContributionResolveException { + + } + + + public class MockPolicyImplOne { + public QName getSchemaName() { + return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment"); + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + + } +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/ws/WSPolicyProcessorTestCase.java b/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/ws/WSPolicyProcessorTestCase.java new file mode 100644 index 0000000000..907a50984c --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/ws/WSPolicyProcessorTestCase.java @@ -0,0 +1,111 @@ +/* + * 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.policy.xml.ws; + +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import java.io.StringReader; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.policy.xml.ws.WSPolicyProcessor; + +import junit.framework.TestCase; + +/** + * Test reading SCA XML assembly documents. + * + * @version $Rev$ $Date$ + */ +public class WSPolicyProcessorTestCase extends TestCase { + + private static final String VALID_WS_POLICY = + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + + "<definitions xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200903\"" + + " targetNamespace=\"http://test\"" + + " xmlns:test=\"http://test\"" + + " xmlns:sca=\"http://docs.oasis-open.org/ns/opencsa/sca/200903\">" + + " " + + " <policySet name=\"SecureWSPolicy\"" + + " provides=\"test:confidentiality\"" + + " appliesTo=\"sca:binding.ws\"" + + " xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200903\"" + + " xmlns:sp=\"http://schemas.xmlsoap.org/ws/2002/12/secext\"" + + " xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\">" + + " <wsp:Policy>" + + " <wsp:ExactlyOne>" + + " <wsp:All>" + + " <sp:SecurityToken>" + + " <sp:TokenType>sp:X509v3</sp:TokenType>" + + " </sp:SecurityToken>" + + " <sp:UsernameToken />" + + " <sp:SignedParts />" + + " <sp:EncryptedParts>" + + " <sp:Body />" + + " </sp:EncryptedParts>" + + " <sp:TransportBinding>" + + " <sp:IncludeTimeStamp />" + + " </sp:TransportBinding>" + + " </wsp:All>" + + " </wsp:ExactlyOne>" + + " </wsp:Policy>" + + " </policySet>" + + " </definitions>"; + + private XMLInputFactory inputFactory; + + @Override + public void setUp() throws Exception { + inputFactory = XMLInputFactory.newInstance(); + + } + + public void testReadWsPolicy() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_WS_POLICY)); + WSPolicyProcessor processor = new WSPolicyProcessor(); + Object artifact = null; + + QName name = null; + reader.next(); + while ( true ) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: { + name = reader.getName(); + + if(WSPolicyProcessor.WS_POLICY_QNAME.equals(name)) { + artifact = processor.read(reader); + } + + break; + } + } + + if ( reader.hasNext() ) { + reader.next(); + } else { + break; + } + } + assertNotNull(artifact); + } +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/src/test/resources/org/apache/tuscany/sca/policy/xml/test_definitions.xml b/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/src/test/resources/org/apache/tuscany/sca/policy/xml/test_definitions.xml new file mode 100644 index 0000000000..a2e321068f --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml-ws/src/test/resources/org/apache/tuscany/sca/policy/xml/test_definitions.xml @@ -0,0 +1,106 @@ +<?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://docs.oasis-open.org/ns/opencsa/sca/200903" + targetNamespace="http://test" + xmlns:test="http://test" + xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200903"> + +<policySet name="SecureWSPolicy" + provides="test:confidentiality" + appliesTo="sca:binding.ws" + xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" + xmlns:sp="http://schemas.xmlsoap.org/ws/2002/12/secext" + xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> + <wsp:Policy> + <wsp:ExactlyOne> + <wsp:All> + <sp:SecurityToken> + <sp:TokenType>sp:X509v3</sp:TokenType> + </sp:SecurityToken> + <sp:UsernameToken /> + <sp:SignedParts /> + <sp:EncryptedParts> + <sp:Body /> + </sp:EncryptedParts> + <sp:TransportBinding> + <sp:IncludeTimeStamp /> + </sp:TransportBinding> + </wsp:All> + </wsp:ExactlyOne> + </wsp:Policy> + </policySet> + +<!-- profile intent --> + <intent name="reliableMessageProtection" + constrains="sca:binding" + requires="test:messageProtection"> + <description> + Protect messages from unauthorized reading or modification + </description> + </intent> + + <intent name="messageProtection" + constrains="sca:binding" + requires="test:confidentiality test:integrity"> + <description> + Protect messages from unauthorized reading or modification + </description> + </intent> + +<!-- simple intent --> + <intent name="confidentiality" + constrains="sca:binding"> + <description> + Communitcation thro this binding must prevent + unauthorized users from reading the messages. + </description> + </intent> + + <intent name="integrity" + constrains="sca:binding"> + <description> + Communitcation thro this binding must prevent + unauthorized modification of the messages. + </description> + </intent> + + <intent name="authentication" + constrains="sca:binding"> + <description> + Communitcation thro this binding required + Authentication. + </description> + </intent> + + <intent name="logging" + constrains="sca:implementation"> + <description> + All messages to and from this implementation must be logged + </description> + </intent> + + <intent name="tracing" + constrains="sca:implementation.java"> + <description> + Need to figure out some description for this + </description> + </intent> + +</definitions>
\ No newline at end of file diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml/LICENSE b/sandbox/ant/sca/branches/tb7/modules/policy-xml/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml/LICENSE @@ -0,0 +1,205 @@ +
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
+
+
+
diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml/META-INF/MANIFEST.MF b/sandbox/ant/sca/branches/tb7/modules/policy-xml/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..3e5ce44e75 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0
+Private-Package: org.apache.tuscany.sca.policy.xml;version="2.0.0"
+Tool: Bnd-0.0.255
+Bundle-Name: Apache Tuscany SCA Policy XML Model
+Created-By: 1.6.0_07 (Sun Microsystems Inc.)
+Bundle-Vendor: The Apache Software Foundation
+Bundle-Version: 2.0.0
+Bnd-LastModified: 1225397115375
+Bundle-ManifestVersion: 2
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Bundle-Description: Apache Tuscany SCA Policy XML Model
+Import-Package: javax.xml.namespace,javax.xml.stream,javax.xml.xpath,o
+ rg.apache.tuscany.sca.contribution.processor;version="2.0.0",org.apache
+ .tuscany.sca.contribution.resolver;version="2.0.0",org.apache.tuscany.s
+ ca.core;version="2.0.0",org.apache.tuscany.sca.monitor;version="2.0.0",or
+ g.apache.tuscany.sca.policy;version="2.0.0",org.apache.tuscany.sca.poli
+ cy.impl;version="2.0.0"
+Bundle-SymbolicName: org.apache.tuscany.sca.policy.xml
+Bundle-DocURL: http://www.apache.org/
+
diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml/NOTICE b/sandbox/ant/sca/branches/tb7/modules/policy-xml/NOTICE new file mode 100644 index 0000000000..51042eab05 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml/NOTICE @@ -0,0 +1,6 @@ +${pom.name}
+Copyright (c) 2005 - 2009 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml/pom.xml b/sandbox/ant/sca/branches/tb7/modules/policy-xml/pom.xml new file mode 100644 index 0000000000..553b701290 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml/pom.xml @@ -0,0 +1,58 @@ +<?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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>2.0-TB3-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-policy-xml</artifactId>
+ <name>Apache Tuscany SCA Policy XML Model</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-policy</artifactId>
+ <version>2.0-TB3-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution</artifactId>
+ <version>2.0-TB3-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ <version>3.2.4</version>
+ <scope>runtime</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java new file mode 100644 index 0000000000..38c7b57f12 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java @@ -0,0 +1,67 @@ +/* + * 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.policy.xml; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.policy.BindingType; +import org.apache.tuscany.sca.policy.ExtensionType; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * Processor for handling XML models of BindingType meta data definitions + * + * @version $Rev$ $Date$ + */ +public class BindingTypeProcessor extends ExtensionTypeProcessor { + + public BindingTypeProcessor(PolicyFactory policyFactory, + StAXArtifactProcessor<Object> extensionProcessor, + Monitor monitor) { + super(policyFactory, extensionProcessor, monitor); + } + + public BindingTypeProcessor(FactoryExtensionPoint modelFactories, + StAXArtifactProcessor<Object> extensionProcessor, + Monitor monitor) { + super(modelFactories.getFactory(PolicyFactory.class), extensionProcessor, monitor); + } + + public QName getArtifactType() { + return BINDING_TYPE_QNAME; + } + + @Override + protected ExtensionType resolveExtensionType(ExtensionType extnType, ModelResolver resolver) + throws ContributionResolveException { + if (extnType instanceof BindingType) { + BindingType bindingType = (BindingType)extnType; + return resolver.resolveModel(BindingType.class, bindingType); + } else { + return extnType; + } + + } +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ExtensionTypeProcessor.java b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ExtensionTypeProcessor.java new file mode 100644 index 0000000000..f437b5d599 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ExtensionTypeProcessor.java @@ -0,0 +1,251 @@ +/* + * 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.policy.xml; + +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.policy.BindingType; +import org.apache.tuscany.sca.policy.ExtensionType; +import org.apache.tuscany.sca.policy.ImplementationType; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * Processor for handling XML models of ExtensionType meta data definitions + * + * @version $Rev$ $Date$ + */ +abstract class ExtensionTypeProcessor extends BaseStAXArtifactProcessor implements + StAXArtifactProcessor<ExtensionType>, PolicyConstants { + + private PolicyFactory policyFactory; + private Monitor monitor; + + protected abstract ExtensionType resolveExtensionType(ExtensionType extnType, ModelResolver resolver) + throws ContributionResolveException; + + public ExtensionTypeProcessor(PolicyFactory policyFactory, + StAXArtifactProcessor<Object> extensionProcessor, + Monitor monitor) { + this.policyFactory = policyFactory; + this.monitor = monitor; + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = + monitor.createProblem(this.getClass().getName(), + "policy-xml-validation-messages", + Severity.ERROR, + model, + message, + (Object[])messageParameters); + monitor.problem(problem); + } + } + + public ExtensionType read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + QName extType = getArtifactType(); + QName type = getQName(reader, "type"); + + if (type != null) { + ExtensionType extensionType = null; + if (BINDING_TYPE_QNAME.equals(extType)) { + extensionType = policyFactory.createBindingType(); + } else if (IMPLEMENTATION_TYPE_QNAME.equals(extType)) { + extensionType = policyFactory.createImplementationType(); + } else { + error("UnrecognizedExtensionType", reader, type); + return null; + //throw new ContributionReadException("Unrecognized ExtensionType - " + type); + } + extensionType.setType(type); + extensionType.setUnresolved(true); + + readAlwaysProvidedIntents(extensionType, reader); + readMayProvideIntents(extensionType, reader); + return extensionType; + + } else { + error("RequiredAttributeMissing", reader, extType); + //throw new ContributionReadException("Required attribute '" + TYPE + + //"' missing from BindingType Definition"); + } + return null; + } + + private void readAlwaysProvidedIntents(ExtensionType extnType, XMLStreamReader reader) { + String value = reader.getAttributeValue(null, ALWAYS_PROVIDES); + if (value != null) { + List<Intent> alwaysProvided = extnType.getAlwaysProvidedIntents(); + for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { + QName qname = getQNameValue(reader, tokens.nextToken()); + Intent intent = policyFactory.createIntent(); + intent.setName(qname); + alwaysProvided.add(intent); + } + } + } + + private void readMayProvideIntents(ExtensionType extnType, XMLStreamReader reader) { + String value = reader.getAttributeValue(null, MAY_PROVIDE); + if (value != null) { + List<Intent> mayProvide = extnType.getMayProvidedIntents(); + for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { + QName qname = getQNameValue(reader, tokens.nextToken()); + Intent intent = policyFactory.createIntent(); + intent.setName(qname); + mayProvide.add(intent); + } + } + } + + public void write(ExtensionType extnType, XMLStreamWriter writer) throws ContributionWriteException, + XMLStreamException { + + // Write an <sca:bindingType or sca:implementationType> + if (extnType instanceof BindingType) { + writer.writeStartElement(SCA11_NS, BINDING_TYPE); + } else if (extnType instanceof ImplementationType) { + writer.writeStartElement(SCA11_NS, IMPLEMENTATION_TYPE); + } + + writeAlwaysProvidesIntentsAttribute(extnType, writer); + writeMayProvideIntentsAttribute(extnType, writer); + + writer.writeEndElement(); + } + + private void writeMayProvideIntentsAttribute(ExtensionType extnType, XMLStreamWriter writer) + throws XMLStreamException { + StringBuffer sb = new StringBuffer(); + for (Intent intent : extnType.getMayProvidedIntents()) { + writer.writeNamespace(intent.getName().getPrefix(), intent.getName().getNamespaceURI()); + sb.append(intent.getName().getPrefix() + COLON + intent.getName().getLocalPart()); + sb.append(WHITE_SPACE); + } + + if (sb.length() > 0) { + writer.writeAttribute(MAY_PROVIDE, sb.toString()); + } + } + + private void writeAlwaysProvidesIntentsAttribute(ExtensionType extnType, XMLStreamWriter writer) + throws XMLStreamException { + StringBuffer sb = new StringBuffer(); + for (Intent intent : extnType.getAlwaysProvidedIntents()) { + writer.writeNamespace(intent.getName().getPrefix(), intent.getName().getNamespaceURI()); + sb.append(intent.getName().getPrefix() + COLON + intent.getName().getLocalPart()); + sb.append(WHITE_SPACE); + } + + if (sb.length() > 0) { + writer.writeAttribute(ALWAYS_PROVIDES, sb.toString()); + + } + } + + public void resolve(ExtensionType extnType, ModelResolver resolver) throws ContributionResolveException { + + if (extnType != null && extnType.isUnresolved()) { + resolveAlwaysProvidedIntents(extnType, resolver); + resolveMayProvideIntents(extnType, resolver); + extnType.setUnresolved(false); + //resolveExtensionType(extnType, resolver); + } + } + + private void resolveAlwaysProvidedIntents(ExtensionType extensionType, ModelResolver resolver) + throws ContributionResolveException { + if (extensionType != null) { + // resolve all provided intents + List<Intent> alwaysProvided = new ArrayList<Intent>(); + for (Intent providedIntent : extensionType.getAlwaysProvidedIntents()) { + if (providedIntent.isUnresolved()) { + providedIntent = resolver.resolveModel(Intent.class, providedIntent); + if (!providedIntent.isUnresolved()) { + alwaysProvided.add(providedIntent); + } else { + error("AlwaysProvidedIntentNotFound", resolver, providedIntent, extensionType); + //throw new ContributionResolveException("Always Provided Intent - " + providedIntent + //+ " not found for ExtensionType " + //+ extensionType); + } + } else { + alwaysProvided.add(providedIntent); + } + } + extensionType.getAlwaysProvidedIntents().clear(); + extensionType.getAlwaysProvidedIntents().addAll(alwaysProvided); + } + } + + private void resolveMayProvideIntents(ExtensionType extensionType, ModelResolver resolver) + throws ContributionResolveException { + if (extensionType != null) { + // resolve all provided intents + List<Intent> mayProvide = new ArrayList<Intent>(); + for (Intent providedIntent : extensionType.getMayProvidedIntents()) { + if (providedIntent.isUnresolved()) { + providedIntent = resolver.resolveModel(Intent.class, providedIntent); + if (!providedIntent.isUnresolved()) { + mayProvide.add(providedIntent); + } else { + error("MayProvideIntentNotFound", resolver, providedIntent, extensionType); + //throw new ContributionResolveException("May Provide Intent - " + providedIntent + //+ " not found for ExtensionType " + //+ extensionType); + } + } else { + mayProvide.add(providedIntent); + } + } + extensionType.getMayProvidedIntents().clear(); + extensionType.getMayProvidedIntents().addAll(mayProvide); + } + } + + public Class<ExtensionType> getModelType() { + return ExtensionType.class; + } +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java new file mode 100644 index 0000000000..41e2af3809 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java @@ -0,0 +1,67 @@ +/* + * 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.policy.xml; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.policy.ExtensionType; +import org.apache.tuscany.sca.policy.ImplementationType; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * Processor for handling XML models of ImplementationType meta data definitions + * + * @version $Rev$ $Date$ + */ +public class ImplementationTypeProcessor extends ExtensionTypeProcessor { + + public ImplementationTypeProcessor(PolicyFactory policyFactory, + StAXArtifactProcessor<Object> extensionProcessor, + Monitor monitor) { + super(policyFactory, extensionProcessor, monitor); + } + + public ImplementationTypeProcessor(FactoryExtensionPoint modelFactories, + StAXArtifactProcessor<Object> extensionProcessor, + Monitor monitor) { + super(modelFactories.getFactory(PolicyFactory.class), extensionProcessor, monitor); + } + + public QName getArtifactType() { + return IMPLEMENTATION_TYPE_QNAME; + } + + @Override + protected ExtensionType resolveExtensionType(ExtensionType extnType, ModelResolver resolver) + throws ContributionResolveException { + if (extnType instanceof ImplementationType) { + ImplementationType implType = (ImplementationType)extnType; + return resolver.resolveModel(ImplementationType.class, implType); + } else { + return extnType; + } + + } +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentProcessor.java b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentProcessor.java new file mode 100644 index 0000000000..d87921dbbf --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentProcessor.java @@ -0,0 +1,387 @@ +/* + * 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.policy.xml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.StringTokenizer; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.policy.ExtensionType; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.Intent.Type; + +/** + * Processor for handling XML models of PolicyIntent definitions + * + * @version $Rev$ $Date$ + */ +public class IntentProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<Intent>, + PolicyConstants { + + private PolicyFactory policyFactory; + private Monitor monitor; + + public IntentProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + this.policyFactory = modelFactories.getFactory(PolicyFactory.class); + this.monitor = monitor; + } + + public IntentProcessor(PolicyFactory policyFactory, Monitor monitor) { + this.policyFactory = policyFactory; + this.monitor = monitor; + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = + monitor.createProblem(this.getClass().getName(), + "policy-xml-validation-messages", + Severity.ERROR, + model, + message, + messageParameters); + monitor.problem(problem); + } + } + + private void warn(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = + monitor.createProblem(this.getClass().getName(), + "policy-xml-validation-messages", + Severity.WARNING, + model, + message, + messageParameters); + monitor.problem(problem); + } + } + + public Intent read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + Intent intent = null; + String intentLocalName = reader.getAttributeValue(null, NAME); + if (intentLocalName == null) { + error("IntentNameMissing", reader); + return null; + } + + String intentType = reader.getAttributeValue(null, INTENT_TYPE); + if (intentType == null) { + intentType = Intent.Type.interaction.name(); + } + + intent = policyFactory.createIntent(); + + // [rfeng] the target namespace is not available, set the local part for now + // This will be changed in the definitions processor + intent.setName(new QName(intentLocalName)); + intent.setType(Type.valueOf(intentType)); + + readRequiredIntents(intent, reader); + readExcludedIntents(intent, reader); + + readConstrainedTypes(intent, reader); + + Intent current = intent; + int event = reader.getEventType(); + QName name = null; + while (reader.hasNext()) { + event = reader.getEventType(); + switch (event) { + case START_ELEMENT: { + name = reader.getName(); + if (DESCRIPTION_QNAME.equals(name)) { + current.setDescription(reader.getElementText()); + } else if (INTENT_QUALIFIER_QNAME.equals(name)) { + String qualifierName = reader.getAttributeValue(null, NAME); + String defaultQ = reader.getAttributeValue(null, DEFAULT); + boolean isDefault = defaultQ == null ? false : Boolean.parseBoolean(defaultQ); + String qualifiedIntentName = intentLocalName + QUALIFIER + qualifierName; + Intent qualified = policyFactory.createIntent(); + qualified.setType(intent.getType()); + qualified.setName(new QName(qualifiedIntentName)); + if (isDefault) { + intent.setDefaultQualifiedIntent(qualified); + } + intent.getQualifiedIntents().add(qualified); + qualified.setQualifiableIntent(intent); + current = qualified; + } + break; + } + case END_ELEMENT: { + name = reader.getName(); + if (INTENT_QUALIFIER_QNAME.equals(name)) { + current = intent; + } + break; + } + } + if (event == END_ELEMENT && POLICY_INTENT_QNAME.equals(reader.getName())) { + break; + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + // REVIEW: [rfeng] What's going to happen if there is only one qualified intent + if (intent.getQualifiedIntents().size() == 1) { + intent.setDefaultQualifiedIntent(intent.getQualifiedIntents().get(0)); + } + return intent; + } + + public void write(Intent intent, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + // Write an <sca:intent> + writer.writeStartElement(PolicyConstants.SCA11_NS, INTENT); + writer.writeNamespace(intent.getName().getPrefix(), intent.getName().getNamespaceURI()); + writer.writeAttribute(PolicyConstants.NAME, intent.getName().getPrefix() + COLON + + intent.getName().getLocalPart()); + if (intent.getRequiredIntents() != null && intent.getRequiredIntents().size() > 0) { + StringBuffer sb = new StringBuffer(); + for (Intent requiredIntents : intent.getRequiredIntents()) { + sb.append(requiredIntents.getName()); + sb.append(" "); + } + writer.writeAttribute(PolicyConstants.REQUIRES, sb.toString()); + } + + if (intent.getExcludedIntents() != null && intent.getExcludedIntents().size() > 0) { + StringBuffer sb = new StringBuffer(); + for (Intent excludedIntents : intent.getExcludedIntents()) { + sb.append(excludedIntents.getName()); + sb.append(" "); + } + writer.writeAttribute(PolicyConstants.EXCLUDES, sb.toString()); + } + + if (intent.getConstrainedTypes() != null && intent.getConstrainedTypes().size() > 0) { + StringBuffer sb = new StringBuffer(); + for (ExtensionType contrainedArtifact : intent.getConstrainedTypes()) { + sb.append(contrainedArtifact.getType().getPrefix()); + sb.append(':').append(contrainedArtifact.getType().getLocalPart()); + sb.append(" "); + } + writer.writeAttribute(CONSTRAINS, sb.toString()); + } + + if (intent.getDescription() != null && intent.getDescription().length() > 0) { + writer.writeStartElement(PolicyConstants.SCA11_NS, DESCRIPTION); + writer.writeCData(intent.getDescription()); + writer.writeEndElement(); + } + + writer.writeEndElement(); + } + + private void resolveContrainedTypes(Intent intent, ModelResolver resolver) throws ContributionResolveException { + Collection<ExtensionType> resolvedTypes = new HashSet<ExtensionType>(); + for (ExtensionType extensionType : intent.getConstrainedTypes()) { + if (ExtensionType.BINDING_BASE.equals(extensionType.getType()) || ExtensionType.IMPLEMENTATION_BASE + .equals(extensionType.getType())) { + // HACK: Mark sca:binding and sca:implementation as resolved + extensionType.setUnresolved(false); + resolvedTypes.add(extensionType); + } else { + ExtensionType resolved = resolver.resolveModel(ExtensionType.class, extensionType); + if (!resolved.isUnresolved() || resolved != extensionType) { + resolvedTypes.add(resolved); + } else { + warn("ConstrainedTypeNotFound", intent, extensionType, intent); + } + } + } + intent.getConstrainedTypes().clear(); + intent.getConstrainedTypes().addAll(resolvedTypes); + } + + private void resolveProfileIntent(Intent intent, ModelResolver resolver) throws ContributionResolveException { + // FIXME: Need to check for cyclic references first i.e an A requiring B + // and then B requiring A... + if (intent != null && !intent.getRequiredIntents().isEmpty()) { + // resolve all required intents + List<Intent> requiredIntents = new ArrayList<Intent>(); + for (Intent required : intent.getRequiredIntents()) { + if (required.isUnresolved()) { + Intent resolved = resolver.resolveModel(Intent.class, required); + // At this point, when the required intent is not resolved, it does not mean + // its undeclared, chances are that their dependency are not resolved yet. + // Lets try to resolve them first. + if (resolved.isUnresolved()) { + if (((resolved).getRequiredIntents()).contains(intent)) { + error("CyclicReferenceFound", resolver, required, intent); + return; + } + } + + if (!resolved.isUnresolved() || resolved != required) { + requiredIntents.add(resolved); + } else { + error("RequiredIntentNotFound", resolver, required, intent); + return; + //throw new ContributionResolveException("Required Intent - " + requiredIntent + //+ " not found for Intent " + policyIntent); + } + } else { + requiredIntents.add(required); + } + } + intent.getRequiredIntents().clear(); + intent.getRequiredIntents().addAll(requiredIntents); + } + } + + private void resolveQualifiedIntent(Intent qualifed, ModelResolver resolver) throws ContributionResolveException { + if (qualifed != null) { + //resolve the qualifiable intent + Intent parent = qualifed.getQualifiableIntent(); + if (parent == null) { + return; + } + if (parent.isUnresolved()) { + Intent resolved = resolver.resolveModel(Intent.class, parent); + // At this point, when the qualifiable intent is not resolved, it does not mean + // its undeclared, chances are that their dependency are not resolved yet. + // Lets try to resolve them first. + + if (!resolved.isUnresolved() || resolved != qualifed) { + qualifed.setQualifiableIntent(resolved); + } else { + error("QualifiableIntentNotFound", resolver, parent, qualifed); + //throw new ContributionResolveException("Qualifiable Intent - " + qualifiableIntent + //+ " not found for Intent " + policyIntent); + } + } + } + } + + public void resolve(Intent intent, ModelResolver resolver) throws ContributionResolveException { + resolveProfileIntent(intent, resolver); + resolveExcludedIntents(intent, resolver); + resolveQualifiedIntent(intent, resolver); + resolveContrainedTypes(intent, resolver); + intent.setUnresolved(false); + } + + public QName getArtifactType() { + return POLICY_INTENT_QNAME; + } + + private void readConstrainedTypes(Intent policyIntent, XMLStreamReader reader) throws ContributionReadException { + String value = reader.getAttributeValue(null, CONSTRAINS); + if (value != null) { + List<ExtensionType> constrainedTypes = policyIntent.getConstrainedTypes(); + for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { + QName qname = getQNameValue(reader, tokens.nextToken()); + ExtensionType extensionType = policyFactory.createExtensionType(); + extensionType.setType(qname); + constrainedTypes.add(extensionType); + } + } + } + + private void readRequiredIntents(Intent intent, XMLStreamReader reader) { + String value = reader.getAttributeValue(null, REQUIRES); + if (value != null) { + List<Intent> requiredIntents = intent.getRequiredIntents(); + for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { + QName qname = getQNameValue(reader, tokens.nextToken()); + Intent required = policyFactory.createIntent(); + required.setName(qname); + required.setUnresolved(true); + requiredIntents.add(required); + } + } + } + + private void readExcludedIntents(Intent intent, XMLStreamReader reader) { + String value = reader.getAttributeValue(null, EXCLUDES); + if (value != null) { + List<Intent> excludedIntents = intent.getExcludedIntents(); + for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { + QName qname = getQNameValue(reader, tokens.nextToken()); + Intent excluded = policyFactory.createIntent(); + excluded.setName(qname); + excluded.setUnresolved(true); + excludedIntents.add(excluded); + } + } + } + + private void resolveExcludedIntents(Intent policyIntent, ModelResolver resolver) + throws ContributionResolveException { + if (policyIntent != null) { + // resolve all excluded intents + List<Intent> excludedIntents = new ArrayList<Intent>(); + for (Intent excludedIntent : policyIntent.getExcludedIntents()) { + if (excludedIntent.isUnresolved()) { + Intent resolvedExcludedIntent = resolver.resolveModel(Intent.class, excludedIntent); + if (!resolvedExcludedIntent.isUnresolved()) { + excludedIntents.add(resolvedExcludedIntent); + } else { + error("ExcludedIntentNotFound", resolver, excludedIntent, policyIntent); + return; + //throw new ContributionResolveException("Excluded Intent " + excludedIntent + //+ " not found for intent " + policyIntent); + } + } else { + excludedIntents.add(excludedIntent); + } + } + policyIntent.getExcludedIntents().clear(); + policyIntent.getExcludedIntents().addAll(excludedIntents); + } + } + + public Class<Intent> getModelType() { + return Intent.class; + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java new file mode 100644 index 0000000000..7d63440e23 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.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 org.apache.tuscany.sca.policy.xml;
+
+import javax.xml.namespace.QName;
+
+/**
+ * constants related to policy framework
+ *
+ * @version $Rev$ $Date$
+ */
+public interface PolicyConstants {
+ String WHITE_SPACE = " ";
+ String COLON = ":";
+ String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903";
+ String TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1";
+ String INTENT = "intent";
+ String POLICY_SET = "policySet";
+ String POLICY_SET_REFERENCE = "policySetReference";
+ String INTENT_MAP = "intentMap";
+ String NAME = "name";
+ String TARGET_NAMESPACE = "targetNamespace";
+ String SCA_DEFINITIONS = "definitions";
+ String CONSTRAINS = "constrains";
+ String DESCRIPTION = "description";
+ String PROVIDES = "provides";
+ String APPLIES_TO = "appliesTo";
+ String ATTACH_TO = "attachTo";
+ String ALWAYS_APPLIES_TO = "alwaysAppliesTo";
+ String QUALIFIER = ".";
+ String INTENT_QUALIFIER = "qualifier";
+ String INTENT_MAP_QUALIFIER = "qualifier";
+ String REQUIRES = "requires";
+ String EXCLUDES = "excludes";
+ String DEFAULT = "default";
+
+ String ALWAYS_PROVIDES = "alwaysProvides";
+ String MAY_PROVIDE = "mayProvide";
+ String INTENT_TYPE = "intentType";
+ String IMPLEMENTATION_TYPE = "implementationType";
+ String BINDING_TYPE = "bindingType";
+ QName IMPLEMENTATION_TYPE_QNAME = new QName(SCA11_NS, IMPLEMENTATION_TYPE);
+ QName BINDING_TYPE_QNAME = new QName(SCA11_NS, BINDING_TYPE);
+ String BINDING = "binding";
+ String IMPLEMENTATION = "implementation";
+
+ QName POLICY_INTENT_QNAME = new QName(SCA11_NS, INTENT);
+ QName POLICY_SET_QNAME = new QName(SCA11_NS, POLICY_SET);
+ QName POLICY_INTENT_MAP_QNAME = new QName(SCA11_NS, INTENT_MAP);
+ QName SCA_DEFINITIONS_QNAME = new QName(SCA11_NS, SCA_DEFINITIONS);
+ QName DESCRIPTION_QNAME = new QName(SCA11_NS, DESCRIPTION);
+ QName POLICY_INTENT_MAP_QUALIFIER_QNAME = new QName(SCA11_NS, INTENT_MAP_QUALIFIER);
+ QName POLICY_SET_REFERENCE_QNAME = new QName(SCA11_NS, POLICY_SET_REFERENCE);
+ QName INTENT_QUALIFIER_QNAME = new QName(SCA11_NS, INTENT_QUALIFIER);
+
+ String QUALIFIED_INTENT_CONSTRAINS_ERROR = " - Qualified Intents must not specify 'constrains' attribute";
+
+}
diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java new file mode 100644 index 0000000000..955788ce8f --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java @@ -0,0 +1,490 @@ +/* + * 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.policy.xml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentMap; +import org.apache.tuscany.sca.policy.PolicyExpression; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.Qualifier; + +/** + * Processor for handling XML models of PolicySet definitions + * + * @version $Rev$ $Date$ + */ +public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<PolicySet>, + PolicyConstants { + + private PolicyFactory policyFactory; + private StAXArtifactProcessor<Object> extensionProcessor; + private XPathFactory xpathFactory = XPathFactory.newInstance(); + private Monitor monitor; + + public PolicySetProcessor(FactoryExtensionPoint modelFactories, + StAXArtifactProcessor<Object> extensionProcessor, + Monitor monitor) { + this.policyFactory = modelFactories.getFactory(PolicyFactory.class); + this.extensionProcessor = extensionProcessor; + this.monitor = monitor; + } + + public PolicySetProcessor(PolicyFactory policyFactory, + StAXArtifactProcessor<Object> extensionProcessor, + Monitor monitor) { + this.policyFactory = policyFactory; + this.extensionProcessor = extensionProcessor; + this.monitor = monitor; + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = + monitor.createProblem(this.getClass().getName(), + "policy-xml-validation-messages", + Severity.ERROR, + model, + message, + ex); + monitor.problem(problem); + } + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = + monitor.createProblem(this.getClass().getName(), + "policy-xml-validation-messages", + Severity.ERROR, + model, + message, + (Object[])messageParameters); + monitor.problem(problem); + } + } + + public PolicySet read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + PolicySet policySet = null; + + String policySetName = reader.getAttributeValue(null, NAME); + String appliesTo = reader.getAttributeValue(null, APPLIES_TO); + if (policySetName == null || appliesTo == null) { + if (policySetName == null) + error("PolicySetNameMissing", reader); + if (appliesTo == null) + error("PolicySetAppliesToMissing", reader); + return policySet; + } + + policySet = policyFactory.createPolicySet(); + policySet.setName(new QName(policySetName)); + + //TODO: with 1.0 version of specs the applies to xpath is given related to the immediate + //parent whereas the runtime evaluates the xpath aginst the composite element. What the runtime + //is doing is what the future version of the specs could be tending towards. When that happens + //this 'if' must be deleted + if (appliesTo != null && !appliesTo.startsWith("/")) { + appliesTo = "//" + appliesTo; + } + + policySet.setAppliesTo(appliesTo); + + XPath path = xpathFactory.newXPath(); + path.setNamespaceContext(reader.getNamespaceContext()); + try { + if (appliesTo != null) { + policySet.setAppliesToXPathExpression(path.compile(appliesTo)); + } + } catch (XPathExpressionException e) { + ContributionReadException ce = new ContributionReadException(e); + error("ContributionReadException", policySet, ce); + //throw ce; + } + + readProvidedIntents(policySet, reader); + + int event = reader.getEventType(); + QName name = null; + reader.next(); + while (reader.hasNext()) { + event = reader.getEventType(); + switch (event) { + case START_ELEMENT: { + name = reader.getName(); + if (POLICY_INTENT_MAP_QNAME.equals(name)) { + Intent mappedIntent = policyFactory.createIntent(); + String provides = reader.getAttributeValue(null, PROVIDES); + if (provides != null) { + mappedIntent.setName(getQName(reader, PROVIDES)); + if (policySet.getProvidedIntents().contains(mappedIntent)) { + readIntentMap(reader, policySet, mappedIntent); + } else { + error("IntentNotSpecified", policySet, policySetName); + //throw new ContributionReadException("Intent Map provides for Intent not specified as provided by parent PolicySet - " + policySetName); + } + } else { + error("IntentMapProvidesMissing", reader, policySetName); + } + } else if (POLICY_SET_REFERENCE_QNAME.equals(name)) { + PolicySet referredPolicySet = policyFactory.createPolicySet(); + String referencename = reader.getAttributeValue(null, NAME); + if (referencename != null) { + referredPolicySet.setName(getQName(reader, NAME)); + policySet.getReferencedPolicySets().add(referredPolicySet); + } else { + error("PolicySetReferenceNameMissing", reader, policySetName); + } + } /*else if ( WS_POLICY_QNAME.equals(name) ) { + OMElement policyElement = loadElement(reader); + org.apache.neethi.Policy wsPolicy = PolicyEngine.getPolicy(policyElement); + policySet.getPolicies().add(wsPolicy); + } */else { + Object extension = extensionProcessor.read(reader); + if (extension != null) { + PolicyExpression exp = policyFactory.createPolicyExpression(); + exp.setName(name); + exp.setPolicy(extension); + policySet.getPolicies().add(exp); + } + } + break; + } + } + if (event == END_ELEMENT) { + if (POLICY_SET_QNAME.equals(reader.getName())) { + break; + } + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + return policySet; + } + + public void readIntentMap(XMLStreamReader reader, PolicySet policySet, Intent mappedIntent) + throws ContributionReadException { + QName name = reader.getName(); + if (POLICY_INTENT_MAP_QNAME.equals(name)) { + + IntentMap intentMap = policyFactory.createIntentMap(); + QName intentName = getQName(reader, INTENT_MAP); + intentMap.setProvidedIntent(mappedIntent); + + policySet.getIntentMaps().add(intentMap); + + String qualifierName = null; + String qualfiedIntentName = null; + Intent qualifiedIntent = null; + + Qualifier qualifier = null; + + int event = reader.getEventType(); + try { + reader.next(); + while (reader.hasNext()) { + event = reader.getEventType(); + switch (event) { + case START_ELEMENT: { + name = reader.getName(); + if (POLICY_INTENT_MAP_QUALIFIER_QNAME.equals(name)) { + qualifierName = getString(reader, NAME); + if (qualifierName != null) { + qualfiedIntentName = + mappedIntent.getName().getLocalPart() + QUALIFIER + qualifierName; + qualifiedIntent = policyFactory.createIntent(); + qualifiedIntent.setName(new QName(mappedIntent.getName().getNamespaceURI(), + qualfiedIntentName)); + qualifier = policyFactory.createQualifier(); + qualifier.setIntent(qualifiedIntent); + intentMap.getQualifiers().add(qualifier); + + } else { + error("QualifierNameMissing", reader, policySet.getName()); + } + } else if (POLICY_INTENT_MAP_QNAME.equals(name)) { + QName providedIntent = getQName(reader, PROVIDES); + if (qualifierName.equals(providedIntent.getLocalPart())) { + readIntentMap(reader, policySet, qualifiedIntent); + } else { + error("IntentMapDoesNotMatch", + providedIntent, + providedIntent, + qualifierName, + policySet); + //throw new ContributionReadException("Intent provided by IntentMap " + + //providedIntent + " does not match parent qualifier " + qualifierName + + //" in policyset - " + policySet); + } + } else { + Object extension = extensionProcessor.read(reader); + if (extension != null && qualifier != null) { + PolicyExpression exp = policyFactory.createPolicyExpression(); + exp.setName(name); + exp.setPolicy(extension); + qualifier.getPolicies().add(exp); + } + } + break; + } + } + if (event == END_ELEMENT && POLICY_INTENT_MAP_QNAME.equals(reader.getName())) { + break; + } + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + } catch (XMLStreamException e) { + ContributionReadException ce = new ContributionReadException(e); + error("ContributionReadException", reader, ce); + throw ce; + } + } + } + + public void write(PolicySet policySet, XMLStreamWriter writer) throws ContributionWriteException, + XMLStreamException { + + // Write an <sca:policySet> + writer.writeStartElement(SCA11_NS, POLICY_SET); + writer.writeNamespace(policySet.getName().getPrefix(), policySet.getName().getNamespaceURI()); + writer.writeAttribute(NAME, policySet.getName().getPrefix() + COLON + policySet.getName().getLocalPart()); + writer.writeAttribute(APPLIES_TO, policySet.getAppliesTo()); + writer.writeAttribute(ATTACH_TO, policySet.getAttachTo()); + + writeProvidedIntents(policySet, writer); + + writer.writeEndElement(); + } + + private void readProvidedIntents(PolicySet policySet, XMLStreamReader reader) { + String value = reader.getAttributeValue(null, PROVIDES); + if (value != null) { + List<Intent> providedIntents = policySet.getProvidedIntents(); + for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { + QName qname = getQNameValue(reader, tokens.nextToken()); + Intent intent = policyFactory.createIntent(); + intent.setName(qname); + providedIntents.add(intent); + } + } + } + + private void writeProvidedIntents(PolicySet policySet, XMLStreamWriter writer) throws XMLStreamException { + if (!policySet.getProvidedIntents().isEmpty()) { + StringBuffer sb = new StringBuffer(); + for (Intent providedIntents : policySet.getProvidedIntents()) { + sb.append(getQualifiedName(providedIntents.getName(), writer)); + sb.append(" "); + } + // Remove the last space + sb.deleteCharAt(sb.length() - 1); + writer.writeAttribute(PolicyConstants.PROVIDES, sb.toString()); + } + } + + private String getQualifiedName(QName name, XMLStreamWriter writer) throws XMLStreamException { + String local = name.getLocalPart(); + String prefix = writer.getPrefix(name.getNamespaceURI()); + if (prefix != null && prefix.length() > 0) { + return prefix + ':' + local; + } else { + return local; + } + } + + private void resolvePolicies(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException { + boolean unresolved = false; + if (policySet != null) { + for (Object o : policySet.getPolicies()) { + extensionProcessor.resolve(o, resolver); + /*if ( o instanceof Policy && ((Policy)o).isUnresolved() ) { + unresolved = true; + }*/ + } + policySet.setUnresolved(unresolved); + } + } + + public QName getArtifactType() { + return POLICY_SET_QNAME; + } + + public Class<PolicySet> getModelType() { + return PolicySet.class; + } + + private void resolveProvidedIntents(PolicySet policySet, ModelResolver resolver) + throws ContributionResolveException { + if (policySet != null) { + //resolve all provided intents + List<Intent> providedIntents = new ArrayList<Intent>(); + for (Intent providedIntent : policySet.getProvidedIntents()) { + if (providedIntent.isUnresolved()) { + Intent resolved = resolver.resolveModel(Intent.class, providedIntent); + if (!resolved.isUnresolved() || resolved != providedIntent) { + providedIntents.add(resolved); + } else { + error("ProvidedIntentNotFound", policySet, providedIntent, policySet); + return; + //throw new ContributionResolveException("Provided Intent - " + providedIntent + //+ " not found for PolicySet " + policySet); + } + } else { + providedIntents.add(providedIntent); + } + } + policySet.getProvidedIntents().clear(); + policySet.getProvidedIntents().addAll(providedIntents); + } + } + + private void resolveIntentsInMappedPolicies(PolicySet policySet, ModelResolver resolver) + throws ContributionResolveException { + for (IntentMap intentMap : policySet.getIntentMaps()) { + Intent intent = intentMap.getProvidedIntent(); + if (intent.isUnresolved()) { + Intent resolved = resolver.resolveModel(Intent.class, intent); + if (!resolved.isUnresolved() || resolved != intent) { + intentMap.setProvidedIntent(resolved); + } else { + error("MappedIntentNotFound", policySet, intent, policySet); + return; + //throw new ContributionResolveException("Mapped Intent - " + mappedIntent + //+ " not found for PolicySet " + policySet); + } + } + for (Qualifier qualifier : intentMap.getQualifiers()) { + intent = qualifier.getIntent(); + if (intent.isUnresolved()) { + Intent resolved = resolver.resolveModel(Intent.class, intent); + if (!resolved.isUnresolved() || resolved != intent) { + qualifier.setIntent(resolved); + } else { + error("MappedIntentNotFound", policySet, intent, policySet); + return; + //throw new ContributionResolveException("Mapped Intent - " + mappedIntent + //+ " not found for PolicySet " + policySet); + } + } + for (PolicyExpression exp : qualifier.getPolicies()) { + // FIXME: How to resolve the policies? + } + } + } + + } + + private void resolveReferredPolicySets(PolicySet policySet, ModelResolver resolver) + throws ContributionResolveException { + + List<PolicySet> referredPolicySets = new ArrayList<PolicySet>(); + for (PolicySet referredPolicySet : policySet.getReferencedPolicySets()) { + if (referredPolicySet.isUnresolved()) { + PolicySet resolved = resolver.resolveModel(PolicySet.class, referredPolicySet); + if (!resolved.isUnresolved() || resolved != referredPolicySet) { + referredPolicySets.add(resolved); + } else { + error("ReferredPolicySetNotFound", policySet, referredPolicySet, policySet); + return; + //throw new ContributionResolveException("Referred PolicySet - " + referredPolicySet + //+ "not found for PolicySet - " + policySet); + } + } else { + referredPolicySets.add(referredPolicySet); + } + } + policySet.getReferencedPolicySets().clear(); + policySet.getReferencedPolicySets().addAll(referredPolicySets); + } + + private void includeReferredPolicySets(PolicySet policySet, PolicySet referredPolicySet) { + for (PolicySet furtherReferredPolicySet : referredPolicySet.getReferencedPolicySets()) { + includeReferredPolicySets(referredPolicySet, furtherReferredPolicySet); + } + policySet.getPolicies().addAll(referredPolicySet.getPolicies()); + policySet.getIntentMaps().addAll(referredPolicySet.getIntentMaps()); + } + + public void resolve(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException { + resolveProvidedIntents(policySet, resolver); + resolveIntentsInMappedPolicies(policySet, resolver); + resolveReferredPolicySets(policySet, resolver); + + for (PolicySet referredPolicySet : policySet.getReferencedPolicySets()) { + includeReferredPolicySets(policySet, referredPolicySet); + } + + if (policySet.isUnresolved()) { + //resolve the policy attachments + resolvePolicies(policySet, resolver); + + /*if ( !policySet.isUnresolved() ) { + resolver.addModel(policySet); + }*/ + } + + policySet.setUnresolved(false); + } +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java new file mode 100644 index 0000000000..1b6d64e4f7 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java @@ -0,0 +1,127 @@ +/* + * 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.policy.xml; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; +import javax.xml.xpath.XPathFunction; +import javax.xml.xpath.XPathFunctionException; + +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * The SCA-defined XPath function + */ +public class PolicyXPathFunction implements XPathFunction { + private static Logger logger = Logger.getLogger(PolicyXPathFunction.class.getName()); + + static final QName InterfaceRef = new QName(PolicyConstants.SCA11_NS, "InterfaceRef"); + static final QName OperationRef = new QName(PolicyConstants.SCA11_NS, "OperationRef"); + static final QName MessageRef = new QName(PolicyConstants.SCA11_NS, "MessageRef"); + static final QName IntentRefs = new QName(PolicyConstants.SCA11_NS, "IntentRefs"); + static final QName URIRef = new QName(PolicyConstants.SCA11_NS, "URIRef"); + + static final Set<QName> functions = + new HashSet<QName>(Arrays.asList(InterfaceRef, OperationRef, MessageRef, IntentRefs, URIRef)); + + private NamespaceContext namespaceContext; + private final QName functionName; + + public PolicyXPathFunction(NamespaceContext namespaceContext, QName functionName) { + super(); + this.namespaceContext = namespaceContext; + this.functionName = functionName; + } + + private Node getContextNode(List args) { + if (args.size() >= 2) { + NodeList nodeList = (NodeList)args.get(1); + if (nodeList.getLength() > 0) { + return nodeList.item(0); + } + } + return null; + } + + public Object evaluate(List args) throws XPathFunctionException { + if (logger.isLoggable(Level.FINE)) { + logger.fine(functionName + "(" + args + ")"); + } + + String arg = (String)args.get(0); + Node node = getContextNode(args); + if (InterfaceRef.equals(functionName)) { + return evaluateInterface(arg, node); + } else if (OperationRef.equals(functionName)) { + String[] params = arg.split("/"); + if (params.length != 2) { + throw new IllegalArgumentException("Invalid argument: " + arg); + } + String interfaceName = params[0]; + String operationName = params[1]; + return evaluateOperation(interfaceName, operationName, node); + } else if (MessageRef.equals(functionName)) { + String[] params = arg.split("/"); + if (params.length != 3) { + throw new IllegalArgumentException("Invalid argument: " + arg); + } + String interfaceName = params[0]; + String operationName = params[1]; + String messageName = params[2]; + return evaluateMessage(interfaceName, operationName, messageName, node); + } else if (URIRef.equals(functionName)) { + return evaluateURI(arg, node); + } else if (IntentRefs.equals(functionName)) { + String[] intents = arg.split("(\\s)+"); + return evaluateIntents(intents, node); + } else { + return Boolean.FALSE; + } + } + + private Boolean evaluateInterface(String interfaceName, Node node) { + return Boolean.FALSE; + } + + private Boolean evaluateOperation(String interfaceName, String operationName, Node node) { + return Boolean.FALSE; + } + + private Boolean evaluateMessage(String interfaceName, String operationName, String messageName, Node node) { + return Boolean.FALSE; + } + + private Boolean evaluateURI(String uri, Node node) { + return Boolean.FALSE; + } + + private Boolean evaluateIntents(String[] intents, Node node) { + return Boolean.FALSE; + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java new file mode 100644 index 0000000000..ca44667903 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java @@ -0,0 +1,72 @@ +/* + * 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.policy.xml; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; +import javax.xml.xpath.XPathFunction; +import javax.xml.xpath.XPathFunctionResolver; + +/** + * A resolver that handles SCA-defined XPath functions + * + * Interface Related Functions + * <ul> + * <li>InterfaceRef( InterfaceName ) + * <li>OperationRef( InterfaceName/OperationName ) + * <li>MessageRef( InterfaceName/OperationName/MessageName ) + * </ul> + * + * Intent Related Functions + * <ul> + * <li>IntentRefs( IntentList ) + * </ul> + * + * URI Based Function + * <ul> + * <li>URIRef( URI ) + * </ul> + */ +public class PolicyXPathFunctionResolver implements XPathFunctionResolver { + private NamespaceContext namespaceContext; + + public PolicyXPathFunctionResolver(NamespaceContext namespaceContext) { + super(); + this.namespaceContext = namespaceContext; + } + + public XPathFunction resolveFunction(QName functionName, int arity) { + if (functionName == null) { + throw new NullPointerException("Function name is null"); + } + if (PolicyXPathFunction.functions.contains(functionName)) { + if (arity >= 1) { + // We are relaxing the arity here so that we can pass in the context node + // by modifying the original xpath so that sca functions take self::node() + // as the 2nd argument + return new PolicyXPathFunction(namespaceContext, functionName); + } else { + throw new IllegalArgumentException("Invalid number of arguments: " + arity); + } + } + return null; + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..a64b22dc2a --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,22 @@ +# 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. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.policy.xml.BindingTypeProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200903#bindingType,model=org.apache.tuscany.sca.policy.BindingType +org.apache.tuscany.sca.policy.xml.ImplementationTypeProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200903#implementationType,model=org.apache.tuscany.sca.policy.ImplementationType +org.apache.tuscany.sca.policy.xml.IntentProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200903#intent,model=org.apache.tuscany.sca.policy.Intent +org.apache.tuscany.sca.policy.xml.PolicySetProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200903#policySet,model=org.apache.tuscany.sca.policy.PolicySet diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver new file mode 100644 index 0000000000..4daf46c790 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver @@ -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. + +org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver;model=org.apache.tuscany.sca.policy.Intent diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/resources/policy-xml-validation-messages.properties b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/resources/policy-xml-validation-messages.properties new file mode 100644 index 0000000000..d092b5959a --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/main/resources/policy-xml-validation-messages.properties @@ -0,0 +1,45 @@ +# +# +# 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. +# +# +ReferredPolicySetNotFound = Referred PolicySet - {0} not found for PolicySet - {1} +MappedIntentNotFound = Mapped Intent - {0} not found for PolicySet {1} +ProvidedIntentNotFound = Provided Intent - {0} not found for PolicySet {1} +UnableToMapPolicies = Unable to map policies for default qualifier in IntentMap for - {0} in policy set - {1} +IntentMapDoesNotMatch = Intent provided by IntentMap {0} does not match parent qualifier {1} in policyset - {2} +IntentNotSpecified = Intent Map provides for Intent not specified as provided by parent PolicySet - {0} +ContrainsAttributeMissing = Constrains attribute missing from Policy Intent Definition {0} +RequiredIntentNotFound = Required Intent - {0} not found for ProfileIntent {1} +QualifiableIntentNotFound = Qualifiable Intent - {0} not found for QualifiedIntent {1} +ErrorInPolicyIntentDefinition = Error in PolicyIntent Definition - {0} {1} +ExcludedIntentNotFound = Excluded Intent {0} not found for intent {1} +UnrecognizedIntentAttachPointType = Unrecognized IntentAttachPointType - {0} +RequiredAttributeMissing = Required attribute {0} missing from extension type definition +AlwaysProvidedIntentNotFound = Always Provided Intent - {0} not found for ExtensionType {1} +MayProvideIntentNotFound = May Provide Intent - {0} not found for ExtensionType {1} +ContributionReadException = ContributionReadException occurred due to: {0} +CyclicReferenceFound = Cyclic reference detected in required attributes of ProfileIntents {0} and {1} +IntentNameMissing = Required attribute "name" missing for Intent Definition +PolicySetReferenceNameMissing = Required attribute "name" missing for PolicySetReference in PolicySet : {0} +PolicySetNameMissing = Required attribute "name" missing for PolicySet Definition +PolicySetAppliesToMissing = Required attribute "appliesTo" missing for PolicySet Definition +IntentMapProvidesMissing = Required attribute "provides" missing for IntentMap in PolicySet : {0} +QualifierNameMissing = Required attribute "name" missing for qualifier definition in PolicySet : {0} +ConstrainedTypeNotFound = Unable to find the extension type {0} constrained by intent: {1} + diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java new file mode 100644 index 0000000000..e954f1ebe4 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java @@ -0,0 +1,132 @@ +/* + * 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.policy.xml; + +import java.util.Collections; +import java.util.Iterator; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathFactory; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; + +/** + * + */ +public class PolicyXPathFunctionResolverTestCase { + private static XPath xpath; + + /** + * @throws java.lang.Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + XPathFactory factory = XPathFactory.newInstance(); + xpath = factory.newXPath(); + xpath.setNamespaceContext(new NamespaceContextImpl()); + xpath.setXPathFunctionResolver(new PolicyXPathFunctionResolver(xpath.getNamespaceContext())); + } + + @Test + public void testIntentsRef() throws Exception { + InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite")); + // Test the rewrite of xpath so that the self:node() is passed into the SCA function + XPathExpression exp = xpath.compile("//sca:composite/sca:component[sca:IntentRefs('sca:confidentiality', self::node())]"); + Object result = exp.evaluate(xml, XPathConstants.NODESET); + Assert.assertTrue(result instanceof NodeList); + NodeList nodes = (NodeList)result; + // Assert.assertEquals(1, nodes.getLength()); + } + + @Test + public void testURIRef() throws Exception { + InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite")); + XPathExpression exp = xpath.compile("sca:composite/sca:component[sca:URIRef('AddServiceComponent')]"); + Object result = exp.evaluate(xml, XPathConstants.NODESET); + Assert.assertTrue(result instanceof NodeList); + NodeList nodes = (NodeList)result; + // Assert.assertEquals(1, nodes.getLength()); + } + + @Test + public void testInterfaceRef() throws Exception { + InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite")); + XPathExpression exp = xpath.compile("//sca:composite/sca:component/sca:service[sca:InterfaceRef('AddService')]"); + Object result = exp.evaluate(xml, XPathConstants.NODESET); + Assert.assertTrue(result instanceof NodeList); + NodeList nodes = (NodeList)result; + // Assert.assertEquals(1, nodes.getLength()); + } + + @Test + public void testOperationRef() throws Exception { + InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite")); + XPathExpression exp = xpath.compile("//sca:composite/sca:component/sca:reference[sca:OperationRef('AddService/add')]"); + Object result = exp.evaluate(xml, XPathConstants.NODESET); + Assert.assertTrue(result instanceof NodeList); + NodeList nodes = (NodeList)result; + // Assert.assertEquals(1, nodes.getLength()); + } + + + /** + * @throws java.lang.Exception + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + private static class NamespaceContextImpl implements NamespaceContext { + + private static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; + + public String getNamespaceURI(String prefix) { + if ("sca".equals(prefix)) { + return SCA11_NS; + } else { + return null; + } + } + + public String getPrefix(String namespaceURI) { + if (SCA11_NS.equals(namespaceURI)) { + return "sca"; + } + return null; + } + + public Iterator getPrefixes(String namespaceURI) { + if (SCA11_NS.equals(namespaceURI)) { + return Collections.singleton("sca").iterator(); + } + return null; + } + + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java new file mode 100644 index 0000000000..0d0f945e43 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java @@ -0,0 +1,295 @@ +/* + * 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.policy.xml; + +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.monitor.DefaultMonitorFactory; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.policy.BindingType; +import org.apache.tuscany.sca.policy.ExtensionType; +import org.apache.tuscany.sca.policy.ImplementationType; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentMap; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.Qualifier; +import org.apache.tuscany.sca.policy.impl.ImplementationTypeImpl; +import org.junit.Before; +import org.junit.Test; + +/** + * Test reading SCA XML assembly documents. + * + * @version $Rev: 551296 $ $Date: 2007-06-28 01:18:35 +0530 (Thu, 28 Jun 2007) $ + */ +public class ReadDocumentTestCase { + + private ModelResolver resolver; + private StAXArtifactProcessor<Object> staxProcessor; + private Monitor monitor; + + private static final QName elementToProcess = + new QName("http://docs.oasis-open.org/ns/opencsa/sca/200903", "implementationType"); + + private Map<QName, Intent> intentTable = new Hashtable<QName, Intent>(); + private Map<QName, PolicySet> policySetTable = new Hashtable<QName, PolicySet>(); + private Map<QName, BindingType> bindingTypesTable = new Hashtable<QName, BindingType>(); + private Map<QName, ImplementationType> implTypesTable = new Hashtable<QName, ImplementationType>(); + private static final String scaNamespace = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; + private static final String namespace = "http://test"; + + private static final QName confidentiality = new QName(namespace, "confidentiality"); + private static final QName integrity = new QName(namespace, "integrity"); + private static final QName messageProtection = new QName(namespace, "messageProtection"); + private static final QName confidentiality_transport = new QName(namespace, "confidentiality.transport"); + private static final QName confidentiality_message = new QName(namespace, "confidentiality.message"); + private static final QName secureReliablePolicy = new QName(namespace, "SecureReliablePolicy"); + private static final QName secureMessagingPolicies = new QName(namespace, "SecureMessagingPolicies"); + private static final QName securityPolicy = new QName(namespace, "SecurityPolicy"); + private static final QName basicAuthMsgProtSecurity = new QName(namespace, "BasicAuthMsgProtSecurity"); + private static final QName wsBinding = new QName(scaNamespace, "binding.ws"); + private static final QName javaImpl = new QName(scaNamespace, "implementation.java"); + + @Before + public void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + resolver = new DefaultModelResolver(); + XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + // Create a monitor + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = new DefaultMonitorFactory(); + if (monitorFactory != null) { + monitor = monitorFactory.createMonitor(); + utilities.addUtility(monitorFactory); + } + StAXArtifactProcessorExtensionPoint staxProcessors = + extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, monitor); + staxProcessors.addArtifactProcessor(new TestPolicyProcessor()); + + URL url = getClass().getResource("test_definitions.xml"); + InputStream urlStream = url.openStream(); + XMLStreamReader reader = inputFactory.createXMLStreamReader(urlStream); + reader.next(); + + //position on the right element qname to get processed + while (reader.hasNext()) { + reader.next(); + int event = reader.getEventType(); + if (event == START_ELEMENT && reader.getName().equals(elementToProcess)) { + break; + } + } + while (true) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: { + Object artifact = staxProcessor.read(reader); + if (artifact instanceof PolicySet) { + PolicySet policySet = (PolicySet)artifact; + policySet.setName(new QName(namespace, policySet.getName().getLocalPart())); + policySetTable.put(policySet.getName(), policySet); + } else if (artifact instanceof Intent) { + Intent intent = (Intent)artifact; + intent.setName(new QName(namespace, intent.getName().getLocalPart())); + intentTable.put(intent.getName(), intent); + for (Intent i : intent.getQualifiedIntents()) { + i.setName(new QName(namespace, i.getName().getLocalPart())); + intentTable.put(i.getName(), i); + resolver.addModel(i); + } + } else if (artifact instanceof BindingType) { + BindingType bindingType = (BindingType)artifact; + bindingTypesTable.put(bindingType.getType(), bindingType); + } else if (artifact instanceof ImplementationTypeImpl) { + ImplementationType implType = (ImplementationType)artifact; + implTypesTable.put(implType.getType(), implType); + } + + if (artifact != null) { + resolver.addModel(artifact); + } + + break; + } + } + if (reader.hasNext()) { + reader.next(); + } else { + break; + } + } + urlStream.close(); + } + + @Test + public void testReadSCADefinitions() throws Exception { + assertNotNull(intentTable.get(confidentiality)); + assertNotNull(intentTable.get(messageProtection)); + assertNotNull(intentTable.get(confidentiality_transport)); + assertTrue(intentTable.get(confidentiality).getDescription().length() > 0); + + assertNotNull(policySetTable.get(secureReliablePolicy)); + assertTrue(policySetTable.get(secureReliablePolicy).getProvidedIntents().size() == 2); + assertTrue(policySetTable.get(secureReliablePolicy).getPolicies().size() == 2); + + assertNotNull(policySetTable.get(secureMessagingPolicies)); + assertEquals(2, policySetTable.get(secureMessagingPolicies).getIntentMaps().get(0).getQualifiers().get(0).getPolicies().size()); + + assertEquals(bindingTypesTable.size(), 1); + assertNotNull(bindingTypesTable.get(wsBinding)); + assertEquals(implTypesTable.size(), 1); + assertNotNull(implTypesTable.get(javaImpl)); + } + + private int getNumberOfQualifiedPolicies(PolicySet policySet) { + int count = 0; + for(IntentMap intentMap: policySet.getIntentMaps()) { + for(Qualifier q: intentMap.getQualifiers()) { + count += q.getPolicies().size(); + } + } + return count; + } + + @Test + public void testResolution() throws Exception { + assertTrue(!intentTable.get(messageProtection).getRequiredIntents().isEmpty()); + Intent profileIntent = intentTable.get(new QName(namespace, "messageProtection")); + assertNull(profileIntent.getRequiredIntents().get(0).getDescription()); + + QName confidentiality_transport = new QName(namespace, "confidentiality.transport"); + assertTrue(intentTable.get(confidentiality_transport) instanceof Intent); + Intent qualifiedIntent = (Intent)intentTable.get(new QName(namespace, "confidentiality.transport")); + assertNull(qualifiedIntent.getDescription()); + assertNotNull(qualifiedIntent.getQualifiableIntent().getDescription()); + + PolicySet secureReliablePolicySet = policySetTable.get(secureReliablePolicy); + PolicySet secureMessagingPolicySet = policySetTable.get(secureMessagingPolicies); + PolicySet securityPolicySet = policySetTable.get(securityPolicy); + + assertEquals(secureReliablePolicySet.getProvidedIntents().get(1).getName(), integrity); + assertNull(secureReliablePolicySet.getProvidedIntents().get(1).getDescription()); + assertTrue(secureMessagingPolicySet.isUnresolved()); + assertEquals(2, getNumberOfQualifiedPolicies(securityPolicySet)); + + //testing to ensure that inclusion of referred policy sets has not happened + PolicySet basicAuthMsgProtSecurityPolicySet = policySetTable.get(basicAuthMsgProtSecurity); + assertTrue(basicAuthMsgProtSecurityPolicySet.getPolicies().isEmpty()); + assertTrue(basicAuthMsgProtSecurityPolicySet.getIntentMaps().isEmpty()); + + ExtensionType wsBindingType = bindingTypesTable.get(wsBinding); + assertNull(wsBindingType.getAlwaysProvidedIntents().get(0).getDescription()); + assertNull(wsBindingType.getMayProvidedIntents().get(0).getDescription()); + + ExtensionType javaImplType = implTypesTable.get(javaImpl); + assertNull(javaImplType.getAlwaysProvidedIntents().get(0).getDescription()); + assertNull(javaImplType.getMayProvidedIntents().get(0).getDescription()); + + List<Intent> intents = new ArrayList<Intent>(intentTable.values()); + + for (Intent intent : intents) { + staxProcessor.resolve(intent, resolver); + } + + for (PolicySet policySet : policySetTable.values()) { + if (policySet.getReferencedPolicySets().isEmpty()) + staxProcessor.resolve(policySet, resolver); + } + + for (PolicySet policySet : policySetTable.values()) { + if (!policySet.getReferencedPolicySets().isEmpty()) + staxProcessor.resolve(policySet, resolver); + } + + for (ExtensionType bindingType : bindingTypesTable.values()) { + staxProcessor.resolve(bindingType, resolver); + } + + for (ExtensionType implType : implTypesTable.values()) { + staxProcessor.resolve(implType, resolver); + } + + //testing if policy intents have been linked have property been linked up + assertNotNull(profileIntent.getRequiredIntents().get(0).getDescription()); + assertNotNull(qualifiedIntent.getQualifiableIntent().getDescription()); + assertEquals(secureReliablePolicySet.getProvidedIntents().get(1).getName(), integrity); + assertNotNull(secureReliablePolicySet.getProvidedIntents().get(1).getDescription()); + + //testing if policysets have been properly linked up with intents + assertFalse(secureMessagingPolicySet.isUnresolved()); + assertTrue(isRealizedBy(secureMessagingPolicySet, intentTable.get(confidentiality))); + assertTrue(isRealizedBy(secureMessagingPolicySet, intentTable.get(confidentiality_transport))); + + //testing if intent maps have been properly mapped to policies + assertFalse(securityPolicySet.isUnresolved()); + assertTrue(isRealizedBy(securityPolicySet, intentTable.get(confidentiality))); + assertTrue(isRealizedBy(securityPolicySet, intentTable.get(confidentiality_message))); + + //testing for inclusion of referred policysets + assertFalse(basicAuthMsgProtSecurityPolicySet.getPolicies().isEmpty()); + assertFalse(basicAuthMsgProtSecurityPolicySet.getIntentMaps().isEmpty()); + assertTrue(isRealizedBy(basicAuthMsgProtSecurityPolicySet, intentTable.get(confidentiality_transport))); + + assertNotNull(wsBindingType.getAlwaysProvidedIntents().get(0).getDescription()); + assertNotNull(wsBindingType.getMayProvidedIntents().get(0).getDescription()); + + assertNotNull(javaImplType.getAlwaysProvidedIntents().get(0).getDescription()); + assertNotNull(javaImplType.getMayProvidedIntents().get(0).getDescription()); + } + + private boolean isRealizedBy(PolicySet policySet, Intent intent) { + if (intent.getName().getLocalPart().indexOf('.') == -1) { + return policySet.getProvidedIntents().contains(intent); + } + for (IntentMap map : policySet.getIntentMaps()) { + for (Qualifier q : map.getQualifiers()) { + if (q.getIntent().equals(intent)) { + return true; + } + } + } + return false; + } +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/TestPolicyProcessor.java b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/TestPolicyProcessor.java new file mode 100644 index 0000000000..6887cd1b42 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/TestPolicyProcessor.java @@ -0,0 +1,82 @@ +/*
+ * 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.policy.xml;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.policy.PolicyExpression;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestPolicyProcessor implements StAXArtifactProcessor<PolicyExpression> {
+
+ public QName getArtifactType() {
+ return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment");
+ }
+
+ public PolicyExpression read(XMLStreamReader arg0) throws ContributionReadException, XMLStreamException {
+ return new MockPolicyImplOne();
+ }
+
+ public void write(PolicyExpression arg0, XMLStreamWriter arg1) throws ContributionWriteException, XMLStreamException {
+ }
+
+ public Class<PolicyExpression> getModelType() {
+ // TODO Auto-generated method stub
+ return PolicyExpression.class;
+ }
+
+ public void resolve(PolicyExpression arg0, ModelResolver arg1) throws ContributionResolveException {
+
+ }
+
+ public class MockPolicyImplOne implements PolicyExpression {
+ public <T> T getPolicy() {
+ return null;
+ }
+
+ public void setName(QName name) {
+ }
+
+ public <T> void setPolicy(T policy) {
+ }
+
+ public QName getName() {
+ return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment");
+ }
+
+ public boolean isUnresolved() {
+ return false;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ }
+
+ }
+}
diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/Calculator.composite b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/Calculator.composite new file mode 100644 index 0000000000..3ade69523c --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/Calculator.composite @@ -0,0 +1,49 @@ +<?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://docs.oasis-open.org/ns/opencsa/sca/200903"
+ targetNamespace="http://sample"
+ xmlns:sample="http://sample"
+ name="Calculator">
+
+ <component name="CalculatorServiceComponent" requires="sca:confidentiality">
+ <implementation.java class="calculator.CalculatorServiceImpl"/>
+ <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"/>
+ </component>
+
+ <component name="SubtractServiceComponent">
+ <implementation.java class="calculator.SubtractServiceImpl"/>
+ </component>
+
+ <component name="MultiplyServiceComponent">
+ <implementation.java class="calculator.MultiplyServiceImpl"/>
+ </component>
+
+ <component name="DivideServiceComponent">
+ <implementation.java class="calculator.DivideServiceImpl"/>
+ </component>
+
+</composite>
diff --git a/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/test_definitions.xml b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/test_definitions.xml new file mode 100644 index 0000000000..911833550f --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/test_definitions.xml @@ -0,0 +1,203 @@ +<?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://docs.oasis-open.org/ns/opencsa/sca/200903" targetNamespace="http://test"
+ xmlns:test="http://test" xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200903">
+
+ <!-- Extension Types Metadata -->
+ <implementationType type="sca:implementation.java" alwaysProvides="test:logging" mayProvide="test:tracing" />
+ <bindingType type="sca:binding.ws" alwaysProvides="test:confidentiality" mayProvide="test:integrity" />
+
+ <!-- Intents and Policysets to assume targetnamespace -->
+ <intent name="TestIntentOne" constrains="sca:binding">
+ <description>
+ Test Intent
+ </description>
+ </intent>
+
+ <intent name="TestIntentTwo" constrains="sca:binding" requires="test:TestIntentOne">
+ <description>
+ Protect messages from unauthorized reading or modification
+ </description>
+ </intent>
+
+ <policySet name="TestPolicySetOne" provides="test:TestIntentOne" appliesTo="sca:binding.ws"
+ xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for
+ "basic authentication" -->
+ </wsp:PolicyAttachment>
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for
+ "reliability" -->
+ </wsp:PolicyAttachment>
+ </policySet>
+
+ <!-- POLICY SETS -->
+ <policySet name="SecureReliablePolicy" provides="test:confidentiality.transport test:integrity" appliesTo="sca:binding.ws"
+ xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for
+ "basic authentication" -->
+ </wsp:PolicyAttachment>
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for
+ "reliability" -->
+ </wsp:PolicyAttachment>
+ </policySet>
+
+ <policySet name="SecureMessagingPolicies" provides="test:confidentiality" appliesTo="binding.ws"
+ xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <intentMap provides="test:confidentiality" default="transport">
+ <qualifier name="transport">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for "transport" alternative -->
+ </wsp:PolicyAttachment>
+ <wsp:PolicyAttachment>...</wsp:PolicyAttachment>
+ </qualifier>
+ <qualifier name="message">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for "message" alternative" -->
+ </wsp:PolicyAttachment>
+ </qualifier>
+ </intentMap>
+ </policySet>
+
+ <policySet name="SecurityPolicy" provides="test:confidentiality" appliesTo="binding.ws"
+ xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <intentMap provides="test:confidentiality" default="message">
+ <qualifier name="message">
+ <wsp:PolicyAttachment>
+ <!-- policy attachment for body encryption -->
+ </wsp:PolicyAttachment>
+ </qualifier>
+ <qualifier name="transport">
+ <wsp:PolicyAttachment>
+ <!-- policy attachment for transport encryption -->
+ </wsp:PolicyAttachment>
+ </qualifier>
+ </intentMap>
+ </policySet>
+
+ <policySet name="BasicAuthMsgProtSecurity" provides="test:authentication test:confidentiality" appliesTo="binding.ws"
+ xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903">
+ <policySetReference name="test:AuthenticationPolicies" />
+ <policySetReference name="test:ConfidentialityPolicies" />
+ </policySet>
+
+ <policySet name="AuthenticationPolicies" provides="test:authentication" appliesTo="binding.ws"
+ xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for "basic
+ authentication" -->
+ </wsp:PolicyAttachment>
+ </policySet>
+
+ <policySet name="ConfidentialityPolicies" provides="test:confidentiality" appliesTo="binding.ws"
+ xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <intentMap provides="test:confidentiality" default="transport">
+ <qualifier name="transport">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for "transport"
+ alternative -->
+ </wsp:PolicyAttachment>
+ <wsp:PolicyAttachment>...</wsp:PolicyAttachment>
+ </qualifier>
+ <qualifier name="message">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for "message"
+ alternative" -->
+ ...
+ </wsp:PolicyAttachment>
+ </qualifier>
+ </intentMap>
+ </policySet>
+
+ <policySet name="SecureWSPolicy" provides="test:confidentiality" appliesTo="sca:binding.ws"
+ xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" xmlns:sp="http://schemas.xmlsoap.org/ws/2002/12/secext"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <wsp:Policy>
+ <wsp:ExactlyOne>
+ <wsp:All>
+ <sp:SecurityToken>
+ <sp:TokenType>sp:X509v3</sp:TokenType>
+ </sp:SecurityToken>
+ <sp:UsernameToken />
+ <sp:SignedParts />
+ <sp:EncryptedParts>
+ <sp:Body />
+ </sp:EncryptedParts>
+ <sp:TransportBinding>
+ <sp:IncludeTimeStamp />
+ </sp:TransportBinding>
+ </wsp:All>
+ </wsp:ExactlyOne>
+ </wsp:Policy>
+ </policySet>
+
+ <!-- profile intent -->
+ <intent name="reliableMessageProtection" constrains="sca:binding" requires="test:messageProtection">
+ <description>
+ Protect messages from unauthorized reading or modification
+ </description>
+ </intent>
+
+ <intent name="messageProtection" constrains="sca:binding" requires="test:confidentiality test:integrity">
+ <description>
+ Protect messages from unauthorized reading or modification
+ </description>
+ </intent>
+
+ <!-- simple intent -->
+ <intent name="confidentiality" constrains="sca:binding">
+ <description>
+ Communitcation thro this binding must prevent
+ unauthorized users from reading the messages.
+ </description>
+ <qualifier name="transport" />
+ <qualifier name="message" default="true" />
+ </intent>
+
+ <intent name="integrity" constrains="sca:binding">
+ <description>
+ Communitcation thro this binding must prevent
+ unauthorized modification of the messages.
+ </description>
+ </intent>
+
+ <intent name="authentication" constrains="sca:binding">
+ <description>
+ Communitcation thro this binding required
+ Authentication.
+ </description>
+ </intent>
+
+ <intent name="logging" constrains="sca:implementation">
+ <description>
+ All messages to and from this implementation must be logged
+ </description>
+ </intent>
+
+ <intent name="tracing" constrains="sca:implementation.java">
+ <description>
+ Need to figure out some description for this
+ </description>
+ </intent>
+
+</definitions>
\ No newline at end of file diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/LICENSE b/sandbox/ant/sca/branches/tb7/modules/policy/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. + + + diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/META-INF/MANIFEST.MF b/sandbox/ant/sca/branches/tb7/modules/policy/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..ce038e7d05 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/META-INF/MANIFEST.MF @@ -0,0 +1,32 @@ +Manifest-Version: 1.0
+Export-Package: org.apache.tuscany.sca.policy.util;uses:="javax.xml.pa
+ rsers,javax.xml.transform.dom,org.apache.tuscany.sca.policy,org.apach
+ e.tuscany.sca.extensibility,org.w3c.dom,javax.xml.namespace,javax.xml
+ .xpath,javax.xml.transform,javax.xml.transform.stream";version="2.0.0",
+ org.apache.tuscany.sca.policy.impl;uses:="javax.xml.xpath,org.apache.
+ tuscany.sca.policy,javax.xml.namespace";version="2.0.0",org.apache.tusc
+ any.sca.policy;uses:="javax.xml.xpath,org.apache.tuscany.sca.policy.i
+ mpl,javax.xml.namespace";version="2.0.0"
+Tool: Bnd-0.0.255
+Bundle-Name: Apache Tuscany SCA Policy Model
+Created-By: 1.6.0_07 (Sun Microsystems Inc.)
+Bundle-Vendor: The Apache Software Foundation
+Bundle-Version: 2.0.0
+Bnd-LastModified: 1225397083703
+Bundle-ManifestVersion: 2
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Bundle-Description: Apache Tuscany SCA Policy Model
+Import-Package: javax.xml.namespace,
+ javax.xml.parsers,
+ javax.xml.transform,
+ javax.xml.transform.dom,
+ javax.xml.transform.stream,
+ javax.xml.xpath,
+ org.apache.tuscany.sca.extensibility;version="2.0.0",
+ org.apache.tuscany.sca.policy;version="2.0.0",
+ org.apache.tuscany.sca.policy.impl;version="2.0.0",
+ org.apache.tuscany.sca.policy.util;version="2.0.0",
+ org.w3c.dom
+Bundle-SymbolicName: org.apache.tuscany.sca.policy
+Bundle-DocURL: http://www.apache.org/
+
diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/NOTICE b/sandbox/ant/sca/branches/tb7/modules/policy/NOTICE new file mode 100644 index 0000000000..25bb89c9b2 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/pom.xml b/sandbox/ant/sca/branches/tb7/modules/policy/pom.xml new file mode 100644 index 0000000000..893193bf15 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/pom.xml @@ -0,0 +1,39 @@ +<?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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-modules</artifactId> + <version>2.0-TB3-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>tuscany-policy</artifactId> + <name>Apache Tuscany SCA Policy Model</name> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-extensibility</artifactId> + <version>2.0-TB3-SNAPSHOT</version> + </dependency> + </dependencies> + +</project> diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/BindingType.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/BindingType.java new file mode 100644 index 0000000000..f43c428563 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/BindingType.java @@ -0,0 +1,27 @@ +/* + * 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.policy; + + +/** + * Definition of binding type which extends from sca:binding + */ +public interface BindingType extends ExtensionType { +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/DefaultPolicyFactory.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/DefaultPolicyFactory.java new file mode 100644 index 0000000000..2da41675a1 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/DefaultPolicyFactory.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.policy; + +import org.apache.tuscany.sca.policy.impl.PolicyFactoryImpl; + +/** + * A factory for the policy model. + * + * @version $Rev$ $Date$ + */ +public class DefaultPolicyFactory extends PolicyFactoryImpl implements PolicyFactory { + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/ExtensionType.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/ExtensionType.java new file mode 100644 index 0000000000..e7a93c8907 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/ExtensionType.java @@ -0,0 +1,81 @@ +/* + * 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.policy; + +import java.util.List; + +import javax.xml.namespace.QName; + +/** + * Definition of extension type: binding or implementation + */ +public interface ExtensionType { + QName BINDING_BASE = new QName("http://docs.oasis-open.org/ns/opencsa/sca/200903", "binding"); + QName IMPLEMENTATION_BASE = new QName("http://docs.oasis-open.org/ns/opencsa/sca/200903", "implementation"); + + /** + * The name of the extension type (binding or implementation). The extension type name + * attribute MUST be the QName of an XSD global element definition used for + * binding/implementation elements of that type + * + * @return The QName of this type + */ + QName getType(); + + /** + * Set the QName for this type + * @param type The QName of this type + */ + void setType(QName type); + + QName getBaseType(); + + /** + * A set of intents. The intents in the alwaysProvides set are always + * provided by this extension type, whether the intents are attached + * to the using component or not. + * + * @return A list of intents that are always provided by this type + */ + List<Intent> getAlwaysProvidedIntents(); + + /** + * a set of intents. The intents in the mayProvide set are provided by this + * extension type if the intent in question is attached to the using + * component. + * + * @return A list of intents that may be provided by this type + */ + List<Intent> getMayProvidedIntents(); + /** + * Returns true if the model element is unresolved. + * + * @return true if the model element is unresolved. + */ + boolean isUnresolved(); + + /** + * Sets whether the model element is unresolved. + * + * @param unresolved whether the model element is unresolved + */ + void setUnresolved(boolean unresolved); + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/ImplementationType.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/ImplementationType.java new file mode 100644 index 0000000000..d142015f57 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/ImplementationType.java @@ -0,0 +1,27 @@ +/* + * 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.policy; + + +/** + * Definition of an implementation type which extends from sca:implementation + */ +public interface ImplementationType extends ExtensionType { +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Intent.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Intent.java new file mode 100644 index 0000000000..b79ccdab78 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Intent.java @@ -0,0 +1,160 @@ +/* + * 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.policy; + +import java.util.List; + +import javax.xml.namespace.QName; + +/** + * Represents a policy intent. See the Policy Framework specification for a + * description of this element. + * + * @version $Rev$ $Date$ + */ +public interface Intent { + enum Type { + interaction, implementation + }; + + /** + * Returns the intent name. + * + * @return the intent name + */ + QName getName(); + + /** + * Sets the intent name + * + * @param name the intent name + */ + void setName(QName name); + + /** + * Returns the list of SCA constructs that this intent is meant to + * configure. + * + * @return the list of SCA constructs that this intent is meant to configure + */ + List<ExtensionType> getConstrainedTypes(); + + /** + * Return a list of required intents + * @return The list of required intents + */ + List<Intent> getRequiredIntents(); + + /** + * Returns the list of intents which are mutually exclusive with this intent. + * + * @return the list of mutually exclusive intents. + */ + List<Intent> getExcludedIntents(); + + /** + * Returns the list of qualified intents. + * + * @return the list of qualified intents. + */ + List<Intent> getQualifiedIntents(); + + /** + * Get the default qualified intent + * + * @return + */ + Intent getDefaultQualifiedIntent(); + + /** + * Set the default qualified intent + * + * @param qualifiedIntent + */ + void setDefaultQualifiedIntent(Intent qualifiedIntent); + + /** + * Get the intent type: Interaction or Implementation + * @return + */ + Type getType(); + + /** + * Set the intent type + * @param type: Interaction or Implementation + */ + void setType(Type type); + + /** + * If this attribute is present and has a value of true it indicates that + * the qualified intents defined for this intent are mutually exclusive + * + * @return + */ + boolean isMutuallyExclusive(); + + /** + * Set the value of mutuallyExclusive + * @param mutuallyExclusive + */ + void setMutuallyExclusive(boolean mutuallyExclusive); + + /** + * Returns the intent description. + * + * @return the intent description + */ + String getDescription(); + + /** + * Sets the intent description. + * + * @param description the intent description + */ + void setDescription(String description); + + /** + * Returns true if the model element is unresolved. + * + * @return true if the model element is unresolved. + */ + + /** + * Get the parent intent for a qualified intent. If an intent is not qualified, + * return null. + * @return The parent intent or null if this intent is not qualified + */ + Intent getQualifiableIntent(); + + /** + * Set the parent intent for a qualified intent + * @param intent + */ + void setQualifiableIntent(Intent intent); + + boolean isUnresolved(); + + /** + * Sets whether the model element is unresolved. + * + * @param unresolved whether the model element is unresolved + */ + void setUnresolved(boolean unresolved); + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentMap.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentMap.java new file mode 100644 index 0000000000..efed4bfdb1 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentMap.java @@ -0,0 +1,51 @@ +/* + * 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.policy; + +import java.util.List; + +import org.apache.tuscany.sca.policy.Intent; + + +/** + * Map policies to the qualified intents + */ +public interface IntentMap { + /** + * Returns the intent realized by this intent map. + * + * @return the intent realized by this intent map + */ + Intent getProvidedIntent(); + + /** + * Sets the intent realized by this intent map. + * + * @param providedIntent the intent realized by this intent map + */ + void setProvidedIntent(Intent providedIntent); + + /** + * Get a list of qualifiers + * + * @return A list of qualifiers + */ + List<Qualifier> getQualifiers(); +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicyAttachment.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicyAttachment.java new file mode 100644 index 0000000000..ee4f5b5236 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicyAttachment.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.policy; + +import java.util.List; + +/** + * Attach a policySet to a collection of policy subjects + */ +public interface PolicyAttachment { + PolicySet getPolicySet(); + void setPolicySet(PolicySet policySet); + List<PolicySubject> getPolicySubjects(); +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicyExpression.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicyExpression.java new file mode 100644 index 0000000000..a29f214f98 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicyExpression.java @@ -0,0 +1,65 @@ +/* + * 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.policy; + +import javax.xml.namespace.QName; + +/** + * Interface that will abstract various types of policy specifications + * and attachments for example WS-Policy + * + * @version $Rev$ $Date$ + */ +public interface PolicyExpression { + /** + * Get the QName of the policy expression + * @return the QName of the policy expression + */ + QName getName(); + + /** + * Set the QName of the policy expression + * @param name + */ + void setName(QName name); + + /** + * Get the policy definition in the type of the specific domain + * @return + */ + <T> T getPolicy(); + + /** + * Set the policy definition + * @param expression + */ + <T> void setPolicy(T policy); + + /** + * + * @param unresolved + */ + void setUnresolved(boolean unresolved); + + /** + * + * @return + */ + boolean isUnresolved(); +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicyFactory.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicyFactory.java new file mode 100644 index 0000000000..9e7de2f6da --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicyFactory.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.policy; + +/** + * A factory for the policy model. + * + * @version $Rev$ $Date$ + */ +public interface PolicyFactory { + + /** + * Create a new intent. + * + * @return a new intent + */ + Intent createIntent(); + + /** + * Create a new policy set. + * + * @return a new policy set + */ + PolicySet createPolicySet(); + + /** + * Create a new intent map. + * + * @return a new intent map + */ + IntentMap createIntentMap(); + + /** + * create a new Qualifier + * + * @return a Qualifier + */ + Qualifier createQualifier(); + + /** + * Create a new PolicyExpression + * @return + */ + PolicyExpression createPolicyExpression(); + + ExtensionType createExtensionType(); + BindingType createBindingType(); + ImplementationType createImplementationType(); + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySet.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySet.java new file mode 100644 index 0000000000..2b5b8458d5 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySet.java @@ -0,0 +1,146 @@ +/* + * 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.policy; + +import java.util.List; + +import javax.xml.namespace.QName; +import javax.xml.xpath.XPathExpression; + +/** + * Represents a policy set. See the Policy Framework specification for a + * description of this element. + * + * @version $Rev$ $Date$ + */ +public interface PolicySet { + + /** + * Returns the intent name. + * + * @return the intent name + */ + QName getName(); + + /** + * Sets the intent name + * + * @param name the intent name + */ + void setName(QName name); + + /** + * Returns the list of + * + * @return + */ + List<PolicySet> getReferencedPolicySets(); + + /** + * Returns the list of provided intents + * + * @return + */ + List<Intent> getProvidedIntents(); + + /** + * Returns the list of concrete policies, either WS-Policy policy + * attachments, policy references, or policies expressed in another policy + * language. + * + * @return the list of concrete policies + */ + List<PolicyExpression> getPolicies(); + + /** + * Returns true if the model element is unresolved. + * + * @return true if the model element is unresolved. + */ + boolean isUnresolved(); + + /** + * Sets whether the model element is unresolved. + * + * @param unresolved whether the model element is unresolved + */ + void setUnresolved(boolean unresolved); + + /** + * Returns the XPath expression that is to be used to evaluate + * if this PolicySet applies to specific policy subject + * + * @return the XPath expression + */ + String getAppliesTo(); + + /** + * Sets the XPath expression that is to be used to evaluate + * if this PolicySet applies to specific policy subject + * + */ + void setAppliesTo(String xpath); + + /** + * A string which is an XPath 1.0 expression identifying one or more + * elements (policy subject) in the Domain. It is used to declare which + * set of elements the policySet is actually attached to. + * + * @return The attachTo XPath + */ + String getAttachTo(); + + /** + * Set the attachTo XPath + * @param xpath + */ + void setAttachTo(String xpath); + + /** + * Get the resolved XPathExpression for attachTo + * @return + */ + XPathExpression getAttachToXPathExpression(); + + /** + * Set the resolved XPathExpression for attachTo + * @param expression + */ + void setAttachToXPathExpression(XPathExpression expression); + + /** + * Returns the policies / policy attachments provided thro intent maps + * + * @return + */ + List<IntentMap> getIntentMaps(); + + /** + * Get the XPath expression for the appliesTo attribute + * @return the XPath expression for the appliesTo attribute + */ + XPathExpression getAppliesToXPathExpression(); + + /** + * Set the XPath expression for the appliesTo attribute + * @param xpathExpression the XPath expression for the appliesTo attribute + */ + void setAppliesToXPathExpression(XPathExpression xpathExpression); + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySubject.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySubject.java new file mode 100644 index 0000000000..41847bad79 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySubject.java @@ -0,0 +1,56 @@ +/* + * 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.policy; + +import java.util.List; + +/** + * A policy subject is an entity in the assembly with which a policy can be + * associated. + * + * For example, a policy subject can be one of the following: + * <ul> + * <li>composite + * <li>component + * <li>implementation + * <li>service + * <li>reference + * <li>binding + * <li>interface + * </ul> + */ +public interface PolicySubject { + /** + * Get a list of required intents + * + * @return + */ + List<Intent> getRequiredIntents(); + + /** + * Get a list of attached policySets + * + * @return A list of policySets + */ + List<PolicySet> getPolicySets(); + + ExtensionType getType(); + void setType(ExtensionType type); +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Qualifier.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Qualifier.java new file mode 100644 index 0000000000..c1862283c7 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Qualifier.java @@ -0,0 +1,44 @@ +/* + * 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.policy; + +import java.util.List; + +/** + * A qualifier provides a list of policies for a qualified intent within the IntentMap + */ +public interface Qualifier { + /** + * Get the qualified intent for this qualifier + * @return The intent + */ + Intent getIntent(); + + /** + * Set the qualified intent for this qualifier + */ + void setIntent(Intent intent); + + /** + * Get the list of policies provided by this qualifier + * @return A list of policies + */ + List<PolicyExpression> getPolicies(); +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/BindingTypeImpl.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/BindingTypeImpl.java new file mode 100644 index 0000000000..53c6684d11 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/BindingTypeImpl.java @@ -0,0 +1,38 @@ +/*
+ * 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.policy.impl;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.policy.BindingType;
+
+/**
+ * Concrete implementation for a BindingType
+ *
+ * @version $Rev$ $Date$
+ */
+public class BindingTypeImpl extends ExtensionTypeImpl implements BindingType {
+ protected BindingTypeImpl() {
+ super();
+ }
+
+ public QName getBaseType() {
+ return BINDING_BASE;
+ }
+}
diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/ExtensionTypeImpl.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/ExtensionTypeImpl.java new file mode 100644 index 0000000000..97fbc19ced --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/ExtensionTypeImpl.java @@ -0,0 +1,97 @@ +/* + * 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.policy.impl; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.policy.ExtensionType; +import org.apache.tuscany.sca.policy.Intent; + +/** + * Concrete implementation for a BindingType + * + * @version $Rev$ $Date$ + */ +public class ExtensionTypeImpl implements ExtensionType { + + private List<Intent> alwaysProvides = new ArrayList<Intent>(); + private List<Intent> mayProvide = new ArrayList<Intent>(); + private QName typeName; + private boolean unResolved = true; + + protected ExtensionTypeImpl() { + + } + + public List<Intent> getAlwaysProvidedIntents() { + return alwaysProvides; + } + + public List<Intent> getMayProvidedIntents() { + return mayProvide; + } + + public QName getType() { + return typeName; + } + + public void setType(QName type) { + this.typeName = type; + } + + public boolean isUnresolved() { + return unResolved; + } + + public void setUnresolved(boolean unresolved) { + this.unResolved = unresolved; + } + + @Override + public int hashCode() { + return String.valueOf(getType()).hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else if (obj instanceof ExtensionTypeImpl) { + if (getType() != null) { + return getType().equals(((ExtensionTypeImpl)obj).getType()); + } else { + return ((ExtensionTypeImpl)obj).getType() == null; + } + } else { + return false; + } + } + + @Override + public String toString() { + return (this.typeName != null) ? getType().toString() : "null"; + } + + public QName getBaseType() { + return null; + } +}; diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/ImplementationTypeImpl.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/ImplementationTypeImpl.java new file mode 100644 index 0000000000..169ca29833 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/ImplementationTypeImpl.java @@ -0,0 +1,39 @@ +/*
+ * 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.policy.impl;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.policy.ImplementationType;
+
+/**
+ * Concrete implementation for a Implementation Type
+ *
+ * @version $Rev$ $Date$
+ */
+public class ImplementationTypeImpl extends ExtensionTypeImpl implements ImplementationType {
+ protected ImplementationTypeImpl() {
+ super();
+ }
+
+ public QName getBaseType() {
+ return IMPLEMENTATION_BASE;
+ }
+
+}
diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentImpl.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentImpl.java new file mode 100644 index 0000000000..27a77f3ba8 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentImpl.java @@ -0,0 +1,168 @@ +/* + * 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.policy.impl; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.policy.ExtensionType; +import org.apache.tuscany.sca.policy.Intent; + +/** + * Represents a policy intent. + * + * @version $Rev$ $Date$ + */ +public class IntentImpl implements Intent { + + private QName name; + private Type type; + private List<ExtensionType> constrainedTypes = new ArrayList<ExtensionType>(); + private String description; + private List<Intent> qualifiedIntents = new ArrayList<Intent>(); + private Intent defaultQualifiedIntent; + private Intent parent; + private List<Intent> requiredIntents = new ArrayList<Intent>(); + private List<Intent> excludedIntents = new ArrayList<Intent>(); + private boolean mutuallyExclusive; + private boolean unresolved = true; + + protected IntentImpl() { + } + + public QName getName() { + return name; + } + + public void setName(QName name) { + this.name = name; + } + + public List<ExtensionType> getConstrainedTypes() { + return constrainedTypes; + } + + public void setConstrainedTypes(List<ExtensionType> constrainedTypes) { + this.constrainedTypes = constrainedTypes; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Intent getQualifiableIntent() { + return parent; + } + + public void setQualifiableIntent(Intent parent) { + this.parent = parent; + } + + public List<Intent> getQualifiedIntents() { + return qualifiedIntents; + } + + public void setQualifiedIntents(List<Intent> qualifiedIntents) { + this.qualifiedIntents = qualifiedIntents; + } + + public List<Intent> getRequiredIntents() { + return requiredIntents; + } + + public void setRequiredIntents(List<Intent> requiredIntents) { + this.requiredIntents = requiredIntents; + } + + public List<Intent> getExcludedIntents() { + return excludedIntents; + } + + public void setExcludedIntents(List<Intent> excludedIntents) { + this.excludedIntents = excludedIntents; + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean unresolved) { + this.unresolved = unresolved; + } + + public Type getType() { + return type; + } + + public void setType(Type type) { + this.type = type; + } + + public boolean isMutuallyExclusive() { + return mutuallyExclusive; + } + + public void setMutuallyExclusive(boolean mutuallyExclusive) { + this.mutuallyExclusive = mutuallyExclusive; + } + + public Intent getDefaultQualifiedIntent() { + return defaultQualifiedIntent; + } + + public void setDefaultQualifiedIntent(Intent defaultQualifiedIntent) { + this.defaultQualifiedIntent = defaultQualifiedIntent; + } + + + @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; + IntentImpl other = (IntentImpl)obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + public String toString() { + return String.valueOf(name); + } +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentMapImpl.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentMapImpl.java new file mode 100644 index 0000000000..6e2941ff5c --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentMapImpl.java @@ -0,0 +1,61 @@ +/* + * 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.policy.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentMap; +import org.apache.tuscany.sca.policy.Qualifier; + +/** + * Represents an intent map. + * + * @version $Rev$ $Date$ + */ +public class IntentMapImpl implements IntentMap { + + private boolean unresolved; + private Intent providedIntent; + private List<Qualifier> qualifiers = new ArrayList<Qualifier>(); + + protected IntentMapImpl() { + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean unresolved) { + this.unresolved = unresolved; + } + + public Intent getProvidedIntent() { + return providedIntent; + } + + public void setProvidedIntent(Intent providedIntent) { + this.providedIntent = providedIntent; + } + + public List<Qualifier> getQualifiers() { + return qualifiers; + } +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyExpressionImpl.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyExpressionImpl.java new file mode 100644 index 0000000000..71e5eef6a7 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyExpressionImpl.java @@ -0,0 +1,86 @@ +/* + * 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.policy.impl; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.policy.PolicyExpression; + +public class PolicyExpressionImpl implements PolicyExpression { + private QName name; + private Object policy; + private boolean unresolved = true; + + protected PolicyExpressionImpl() { + } + + public QName getName() { + return name; + } + + public <T> T getPolicy() { + return (T)policy; + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setName(QName name) { + this.name = name; + } + + public <T> void setPolicy(T policy) { + this.policy = policy; + } + + public void setUnresolved(boolean unresolved) { + this.unresolved = unresolved; + } + + public String toString() { + return String.valueOf(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; + PolicyExpressionImpl other = (PolicyExpressionImpl)obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyFactoryImpl.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyFactoryImpl.java new file mode 100644 index 0000000000..c67ff1eab8 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyFactoryImpl.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.policy.impl; + +import org.apache.tuscany.sca.policy.BindingType; +import org.apache.tuscany.sca.policy.ExtensionType; +import org.apache.tuscany.sca.policy.ImplementationType; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentMap; +import org.apache.tuscany.sca.policy.PolicyExpression; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.Qualifier; + +/** + * A factory for the policy model. + * + * @version $Rev$ $Date$ + */ +public abstract class PolicyFactoryImpl implements PolicyFactory { + + public Intent createIntent() { + return new IntentImpl(); + } + + public PolicySet createPolicySet() { + return new PolicySetImpl(); + } + + public IntentMap createIntentMap() { + return new IntentMapImpl(); + } + + public Qualifier createQualifier() { + return new QualifierImpl(); + } + + public PolicyExpression createPolicyExpression() { + return new PolicyExpressionImpl(); + } + + public BindingType createBindingType() { + return new BindingTypeImpl(); + } + + public ImplementationType createImplementationType() { + return new ImplementationTypeImpl(); + } + + public ExtensionType createExtensionType() { + return new ExtensionTypeImpl(); + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicySetImpl.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicySetImpl.java new file mode 100644 index 0000000000..75d1229cd8 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicySetImpl.java @@ -0,0 +1,145 @@ +/* + * 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.policy.impl; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; +import javax.xml.xpath.XPathExpression; + +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentMap; +import org.apache.tuscany.sca.policy.PolicyExpression; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Represents a policy set. + * + * @version $Rev$ $Date$ + */ +public class PolicySetImpl implements PolicySet { + + private QName name; + private String appliesTo; + private String attachTo; + private List<Intent> providedIntents = new ArrayList<Intent>(); + private List<PolicySet> referencedPolicySets = new ArrayList<PolicySet>(); + private boolean unresolved = true; + + private XPathExpression appliesToXPathExpression; + private XPathExpression attachToXPathExpression; + + private List<IntentMap> intentMaps = new ArrayList<IntentMap>(); + private List<PolicyExpression> policies = new ArrayList<PolicyExpression>(); + + public QName getName() { + return name; + } + + public void setName(QName name) { + this.name = name; + } + + public String getAppliesTo() { + return appliesTo; + } + + public void setAppliesTo(String appliesTo) { + this.appliesTo = appliesTo; + } + + public String getAttachTo() { + return attachTo; + } + + public void setAttachTo(String attachTo) { + this.attachTo = attachTo; + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean unresolved) { + this.unresolved = unresolved; + } + + public XPathExpression getAppliesToXPathExpression() { + return appliesToXPathExpression; + } + + public void setAppliesToXPathExpression(XPathExpression appliesToXPathExpression) { + this.appliesToXPathExpression = appliesToXPathExpression; + } + + public XPathExpression getAttachToXPathExpression() { + return attachToXPathExpression; + } + + public void setAttachToXPathExpression(XPathExpression attachToXPathExpression) { + this.attachToXPathExpression = attachToXPathExpression; + } + + public List<IntentMap> getIntentMaps() { + return intentMaps; + } + + public List<Intent> getProvidedIntents() { + return providedIntents; + } + + public List<PolicySet> getReferencedPolicySets() { + return referencedPolicySets; + } + + public List<PolicyExpression> getPolicies() { + return policies; + } + + public String toString() { + return String.valueOf(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; + PolicySetImpl other = (PolicySetImpl)obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/QualifierImpl.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/QualifierImpl.java new file mode 100644 index 0000000000..102bea8d41 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/QualifierImpl.java @@ -0,0 +1,48 @@ +/* + * 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.policy.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicyExpression; +import org.apache.tuscany.sca.policy.Qualifier; + +public class QualifierImpl implements Qualifier { + private Intent intent; + private List<PolicyExpression> policies = new ArrayList<PolicyExpression>(); + + protected QualifierImpl() { + } + + public Intent getIntent() { + return intent; + } + + public List<PolicyExpression> getPolicies() { + return policies; + } + + public void setIntent(Intent intent) { + this.intent = intent; + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyComputationUtils.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyComputationUtils.java new file mode 100644 index 0000000000..fe61ce707c --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyComputationUtils.java @@ -0,0 +1,370 @@ +/* + * 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.policy.util; + +import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI; + +import java.io.InputStream; +import java.io.StringWriter; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; + +import org.apache.tuscany.sca.policy.ExtensionType; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * Utility methods used during computation of PolicyIntents and PolicySets sets + * + * @version $Rev$ $Date$ + */ +public class PolicyComputationUtils { + private static final String POLICYSET_PREFIX = "tp_"; + private static final String APPLICABLE_POLICYSET_ATTR_NS = "http://tuscany.apache.org/xmlns/sca/1.1"; + private static final String APPLICABLE_POLICYSET_ATTR = "applicablePolicySets"; + private static final String POLICY_SETS_ATTR = "policySets"; + private static final String APPLICABLE_POLICYSET_ATTR_PREFIX = "tuscany"; + private static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; + + /** + * This method unconditionally adds intents from the source list to the target list. + * It is used for intermediate intent inheritance between promotion levels + * (e.g. between a composite service and a component service). It does not check + * whether there are conflicting (mutually exclusive) intents. This is because + * promotion cannot override intents. If the resulting target list has conflicting + * intents, this will be detected later during policy computation. + */ + public static void addInheritedIntents(List<Intent> sourceList, List<Intent> targetList) { + if (sourceList != null) { + targetList.addAll(sourceList); + } + } + + public static void addInheritedPolicySets(List<PolicySet> sourceList, + List<PolicySet> targetList, + boolean checkOverrides) { + // check overrides is true when policysets are to be copied from + // componentType to component level + if (checkOverrides) { + // aggregate all the provided intents present in the target + List<Intent> targetProvidedIntents = new ArrayList<Intent>(); + for (PolicySet policySet : targetList) { + targetProvidedIntents.addAll(policySet.getProvidedIntents()); + } + + // for every policy set in the source check if it provides one of + // the intents that is + // already provided by the policysets in the destination and do not + // copy them. + for (PolicySet policySet : sourceList) { + for (Intent sourceProvidedIntent : policySet.getProvidedIntents()) { + if (!targetProvidedIntents.contains(sourceProvidedIntent)) { + targetList.add(policySet); + } + } + } + } else { + targetList.addAll(sourceList); + } + } + + /** + * This method is used to inherit intents and policy sets between hierarchical levels + * within the same composite (e.g. between a component and its services and references). + * In this case the source intents and policy sets provide defaults which are inherited + * into the target lists only when there is no conflict. For example consider a component + * with 3 references. The component level requires intent 'propagatesTransaction'. + * Reference 1 and 2 do not specify an intent, but reference 3 requires 'suspendsTransaction'. + * In this case the 'propagatesTransaction' intent is inherited by reference 1 and 2 + * but not by reference 3. + */ + public static void addDefaultPolicies(List<Intent> sourceIntents, + List<PolicySet> sourcePolicySets, + List<Intent> targetIntents, + List<PolicySet> targetPolicySets) { + // form a list of all intents required by the target + List<Intent> combinedTargetIntents = new ArrayList<Intent>(); + combinedTargetIntents.addAll(findAndExpandProfileIntents(targetIntents)); + for (PolicySet targetPolicySet : targetPolicySets) { + combinedTargetIntents.addAll(findAndExpandProfileIntents(targetPolicySet.getProvidedIntents())); + } + + // inherit intents in the source list that do not conflict with intents already in the target list + for (Intent sourceIntent : findAndExpandProfileIntents(sourceIntents)) { + boolean conflict = false; + for (Intent excluded : sourceIntent.getExcludedIntents()) { + if (combinedTargetIntents.contains(excluded)) { + conflict = true; + break; + } + } + if (!conflict) { + targetIntents.add(sourceIntent); + } + } + + // inherit policy sets in the source list that do not conflict with policy sets or intents + // in the target list + for (PolicySet sourcePolicySet : sourcePolicySets) { + boolean conflict = false; + List<Intent> providedIntents = findAndExpandProfileIntents(sourcePolicySet.getProvidedIntents()); + checkConflict: for (Intent intent : providedIntents) { + for (Intent excluded : intent.getExcludedIntents()) { + if (combinedTargetIntents.contains(excluded)) { + conflict = true; + break checkConflict; + } + } + } + if (!conflict) + targetPolicySets.add(sourcePolicySet); + } + + } + + public static void checkForMutuallyExclusiveIntents(List<Intent> intents, + List<PolicySet> policySets, + ExtensionType intentAttachPointType, + String id) throws PolicyValidationException { + // gather all intents (keeping track of where they come from) + Map<Intent, PolicySet> combinedIntents = new HashMap<Intent, PolicySet>(); + for (PolicySet policySet : policySets) { + for (Intent providedIntent : findAndExpandProfileIntents(policySet.getProvidedIntents())) { + combinedIntents.put(providedIntent, policySet); + } + } + for (Intent intent : intents) { + combinedIntents.put(intent, null); + } + + // check for conflicts + for (Intent intent : combinedIntents.keySet()) { + for (Intent excluded : intent.getExcludedIntents()) { + if (combinedIntents.keySet().contains(excluded)) { + String sIntent1, sIntent2; + if (combinedIntents.get(intent) == null) + sIntent1 = intent.getName().toString(); + else + sIntent1 = + intent.getName().toString() + " in policy set " + + combinedIntents.get(intent).getName().toString(); + if (combinedIntents.get(excluded) == null) + sIntent2 = excluded.getName().toString(); + else + sIntent2 = + excluded.getName().toString() + " in policy set " + + combinedIntents.get(excluded).getName().toString(); + throw new PolicyValidationException(intentAttachPointType.getType() + " for " + + id + + " uses mutually-exclusive intents " + + sIntent1 + + " and " + + sIntent2); + } + } + } + } + + public static void expandProfileIntents(List<Intent> intents) { + List<Intent> expandedIntents = null; + if (intents.size() > 0) { + expandedIntents = findAndExpandProfileIntents(intents); + intents.clear(); + intents.addAll(expandedIntents); + } + } + + public static List<Intent> findAndExpandProfileIntents(List<Intent> intents) { + List<Intent> expandedIntents = new ArrayList<Intent>(); + for (Intent intent : intents) { + if (!intent.getRequiredIntents().isEmpty()) { + List<Intent> requiredIntents = intent.getRequiredIntents(); + expandedIntents.addAll(findAndExpandProfileIntents(requiredIntents)); + } else { + expandedIntents.add(intent); + } + } + return expandedIntents; + } + + private static byte[] addApplicablePolicySets(Document doc, Collection<PolicySet> policySets) + throws XPathExpressionException, TransformerConfigurationException, TransformerException { + + for (PolicySet policySet : policySets) { + if (policySet.getAppliesTo() != null) { + addApplicablePolicySets(policySet, doc); + } + } + + StringWriter sw = new StringWriter(); + final Source domSource = new DOMSource(doc); + final Result finalResult = new StreamResult(sw); + final Transformer transformer = TransformerFactory.newInstance().newTransformer(); + // transformer.setOutputProperty("omit-xml-declaration", "yes"); + // Allow priviledged access to let transformers read property files. Requires + // PropertyPermission in security policy. + try { + AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { + public Object run() throws TransformerException { + transformer.transform(domSource, finalResult); + return null; + } + }); + } catch (PrivilegedActionException e) { + throw (TransformerException)e.getException(); + } + + return sw.toString().getBytes(); + } + + private static void addApplicablePolicySets(PolicySet policySet, Document doc) throws XPathExpressionException { + XPathExpression expression = policySet.getAppliesToXPathExpression(); + NodeList result = (NodeList)expression.evaluate(doc, XPathConstants.NODESET); + + if (result != null) { + for (int counter = 0; counter < result.getLength(); ++counter) { + Node aResultNode = result.item(counter); + + String applicablePolicySets = null; + + String policySetPrefix = declareNamespace((Element)aResultNode, policySet.getName().getNamespaceURI()); + String appPolicyAttrPrefix = declareNamespace((Element)aResultNode, APPLICABLE_POLICYSET_ATTR_NS); + if (aResultNode.getAttributes().getNamedItemNS(APPLICABLE_POLICYSET_ATTR_NS, APPLICABLE_POLICYSET_ATTR) != null) { + applicablePolicySets = + aResultNode.getAttributes().getNamedItemNS(APPLICABLE_POLICYSET_ATTR_NS, + APPLICABLE_POLICYSET_ATTR).getNodeValue(); + } + + if (applicablePolicySets != null && applicablePolicySets.length() > 0) { + applicablePolicySets = + applicablePolicySets + " " + policySetPrefix + ":" + policySet.getName().getLocalPart(); + } else { + applicablePolicySets = policySetPrefix + ":" + policySet.getName().getLocalPart(); + } + + ((Element)aResultNode).setAttributeNS(APPLICABLE_POLICYSET_ATTR_NS, appPolicyAttrPrefix + ":" + + APPLICABLE_POLICYSET_ATTR, applicablePolicySets); + } + } + } + + public static byte[] addApplicablePolicySets(InputStream is, + Collection<PolicySet> domainPolicySets, + DocumentBuilderFactory documentBuilderFactory) throws Exception { + documentBuilderFactory.setNamespaceAware(true); + DocumentBuilder db = documentBuilderFactory.newDocumentBuilder(); + Document doc = db.parse(is); + is.close(); + return addApplicablePolicySets(doc, domainPolicySets); + } + + private static class DOMNamespaceContext implements NamespaceContext { + private Node node; + + /** + * @param node + */ + public DOMNamespaceContext(Node node) { + super(); + this.node = node; + } + + public String getNamespaceURI(String prefix) { + return node.lookupNamespaceURI(prefix); + } + + public String getPrefix(String namespaceURI) { + return node.lookupPrefix(namespaceURI); + } + + public Iterator<?> getPrefixes(String namespaceURI) { + return null; + } + + } + + private static String declareNamespace(Element element, String ns) { + if (ns == null) { + ns = ""; + } + Node node = element; + String prefix = ""; + boolean declared = false; + while (node != null && node.getNodeType() == Node.ELEMENT_NODE) { + if (node.lookupPrefix(ns) != null) { + prefix = node.lookupPrefix(ns); + declared = true; + break; + } else { + /*NamedNodeMap attrs = node.getAttributes(); + if (attrs == null) { + break; + } + Node attr = attrs.getNamedItem(qname); + if (attr != null) { + declared = ns.equals(attr.getNodeValue()); + break; + }*/ + node = node.getParentNode(); + } + } + if (!declared) { + // Find an available prefix + for (int i = 1;; i++) { + prefix = POLICYSET_PREFIX + i; + if (element.lookupNamespaceURI(prefix) == null) { + break; + } + } + String qname = "xmlns:" + prefix; + org.w3c.dom.Attr attr = element.getOwnerDocument().createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, qname); + attr.setValue(ns); + element.setAttributeNodeNS(attr); + } + return prefix; + } + +} diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationException.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationException.java new file mode 100644 index 0000000000..eb97818042 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationException.java @@ -0,0 +1,38 @@ +/*
+ * 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.policy.util;
+
+/**
+ * Exception to be throw for invalid policy intents / policysets
+ *
+ * @version $Rev$ $Date$
+ */
+public class PolicyValidationException extends Exception {
+ private static final long serialVersionUID = 506979037642587755L;
+
+ public PolicyValidationException(String message) {
+ super(message);
+ }
+
+ public PolicyValidationException(Throwable e) {
+ super(e);
+ }
+
+}
diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationUtils.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationUtils.java new file mode 100644 index 0000000000..c8fe89f364 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationUtils.java @@ -0,0 +1,98 @@ +/*
+ * 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.policy.util;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.policy.ExtensionType;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.PolicySubject;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PolicyValidationUtils {
+
+ public static boolean isConstrained(ExtensionType constrained, ExtensionType attachPointType) {
+ return (attachPointType != null
+ && (attachPointType.equals(constrained)) || (attachPointType.getBaseType().equals(constrained)));
+ }
+
+ public static void validateIntents(PolicySubject attachPoint, ExtensionType attachPointType)
+ throws PolicyValidationException {
+ boolean found = false;
+ if (attachPointType != null) {
+ // validate intents specified against the parent (binding /
+ // implementation)
+ found = false;
+ for (Intent intent : attachPoint.getRequiredIntents()) {
+ if (!intent.isUnresolved()) {
+ for (ExtensionType constrained : intent.getConstrainedTypes()) {
+ if (isConstrained(constrained, attachPointType)) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ throw new PolicyValidationException("Policy Intent '" + intent.getName()
+ + "' does not constrain extension type "
+ + attachPointType.getType());
+ }
+ } else {
+ throw new PolicyValidationException("Policy Intent '" + intent.getName()
+ + "' is not defined in this domain ");
+ }
+ }
+ }
+ }
+
+ public static void validatePolicySets(PolicySubject subject) throws PolicyValidationException {
+ // validatePolicySets(subject, subject.getType(), subject.getAttachedPolicySets());
+ }
+
+ public static void validatePolicySets(PolicySubject subject, ExtensionType attachPointType)
+ throws PolicyValidationException {
+ validatePolicySets(subject, attachPointType, subject.getPolicySets());
+ }
+
+ public static void validatePolicySets(PolicySubject subject,
+ ExtensionType attachPointType,
+ List<PolicySet> applicablePolicySets) throws PolicyValidationException {
+ // Since the applicablePolicySets in a subject will already
+ // have the list of policysets that might ever be applicable to this attachPoint,
+ // just check if the defined policysets feature in the list of applicable
+ // policysets
+ for (PolicySet definedPolicySet : subject.getPolicySets()) {
+ if (!definedPolicySet.isUnresolved()) {
+ if (!applicablePolicySets.contains(definedPolicySet)) {
+ throw new PolicyValidationException("Policy Set '" + definedPolicySet.getName()
+ + "' does not apply to extension type "
+ + attachPointType.getType());
+ }
+ } else {
+ throw new PolicyValidationException("Policy Set '" + definedPolicySet.getName()
+ + "' is not defined in this domain ");
+
+ }
+ }
+ }
+}
diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.PolicyFactory b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.PolicyFactory new file mode 100644 index 0000000000..846b3b24a4 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.PolicyFactory @@ -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. + +org.apache.tuscany.sca.policy.DefaultPolicyFactory
\ No newline at end of file diff --git a/sandbox/ant/sca/branches/tb7/modules/policy/src/test/java/org/apache/tuscany/sca/policy/PolicyFactoryTestCase.java b/sandbox/ant/sca/branches/tb7/modules/policy/src/test/java/org/apache/tuscany/sca/policy/PolicyFactoryTestCase.java new file mode 100644 index 0000000000..2775c4ac71 --- /dev/null +++ b/sandbox/ant/sca/branches/tb7/modules/policy/src/test/java/org/apache/tuscany/sca/policy/PolicyFactoryTestCase.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.policy; + +import static org.junit.Assert.assertEquals; + +import javax.xml.namespace.QName; + +import org.junit.Before; +import org.junit.Test; + +/** + * Test building of policy model instances using the policy factory. + * + * @version $Rev$ $Date$ + */ +public class PolicyFactoryTestCase { + + PolicyFactory factory; + + @Before + public void setUp() throws Exception { + factory = new DefaultPolicyFactory(); + } + + @Test + public void testCreateIntent() { + Intent intent = factory.createIntent(); + intent.setName(new QName("http://test", "reliability")); + assertEquals(intent.getName(), new QName("http://test", "reliability")); + } + + @Test + public void testCreatePolicySet() { + PolicySet policySet = factory.createPolicySet(); + policySet.setName(new QName("http://test", "reliability")); + assertEquals(policySet.getName(), new QName("http://test", "reliability")); + } +} |