From: Sanjay Dalal Date: Thu, 3 Dec 2009 23:03:45 +0000 (+0000) Subject: NOJIRA temp fix for intermittent problem seen by aron where even in non-auth mode... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=26dfe065e2e19951b434c918900ee02c61542da5;p=tmp%2Fjakarta-migration.git NOJIRA temp fix for intermittent problem seen by aron where even in non-auth mode subject and pricipals are not null. need more investigation if subject is lying around on thread by mistake (nuxeo or cspace) M trunk/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContext.java --- diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContext.java b/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContext.java index d6d0a4b77..3f4f92f3f 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContext.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContext.java @@ -223,14 +223,22 @@ public abstract class AbstractServiceContext private String retrieveTenantId() throws UnauthorizedException { String tenantId = null; + Subject caller = null; Set 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 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);