fix(licensing): stop persisting the capacity breakdown

db-migration-test failed on all three upgrade fixtures (v2.0.0, v2.5.0,
v2.10.0) with: Column "ULS1_0.SERVER_QUANTITY" not found.

ddl-auto=update cannot add a NOT NULL column to a table that already holds
rows, and user_license_settings always does - it is a singleton created at
first boot. Hibernate logs the failed ALTER and carries on, so the column
never exists and the next SELECT blows up. Every upgrading installation would
have hit this, not just the fixtures.

server_quantity and user_block_size are display-only; the enforced limit is
licenseMaxUsers, which is unchanged. They do not need to be in the database at
all. ApplicationProperties.Premium already holds them, repopulated on every
licence verification - at boot and on the weekly refresh - so the admin payload
can read them straight off the verified licence.

That removes the schema change entirely rather than working around it with a
column default, which is the smaller and safer fix.

Also resets the breakdown at the top of verifyLicense. Without persistence the
values live only in memory, so removing or invalidating a licence would
otherwise leave the previous server count there and the UI would keep reporting
capacity the installation no longer has.
This commit is contained in:
Connor Yoh
2026-08-28 17:04:37 +01:00
parent 06f2e0f0b2
commit 036fa7a157
4 changed files with 12 additions and 30 deletions
@@ -39,7 +39,6 @@ import stirling.software.proprietary.audit.AuditLevel;
import stirling.software.proprietary.config.AuditConfigurationProperties;
import stirling.software.proprietary.model.Team;
import stirling.software.proprietary.model.TeamMembership;
import stirling.software.proprietary.model.UserLicenseSettings;
import stirling.software.proprietary.model.dto.TeamWithUserCountDTO;
import stirling.software.proprietary.repository.PersistentAuditEventRepository;
import stirling.software.proprietary.security.config.EnterpriseEndpoint;
@@ -348,8 +347,7 @@ public class ProprietaryUIDataController {
int maxAllowedUsers = licenseSettingsService.calculateMaxAllowedUsers();
long availableSlots = licenseSettingsService.getAvailableUserSlots();
int grandfatheredCount = licenseSettingsService.getDisplayGrandfatheredCount();
UserLicenseSettings licenseSettings = licenseSettingsService.getSettings();
int licenseMaxUsers = licenseSettings.getLicenseMaxUsers();
int licenseMaxUsers = licenseSettingsService.getSettings().getLicenseMaxUsers();
boolean premiumEnabled = applicationProperties.getPremium().isEnabled();
long pendingInvites = inviteTokenRepository.countActiveInvites(LocalDateTime.now());
@@ -394,8 +392,10 @@ public class ProprietaryUIDataController {
data.setAvailableSlots(availableSlots);
data.setGrandfatheredUserCount(grandfatheredCount);
data.setLicenseMaxUsers(licenseMaxUsers);
data.setServerQuantity(licenseSettings.getServerQuantity());
data.setUserBlockSize(licenseSettings.getUserBlockSize());
// Read straight off the verified licence rather than the settings row: these are display
// fields, repopulated on every licence check, and not worth a schema change.
data.setServerQuantity(applicationProperties.getPremium().getServerQuantity());
data.setUserBlockSize(applicationProperties.getPremium().getUserBlockSize());
data.setPendingInvites(pendingInvites);
data.setPremiumEnabled(premiumEnabled);
data.setMailEnabled(applicationProperties.getMail().isEnabled());
@@ -49,17 +49,6 @@ public class UserLicenseSettings implements Serializable {
@Column(name = "license_max_users", nullable = false)
private int licenseMaxUsers = 0;
/**
* Servers purchased and users granted per server, from licence metadata. Presentation only, so
* the capacity UI can say "2 servers, 100 users each" between the weekly Keygen refreshes.
* {@code licenseMaxUsers} stays the enforced limit. Zero on any licence issued before the cap.
*/
@Column(name = "server_quantity", nullable = false)
private int serverQuantity = 0;
@Column(name = "user_block_size", nullable = false)
private int userBlockSize = 0;
/**
* Random salt used when generating signatures. Makes it harder to recompute the signature when
* manually editing the table.
@@ -84,6 +84,11 @@ public class KeygenLicenseVerifier {
}
public License verifyLicense(String licenseKeyOrCert) {
// Clear last verification's breakdown up front. Without this, removing or invalidating a
// licence leaves the previous server count in memory and the UI keeps reporting capacity
// the installation no longer has. Each parse path sets real values below.
applyCapacityBreakdown(null);
if (!applicationProperties.getPremium().isEnabled()) {
return License.NORMAL;
}
@@ -156,26 +156,14 @@ public class UserLicenseSettingsService {
UserLicenseSettings settings = getOrCreateSettings();
int licenseMaxUsers = 0;
int serverQuantity = 0;
int userBlockSize = 0;
if (hasPaidLicense()) {
licenseMaxUsers = applicationProperties.getPremium().getMaxUsers();
serverQuantity = applicationProperties.getPremium().getServerQuantity();
userBlockSize = applicationProperties.getPremium().getUserBlockSize();
}
if (settings.getLicenseMaxUsers() != licenseMaxUsers
|| settings.getServerQuantity() != serverQuantity
|| settings.getUserBlockSize() != userBlockSize) {
if (settings.getLicenseMaxUsers() != licenseMaxUsers) {
settings.setLicenseMaxUsers(licenseMaxUsers);
settings.setServerQuantity(serverQuantity);
settings.setUserBlockSize(userBlockSize);
settingsRepository.save(settings);
log.info(
"Updated license capacity: maxUsers={}, servers={}, usersPerServer={}",
licenseMaxUsers,
serverQuantity,
userBlockSize);
log.info("Updated license max users to: {}", licenseMaxUsers);
}
}