diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2011-10-19 14:03:07 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2011-10-19 14:03:07 +0000 |
commit | c79fbcb63cc5b097533f0d36b43e4c32782c71b1 (patch) | |
tree | 29f852f32a3660588ce49fcc642317ea8d7ba02a | |
parent | 7fc8467572a9691e152123f44c38076f08ec0bd4 (diff) |
Resolve operation policy and take account of it in base policy processor.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1186226 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
14 files changed, 101 insertions, 73 deletions
diff --git a/sca-java-2.x/trunk/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java b/sca-java-2.x/trunk/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java index 091b3c01d3..966c0ac275 100644 --- a/sca-java-2.x/trunk/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java +++ b/sca-java-2.x/trunk/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java @@ -81,6 +81,7 @@ import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.Problem; import org.apache.tuscany.sca.monitor.Problem.Severity; @@ -365,7 +366,7 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor { // Resolve the interface contract InterfaceContract interfaceContract = contract.getInterfaceContract(); if (interfaceContract != null) { - extensionProcessor.resolve(interfaceContract, resolver, context); + extensionProcessor.resolve(interfaceContract, resolver, context); } // Resolve bindings @@ -382,6 +383,32 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor { Binding binding = contract.getCallback().getBindings().get(i); extensionProcessor.resolve(binding, resolver, context); } + } + } + } + + /* + * Resolve policy that's been attached to interface operations + */ + protected <C extends Contract> void resolveContractOperationPolicy(List<C> contracts, ModelResolver resolver, ProcessorContext context){ + if (contracts != null){ + for (Contract contract : contracts) { + InterfaceContract interfaceContract = contract.getInterfaceContract(); + if (interfaceContract != null) { + + // Resolve any policy on the interface operations + if (interfaceContract.getInterface() != null){ + for (Operation op : interfaceContract.getInterface().getOperations()){ + policyProcessor.resolvePolicies(op, resolver, context); + } + } + + if (interfaceContract.getCallbackInterface() != null){ + for (Operation op : interfaceContract.getCallbackInterface().getOperations()){ + policyProcessor.resolvePolicies(op, resolver, context); + } + } + } } } } diff --git a/sca-java-2.x/trunk/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java b/sca-java-2.x/trunk/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java index 55a31e1bc0..55e4cc53ae 100644 --- a/sca-java-2.x/trunk/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java +++ b/sca-java-2.x/trunk/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java @@ -103,6 +103,7 @@ import org.apache.tuscany.sca.contribution.resolver.ResolverExtension; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.policy.ExtensionType; import org.apache.tuscany.sca.policy.Intent; @@ -1112,8 +1113,17 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt implementation.getPolicySets().addAll(policySets); } - implementation.getRequiredIntents().addAll(intents); - + implementation.getRequiredIntents().addAll(intents); + + // resolve any policy on implementation operations + for (Operation op : implementation.getOperations()){ + policyProcessor.resolvePolicies(op, resolver, context); + } + + // resolve any policy on interface operations + resolveContractOperationPolicy(implementation.getServices(), resolver, context); + resolveContractOperationPolicy(implementation.getReferences(), resolver, context); + component.setImplementation(implementation); } diff --git a/sca-java-2.x/trunk/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/sca-java-2.x/trunk/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver index f8e4d5bbd4..fdd8efffa2 100644 --- a/sca-java-2.x/trunk/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver +++ b/sca-java-2.x/trunk/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver @@ -18,4 +18,5 @@ org.apache.tuscany.sca.assembly.xml.CompositeModelResolver;model=org.apache.tuscany.sca.assembly.Composite
org.apache.tuscany.sca.assembly.xml.ComponentTypeModelResolver;model=org.apache.tuscany.sca.assembly.ComponentType
org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver;model=org.apache.tuscany.sca.policy.Intent
+org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver;model=org.apache.tuscany.sca.policy.PolicySet
diff --git a/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGenerator.java b/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGenerator.java index 516a62a556..b66ac4e370 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGenerator.java +++ b/sca-java-2.x/trunk/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGenerator.java @@ -41,6 +41,7 @@ import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; @@ -352,6 +353,18 @@ public class BindingWSDLGenerator { } catch (InvalidInterfaceException e) { throw new WSDLGenerationException(e); } + + // copy operation intents and policy sets from Java to WSDL interface + // in case we need to refer to them in later processing + for(Operation javaOperation : javaInterface.getOperations()){ + for(Operation wsdlOperation : wsdlInterface.getOperations()){ + if (wsdlOperation.getName().equals(javaOperation.getName())){ + wsdlOperation.getRequiredIntents().addAll(javaOperation.getRequiredIntents()); + wsdlOperation.getPolicySets().addAll(javaOperation.getPolicySets()); + break; + } + } + } return wsdlInterface; } diff --git a/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java b/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java index 1ba394dde9..301320fccd 100644 --- a/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java +++ b/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java @@ -23,6 +23,8 @@ import java.io.IOException; import java.lang.ref.WeakReference; import java.net.URL; import java.net.URLClassLoader; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; @@ -73,8 +75,9 @@ public class ClassLoaderModelResolver extends URLClassLoader implements ModelRes return urls.toArray(new URL[urls.size()]); } - public ClassLoaderModelResolver(final Contribution contribution, FactoryExtensionPoint modelFactories) throws IOException { + public ClassLoaderModelResolver(final Contribution contribution, FactoryExtensionPoint modelFactories) throws IOException { super(getContributionURLs(contribution), parentClassLoader(contribution)); + this.contribution = new WeakReference<Contribution>(contribution); // Index Java import resolvers by package name Map<String, List<ModelResolver>> resolverMap = new HashMap<String, List<ModelResolver>>(); diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BasePolicyProvider.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BasePolicyProvider.java index ab1b33ac3c..ba6d6f5df0 100644 --- a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BasePolicyProvider.java +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BasePolicyProvider.java @@ -69,10 +69,38 @@ public abstract class BasePolicyProvider<T> implements PolicyProvider { return findPolicies(applicablePolicySets); } + /* + * return policies for the service as a whole not including + * operation specific policies + */ protected List<T> findPolicies() { return findPolicies(subject.getPolicySets()); } + /* + * return policies for the service as a whole including + * operation specific policies + */ + protected List<T> findPolicies(Operation operation) { + // collect together all the candidate policy sets + List<PolicySet> policySets = new ArrayList<PolicySet>(); + // add endpoint or endpoint reference policy sets + policySets.addAll(subject.getPolicySets()); + // add interface operation policy sets + policySets.addAll(operation.getPolicySets()); + // add implementation operation policy sets + if (subject instanceof Endpoint){ + for(Operation op :((Endpoint)subject).getComponent().getImplementation().getOperations()){ + if (op.getName().equals(operation.getName())){ + policySets.addAll(op.getPolicySets()); + break; + } + } + } + + return findPolicies(policySets); + } + private List<T> findPolicies(List<PolicySet> policySets) { List<T> policies = new ArrayList<T>(); diff --git a/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java index 67eb9bd047..a2ea5e306e 100644 --- a/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java +++ b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java @@ -98,12 +98,20 @@ class BPELImplementationImpl extends ImplementationImpl implements BPELImplement @Override public List<Service> getServices() { - return componentType.getServices(); + if (componentType != null){ + return componentType.getServices(); + } else { + return null; + } } @Override public List<Reference> getReferences() { - return componentType.getReferences(); + if (componentType != null){ + return componentType.getReferences(); + } else { + return null; + } } @Override diff --git a/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingImplementationPolicyProvider.java b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingImplementationPolicyProvider.java index 2963d8ce53..a418cbb81c 100644 --- a/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingImplementationPolicyProvider.java +++ b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingImplementationPolicyProvider.java @@ -40,7 +40,7 @@ public class JDKLoggingImplementationPolicyProvider extends BasePolicyProvider<J * @see org.apache.tuscany.sca.provider.PolicyProvider#createInterceptor(org.apache.tuscany.sca.interfacedef.Operation) */ public PhasedInterceptor createInterceptor(Operation operation) { - List<JDKLoggingPolicy> policies = findPolicies(); + List<JDKLoggingPolicy> policies = findPolicies(operation); return policies.isEmpty() ? null : new JDKLoggingPolicyInterceptor(subject, getContext(), operation, policies, Phase.IMPLEMENTATION_POLICY); } diff --git a/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingReferencePolicyProvider.java b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingReferencePolicyProvider.java index 80867f57de..ee9a8f0e9f 100644 --- a/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingReferencePolicyProvider.java +++ b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingReferencePolicyProvider.java @@ -37,7 +37,7 @@ public class JDKLoggingReferencePolicyProvider extends BasePolicyProvider<JDKLog } public PhasedInterceptor createInterceptor(Operation operation) { - List<JDKLoggingPolicy> policies = findPolicies(); + List<JDKLoggingPolicy> policies = findPolicies(operation); return policies.isEmpty() ? null : new JDKLoggingPolicyInterceptor(subject, getContext(), operation, policies, Phase.REFERENCE_POLICY); } diff --git a/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingServicePolicyProvider.java b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingServicePolicyProvider.java index 99f0563603..f947ab3afc 100644 --- a/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingServicePolicyProvider.java +++ b/sca-java-2.x/trunk/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingServicePolicyProvider.java @@ -37,7 +37,7 @@ public class JDKLoggingServicePolicyProvider extends BasePolicyProvider<JDKLoggi } public PhasedInterceptor createInterceptor(Operation operation) { - List<JDKLoggingPolicy> policies = findPolicies(); + List<JDKLoggingPolicy> policies = findPolicies(operation); return policies.isEmpty() ? null : new JDKLoggingPolicyInterceptor(subject, getContext(), operation, policies, Phase.SERVICE_POLICY); } diff --git a/sca-java-2.x/trunk/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityImplementationPolicyProvider.java b/sca-java-2.x/trunk/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityImplementationPolicyProvider.java index 04d7152a49..29e00dc4b0 100644 --- a/sca-java-2.x/trunk/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityImplementationPolicyProvider.java +++ b/sca-java-2.x/trunk/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityImplementationPolicyProvider.java @@ -41,37 +41,6 @@ public class SecurityIdentityImplementationPolicyProvider extends BasePolicyProv this.implementation = component.getImplementation(); } - 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 = implementation.getPolicySets(); - for (PolicySet ps : policySets) { - for (Object p : ps.getPolicies()) { - if (SecurityIdentityPolicy.class.isInstance(p)) { - polices.add((SecurityIdentityPolicy)p); - } - } - } - return polices; - } - public PhasedInterceptor createInterceptor(Operation operation) { List<SecurityIdentityPolicy> policies = findPolicies(operation); if (policies == null || policies.isEmpty()) { diff --git a/sca-java-2.x/trunk/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationImplementationPolicyProvider.java b/sca-java-2.x/trunk/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationImplementationPolicyProvider.java index 20a064574d..f131d5bed4 100644 --- a/sca-java-2.x/trunk/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationImplementationPolicyProvider.java +++ b/sca-java-2.x/trunk/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationImplementationPolicyProvider.java @@ -43,37 +43,6 @@ public class JaasAuthenticationImplementationPolicyProvider extends BasePolicyPr this.implementation = component.getImplementation(); } - 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 = implementation.getPolicySets(); - for (PolicySet ps : policySets) { - for (Object p : ps.getPolicies()) { - if (JaasAuthenticationPolicy.class.isInstance(p)) { - polices.add((JaasAuthenticationPolicy)p); - } - } - } - return polices; - } - public PhasedInterceptor createInterceptor(Operation operation) { List<JaasAuthenticationPolicy> policies = findPolicies(operation); if (policies == null || policies.isEmpty()) { diff --git a/sca-java-2.x/trunk/modules/policy-transaction-runtime/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionReferencePolicyProvider.java b/sca-java-2.x/trunk/modules/policy-transaction-runtime/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionReferencePolicyProvider.java index 1dc0feb0b5..0c5f546720 100644 --- a/sca-java-2.x/trunk/modules/policy-transaction-runtime/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionReferencePolicyProvider.java +++ b/sca-java-2.x/trunk/modules/policy-transaction-runtime/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionReferencePolicyProvider.java @@ -40,7 +40,7 @@ public class TransactionReferencePolicyProvider extends BasePolicyProvider<Trans } public PhasedInterceptor createInterceptor(Operation operation) { - List<TransactionPolicy> policies = findPolicies(); + List<TransactionPolicy> policies = findPolicies(operation); return policies.isEmpty() ? null : new TransactionInterceptor(helper, true, policies.get(0), null, getPhase()); } diff --git a/sca-java-2.x/trunk/modules/policy-transaction-runtime/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionServicePolicyProvider.java b/sca-java-2.x/trunk/modules/policy-transaction-runtime/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionServicePolicyProvider.java index c2a7c1039b..e59bfbbab7 100644 --- a/sca-java-2.x/trunk/modules/policy-transaction-runtime/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionServicePolicyProvider.java +++ b/sca-java-2.x/trunk/modules/policy-transaction-runtime/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionServicePolicyProvider.java @@ -40,7 +40,7 @@ public class TransactionServicePolicyProvider extends BasePolicyProvider<Transac } public PhasedInterceptor createInterceptor(Operation operation) { - List<TransactionPolicy> policies = findPolicies(); + List<TransactionPolicy> policies = findPolicies(operation); return policies.isEmpty() ? null : new TransactionInterceptor(helper, true, policies.get(0), null, getPhase()); } |