Check for free licenses
Starting with version 6.1, it's possible to check the amount of available user licenses before creating a user.
When using SAML Just-In-Time provisioning, this works using a Groovy transformation on the "find User"-attribute, usually the username.

- // In this example, it's assumed that the SAML Name ID contains the username.
- // Check if the user already exists in the system and just
- // return the Name ID in this case
- def existingUser = findUserKeyByUsername(mapping.ATTR_NAMEID)
- if(existingUser != null) {
- return mapping.ATTR_NAMEID
- }
- int freeLicenses = getAvailableJiraSoftwareUserLicenses(); // Jira Software
- //int freeLicenses = getAvailableJSMUserLicenses(); // Jira Service Management
- //int freeLicenses = getAvailableJiraCoreUserLicenses(); // Jira Core
- //int freeLicenses = getAvailableBitbucketUserLicenses(); // Bitbucket
- //int freeLicenses = getAvailableConfluenceUserLicenses(); // Confluence
- // If there are less than 5 free license available, drop the user with an appropriate message
- // Which will be shown on the error page.
- if(freeLicenses < 5 ) {
- return dropAll("Not enough Licenses: $freeLicenses")
- } else {
- return mapping.ATTR_NAMEID
- }