You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2014/12/03 10:49:32 UTC

tomee git commit: SecurityContext#getUserPrincipal returns null when not authenticated, not a default user

Repository: tomee
Updated Branches:
  refs/heads/tomee-1.7.x f649c2cf6 -> 9a340c02f


SecurityContext#getUserPrincipal returns null when not authenticated, not a default user


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

Branch: refs/heads/tomee-1.7.x
Commit: 9a340c02f2dcb0030731c142b70b3b6cb7d3814a
Parents: f649c2c
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Wed Dec 3 10:41:20 2014 +0100
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Wed Dec 3 10:41:53 2014 +0100

----------------------------------------------------------------------
 .../openejb/rest/ThreadLocalSecurityContext.java      | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/9a340c02/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalSecurityContext.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalSecurityContext.java b/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalSecurityContext.java
index eb22c45..33f9a39 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalSecurityContext.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/rest/ThreadLocalSecurityContext.java
@@ -17,6 +17,7 @@
 
 package org.apache.openejb.rest;
 
+import org.apache.openejb.core.security.AbstractSecurityService;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.spi.SecurityService;
 
@@ -24,10 +25,13 @@ import javax.ws.rs.core.SecurityContext;
 import java.security.Principal;
 
 public class ThreadLocalSecurityContext extends AbstractRestThreadLocalProxy<SecurityContext>
-    implements SecurityContext {
+        implements SecurityContext {
+    private final String defaultUser;
 
     protected ThreadLocalSecurityContext() {
         super(SecurityContext.class);
+        final SecurityService securityService = service();
+        defaultUser = AbstractSecurityService.class.isInstance(securityService) ? AbstractSecurityService.class.cast(securityService).getDefaultUser() : null;
     }
 
     private static SecurityService service() {
@@ -46,7 +50,8 @@ public class ThreadLocalSecurityContext extends AbstractRestThreadLocalProxy<Sec
                 return securityContext.getUserPrincipal();
             }
         }
-        return callerPrincipal;
+        // JAX-RS doesn't return a default Principal
+        return callerPrincipal == null || callerPrincipal.getName().equals(defaultUser) ? null : callerPrincipal;
     }
 
     public boolean isSecure() {
@@ -58,10 +63,7 @@ public class ThreadLocalSecurityContext extends AbstractRestThreadLocalProxy<Sec
             return true;
         }
         final SecurityContext sc = get();
-        if (sc != null) {
-            return sc.isUserInRole(role);
-        }
-        return false;
+        return sc != null && sc.isUserInRole(role);
     }
 
 }