]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
NOJIRA temp fix for intermittent problem seen by aron where even in non-auth mode...
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Thu, 3 Dec 2009 23:03:45 +0000 (23:03 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Thu, 3 Dec 2009 23:03:45 +0000 (23:03 +0000)
M    trunk/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContext.java

services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContext.java

index d6d0a4b779de4a59c6f81a82a21f193a41a5ce1f..3f4f92f3fc80b213523ca30df7c740fe2769bf3d 100644 (file)
@@ -223,14 +223,22 @@ public abstract class AbstractServiceContext<IT, OT>
     private String retrieveTenantId() throws UnauthorizedException {
 
         String tenantId = null;
+        Subject caller = null;
         Set<Principal> principals = null;
         try {
-            Subject caller = (Subject) PolicyContext.getContext(SUBJECT_CONTEXT_KEY);
-            if(caller == null) {
+            caller = (Subject) PolicyContext.getContext(SUBJECT_CONTEXT_KEY);
+            if (caller == null) {
                 //logger.warn("security not enabled...");
                 return tenantId;
             }
             principals = caller.getPrincipals(Principal.class);
+            if (principals != null && principals.size() == 0) {
+                //TODO: find out why subject is not null
+                if (logger.isDebugEnabled()) {
+                    logger.debug("weird case where subject is not null and there are no principals");
+                }
+                return tenantId;
+            }
         } catch (PolicyContextException pce) {
             String msg = "Could not retrieve principal information";
             logger.error(msg, pce);
@@ -248,9 +256,9 @@ public abstract class AbstractServiceContext<IT, OT>
                 break;
             } catch (Exception e) {
                 //continue with next principal
-            } 
+            }
         }
-        if(tenantId == null) {
+        if (tenantId == null) {
             String msg = "Could not find tenant context";
             logger.error(msg);
             throw new UnauthorizedException(msg);