cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jp...@apache.org
Subject [1/2] cxf git commit: CXF-6120 added a new property to JMSConfiguration to stop creation of the Security Context
Date Mon, 01 Dec 2014 03:25:32 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes fd659c11e -> b2bbfa3c3


CXF-6120 added a new property to JMSConfiguration to stop creation of the Security Context


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/526d4ef9
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/526d4ef9
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/526d4ef9

Branch: refs/heads/3.0.x-fixes
Commit: 526d4ef97a9b459a7c6c8b48e8e1b072a54b55b0
Parents: fd659c1
Author: Jason Pell <jpell@apache.org>
Authored: Mon Dec 1 11:33:27 2014 +1100
Committer: Jason Pell <jpell@apache.org>
Committed: Mon Dec 1 12:24:22 2014 +1100

----------------------------------------------------------------------
 .../apache/cxf/transport/jms/JMSConduit.java    |  6 ++-
 .../cxf/transport/jms/JMSConfiguration.java     |  9 ++++
 .../cxf/transport/jms/JMSDestination.java       |  9 ++--
 .../cxf/transport/jms/JMSDestinationTest.java   | 43 ++++++++++++++++++--
 4 files changed, 57 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/526d4ef9/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java
----------------------------------------------------------------------
diff --git a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java
b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java
index bff0dd9..00eba50 100644
--- a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java
+++ b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java
@@ -396,8 +396,10 @@ public class JMSConduit extends AbstractConduit implements JMSExchangeSender,
Me
         try {
             Message inMessage = JMSMessageUtils.asCXFMessage(jmsMessage, 
                                                              JMSConstants.JMS_CLIENT_RESPONSE_HEADERS);
-            SecurityContext securityContext = JMSMessageUtils.buildSecurityContext(jmsMessage,
jmsConfig);
-            inMessage.put(SecurityContext.class, securityContext);
+            if (jmsConfig.isCreateSecurityContext()) {
+                SecurityContext securityContext = JMSMessageUtils.buildSecurityContext(jmsMessage,
jmsConfig);
+                inMessage.put(SecurityContext.class, securityContext);
+            }
             exchange.setInMessage(inMessage);
             Object responseCode = inMessage.get(org.apache.cxf.message.Message.RESPONSE_CODE);
             exchange.put(org.apache.cxf.message.Message.RESPONSE_CODE, responseCode);

http://git-wip-us.apache.org/repos/asf/cxf/blob/526d4ef9/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConfiguration.java
----------------------------------------------------------------------
diff --git a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConfiguration.java
b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConfiguration.java
index e1b51aa..b4ec3f0 100644
--- a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConfiguration.java
+++ b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConfiguration.java
@@ -52,6 +52,7 @@ public class JMSConfiguration {
     private int priority = Message.DEFAULT_PRIORITY;
     private long timeToLive = Message.DEFAULT_TIME_TO_LIVE;
     private boolean sessionTransacted;
+    private boolean createSecurityContext = true;
 
     private int maxSuspendedContinuations = DEFAULT_VALUE;
     private int reconnectPercentOfMax = 70;
@@ -303,6 +304,14 @@ public class JMSConfiguration {
         this.sessionTransacted = sessionTransacted;
     }
 
+    public boolean isCreateSecurityContext() {
+        return createSecurityContext;
+    }
+    
+    public void setCreateSecurityContext(boolean b) {
+        this.createSecurityContext = b;
+    }
+    
     /**
      * For compatibility with old spring based code
      * @param transactionManager

http://git-wip-us.apache.org/repos/asf/cxf/blob/526d4ef9/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
----------------------------------------------------------------------
diff --git a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
index e8ebd07..e4127d3 100644
--- a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
+++ b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
@@ -210,10 +210,11 @@ public class JMSDestination extends AbstractMultiplexDestination implements
Mess
             getLogger().log(Level.FINE,
                             "JMS destination received message " + message + " on "
                                 + jmsConfig.getTargetDestination());
-            Message inMessage = JMSMessageUtils
-                .asCXFMessage(message, JMSConstants.JMS_SERVER_REQUEST_HEADERS);
-            SecurityContext securityContext = JMSMessageUtils.buildSecurityContext(message,
jmsConfig);
-            inMessage.put(SecurityContext.class, securityContext);
+            Message inMessage = JMSMessageUtils.asCXFMessage(message, JMSConstants.JMS_SERVER_REQUEST_HEADERS);
+            if (jmsConfig.isCreateSecurityContext()) {
+                SecurityContext securityContext = JMSMessageUtils.buildSecurityContext(message,
jmsConfig);
+                inMessage.put(SecurityContext.class, securityContext);
+            }
             inMessage.put(JMSConstants.JMS_SERVER_RESPONSE_HEADERS, new JMSMessageHeadersType());
             inMessage.put(JMSConstants.JMS_REQUEST_MESSAGE, message);
             ((MessageImpl)inMessage).setDestination(this);

http://git-wip-us.apache.org/repos/asf/cxf/blob/526d4ef9/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSDestinationTest.java
----------------------------------------------------------------------
diff --git a/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSDestinationTest.java
b/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSDestinationTest.java
index 0e19590..715de58 100644
--- a/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSDestinationTest.java
+++ b/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSDestinationTest.java
@@ -180,12 +180,31 @@ public class JMSDestinationTest extends AbstractJMSTester {
 
     @Test
     public void testRoundTripDestination() throws Exception {
+        Message msg = testRoundTripDestination(true);
+        SecurityContext securityContext = msg.get(SecurityContext.class);
+        
+        assertNotNull("SecurityContext should be set in message received by JMSDestination",
securityContext);
+        assertEquals("Principal in SecurityContext should be", "testUser", 
+                securityContext.getUserPrincipal().getName());
+    }
+    
+    @Test
+    public void testRoundTripDestinationDoNotCreateSecurityContext() throws Exception {
+        Message msg = testRoundTripDestination(false);
+        SecurityContext securityContext = msg.get(SecurityContext.class);
+        assertNull("SecurityContext should not be set in message received by JMSDestination",
securityContext);
+    }
+    
+    private Message testRoundTripDestination(boolean createSecurityContext) throws Exception
{
         EndpointInfo ei = setupServiceInfo("HelloWorldService", "HelloWorldPort");
         JMSConduit conduit = setupJMSConduitWithObserver(ei);
+        conduit.getJmsConfig().setCreateSecurityContext(createSecurityContext);
+        
         final Message outMessage = new MessageImpl();
         setupMessageHeader(outMessage, null);
         final JMSDestination destination = setupJMSDestination(ei);
-
+        
+        
         // set up MessageObserver for handling the conduit message
         MessageObserver observer = new MessageObserver() {
             public void onMessage(Message m) {
@@ -225,6 +244,8 @@ public class JMSDestinationTest extends AbstractJMSTester {
         Thread.sleep(1000);
         conduit.close();
         destination.shutdown();
+        
+        return inMessage;
     }
 
     @Test
@@ -302,8 +323,22 @@ public class JMSDestinationTest extends AbstractJMSTester {
     
     @Test
     public void testSecurityContext() throws Exception {
+        SecurityContext ctx = testSecurityContext(true);
+        assertNotNull("SecurityContext should be set in message received by JMSDestination",
ctx);
+        assertEquals("Principal in SecurityContext should be", "testUser", 
+                ctx.getUserPrincipal().getName());
+    }
+    
+    @Test
+    public void testDoNotCreateSecurityContext() throws Exception {
+        SecurityContext ctx = testSecurityContext(false);
+        assertNull("SecurityContext should not be set in message received by JMSDestination",
ctx);
+    }
+    
+    private SecurityContext testSecurityContext(boolean createSecurityContext) throws Exception
{
         EndpointInfo ei = setupServiceInfo("HelloWorldService", "HelloWorldPort");
         final JMSDestination destination = setupJMSDestination(ei);
+        destination.getJmsConfig().setCreateSecurityContext(createSecurityContext);
         destination.setMessageObserver(createMessageObserver());
         // set up the conduit send to be true
         JMSConduit conduit = setupJMSConduitWithObserver(ei);
@@ -312,11 +347,11 @@ public class JMSDestinationTest extends AbstractJMSTester {
         sendOneWayMessage(conduit, outMessage);
         waitForReceiveDestMessage();
         SecurityContext securityContext = destMessage.get(SecurityContext.class);
-        assertNotNull("SecurityContext should be set in message received by JMSDestination",
securityContext);
-        assertEquals("Principal in SecurityContext should be", "testUser", 
-                     securityContext.getUserPrincipal().getName());
+        
         conduit.close();
         destination.shutdown();
+        
+        return securityContext;
     }
 
     


Mime
View raw message