public class

DefaultApplicationRoleManager

extends Object
implements ApplicationConfigurationManager CachingComponent ApplicationRoleManager LicenseCountService
java.lang.Object
   ↳ com.atlassian.jira.application.DefaultApplicationRoleManager

Class Overview

Default implementation of ApplicationRoleManager.

Summary

Public Constructors
DefaultApplicationRoleManager(CacheManager cacheManager, ApplicationRoleStore store, ApplicationRoleDefinitions definitions, GroupManager groupManager, JiraLicenseManager licenseManager, FeatureManager featureManager, RecoveryMode recoveryMode, CrowdService crowdService, EventPublisher eventPublisher, InternalMembershipDao internalMembershipDao, DirectoryDao directoryDao, OfBizUserDao ofBizUserDao, OfBizTransactionManager ofBizTransactionManager)
Public Methods
@Internal void clearCache()
Clear the cache within the component.
void clearConfiguration(ApplicationKey key)
void flush()
Clear the billable users cache.
void flushBillableUsersCache()
Clear the cache for billable users.
@Nonnull Set<ApplicationKey> getDefaultApplicationKeys()
Returns an immutable Set of ApplicationKeys that are configured as the default applications for new users.
@Nonnull Set<Group> getDefaultGroups(ApplicationKey key)
Get the default Groups associated with the ApplicationRole backed by a (potentially exceeded) license.
@Nonnull @Deprecated Set<ApplicationRole> getDefaultRoles()
Returns an immutable Set of ApplicationRoles that are configured be default for new users.
@Nonnull Set<Group> getGroupsForLicensedRoles()
Get the Set of group names that have been associated with all the ApplicationRoles that have a backing (but potentially exceeded) license.
Set<ApplicationRole> getOccupiedLicenseRolesForUser(ApplicationUser user)
Returns the Set of ApplicationRoles that the given ApplicationUser occupies seats in.
int getRemainingSeats(ApplicationKey key)
Retrieve the number of available (unoccupied) user seats for the ApplicationRole backed by a (potentially exceeded) license.
@Nonnull Option<ApplicationRole> getRole(ApplicationKey role)
Returns the ApplicationRole identified by the given com.atlassian.application.api.ApplicationKey, or none() if no such ApplicationRole exists.
@Nonnull Set<ApplicationRole> getRoles()
Returns an immutable Set of all ApplicationRoles that are backed by a (potentially exceeded) license.
Set<ApplicationRole> getRolesForGroup(Group group)
Returns the Set of ApplicationRoles associated with the given Group, or groups for which the given group is a nested group (sub-group).
Set<ApplicationRole> getRolesForUser(ApplicationUser user)
Returns the Set of ApplicationRoles granted to the given ApplicationUser.
int getUserCount(ApplicationKey key)
Retrieve the number of active users for the given ApplicationRole.
boolean hasAnyRole(ApplicationUser user)
Returns true if the given user has been assigned to any ApplicationRole that is backed by a (potentially exceeded) license.
boolean hasExceededAllRoles(ApplicationUser user)
Returns true if the user limits of all of the given user's assigned ApplicationRoles have been exceeded.
boolean hasSeatsAvailable(ApplicationKey key, int seatCount)
Determines whether the ApplicationRole backed by a license has the requested number of user seats available.
boolean isAnyRoleLimitExceeded()
Returns true if the number of users assigned to any ApplicationRole exceeds the number of seats granted to that role by its license.
boolean isRoleInstalledAndLicensed(ApplicationKey key)

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

