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):
- Persist change to database via store
- 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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionJiraRuleComponentRestrictionCacheManager(RuleComponentRestrictionStore restrictionStore, com.atlassian.cache.CacheManager cacheManager, ApplicationProperties applicationProperties) -
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteRestrictions(TenantContext context, String ruleComponentKey) Removes restrictions for a specific rule component.getAllRestrictionConfigs(TenantContext context) Retrieves all restriction configurations with metadata.getAllRestrictions(TenantContext context) Retrieves all rule component restrictions from the cache.getRestrictedComponents(TenantContext context, String userKey, Set<String> groupNames) Retrieves per-user restricted component keys based on the current global restrictions and the user's group memberships.getRestrictionConfig(TenantContext context, String ruleComponentKey) Retrieves detailed configuration for a specific rule component restriction, including metadata like creation/update timestamps.getRestrictions(TenantContext context, String ruleComponentKey) Retrieves restrictions for a specific rule component from the cache.voidExplicitly invalidates the global restrictions cache.intremoveGroupFromAllRestrictions(TenantContext context, String groupName) Removes a group from all rule component restrictions.voidreplaceAllRestrictions(TenantContext context, Map<String, Set<String>> restrictions, String updatedBy) Replaces all restrictions with a new set of restrictions atomically.voidsetRestrictions(TenantContext context, String ruleComponentKey, Set<String> groupNames, String updatedBy) Sets restrictions for a specific rule component.
-
Field Details
-
DEFAULT_USER_CACHE_MAX_ENTRIES
public static final int DEFAULT_USER_CACHE_MAX_ENTRIES- See Also:
-
-
Constructor Details
-
JiraRuleComponentRestrictionCacheManager
@Inject public JiraRuleComponentRestrictionCacheManager(RuleComponentRestrictionStore restrictionStore, com.atlassian.cache.CacheManager cacheManager, ApplicationProperties applicationProperties)
-
-
Method Details
-
getAllRestrictions
Description copied from interface:RuleComponentRestrictionCacheManagerRetrieves 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:
getAllRestrictionsin interfaceRuleComponentRestrictionCacheManager- 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:RuleComponentRestrictionCacheManagerRetrieves restrictions for a specific rule component from the cache.- Specified by:
getRestrictionsin interfaceRuleComponentRestrictionCacheManager- Parameters:
context- the tenant contextruleComponentKey- 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:RuleComponentRestrictionCacheManagerRetrieves 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:
getRestrictedComponentsin interfaceRuleComponentRestrictionCacheManager- Parameters:
context- the tenant contextuserKey- the user keygroupNames- 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:RuleComponentRestrictionCacheManagerRetrieves detailed configuration for a specific rule component restriction, including metadata like creation/update timestamps.- Specified by:
getRestrictionConfigin interfaceRuleComponentRestrictionCacheManager- Parameters:
context- the tenant contextruleComponentKey- 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:RuleComponentRestrictionCacheManagerRetrieves all restriction configurations with metadata.- Specified by:
getAllRestrictionConfigsin interfaceRuleComponentRestrictionCacheManager- 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:RuleComponentRestrictionCacheManagerSets 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:
setRestrictionsin interfaceRuleComponentRestrictionCacheManager- Parameters:
context- the tenant contextruleComponentKey- the rule component keygroupNames- the set of allowed group names (empty means fully restricted)updatedBy- the user key of the user making the change
-
deleteRestrictions
Description copied from interface:RuleComponentRestrictionCacheManagerRemoves restrictions for a specific rule component. After removal, the component becomes unrestricted. Invalidates global cache locally and across cluster nodes.- Specified by:
deleteRestrictionsin interfaceRuleComponentRestrictionCacheManager- Parameters:
context- the tenant contextruleComponentKey- the rule component key
-
invalidateGlobalCache
public void invalidateGlobalCache()Description copied from interface:RuleComponentRestrictionCacheManagerExplicitly invalidates the global restrictions cache. Propagates invalidation across cluster nodes, including per-user access caches.- Specified by:
invalidateGlobalCachein interfaceRuleComponentRestrictionCacheManager
-
replaceAllRestrictions
public void replaceAllRestrictions(@Nonnull TenantContext context, @Nonnull Map<String, Set<String>> restrictions, @Nonnull String updatedBy) Description copied from interface:RuleComponentRestrictionCacheManagerReplaces 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:
replaceAllRestrictionsin interfaceRuleComponentRestrictionCacheManager- Parameters:
context- the tenant contextrestrictions- 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:RuleComponentRestrictionCacheManagerRemoves 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:
removeGroupFromAllRestrictionsin interfaceRuleComponentRestrictionCacheManager- Parameters:
context- the tenant contextgroupName- the name of the group to remove from all restrictions- Returns:
- the number of restrictions that were modified
-