Uploaded image for project: 'Jira Cloud'
  1. Jira Cloud
  2. JRACLOUD-28446

SAP ThreadLocalCachingPermissionManager

    XMLWordPrintable

Details

    • Our product teams collect and evaluate feedback from a number of different sources. To learn more about how we use customer feedback in the planning process, check out our new feature policy.

    Description

      NOTE: This suggestion is for JIRA Cloud. Using JIRA Server? See the corresponding suggestion.

      Package: com.atlassian.jira.security

      Current Implementation: The cache is stored in the action context:

      PermissionsCache cache = (PermissionsCache) JiraAuthenticationContextImpl.getRequestCache().get(RequestCacheKeys.PERMISSIONS_CACHE);
      if (cache == null) {
       ...         
      JiraAuthenticationContextImpl.getRequestCache().put(RequestCacheKeys.PERMISSIONS_CACHE, cache);
      }
      

      One Alternative Implementation: Store the cache in the session context:

      PermissionsCache cache = (PermissionsCache) ActionContext.getSession().get(RequestCacheKeys.PERMISSIONS_CACHE);
      if (cache == null)  {
      …
      ActionContext.getSession().put(RequestCacheKeys.PERMISSIONS_CACHE, cache);
      }
      

      Maybe this alternative implementation could be turned on by a configuration option. Even better would be to speed up the execution of AbstractPermissionManager.getProjectObjectsWithPermission (permissionId, user) itself, e.g. by caching the permission meta data in a controlled way.

      Complete source of alternative implemenation:

      package com.atlassian.jira.security;
      
      import com.atlassian.jira.permission.PermissionContextFactory;
      import com.atlassian.jira.permission.WorkflowPermissionFactory;
      import com.atlassian.jira.project.Project;
      import com.atlassian.jira.project.ProjectFactory;
      import org.apache.log4j.Logger;
      
      import webwork.action.ActionContext;
      
      import java.util.Collection;
      
      public class ThreadLocalCachingPermissionManager extends WorkflowBasedPermissionManager
      {
          private static final Logger log = Logger.getLogger(ThreadLocalCachingPermissionManager.class);
          private final ProjectFactory projectFactory;
      
          public ThreadLocalCachingPermissionManager(final WorkflowPermissionFactory workflowPermissionFactory,
                  final PermissionContextFactory permissionContextFactory, final ProjectFactory projectFactory)
          {
              super(workflowPermissionFactory, permissionContextFactory);
              this.projectFactory = projectFactory;
          }
      
          @Override
          public Collection<Project> getProjectObjects(final int permissionId, final com.atlassian.crowd.embedded.api.User user)
          {
              if (Permissions.BROWSE == permissionId)
              {
                  final PermissionsCache cache = getCache();
                  final Collection<Project> cachedProjects = cache.getProjectObjectsWithBrowsePermission(user);
                  if (cachedProjects != null)
                  {
                      return cachedProjects;
                  }
      
                  cache.setProjectObjectsWithBrowsePermission(user, super.getProjectObjects(permissionId, user));
                  return cache.getProjectObjectsWithBrowsePermission(user);
              }
      
              return super.getProjectObjects(permissionId, user);
          }
      
          private PermissionsCache getCache()
          {
              PermissionsCache cache = (PermissionsCache) ActionContext.getSession().get(RequestCacheKeys.PERMISSIONS_CACHE);
      
              if (cache == null)
              {
                  if (log.isDebugEnabled())
                  {
                      log.debug("Creating new PermissionsCache");
                  }
                  cache = new PermissionsCache(projectFactory);
                  ActionContext.getSession().put(RequestCacheKeys.PERMISSIONS_CACHE, cache);
              }
      
              return cache;
          }
      }
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              dchan David Chan
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: