This is an automated email from the ASF dual-hosted git repository.

dkulp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new 2e2dbb7  [CXF-6968] Make sure policies configured on the bus level 
features will be used
2e2dbb7 is described below

commit 2e2dbb7ac213cb75a5ee5cf2410b2f70c701ea21
Author: Daniel Kulp <dk...@apache.org>
AuthorDate: Thu Jun 14 12:13:16 2018 -0400

    [CXF-6968] Make sure policies configured on the bus level features will be 
used
---
 .../org/apache/cxf/ws/policy/PolicyEngine.java     |  3 +-
 .../org/apache/cxf/ws/policy/PolicyEngineImpl.java | 12 +++++-
 .../org/apache/cxf/ws/policy/WSPolicyFeature.java  | 46 ++++++++++++++++++++--
 .../systest/ws/policy/PolicyAlternativeTest.java   |  1 -
 4 files changed, 56 insertions(+), 6 deletions(-)

diff --git 
a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java 
b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java
index 74a8d7d..dadbd3c 100644
--- a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java
+++ b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java
@@ -29,6 +29,7 @@ import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.Conduit;
 import org.apache.cxf.transport.Destination;
 import org.apache.neethi.Assertion;
+import org.apache.neethi.Policy;
 import org.apache.neethi.PolicyComponent;
 import org.apache.neethi.PolicyRegistry;
 
@@ -97,7 +98,7 @@ public interface PolicyEngine {
 
     void setEffectiveClientFaultPolicy(EndpointInfo ei, BindingFaultInfo bfi, 
EffectivePolicy ep);
 
-
+    void addPolicy(Policy p);
 
     PolicyRegistry getRegistry();
 
diff --git 
a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java 
b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java
index e264ffe..62b6ac1 100644
--- a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java
+++ b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java
@@ -74,6 +74,7 @@ public class PolicyEngineImpl implements PolicyEngine, 
BusExtension {
     private PolicyRegistry registry;
     private Collection<PolicyProvider> policyProviders;
     private Collection<PolicyProvider> preSetPolicyProviders = new 
LinkedList<PolicyProvider>();
+    private Policy busPolicy;
     private boolean enabled = true;
     private Boolean ignoreUnknownAssertions;
     private boolean addedBusInterceptors;
@@ -120,7 +121,16 @@ public class PolicyEngineImpl implements PolicyEngine, 
BusExtension {
     public Bus getBus() {
         return bus;
     }
+    @Override
+    public void addPolicy(Policy p) {
+        if (busPolicy == null) {
+            busPolicy = p;
+        } else {
+            busPolicy = busPolicy.merge(p);
+        }
+    }
 
+    
     public void setPolicyProviders(Collection<PolicyProvider> p) {
         policyProviders = new CopyOnWriteArrayList<PolicyProvider>(p);
     }
@@ -446,7 +456,7 @@ public class PolicyEngineImpl implements PolicyEngine, 
BusExtension {
         if (si == null) {
             return new Policy();
         }
-        Policy aggregated = null;
+        Policy aggregated = busPolicy;
         for (PolicyProvider pp : getPolicyProviders()) {
             Policy p = pp.getEffectivePolicy(si, m);
             if (null == aggregated) {
diff --git 
a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/WSPolicyFeature.java 
b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/WSPolicyFeature.java
index f5c48e7..ba01119 100644
--- a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/WSPolicyFeature.java
+++ b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/WSPolicyFeature.java
@@ -91,8 +91,49 @@ public class WSPolicyFeature extends AbstractFeature {
 
     @Override
     public void initialize(Bus bus) {
+        initializePolicyEngine(bus);
+        Collection<Policy> loadedPolicies = null;
+        if (policyElements != null || policyReferenceElements != null) {
+            loadedPolicies = new ArrayList<>();
+            PolicyBuilder builder = bus.getExtension(PolicyBuilder.class);
+            if (null != policyElements) {
+                for (Element e : policyElements) {
+                    loadedPolicies.add(builder.getPolicy(e));
+                }
+            }
+            if (null != policyReferenceElements) {
+                for (Element e : policyReferenceElements) {
+                    PolicyReference pr = builder.getPolicyReference(e);
+                    Policy resolved = resolveReference(pr, builder, bus, null);
+                    if (null != resolved) {
+                        loadedPolicies.add(resolved);
+                    }
+                }
+            }
+        }
 
-        // this should never be null as features are initialised only
+        Policy thePolicy = new Policy();
+        if (policies != null) {
+            for (Policy p : policies) {
+                thePolicy = thePolicy.merge(p);
+            }
+        }
+
+        if (loadedPolicies != null) {
+            for (Policy p : loadedPolicies) {
+                thePolicy = thePolicy.merge(p);
+            }
+        }
+        if (!thePolicy.isEmpty()) {
+            PolicyEngine pe = bus.getExtension(PolicyEngine.class);
+
+            synchronized (pe) {
+                pe.addPolicy(thePolicy);
+            }
+        }
+    }
+    public void initializePolicyEngine(Bus bus) {
+        // this should never be null as features are initialized only
         // after the bus and all its extensions have been created
 
         PolicyEngine pe = bus.getExtension(PolicyEngine.class);
@@ -149,8 +190,7 @@ public class WSPolicyFeature extends AbstractFeature {
     }
 
     private Policy initializeEndpointPolicy(Endpoint endpoint, Bus bus) {
-
-        initialize(bus);
+        initializePolicyEngine(bus);
         DescriptionInfo i = endpoint.getEndpointInfo().getDescription();
         Collection<Policy> loadedPolicies = null;
         if (policyElements != null || policyReferenceElements != null) {
diff --git 
a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/policy/PolicyAlternativeTest.java
 
b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/policy/PolicyAlternativeTest.java
index 344f34e..c2aae1a 100644
--- 
a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/policy/PolicyAlternativeTest.java
+++ 
b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/policy/PolicyAlternativeTest.java
@@ -290,7 +290,6 @@ public class PolicyAlternativeTest extends 
AbstractBusClientServerTestBase {
     /**
      * The client uses the Asymmetric policy defined at the bus level - this 
should succeed.
      */
-    @org.junit.Ignore("See CXF-6968")
     @org.junit.Test
     public void testAsymmetricBusLevel() throws Exception {
 

-- 
To stop receiving notification emails like this one, please contact
dk...@apache.org.

Reply via email to