cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject [2/7] cxf git commit: Extract Security Conetext handling
Date Tue, 25 Apr 2017 15:06:06 GMT
Extract Security Conetext handling


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

Branch: refs/heads/master
Commit: 62fd990682c0c6ff915356fb9b5f0a32efc20424
Parents: 4a714eb
Author: Christian Schneider <chris@die-schneider.net>
Authored: Mon Apr 24 17:55:04 2017 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Tue Apr 25 16:10:47 2017 +0200

----------------------------------------------------------------------
 .../apache/cxf/transport/jms/JMSConduit.java    |  2 +-
 .../cxf/transport/jms/JMSDestination.java       |  2 +-
 .../cxf/transport/jms/JMSMessageUtils.java      | 44 ------------
 .../transport/jms/SecurityContextFactory.java   | 75 ++++++++++++++++++++
 4 files changed, 77 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/62fd9906/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 e588542..cbf2a6b 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
@@ -436,7 +436,7 @@ public class JMSConduit extends AbstractConduit implements JMSExchangeSender,
Me
             Message inMessage = JMSMessageUtils.asCXFMessage(jmsMessage,
                                                              JMSConstants.JMS_CLIENT_RESPONSE_HEADERS);
             if (jmsConfig.isCreateSecurityContext()) {
-                SecurityContext securityContext = JMSMessageUtils.buildSecurityContext(jmsMessage,
jmsConfig);
+                SecurityContext securityContext = SecurityContextFactory.buildSecurityContext(jmsMessage,
jmsConfig);
                 inMessage.put(SecurityContext.class, securityContext);
             }
             exchange.setInMessage(inMessage);

http://git-wip-us.apache.org/repos/asf/cxf/blob/62fd9906/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 22a94de..3362c35 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
@@ -217,7 +217,7 @@ public class JMSDestination extends AbstractMultiplexDestination implements
Mess
                                 + jmsConfig.getTargetDestination());
             Message inMessage = JMSMessageUtils.asCXFMessage(message, JMSConstants.JMS_SERVER_REQUEST_HEADERS);
             if (jmsConfig.isCreateSecurityContext()) {
-                SecurityContext securityContext = JMSMessageUtils.buildSecurityContext(message,
jmsConfig);
+                SecurityContext securityContext = SecurityContextFactory.buildSecurityContext(message,
jmsConfig);
                 inMessage.put(SecurityContext.class, securityContext);
             }
             inMessage.put(JMSConstants.JMS_SERVER_RESPONSE_HEADERS, new JMSMessageHeadersType());

http://git-wip-us.apache.org/repos/asf/cxf/blob/62fd9906/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSMessageUtils.java
----------------------------------------------------------------------
diff --git a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSMessageUtils.java
b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSMessageUtils.java
index 31ba9f8..6ea346a 100644
--- a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSMessageUtils.java
+++ b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSMessageUtils.java
@@ -25,7 +25,6 @@ import java.io.Reader;
 import java.io.StringReader;
 import java.io.UnsupportedEncodingException;
 import java.nio.charset.StandardCharsets;
-import java.security.Principal;
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.List;
@@ -49,7 +48,6 @@ import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.HttpHeaderHelper;
 import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.message.MessageUtils;
-import org.apache.cxf.security.SecurityContext;
 import org.apache.cxf.transport.jms.spec.JMSSpecConstants;
 import org.apache.cxf.transport.jms.uri.JMSEndpoint;
 import org.apache.cxf.transport.jms.util.JMSMessageConverter;
@@ -222,48 +220,6 @@ final class JMSMessageUtils {
 
     }
 
-    /**
-     * Extract the property JMSXUserID or JMS_TIBCO_SENDER from the jms message and
-     * create a SecurityContext from it.
-     * For more info see Jira Issue CXF-2055
-     * {@link https://issues.apache.org/jira/browse/CXF-2055}
-     *
-     * @param message jms message to retrieve user information from
-     * @return SecurityContext that contains the user of the producer of the message as the
Principal
-     * @throws JMSException if something goes wrong
-     */
-    public static SecurityContext buildSecurityContext(javax.jms.Message message,
-                                                        JMSConfiguration config) throws JMSException
{
-        String tempUserName = message.getStringProperty("JMSXUserID");
-        if (tempUserName == null && config.isJmsProviderTibcoEms()) {
-            tempUserName = message.getStringProperty("JMS_TIBCO_SENDER");
-        }
-        if (tempUserName == null) {
-            return null;
-        }
-        final String jmsUserName = tempUserName;
-
-        final Principal principal = new Principal() {
-            public String getName() {
-                return jmsUserName;
-            }
-
-        };
-
-        SecurityContext securityContext = new SecurityContext() {
-
-            public Principal getUserPrincipal() {
-                return principal;
-            }
-
-            public boolean isUserInRole(String role) {
-                return false;
-            }
-
-        };
-        return securityContext;
-    }
-
     static String getEncoding(String ct) throws UnsupportedEncodingException {
         String contentType = ct.toLowerCase();
         String enc = null;

http://git-wip-us.apache.org/repos/asf/cxf/blob/62fd9906/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/SecurityContextFactory.java
----------------------------------------------------------------------
diff --git a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/SecurityContextFactory.java
b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/SecurityContextFactory.java
new file mode 100644
index 0000000..d51ff3d
--- /dev/null
+++ b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/SecurityContextFactory.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.cxf.transport.jms;
+
+import java.security.Principal;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+
+import org.apache.cxf.security.SecurityContext;
+
+public final class SecurityContextFactory {
+    
+    private SecurityContextFactory() {
+    }
+
+    /**
+     * Extract the property JMSXUserID or JMS_TIBCO_SENDER from the jms message and
+     * create a SecurityContext from it.
+     * For more info see Jira Issue CXF-2055
+     * {@link https://issues.apache.org/jira/browse/CXF-2055}
+     *
+     * @param message jms message to retrieve user information from
+     * @return SecurityContext that contains the user of the producer of the message as the
Principal
+     * @throws JMSException if something goes wrong
+     */
+    public static SecurityContext buildSecurityContext(Message message,
+                                                       JMSConfiguration config) throws JMSException
{
+        String tempUserName = message.getStringProperty("JMSXUserID");
+        if (tempUserName == null && config.isJmsProviderTibcoEms()) {
+            tempUserName = message.getStringProperty("JMS_TIBCO_SENDER");
+        }
+        if (tempUserName == null) {
+            return null;
+        }
+        final String jmsUserName = tempUserName;
+    
+        final Principal principal = new Principal() {
+            public String getName() {
+                return jmsUserName;
+            }
+    
+        };
+    
+        SecurityContext securityContext = new SecurityContext() {
+    
+            public Principal getUserPrincipal() {
+                return principal;
+            }
+    
+            public boolean isUserInRole(String role) {
+                return false;
+            }
+    
+        };
+        return securityContext;
+    }
+
+}


Mime
View raw message