boolean isRoleLimitExceeded(ApplicationKey role)
Returns true if the number of users assigned to the given ApplicationRole exceeds the number of seats granted by its license.
@EventListener void onApplicationDefined(ApplicationDefinedEvent event)
@EventListener void onApplicationUndefined(ApplicationUndefinedEvent event)
@EventListener void onClearCache(ClearCacheEvent event)
@EventListener void onDirectoryReorder(ApplicationDirectoryOrderUpdatedEvent event)
@EventListener void onDirectoryUpdated(DirectoryUpdatedEvent event)
@EventListener void onGroupCreated(GroupCreatedEvent createdEvent)
@EventListener void onGroupDeleted(GroupDeletedEvent deletedEvent)
@EventListener void onGroupMembershipCreated(GroupMembershipCreatedEvent e)
@EventListener void onGroupMembershipDeleted(GroupMembershipDeletedEvent e)
@EventListener void onGroupUpdated(GroupUpdatedEvent updatedEvent)
@EventListener void onLicenseChanged(LicenseChangedEvent event)
@EventListener void onUserDeleted(UserDeletedEvent e)
@EventListener void onUserUpdated(UserEditedEvent event)
@EventListener void onUserUpdated(AutoUserUpdatedEvent event)
void removeGroupFromRoles(Group group)
Removes any/all associations of the given group from all ApplicationRoles (irrespective of whether the ApplicationRoles is backed by a license).
boolean rolesEnabled()
Determines whether ApplicationRoles are enabled.
@Nonnull ApplicationRole setRole(ApplicationRole role)
Save the passed ApplicationRole information to the database.
int totalBillableUsers()
Gets the number of active users who currently count towards the license and should be charged for.
boolean userHasRole(ApplicationUser user, ApplicationKey key)
Returns true if the passed user belongs to the ApplicationRole associated with the given key.
boolean userOccupiesRole(ApplicationUser user, ApplicationKey key)
Returns true if the passed user occupies a seat in the ApplicationRole associated with the given key.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.atlassian.application.host.ApplicationConfigurationManager
From interface com.atlassian.jira.CachingComponent
From interface com.atlassian.jira.application.ApplicationRoleManager
From interface com.atlassian.jira.license.LicenseCountService

Public Constructors

public DefaultApplicationRoleManager (CacheManager cacheManager, ApplicationRoleStore store, ApplicationRoleDefinitions definitions, GroupManager groupManager, JiraLicenseManager licenseManager, FeatureManager featureManager, RecoveryMode recoveryMode, CrowdService crowdService, EventPublisher eventPublisher, InternalMembershipDao internalMembershipDao, DirectoryDao directoryDao, OfBizUserDao ofBizUserDao, OfBizTransactionManager ofBizTransactionManager)

Public Methods

@Internal public void clearCache ()

@Internal

This method is an internal implementation detail and will change without notice.

Clients that depend on @Internal classes and interfaces can not expect to be compatible with any version other than the version they were compiled against (even minor version and milestone releases may break binary compatibility with respect to @Internal elements).

Clear the cache within the component.

public void clearConfiguration (ApplicationKey key)

public void flush ()

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.

public void flushBillableUsersCache ()

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.

@Nonnull public Set<ApplicationKey> getDefaultApplicationKeys ()

Returns an immutable Set of ApplicationKeys that are configured as the default applications for new users.

Returns
  • the Set of ApplicationKeys that are configured as the default applications for new users.

@Nonnull public Set<Group> getDefaultGroups (ApplicationKey key)

Get the default Groups associated with the ApplicationRole backed by a (potentially exceeded) license.

Parameters
key the key that identifies the ApplicationRole.
Returns
  • the Set of default groups associated with the ApplicationRole.

@Nonnull @Deprecated public Set<ApplicationRole> getDefaultRoles ()

Returns an immutable Set of ApplicationRoles that are configured be default for new users.

Returns

@Nonnull public Set<Group> getGroupsForLicensedRoles ()

Get the Set of group names that have been associated with all the ApplicationRoles that have a backing (but potentially exceeded) license.

Returns
  • Groups associated with all the ApplicationRoles that have a backing (but potentially exceeded) license.

public Set<ApplicationRole> getOccupiedLicenseRolesForUser (ApplicationUser user)

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.

Parameters
user the user whose roles will be checked.
Returns

public int getRemainingSeats (ApplicationKey key)

Retrieve the number of available (unoccupied) user seats for the ApplicationRole backed by a (potentially exceeded) license.

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)

