2024-09-13 16:42:38 +01:00
|
|
|
package stirling.software.SPDF.EE;
|
|
|
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
2024-11-29 15:11:59 +00:00
|
|
|
import org.springframework.core.Ordered;
|
|
|
|
import org.springframework.core.annotation.Order;
|
2024-09-13 16:42:38 +01:00
|
|
|
|
2024-10-22 12:22:08 +01:00
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2025-02-23 13:36:21 +00:00
|
|
|
|
2024-09-13 16:42:38 +01:00
|
|
|
import stirling.software.SPDF.model.ApplicationProperties;
|
2025-03-25 17:57:17 +00:00
|
|
|
import stirling.software.SPDF.model.ApplicationProperties.EnterpriseEdition;
|
|
|
|
import stirling.software.SPDF.model.ApplicationProperties.Premium;
|
2024-09-13 16:42:38 +01:00
|
|
|
|
|
|
|
@Configuration
|
2024-11-29 15:11:59 +00:00
|
|
|
@Order(Ordered.HIGHEST_PRECEDENCE)
|
2024-10-22 12:22:08 +01:00
|
|
|
@Slf4j
|
2024-09-13 16:42:38 +01:00
|
|
|
public class EEAppConfig {
|
|
|
|
|
2024-12-24 09:52:53 +00:00
|
|
|
private final ApplicationProperties applicationProperties;
|
|
|
|
|
|
|
|
private final LicenseKeyChecker licenseKeyChecker;
|
|
|
|
|
|
|
|
public EEAppConfig(
|
|
|
|
ApplicationProperties applicationProperties, LicenseKeyChecker licenseKeyChecker) {
|
|
|
|
this.applicationProperties = applicationProperties;
|
|
|
|
this.licenseKeyChecker = licenseKeyChecker;
|
2025-03-25 17:57:17 +00:00
|
|
|
migrateEnterpriseSettingsToPremium(this.applicationProperties);
|
2024-12-24 09:52:53 +00:00
|
|
|
}
|
2024-10-14 22:34:41 +01:00
|
|
|
|
|
|
|
@Bean(name = "runningEE")
|
2024-09-13 16:42:38 +01:00
|
|
|
public boolean runningEnterpriseEdition() {
|
2025-01-17 12:25:02 +00:00
|
|
|
return licenseKeyChecker.getEnterpriseEnabledResult();
|
2024-09-13 16:42:38 +01:00
|
|
|
}
|
2025-01-09 14:40:51 +00:00
|
|
|
|
|
|
|
@Bean(name = "SSOAutoLogin")
|
|
|
|
public boolean ssoAutoLogin() {
|
2025-03-25 17:57:17 +00:00
|
|
|
return applicationProperties.getPremium().getProFeatures().isSsoAutoLogin();
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Remove post migration
|
|
|
|
public void migrateEnterpriseSettingsToPremium(ApplicationProperties applicationProperties) {
|
|
|
|
EnterpriseEdition enterpriseEdition = applicationProperties.getEnterpriseEdition();
|
|
|
|
Premium premium = applicationProperties.getPremium();
|
|
|
|
|
|
|
|
// Only proceed if both objects exist
|
|
|
|
if (enterpriseEdition == null || premium == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the license key if it's set in enterprise but not in premium
|
|
|
|
if (premium.getKey() == null
|
|
|
|
|| premium.getKey().equals("00000000-0000-0000-0000-000000000000")) {
|
|
|
|
if (enterpriseEdition.getKey() != null
|
|
|
|
&& !enterpriseEdition.getKey().equals("00000000-0000-0000-0000-000000000000")) {
|
|
|
|
premium.setKey(enterpriseEdition.getKey());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy enabled state if enterprise is enabled but premium is not
|
|
|
|
if (!premium.isEnabled() && enterpriseEdition.isEnabled()) {
|
|
|
|
premium.setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy SSO auto login setting
|
|
|
|
if (!premium.getProFeatures().isSsoAutoLogin() && enterpriseEdition.isSsoAutoLogin()) {
|
|
|
|
premium.getProFeatures().setSsoAutoLogin(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy CustomMetadata settings
|
|
|
|
Premium.ProFeatures.CustomMetadata premiumMetadata =
|
|
|
|
premium.getProFeatures().getCustomMetadata();
|
|
|
|
EnterpriseEdition.CustomMetadata enterpriseMetadata = enterpriseEdition.getCustomMetadata();
|
|
|
|
|
|
|
|
if (enterpriseMetadata != null && premiumMetadata != null) {
|
|
|
|
// Copy autoUpdateMetadata setting
|
|
|
|
if (!premiumMetadata.isAutoUpdateMetadata()
|
|
|
|
&& enterpriseMetadata.isAutoUpdateMetadata()) {
|
|
|
|
premiumMetadata.setAutoUpdateMetadata(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy author if not set in premium but set in enterprise
|
|
|
|
if ((premiumMetadata.getAuthor() == null
|
|
|
|
|| premiumMetadata.getAuthor().trim().isEmpty()
|
|
|
|
|| "username".equals(premiumMetadata.getAuthor()))
|
|
|
|
&& enterpriseMetadata.getAuthor() != null
|
|
|
|
&& !enterpriseMetadata.getAuthor().trim().isEmpty()) {
|
|
|
|
premiumMetadata.setAuthor(enterpriseMetadata.getAuthor());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy creator if not set in premium but set in enterprise and different from default
|
|
|
|
if ((premiumMetadata.getCreator() == null
|
|
|
|
|| "Stirling-PDF".equals(premiumMetadata.getCreator()))
|
|
|
|
&& enterpriseMetadata.getCreator() != null
|
|
|
|
&& !"Stirling-PDF".equals(enterpriseMetadata.getCreator())) {
|
|
|
|
premiumMetadata.setCreator(enterpriseMetadata.getCreator());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy producer if not set in premium but set in enterprise and different from default
|
|
|
|
if ((premiumMetadata.getProducer() == null
|
|
|
|
|| "Stirling-PDF".equals(premiumMetadata.getProducer()))
|
|
|
|
&& enterpriseMetadata.getProducer() != null
|
|
|
|
&& !"Stirling-PDF".equals(enterpriseMetadata.getProducer())) {
|
|
|
|
premiumMetadata.setProducer(enterpriseMetadata.getProducer());
|
|
|
|
}
|
|
|
|
}
|
2025-01-09 14:40:51 +00:00
|
|
|
}
|
2024-10-23 07:17:40 -04:00
|
|
|
}
|