diff --git a/src/main/java/org/gcube/portal/threadlocalexec/SmartGearsPortalValve.java b/src/main/java/org/gcube/portal/threadlocalexec/SmartGearsPortalValve.java index 300f7cc..2782a46 100644 --- a/src/main/java/org/gcube/portal/threadlocalexec/SmartGearsPortalValve.java +++ b/src/main/java/org/gcube/portal/threadlocalexec/SmartGearsPortalValve.java @@ -30,7 +30,7 @@ import com.liferay.portal.service.UserLocalServiceUtil; public class SmartGearsPortalValve extends ValveBase { private static final Logger _log = LoggerFactory.getLogger(SmartGearsPortalValve.class); private final static String DEFAULT_ROLE = "OrganizationMember"; - + private final static String LIFERAY_POLLER_CONTEXT = "poller/receive"; @Override @@ -41,19 +41,20 @@ public class SmartGearsPortalValve extends ValveBase { //_log.trace("SmartGearsPortalValve SecurityTokenProvider and AuthorizationProvider reset OK"); if (req instanceof HttpServletRequest) { HttpServletRequest request = (HttpServletRequest) req; - PortalContext context = PortalContext.getConfiguration(); - - String scope = context.getCurrentScope(request); - String username = getCurrentUsername(request); - if (scope != null && username != null) { - try { - String userToken = getAuthorizationToken(username, scope); - SecurityTokenProvider.instance.set(userToken); - } catch (Exception e) { - _log.error("Something went wrong in generating token for " + username + " in scope " + scope); - e.printStackTrace(); + if (!req.getRequestURL().toString().endsWith(LIFERAY_POLLER_CONTEXT)) { //avoid calling gCube auth service for liferay internal poller + PortalContext context = PortalContext.getConfiguration(); + String scope = context.getCurrentScope(request); + String username = getCurrentUsername(request); + if (scope != null && username != null) { + try { + String userToken = getAuthorizationToken(username, scope); + SecurityTokenProvider.instance.set(userToken); + } catch (Exception e) { + _log.error("Something went wrong in generating token for " + username + " in scope " + scope); + e.printStackTrace(); + } + //_log.trace("Security token set OK for " + username + " in scope " + scope); } - //_log.trace("Security token set OK for " + username + " in scope " + scope); } } getNext().invoke(req, resp); @@ -72,7 +73,7 @@ public class SmartGearsPortalValve extends ValveBase { String token = authorizationService().generateUserToken(new UserInfo(username, userRoles), scope); return token; } - + /** * * @param httpServletRequest the httpServletRequest object