diff --git a/src/main/java/stirling/software/SPDF/config/InitialSetup.java b/src/main/java/stirling/software/SPDF/config/InitialSetup.java index 043b08c9..4be2e5e6 100644 --- a/src/main/java/stirling/software/SPDF/config/InitialSetup.java +++ b/src/main/java/stirling/software/SPDF/config/InitialSetup.java @@ -8,6 +8,7 @@ import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; +import io.micrometer.common.util.StringUtils; import jakarta.annotation.PostConstruct; import lombok.extern.slf4j.Slf4j; import stirling.software.SPDF.model.ApplicationProperties; @@ -39,4 +40,26 @@ public class InitialSetup { applicationProperties.getAutomaticallyGenerated().setKey(secretKey); } } + + @PostConstruct + public void initLegalUrls() throws IOException { + // Initialize Terms and Conditions + String termsUrl = applicationProperties.getLegal().getTermsAndConditions(); + if (StringUtils.isEmpty(termsUrl)) { + String defaultTermsUrl = "https://www.stirlingpdf.com/terms-and-conditions"; + GeneralUtils.saveKeyToConfig("legal.termsAndConditions", defaultTermsUrl); + applicationProperties.getLegal().setTermsAndConditions(defaultTermsUrl); + } + + // Initialize Privacy Policy + String privacyUrl = applicationProperties.getLegal().getPrivacyPolicy(); + if (StringUtils.isEmpty(privacyUrl)) { + String defaultPrivacyUrl = "https://www.stirlingpdf.com/privacy-policy"; + GeneralUtils.saveKeyToConfig("legal.privacyPolicy", defaultPrivacyUrl); + applicationProperties.getLegal().setPrivacyPolicy(defaultPrivacyUrl); + } + } + } + + diff --git a/src/main/java/stirling/software/SPDF/config/security/SecurityConfiguration.java b/src/main/java/stirling/software/SPDF/config/security/SecurityConfiguration.java index cc2eea45..e6b149ba 100644 --- a/src/main/java/stirling/software/SPDF/config/security/SecurityConfiguration.java +++ b/src/main/java/stirling/software/SPDF/config/security/SecurityConfiguration.java @@ -203,7 +203,7 @@ public class SecurityConfiguration { } // Handle SAML - if (applicationProperties.getSecurity().isSaml2Activ()) { + if (applicationProperties.getSecurity().isSaml2Activ() && applicationProperties.getSystem().getEnableAlphaFunctionality()) { http.authenticationProvider(samlAuthenticationProvider()); http.saml2Login( saml2 -> diff --git a/src/main/java/stirling/software/SPDF/config/security/UserService.java b/src/main/java/stirling/software/SPDF/config/security/UserService.java index bb78989f..c49002d6 100644 --- a/src/main/java/stirling/software/SPDF/config/security/UserService.java +++ b/src/main/java/stirling/software/SPDF/config/security/UserService.java @@ -45,9 +45,6 @@ public class UserService implements UserServiceInterface { @Autowired DatabaseBackupInterface databaseBackupHelper; - public long getTotalUserCount() { - return userRepository.count(); - } // Handle OAUTH2 login and user auto creation. public boolean processOAuth2PostLogin(String username, boolean autoCreateUser) @@ -362,4 +359,9 @@ public class UserService implements UserServiceInterface { return principal.toString(); } } + + @Override + public long getTotalUsersCount() { + return userRepository.count(); + } } diff --git a/src/main/java/stirling/software/SPDF/controller/api/pipeline/UserServiceInterface.java b/src/main/java/stirling/software/SPDF/controller/api/pipeline/UserServiceInterface.java index c3facb35..4ef6e6ec 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/pipeline/UserServiceInterface.java +++ b/src/main/java/stirling/software/SPDF/controller/api/pipeline/UserServiceInterface.java @@ -4,4 +4,6 @@ public interface UserServiceInterface { String getApiKeyForUser(String username); String getCurrentUsername(); + + long getTotalUsersCount(); } diff --git a/src/main/java/stirling/software/SPDF/service/PostHogService.java b/src/main/java/stirling/software/SPDF/service/PostHogService.java index 9b22cf1c..381bb014 100644 --- a/src/main/java/stirling/software/SPDF/service/PostHogService.java +++ b/src/main/java/stirling/software/SPDF/service/PostHogService.java @@ -19,6 +19,7 @@ import org.springframework.stereotype.Service; import com.posthog.java.PostHog; +import stirling.software.SPDF.controller.api.pipeline.UserServiceInterface; import stirling.software.SPDF.model.ApplicationProperties; @Service @@ -26,15 +27,18 @@ public class PostHogService { private final PostHog postHog; private final String uniqueId; private final ApplicationProperties applicationProperties; + private final UserServiceInterface userService; + @Autowired public PostHogService( PostHog postHog, @Qualifier("UUID") String uuid, - ApplicationProperties applicationProperties) { + ApplicationProperties applicationProperties, @Autowired(required = false) UserServiceInterface userService) { this.postHog = postHog; this.uniqueId = uuid; this.applicationProperties = applicationProperties; + this.userService = userService; captureSystemInfo(); } @@ -133,6 +137,11 @@ public class PostHogService { metrics.put("docker_metrics", getDockerMetrics()); } metrics.put("application_properties", captureApplicationProperties()); + + + if(userService != null) { + metrics.put("total_users_created", userService.getTotalUsersCount()); + } } catch (Exception e) { metrics.put("error", e.getMessage()); diff --git a/src/main/resources/settings.yml.template b/src/main/resources/settings.yml.template index 3ee1b928..0381d2cf 100644 --- a/src/main/resources/settings.yml.template +++ b/src/main/resources/settings.yml.template @@ -47,8 +47,8 @@ security: useAsUsername: email # Default is 'email'; custom fields can be used as the username scopes: openid, profile, email # Specify the scopes for which the application will request permissions provider: google # Set this to your OAuth provider's name, e.g., 'google' or 'keycloak' - saml2: - enabled: false + saml2: + enabled: false # Currently in alpha, not recommended for use yet, enableAlphaFunctionality must be set to true autoCreateUser: false # set to 'true' to allow auto-creation of non-existing users blockRegistration: false # set to 'true' to deny login with SSO without prior registration by an admin registrationId: stirling @@ -60,19 +60,18 @@ security: privateKey: classpath:saml-private-key.key spCert: classpath:saml-public-cert.crt -# Enterprise edition settings unused for now please ignore! enterpriseEdition: enabled: false # set to 'true' to enable enterprise edition key: 00000000-0000-0000-0000-000000000000 CustomMetadata: - autoUpdateMetadata: true # set to 'true' to automatically update metadata with below values - author: username # Supports text such as 'John Doe' or types such as username + autoUpdateMetadata: false # set to 'true' to automatically update metadata with below values + author: username # Supports text such as 'John Doe' or types such as username to autopopulate with users username creator: Stirling-PDF # Supports text such as 'Company-PDF' producer: Stirling-PDF # Supports text such as 'Company-PDF' legal: - termsAndConditions: '' # URL to the terms and conditions of your application (e.g. https://example.com/terms) Empty string to disable or filename to load from local file in static folder - privacyPolicy: '' # URL to the privacy policy of your application (e.g. https://example.com/privacy) Empty string to disable or filename to load from local file in static folder + termsAndConditions: https://www.stirlingpdf.com/terms-and-conditions # URL to the terms and conditions of your application (e.g. https://example.com/terms) Empty string to disable or filename to load from local file in static folder + privacyPolicy: https://www.stirlingpdf.com/privacy-policy # URL to the privacy policy of your application (e.g. https://example.com/privacy) Empty string to disable or filename to load from local file in static folder accessibilityStatement: '' # URL to the accessibility statement of your application (e.g. https://example.com/accessibility) Empty string to disable or filename to load from local file in static folder cookiePolicy: '' # URL to the cookie policy of your application (e.g. https://example.com/cookie) Empty string to disable or filename to load from local file in static folder impressum: '' # URL to the impressum of your application (e.g. https://example.com/impressum) Empty string to disable or filename to load from local file in static folder