Class DefaultApplicationRoleManager

java.lang.Object
com.atlassian.jira.application.DefaultApplicationRoleManager
All Implemented Interfaces:
com.atlassian.application.host.ApplicationConfigurationManager, ApplicationRoleManager, CachingComponent, InitializingComponent, LicenseCountService

public class DefaultApplicationRoleManager extends Object implements ApplicationRoleManager, CachingComponent, LicenseCountService, com.atlassian.application.host.ApplicationConfigurationManager, InitializingComponent
Default implementation of ApplicationRoleManager.
Since:
6.3
  • Constructor Details

  • Method Details

    • afterInstantiation

      public void afterInstantiation() throws Exception
      Description copied from interface: InitializingComponent
      Called after all the beans are constructed and the ApplicationContext is fully populated. Order of execution is order of bean creation, driven by InitializingComponentProcessor.
      Specified by:
      afterInstantiation in interface InitializingComponent
      Throws:
      Exception
    • waitForActiveUsersCacheLoader

      protected void waitForActiveUsersCacheLoader()
    • getRole

      @Nonnull public io.atlassian.fugue.Option<ApplicationRole> getRole(@Nonnull com.atlassian.application.api.ApplicationKey role)
      Description copied from interface: ApplicationRoleManager
      Returns the ApplicationRole identified by the given ApplicationKey, or Option.none() if no such ApplicationRole exists.

      Note: ApplicationRoles returned by this method are guaranteed to be backed by a (potentially exceeded) license, however the installation state of the plugin/product that uses this role may not necessarily physically installed.

      Specified by:
      getRole in interface ApplicationRoleManager
      Parameters:
      role - the ApplicationKey of the role to search for.
      Returns:
      the ApplicationRole associated with the passed role identifier, or Option.none().
    • getRoles

      @Nonnull public Set<ApplicationRole> getRoles()
      Description copied from interface: ApplicationRoleManager
      Returns an immutable Set of all ApplicationRoles that are backed by a (potentially exceeded) license.
      Specified by:
      getRoles in interface ApplicationRoleManager
      Returns:
      the Set of all ApplicationRoles that are backed by a (potentially exceeded) license.
    • getDefaultApplicationKeys

      @Nonnull public Set<com.atlassian.application.api.ApplicationKey> getDefaultApplicationKeys()
      Description copied from interface: ApplicationRoleManager
      Returns an immutable Set of ApplicationKeys that are configured as the default applications for new users.
      Specified by:
      getDefaultApplicationKeys in interface ApplicationRoleManager
      Returns:
      the Set of ApplicationKeys that are configured as the default applications for new users.
    • hasAnyRole

      public boolean hasAnyRole(@Nullable ApplicationUser user)
      Description copied from interface: ApplicationRoleManager
      Returns true if the given user has been assigned to any ApplicationRole that is backed by a (potentially exceeded) license.
      Specified by:
      hasAnyRole in interface ApplicationRoleManager
      Returns:
      true if the given user has been assigned to any ApplicationRole that is backed by a (potentially exceeded) license.
    • userHasRole

      public boolean userHasRole(@Nullable ApplicationUser user, com.atlassian.application.api.ApplicationKey key)
      Description copied from interface: ApplicationRoleManager
      Returns true if the passed user belongs to the ApplicationRole associated with the given key. NOTE: This does not check that the application is licensed with a valid license.
      Specified by:
      userHasRole in interface ApplicationRoleManager
      Parameters:
      user - the user to check - if this is null, returns false
      key - the key corresponding to the ApplicationRole
      Returns:
      true if the user belongs to a group of the given application
    • userOccupiesRole

      public boolean userOccupiesRole(@Nullable ApplicationUser user, com.atlassian.application.api.ApplicationKey key)
      Description copied from interface: ApplicationRoleManager
      Returns true if the passed user occupies a seat in the ApplicationRole associated with the given key.
      Specified by:
      userOccupiesRole in interface ApplicationRoleManager
      Parameters:
      user - the user to check - if this is null, returns false
      key - the key corresponding to the ApplicationRole
      Returns:
      true if the user occupies seat in the given application
    • isAnyRoleLimitExceeded

      public boolean isAnyRoleLimitExceeded()
      Description copied from interface: ApplicationRoleManager
      Returns true if the number of users assigned to any ApplicationRole exceeds the number of seats granted to that role by its license.

      The method is known to be slow in some circumstances, and to block Jira instance. It's strongly recommended to use ApplicationRoleManager.isAnyRoleLimitExceededAsync() async version of the method} Note: this method does NOT take into account whether licenses for installed roles are expired; this must be tested separately.

      Specified by:
      isAnyRoleLimitExceeded in interface ApplicationRoleManager
      Returns:
      true if the number of users for any role is greater than the number of seats granted to that role by its license.
    • isAnyRoleLimitExceededAsync

      public boolean isAnyRoleLimitExceededAsync()
      Description copied from interface: ApplicationRoleManager
      Async version of ApplicationRoleManager.isAnyRoleLimitExceeded(). The method returns the last know value without waiting for the current changes to be propagated. This implementation is safer and offers a better performance. Returns true if the number of users assigned to any ApplicationRole exceeds the number of seats granted to that role by its license.

      Note: this method does NOT take into account whether licenses for installed roles are expired; this must be tested separately.

      Specified by:
      isAnyRoleLimitExceededAsync in interface ApplicationRoleManager
      Returns:
      true if the number of users for any role is greater than the number of seats granted to that role by its license.
    • isRoleLimitExceeded

      public boolean isRoleLimitExceeded(@Nonnull com.atlassian.application.api.ApplicationKey applicationKey)
      Description copied from interface: ApplicationRoleManager
      Returns true if the number of users assigned to the given ApplicationRole exceeds the number of seats granted by its license. This method unconditionally returns false if the passed role is not considered to be installed (ie: backed by a license).

      Note: this method does NOT take into account whether licenses for installed roles are expired; this must be tested separately.

      The method is known to be slow in some circumstances, and to block Jira instance. It's strongly recommended to use async version of the method
      Specified by:
      isRoleLimitExceeded in interface ApplicationRoleManager
      Parameters:
      applicationKey - the identifier of the ApplicationRole.
      Returns:
      true if the installed ApplicationRole is exceeded or false otherwise.
    • isRoleLimitExceededAsync

      public boolean isRoleLimitExceededAsync(@Nonnull com.atlassian.application.api.ApplicationKey applicationKey)
      Description copied from interface: ApplicationRoleManager
      Async version of ApplicationRoleManager.isRoleLimitExceeded(ApplicationKey). The method returns the last know value without waiting for the current changes to be propagated. This implementation is safer and offers a better performance. Returns true if the number of users assigned to the given ApplicationRole exceeds the number of seats granted by its license. This method unconditionally returns false if the passed role is not considered to be installed (ie: backed by a license).

      Note: this method does NOT take into account whether licenses for installed roles are expired; this must be tested separately.

      Specified by:
      isRoleLimitExceededAsync in interface ApplicationRoleManager
      Parameters:
      applicationKey - the identifier of the ApplicationRole.
      Returns:
      true if the installed ApplicationRole is exceeded or false otherwise.
    • hasExceededAllRoles

      public boolean hasExceededAllRoles(@Nonnull ApplicationUser user)
      Description copied from interface: ApplicationRoleManager
      Returns true if the user limits of all of the given user's assigned ApplicationRoles have been exceeded. The user limit of an ApplicationRole is exceeded when the combined number of users assigned to that role (through assigned groups) exceeds the number of seats granted for that role in its license.

      Note: this method does NOT take into account whether licenses for application roles are expired; this must be tested separately.

      The method is known to be slow in some circumstances, and to block Jira instance. It's strongly recommended to use ApplicationRoleManager.hasExceededAllRolesAsync(ApplicationUser) async version of the method}
      Specified by:
      hasExceededAllRoles in interface ApplicationRoleManager
      Parameters:
      user - the user whose roles will be checked.
      Returns:
      true if all of the user's roles have user counts that exceed the number of seats granted by licenses.
    • hasExceededAllRolesAsync

      public boolean hasExceededAllRolesAsync(@Nonnull ApplicationUser user)
      Description copied from interface: ApplicationRoleManager
      Async version of ApplicationRoleManager.hasExceededAllRoles(ApplicationUser). The method returns the last know value without waiting for the current changes to be propagated. This implementation is safer and offers a better performance. Returns true if the user limits of all of the given user's assigned ApplicationRoles have been exceeded. The user limit of an ApplicationRole is exceeded when the combined number of users assigned to that role (through assigned groups) exceeds the number of seats granted for that role in its license.

      Note: this method does NOT take into account whether licenses for application roles are expired; this must be tested separately.

      Specified by:
      hasExceededAllRolesAsync in interface ApplicationRoleManager
      Parameters:
      user - the user whose roles will be checked.
      Returns:
      true if all of the user's roles have user counts that exceed the number of seats granted by licenses.
    • getRolesForUser

      public Set<ApplicationRole> getRolesForUser(@Nonnull ApplicationUser user)
      Description copied from interface: ApplicationRoleManager
      Returns the Set of ApplicationRoles granted to the given ApplicationUser.
      Specified by:
      getRolesForUser in interface ApplicationRoleManager
      Parameters:
      user - the user whose roles will be checked.
      Returns:
      the Set of ApplicationRoles for the given user.
    • getOccupiedLicenseRolesForUser

      public Set<ApplicationRole> getOccupiedLicenseRolesForUser(@Nonnull ApplicationUser user)
      Description copied from interface: ApplicationRoleManager
      Returns the Set of ApplicationRoles that the given ApplicationUser occupies seats in. ApplicationUser has to actively take a seat in the returned ApplicationRoles eg. for an ApplicationUser who has access to SOFTWARE and implicitly (or explicitly) CORE, they will only have SOFTWARE returned. For an ApplicationUser who has explicit access to SOFTWARE and CORE - with the SOFTWARE license exceeded, this will return both as the user effectively occupies a seat in both CORE and SOFTWARE now.
      Specified by:
      getOccupiedLicenseRolesForUser in interface ApplicationRoleManager
      Parameters:
      user - the user whose roles will be checked.
      Returns:
      the Set of ApplicationRoles that the given user is actively taking seats.
    • getRolesForGroup

      public Set<ApplicationRole> getRolesForGroup(@Nonnull com.atlassian.crowd.embedded.api.Group group)
      Description copied from interface: ApplicationRoleManager
      Returns the Set of ApplicationRoles associated with the given Group, or groups for which the given group is a nested group (sub-group).
      Specified by:
      getRolesForGroup in interface ApplicationRoleManager
      Parameters:
      group - the group which roles will be checked.
      Returns:
      the Set of ApplicationRoles associated with the group or its super-groups.
    • getGroupsForLicensedRoles

      @Nonnull public Set<com.atlassian.crowd.embedded.api.Group> getGroupsForLicensedRoles()
      Description copied from interface: ApplicationRoleManager
      Get the Set of group names that have been associated with all the ApplicationRoles that have a backing (but potentially exceeded) license.
      Specified by:
      getGroupsForLicensedRoles in interface ApplicationRoleManager
      Returns:
      Groups associated with all the ApplicationRoles that have a backing (but potentially exceeded) license.
    • removeGroupFromRoles

      public void removeGroupFromRoles(@Nonnull com.atlassian.crowd.embedded.api.Group group)
      Description copied from interface: ApplicationRoleManager
      Removes any/all associations of the given group from all ApplicationRoles (irrespective of whether the ApplicationRoles is backed by a license).
      Specified by:
      removeGroupFromRoles in interface ApplicationRoleManager
      Parameters:
      group - the group to remove.
    • isRoleInstalledAndLicensed

      public boolean isRoleInstalledAndLicensed(@Nonnull com.atlassian.application.api.ApplicationKey key)
      Description copied from interface: ApplicationRoleManager

      Determines whether an application identified by the given ApplicationKey is installed and running in this JIRA instance AND has a backing license key.

      Specified by:
      isRoleInstalledAndLicensed in interface ApplicationRoleManager
      Parameters:
      key - the key that identifies the ApplicationRole backed by a (potentially exceeded) license.
      Returns:
      true when the ApplicationRole backed by a (potentially exceeded) license has an associated application installed and running in this JIRA instance.
    • setRole

      @Nonnull public ApplicationRole setRole(@Nonnull ApplicationRole role)
      Description copied from interface: ApplicationRoleManager
      Save the passed ApplicationRole information to the database. This method will only accept the passed role if:
      1. The role is backed by a (potentially exceeded) license.
      2. The role only contains currently valid groups.
      3. The default group are not a subset of the groups in the role.
      Specified by:
      setRole in interface ApplicationRoleManager
      Parameters:
      role - the role to save.
      Returns:
      the role as persisted to the database.
    • clearConfiguration

      public void clearConfiguration(com.atlassian.application.api.ApplicationKey key)
      Specified by:
      clearConfiguration in interface com.atlassian.application.host.ApplicationConfigurationManager
    • getUserCount

      public int getUserCount(@Nonnull com.atlassian.application.api.ApplicationKey key)
      Description copied from interface: ApplicationRoleManager
      Retrieve the number of active users for the given ApplicationRole. It will uniquely count all users who are found in the groups associated with the application. The method is known to be slow in some circumstances, and to block Jira instance. It's strongly recommended to use ApplicationRoleManager.getUserCountAsync(ApplicationKey) async version of the method}
      Specified by:
      getUserCount in interface ApplicationRoleManager
      Parameters:
      key - the key that identifies the ApplicationRole.
      Returns:
      the number of active users for the given ApplicationRole, or zero if the ApplicationRole does not exist.
    • getUserCountAsync

      public int getUserCountAsync(@Nonnull com.atlassian.application.api.ApplicationKey key)
      Description copied from interface: ApplicationRoleManager
      Async version of ApplicationRoleManager.getUserCount(ApplicationKey). The method returns the last know value without waiting for the current changes to be propagated. This implementation is safer and offers a better performance. Retrieve the number of active users for the given ApplicationRole. It will uniquely count all users who are found in the groups associated with the application.
      Specified by:
      getUserCountAsync in interface ApplicationRoleManager
      Parameters:
      key - the key that identifies the ApplicationRole.
      Returns:
      the number of active users for the given ApplicationRole, or zero if the ApplicationRole does not exist.
    • getRemainingSeats

      public int getRemainingSeats(@Nonnull com.atlassian.application.api.ApplicationKey key)
      Description copied from interface: ApplicationRoleManager
      Retrieve the number of available (unoccupied) user seats for the ApplicationRole backed by a (potentially exceeded) license. The method is known to be slow in some circumstances, and to block Jira instance. It's strongly recommended to use ApplicationRoleManager.getRemainingSeatsAsync(ApplicationKey) async version of the method}
      Specified by:
      getRemainingSeats in interface ApplicationRoleManager
      Parameters:
      key - the key that identifies the licensed ApplicationRole.
      Returns:
      the number of remaining users seats. Will return zero when there are more users than seats licensed, the ApplicationRole is not valid or there are as many active users as seats in the license. When the license is unlimited, it will return minus one (-1)
      See Also:
    • getRemainingSeatsAsync

      public int getRemainingSeatsAsync(@Nonnull com.atlassian.application.api.ApplicationKey key)
      Description copied from interface: ApplicationRoleManager
      Async version of ApplicationRoleManager.getRemainingSeats(ApplicationKey). The method returns the last know value without waiting for the current changes to be propagated. This implementation is safer and offers a better performance. Retrieve the number of available (unoccupied) user seats for the ApplicationRole backed by a (potentially exceeded) license.
      Specified by:
      getRemainingSeatsAsync in interface ApplicationRoleManager
      Parameters:
      key - the key that identifies the licensed ApplicationRole.
      Returns:
      the number of remaining users seats. Will return zero when there are more users than seats licensed, the ApplicationRole is not valid or there are as many active users as seats in the license. When the license is unlimited, it will return minus one (-1)
      See Also:
    • hasSeatsAvailable

      public boolean hasSeatsAvailable(@Nonnull com.atlassian.application.api.ApplicationKey key, int seatCount)
      Description copied from interface: ApplicationRoleManager
      Determines whether the ApplicationRole backed by a license has the requested number of user seats available. The method is known to be slow in some circumstances, and to block Jira instance. It's strongly recommended to use ApplicationRoleManager.hasSeatsAvailableAsync(ApplicationKey, int) async version of the method}
      Specified by:
      hasSeatsAvailable in interface ApplicationRoleManager
      Parameters:
      key - the key that identifies the ApplicationRole.
      seatCount - the number of user seats that this ApplicationRole should have capacity for.
      Returns:
      true if the ApplicationRole for the provided ApplicationKey has the number of user seats available. false if the there are not enough seats available.
    • hasSeatsAvailableAsync

      public boolean hasSeatsAvailableAsync(@Nonnull com.atlassian.application.api.ApplicationKey key, int seatCount)
      Description copied from interface: ApplicationRoleManager
      Async version of ApplicationRoleManager.hasSeatsAvailable(ApplicationKey, int). The method returns the last know value without waiting for the current changes to be propagated. This implementation is safer and offers a better performance. Determines whether the ApplicationRole backed by a license has the requested number of user seats available.
      Specified by:
      hasSeatsAvailableAsync in interface ApplicationRoleManager
      Parameters:
      key - the key that identifies the ApplicationRole.
      seatCount - the number of user seats that this ApplicationRole should have capacity for.
      Returns:
      true if the ApplicationRole for the provided ApplicationKey has the number of user seats available. false if the there are not enough seats available.
    • getDefaultGroups

      @Nonnull public Set<com.atlassian.crowd.embedded.api.Group> getDefaultGroups(@Nonnull com.atlassian.application.api.ApplicationKey key)
      Description copied from interface: ApplicationRoleManager
      Get the default Groups associated with the ApplicationRole backed by a (potentially exceeded) license.
      Specified by:
      getDefaultGroups in interface ApplicationRoleManager
      Parameters:
      key - the key that identifies the ApplicationRole.
      Returns:
      the Set of default groups associated with the ApplicationRole.
    • onClearCache

      @EventListener public void onClearCache(ClearCacheEvent event)
    • onApplicationDefined

      @EventListener public void onApplicationDefined(com.atlassian.application.host.events.ApplicationDefinedEvent event)
    • onApplicationUndefined

      @EventListener public void onApplicationUndefined(com.atlassian.application.host.events.ApplicationUndefinedEvent event)
    • onLicenseChanged

      @EventListener public void onLicenseChanged(LicenseChangedEvent event)
    • onGroupCreated

      @EventListener public void onGroupCreated(com.atlassian.crowd.event.group.GroupCreatedEvent createdEvent)
    • onGroupDeleted

      @EventListener public void onGroupDeleted(com.atlassian.crowd.event.group.GroupDeletedEvent deletedEvent)
    • onGroupUpdated

      @EventListener public void onGroupUpdated(com.atlassian.crowd.event.group.GroupUpdatedEvent updatedEvent)
    • onDirectoryReorder

      @EventListener public void onDirectoryReorder(com.atlassian.crowd.event.application.ApplicationDirectoryOrderUpdatedEvent event)
    • onDirectoryUpdated

      @EventListener public void onDirectoryUpdated(com.atlassian.crowd.event.directory.DirectoryUpdatedEvent event)
    • onGroupMembershipsCreated

      @EventListener public void onGroupMembershipsCreated(com.atlassian.crowd.event.group.GroupMembershipsCreatedEvent e)
    • onGroupMembershipDeleted

      @EventListener public void onGroupMembershipDeleted(com.atlassian.crowd.event.group.GroupMembershipDeletedEvent e)
    • onUserDeleted

      @EventListener public void onUserDeleted(com.atlassian.crowd.event.user.UserDeletedEvent e)
    • onUserUpdated

      @EventListener public void onUserUpdated(com.atlassian.crowd.event.user.UserEditedEvent event)
    • onUserUpdated

      @EventListener public void onUserUpdated(com.atlassian.crowd.event.user.AutoUserUpdatedEvent event)
    • onSyncFinished

      @EventListener public void onSyncFinished(com.atlassian.crowd.event.directory.RemoteDirectorySynchronisationFinishedEvent e)
    • onComponentManagerShutdown

      @EventListener public void onComponentManagerShutdown(ComponentManagerShutdownEvent shutdownEvent)
    • clearCache

      @Internal public void clearCache()
      Description copied from interface: CachingComponent
      Clear the cache within the component.
      Specified by:
      clearCache in interface CachingComponent
    • totalBillableUsers

      public int totalBillableUsers()
      Description copied from interface: LicenseCountService
      Gets the number of active users who currently count towards the license and should be charged for. This method should be used when determining user counts for billing purposes, such as purchase tier recommendations for plugins, and by plugins who wish to enforce tier-based licenses.

      Implementations of this method should take performance into consideration, and ensure that the value is cached. Use LicenseCountService.flush() to clear the cache.

      Specified by:
      totalBillableUsers in interface LicenseCountService
      Returns:
      the number of users in JIRA which currently count against at least one license
      See Also:
    • flush

      public void flush()
      Description copied from interface: LicenseCountService
      Clear the billable users cache. Note, despite the general name this clears only the billable users cache. Usually it is not necessary to call this method as implementors are expected to clear cached state in response to appropriate events.
      Specified by:
      flush in interface LicenseCountService
    • flushBillableUsersCache

      public void flushBillableUsersCache()
      Description copied from interface: LicenseCountService
      Clear the cache for billable users. Usually it is not necessary to call this method as implementors are expected to clear cached state in response to appropriate events.
      Specified by:
      flushBillableUsersCache in interface LicenseCountService