Class JiraRuleComponentRestrictionCacheManager

java.lang.Object
com.codebarrel.jira.plugin.automation.service.JiraRuleComponentRestrictionCacheManager
All Implemented Interfaces:
RuleComponentRestrictionCacheManager

@Named public class JiraRuleComponentRestrictionCacheManager extends Object implements RuleComponentRestrictionCacheManager
Implementation of RuleComponentRestrictionCacheManager providing cached access to rule component restrictions with global caching. Global Restrictions Cache: Stores all restrictions as Map<componentKey, Set<groupName>> TTL: 24 hours User Access Cache: Stores per-user restricted components derived from global restrictions TTL: 5 minutes

On any write operation (set/delete/replaceAll):

  1. Persist change to database via store
  2. Invalidate global + per-user caches (propagates across cluster)

Edge Case: User Group Membership Changes

The user access cache is keyed by userKey only (not including group membership). This means if a user's group membership changes, the cached restricted components may be stale until the cache entry expires. This is an acceptable trade-off because:

  • The user access cache has a short TTL (5 minutes)
  • This edge case only affects users actively configuring automation rules at the exact moment their group membership changes
  • The restriction will be correctly applied on the next cache miss
See Also:
  • Field Details

    • DEFAULT_USER_CACHE_MAX_ENTRIES

      public static final int DEFAULT_USER_CACHE_MAX_ENTRIES
      See Also:
  • Constructor Details

  • Method Details

    • getAllRestrictions

      @Nonnull public Map<String,Set<String>> getAllRestrictions(@Nonnull TenantContext context)
      Description copied from interface: RuleComponentRestrictionCacheManager
      Retrieves all rule component restrictions from the cache. On first access or after cache expiry, loads from persistent store.

      Returns a map where:

      • Key: rule component key (e.g., "jira.issue.created")
      • Value: set of allowed group names (empty set = fully restricted)

      Components not in the map are unrestricted.

      Specified by:
      getAllRestrictions in interface RuleComponentRestrictionCacheManager
      Parameters:
      context - the tenant context
      Returns:
      immutable map of rule component key to set of allowed group names
    • getRestrictions

      @Nonnull public Optional<Set<String>> getRestrictions(@Nonnull TenantContext context, @Nonnull String ruleComponentKey)
      Description copied from interface: RuleComponentRestrictionCacheManager
      Retrieves restrictions for a specific rule component from the cache.
      Specified by:
      getRestrictions in interface RuleComponentRestrictionCacheManager
      Parameters:
      context - the tenant context
      ruleComponentKey - the rule component key (e.g., "jira.issue.created")
      Returns:
      optional set of allowed group names: - Empty optional: component is UNRESTRICTED - Present with empty set: component is FULLY RESTRICTED - Present with non-empty set: component is restricted to those groups
    • getRestrictedComponents

      @Nonnull public Set<String> getRestrictedComponents(@Nonnull TenantContext context, @Nonnull String userKey, @Nonnull Set<String> groupNames)
      Description copied from interface: RuleComponentRestrictionCacheManager
      Retrieves per-user restricted component keys based on the current global restrictions and the user's group memberships.

      Components not present in the returned set are unrestricted.

      Specified by:
      getRestrictedComponents in interface RuleComponentRestrictionCacheManager
      Parameters:
      context - the tenant context
      userKey - the user key
      groupNames - group names for the user
      Returns:
      restricted component keys for the user
    • getRestrictionConfig

      @Nonnull public Optional<RuleComponentRestrictionConfig> getRestrictionConfig(@Nonnull TenantContext context, @Nonnull String ruleComponentKey)
      Description copied from interface: RuleComponentRestrictionCacheManager
      Retrieves detailed configuration for a specific rule component restriction, including metadata like creation/update timestamps.
      Specified by:
      getRestrictionConfig in interface RuleComponentRestrictionCacheManager
      Parameters:
      context - the tenant context
      ruleComponentKey - the rule component key
      Returns:
      optional detailed configuration, empty if no restrictions exist
    • getAllRestrictionConfigs

      @Nonnull public Map<String,RuleComponentRestrictionConfig> getAllRestrictionConfigs(@Nonnull TenantContext context)
      Description copied from interface: RuleComponentRestrictionCacheManager
      Retrieves all restriction configurations with metadata.
      Specified by:
      getAllRestrictionConfigs in interface RuleComponentRestrictionCacheManager
      Parameters:
      context - the tenant context
      Returns:
      immutable map of rule component key to detailed configuration
    • setRestrictions

      public void setRestrictions(@Nonnull TenantContext context, @Nonnull String ruleComponentKey, @Nonnull Set<String> groupNames, @Nonnull String updatedBy)
      Description copied from interface: RuleComponentRestrictionCacheManager
      Sets restrictions for a specific rule component. Creates a new restriction or updates an existing one with full replacement. Invalidates global cache locally and across cluster nodes.
      Specified by:
      setRestrictions in interface RuleComponentRestrictionCacheManager
      Parameters:
      context - the tenant context
      ruleComponentKey - the rule component key
      groupNames - the set of allowed group names (empty means fully restricted)
      updatedBy - the user key of the user making the change
    • deleteRestrictions

      public void deleteRestrictions(@Nonnull TenantContext context, @Nonnull String ruleComponentKey)
      Description copied from interface: RuleComponentRestrictionCacheManager
      Removes restrictions for a specific rule component. After removal, the component becomes unrestricted. Invalidates global cache locally and across cluster nodes.
      Specified by:
      deleteRestrictions in interface RuleComponentRestrictionCacheManager
      Parameters:
      context - the tenant context
      ruleComponentKey - the rule component key
    • invalidateGlobalCache

      public void invalidateGlobalCache()
      Description copied from interface: RuleComponentRestrictionCacheManager
      Explicitly invalidates the global restrictions cache. Propagates invalidation across cluster nodes, including per-user access caches.
      Specified by:
      invalidateGlobalCache in interface RuleComponentRestrictionCacheManager
    • replaceAllRestrictions

      public void replaceAllRestrictions(@Nonnull TenantContext context, @Nonnull Map<String,Set<String>> restrictions, @Nonnull String updatedBy)
      Description copied from interface: RuleComponentRestrictionCacheManager
      Replaces all restrictions with a new set of restrictions atomically. This is a bulk operation that delegates to the store and invalidates the cache.

      This operation is transactional - either all restrictions are replaced or none are (rollback on failure).

      Use case: REST PUT endpoint that replaces entire configuration.

      Specified by:
      replaceAllRestrictions in interface RuleComponentRestrictionCacheManager
      Parameters:
      context - the tenant context
      restrictions - map of rule component key to set of allowed group names (empty map = remove all restrictions, empty set = fully restricted)
      updatedBy - the user key of the user making the change
    • removeGroupFromAllRestrictions

      public int removeGroupFromAllRestrictions(@Nonnull TenantContext context, @Nonnull String groupName)
      Description copied from interface: RuleComponentRestrictionCacheManager
      Removes a group from all rule component restrictions. This is used when a group is deleted to ensure stale group references are cleaned up from the restriction database.

      Invalidates the global cache after removal.

      Specified by:
      removeGroupFromAllRestrictions in interface RuleComponentRestrictionCacheManager
      Parameters:
      context - the tenant context
      groupName - the name of the group to remove from all restrictions
      Returns:
      the number of restrictions that were modified