@Nonnull public Option<ApplicationRole> getRole (ApplicationKey role)

Returns the ApplicationRole identified by the given com.atlassian.application.api.ApplicationKey, or 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.

Parameters
role the com.atlassian.application.api.ApplicationKey of the role to search for.
Returns

@Nonnull public Set<ApplicationRole> getRoles ()

Returns an immutable Set of all ApplicationRoles that are backed by a (potentially exceeded) license.

Returns

public Set<ApplicationRole> getRolesForGroup (Group group)

Returns the Set of ApplicationRoles associated with the given Group, or groups for which the given group is a nested group (sub-group).

Parameters
group the group which roles will be checked.
Returns

public Set<ApplicationRole> getRolesForUser (ApplicationUser user)

Returns the Set of ApplicationRoles granted to the given ApplicationUser.

Parameters
user the user whose roles will be checked.
Returns

public int getUserCount (ApplicationKey key)

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.

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.

public boolean hasAnyRole (ApplicationUser user)

Returns true if the given user has been assigned to any ApplicationRole that is backed by a (potentially exceeded) license.

Returns
  • true if the given user has been assigned to any ApplicationRole that is backed by a (potentially exceeded) license.

public boolean hasExceededAllRoles (ApplicationUser user)

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.

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.

public boolean hasSeatsAvailable (ApplicationKey key, int seatCount)

Determines whether the ApplicationRole backed by a license has the requested number of user seats available.

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.

public boolean isAnyRoleLimitExceeded ()

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.

Returns
  • true if the number of users for any role is greater than the number of seats granted to that role by its license.

public boolean isRoleInstalledAndLicensed (ApplicationKey key)

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

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.

public boolean isRoleLimitExceeded (ApplicationKey role)

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.

Parameters
role the identifier of the ApplicationRole.
Returns

@EventListener public void onApplicationDefined (ApplicationDefinedEvent event)

@EventListener public void onApplicationUndefined (ApplicationUndefinedEvent event)

@EventListener public void onClearCache (ClearCacheEvent event)

@EventListener public void onDirectoryReorder (ApplicationDirectoryOrderUpdatedEvent event)

@EventListener public void onDirectoryUpdated (DirectoryUpdatedEvent event)

@EventListener public void onGroupCreated (GroupCreatedEvent createdEvent)

@EventListener public void onGroupDeleted (GroupDeletedEvent deletedEvent)

@EventListener public void onGroupMembershipCreated (GroupMembershipCreatedEvent e)

@EventListener public void onGroupMembershipDeleted (GroupMembershipDeletedEvent e)

@EventListener public void onGroupUpdated (GroupUpdatedEvent updatedEvent)

@EventListener public void onLicenseChanged (LicenseChangedEvent event)

@EventListener public void onUserDeleted (UserDeletedEvent e)

@EventListener public void onUserUpdated (UserEditedEvent event)

@EventListener public void onUserUpdated (AutoUserUpdatedEvent event)

public void removeGroupFromRoles (Group group)

Removes any/all associations of the given group from all ApplicationRoles (irrespective of whether the ApplicationRoles is backed by a license).

Parameters
group the group to remove.

public boolean rolesEnabled ()

Determines whether ApplicationRoles are enabled.

Returns
  • true when ApplicationRole are enabled, false otherwise.

@Nonnull public ApplicationRole setRole (ApplicationRole role)

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.

Parameters
role the role to save.
Returns
  • the role as persisted to the database.

public int totalBillableUsers ()

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.

In all cases this method will exclude Connect users from the count. In Cloud this will also exclude users who exist for the purpose of providing support (such as the Atlassian sysadmin user).

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

Returns
  • the number of users in JIRA which currently count against at least one license

public boolean userHasRole (ApplicationUser user, ApplicationKey key)

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.

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

public boolean userOccupiesRole (ApplicationUser user, ApplicationKey key)

Returns true if the passed user occupies a seat in the ApplicationRole associated with the given key.

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