cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-6072] Updating AbstractHttpDestination to delegate to HttpServletRequest to get Principal
Date Thu, 30 Oct 2014 13:06:18 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 83e5e4570 -> a2c053d19


[CXF-6072] Updating AbstractHttpDestination to delegate to HttpServletRequest to get Principal


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

Branch: refs/heads/3.0.x-fixes
Commit: a2c053d19735520e59d3be587abdaa5ad6de2d60
Parents: 83e5e45
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Thu Oct 30 13:02:52 2014 +0000
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Thu Oct 30 13:05:57 2014 +0000

----------------------------------------------------------------------
 .../transport/http/AbstractHTTPDestination.java | 41 +++++++++++++-------
 1 file changed, 26 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/a2c053d1/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
----------------------------------------------------------------------
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
index 62367c5..6b1714f 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
@@ -155,7 +155,7 @@ public abstract class AbstractHTTPDestination
         return bus;
     }
 
-    private AuthorizationPolicy getAuthorizationPolicyFromMessage(String credentials, Principal
pp) {
+    private AuthorizationPolicy getAuthorizationPolicyFromMessage(String credentials, SecurityContext
sc) {
         if (credentials == null || StringUtils.isEmpty(credentials.trim())) {
             return null;
         }
@@ -177,8 +177,8 @@ public abstract class AbstractHTTPDestination
                     }
                 }
                 
-                AuthorizationPolicy policy = pp == null 
-                    ? new AuthorizationPolicy() : new PrincipalAuthorizationPolicy(pp);
+                AuthorizationPolicy policy = sc.getUserPrincipal() == null 
+                    ? new AuthorizationPolicy() : new PrincipalAuthorizationPolicy(sc);
                 policy.setUserName(username);
                 policy.setPassword(password);
                 policy.setAuthorizationType(authType);
@@ -187,9 +187,8 @@ public abstract class AbstractHTTPDestination
                 // Invalid authentication => treat as not authenticated or use the Principal
             }
         } 
-        if (pp != null) {
-            AuthorizationPolicy policy = new PrincipalAuthorizationPolicy(pp);
-            policy.setUserName(pp.getName());
+        if (sc.getUserPrincipal() != null) {
+            AuthorizationPolicy policy = new PrincipalAuthorizationPolicy(sc);
             policy.setAuthorization(credentials);
             policy.setAuthorizationType(authType);
             return policy;
@@ -197,12 +196,21 @@ public abstract class AbstractHTTPDestination
         return null;
     }
     public static final class PrincipalAuthorizationPolicy extends AuthorizationPolicy {
-        final Principal principal;
-        public PrincipalAuthorizationPolicy(Principal p) {
-            principal = p;
+        final SecurityContext sc;
+        public PrincipalAuthorizationPolicy(SecurityContext sc) {
+            this.sc = sc;
         }
         public Principal getPrincipal() {
-            return principal;
+            return sc.getUserPrincipal();
+        }
+        @Override
+        public String getUserName() {
+            String name = super.getUserName();
+            if (name != null) {
+                return name;
+            }
+            Principal pp = getPrincipal();
+            return pp != null ? pp.getName() : null;
         }
     }
     
@@ -358,21 +366,24 @@ public abstract class AbstractHTTPDestination
         }
         inMessage.put(Message.FIXED_PARAMETER_ORDER, isFixedParameterOrder());
         inMessage.put(Message.ASYNC_POST_RESPONSE_DISPATCH, Boolean.TRUE);
-        final Principal pp = req.getUserPrincipal(); 
-        inMessage.put(SecurityContext.class, new SecurityContext() {
+        
+        SecurityContext httpSecurityContext = new SecurityContext() {
             public Principal getUserPrincipal() {
-                return pp;
+                return req.getUserPrincipal();
             }
             public boolean isUserInRole(String role) {
                 return req.isUserInRole(role);
             }
-        });
+        };
+        
+        inMessage.put(SecurityContext.class, httpSecurityContext);
         
         
         Headers headers = new Headers(inMessage);
         headers.copyFromRequest(req);
         String credentials = headers.getAuthorization();
-        AuthorizationPolicy authPolicy = getAuthorizationPolicyFromMessage(credentials, pp);
+        AuthorizationPolicy authPolicy = getAuthorizationPolicyFromMessage(credentials, 
+                                                                           httpSecurityContext);
         inMessage.put(AuthorizationPolicy.class, authPolicy);
         
         propogateSecureSession(req, inMessage);


Mime
View raw message