Stirling-PDF/src/main/java/stirling/software/SPDF/model/ApplicationProperties.java

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

241 lines
8.4 KiB
Java
Raw Normal View History

2023-08-26 17:30:49 +01:00
package stirling.software.SPDF.model;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
2023-08-27 00:39:22 +01:00
import java.util.List;
import java.util.stream.Collectors;
2023-08-27 00:39:22 +01:00
2024-05-25 18:19:03 +02:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
2023-08-26 17:30:49 +01:00
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
2024-10-14 22:34:41 +01:00
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
2023-08-26 17:30:49 +01:00
import lombok.Data;
import lombok.ToString;
2023-08-26 17:30:49 +01:00
import stirling.software.SPDF.config.YamlPropertySourceFactory;
import stirling.software.SPDF.model.provider.GithubProvider;
import stirling.software.SPDF.model.provider.GoogleProvider;
import stirling.software.SPDF.model.provider.KeycloakProvider;
import stirling.software.SPDF.model.provider.UnsupportedProviderException;
2023-08-26 17:30:49 +01:00
@Configuration
@ConfigurationProperties(prefix = "")
2023-08-26 22:33:23 +01:00
@PropertySource(value = "file:./configs/settings.yml", factory = YamlPropertySourceFactory.class)
@Data
2024-10-14 22:34:41 +01:00
@Order(Ordered.HIGHEST_PRECEDENCE)
2023-08-26 17:30:49 +01:00
public class ApplicationProperties {
2023-12-30 19:11:27 +00:00
private Legal legal = new Legal();
private Security security = new Security();
private System system = new System();
private Ui ui = new Ui();
private Endpoints endpoints = new Endpoints();
private Metrics metrics = new Metrics();
private AutomaticallyGenerated automaticallyGenerated = new AutomaticallyGenerated();
private EnterpriseEdition enterpriseEdition = new EnterpriseEdition();
private AutoPipeline autoPipeline = new AutoPipeline();
private static final Logger logger = LoggerFactory.getLogger(ApplicationProperties.class);
2023-12-30 19:11:27 +00:00
@Data
2023-08-26 22:33:23 +01:00
public static class AutoPipeline {
private String outputFolder;
}
2023-12-30 19:11:27 +00:00
@Data
public static class Legal {
private String termsAndConditions;
private String privacyPolicy;
private String accessibilityStatement;
private String cookiePolicy;
private String impressum;
2023-12-30 19:11:27 +00:00
}
@Data
2023-08-26 17:30:49 +01:00
public static class Security {
private Boolean enableLogin;
private Boolean csrfDisabled;
private InitialLogin initialLogin = new InitialLogin();
private OAUTH2 oauth2 = new OAUTH2();
2024-10-14 22:34:41 +01:00
private SAML saml = new SAML();
2023-12-29 20:48:21 +00:00
private int loginAttemptCount;
private long loginResetTimeMinutes;
private String loginMethod = "all";
@Data
2023-09-29 23:58:37 +01:00
public static class InitialLogin {
private String username;
@ToString.Exclude private String password;
2023-12-30 19:11:27 +00:00
}
2024-10-14 22:34:41 +01:00
@Data
public static class SAML {
private Boolean enabled = false;
private String entityId;
private String registrationId;
private String spBaseUrl;
private String idpMetadataLocation;
private KeyStore keystore;
@Data
public static class KeyStore {
private String keystoreLocation;
private String keystorePassword;
private String keyAlias;
private String keyPassword;
private String realmCertificateAlias;
public Resource getKeystoreResource() {
if (keystoreLocation.startsWith("classpath:")) {
return new ClassPathResource(
keystoreLocation.substring("classpath:".length()));
} else {
return new FileSystemResource(keystoreLocation);
}
}
}
}
@Data
public static class OAUTH2 {
2024-05-25 18:19:03 +02:00
private Boolean enabled = false;
private String issuer;
private String clientId;
@ToString.Exclude private String clientSecret;
2024-05-25 18:19:03 +02:00
private Boolean autoCreateUser = false;
private Boolean blockRegistration = false;
private String useAsUsername;
2024-05-25 18:19:03 +02:00
private Collection<String> scopes = new ArrayList<>();
private String provider;
2024-05-25 18:19:03 +02:00
private Client client = new Client();
2024-05-25 18:19:03 +02:00
public void setScopes(String scopes) {
List<String> scopesList =
2024-05-25 18:19:03 +02:00
Arrays.stream(scopes.split(","))
.map(String::trim)
.collect(Collectors.toList());
this.scopes.addAll(scopesList);
}
2024-05-25 18:19:03 +02:00
protected boolean isValid(String value, String name) {
return value != null && !value.trim().isEmpty();
2024-05-25 18:19:03 +02:00
}
protected boolean isValid(Collection<String> value, String name) {
return value != null && !value.isEmpty();
2024-05-25 18:19:03 +02:00
}
public boolean isSettingsValid() {
return isValid(this.getIssuer(), "issuer")
&& isValid(this.getClientId(), "clientId")
&& isValid(this.getClientSecret(), "clientSecret")
&& isValid(this.getScopes(), "scopes")
&& isValid(this.getUseAsUsername(), "useAsUsername");
}
@Data
2024-05-25 18:19:03 +02:00
public static class Client {
private GoogleProvider google = new GoogleProvider();
private GithubProvider github = new GithubProvider();
private KeycloakProvider keycloak = new KeycloakProvider();
public Provider get(String registrationId) throws UnsupportedProviderException {
switch (registrationId.toLowerCase()) {
case "google":
2024-05-25 18:19:03 +02:00
return getGoogle();
case "github":
return getGithub();
case "keycloak":
return getKeycloak();
default:
throw new UnsupportedProviderException(
"Logout from the provider is not supported? Report it at https://github.com/Stirling-Tools/Stirling-PDF/issues");
2024-05-25 18:19:03 +02:00
}
}
}
}
}
@Data
2023-08-26 17:30:49 +01:00
public static class System {
private String defaultLocale;
private Boolean googlevisibility;
private boolean showUpdate;
private Boolean showUpdateOnlyAdmin;
private boolean customHTMLFiles;
private String tessdataDir;
2023-12-26 20:10:37 +00:00
private Boolean enableAlphaFunctionality;
2024-10-14 22:34:41 +01:00
private String enableAnalytics;
2023-12-30 19:11:27 +00:00
}
@Data
2023-08-26 17:30:49 +01:00
public static class Ui {
2023-08-27 00:38:17 +01:00
private String appName;
private String homeDescription;
private String appNameNavbar;
2023-12-30 19:11:27 +00:00
2023-08-27 00:38:17 +01:00
public String getAppName() {
return appName != null && appName.trim().length() > 0 ? appName : null;
2023-08-27 00:38:17 +01:00
}
2023-12-30 19:11:27 +00:00
2023-08-27 00:38:17 +01:00
public String getHomeDescription() {
return homeDescription != null && homeDescription.trim().length() > 0
? homeDescription
: null;
2023-08-27 00:38:17 +01:00
}
2023-12-30 19:11:27 +00:00
2023-08-27 00:38:17 +01:00
public String getAppNameNavbar() {
return appNameNavbar != null && appNameNavbar.trim().length() > 0
? appNameNavbar
: null;
2023-08-26 17:30:49 +01:00
}
2023-12-30 19:11:27 +00:00
}
@Data
2023-08-26 17:30:49 +01:00
public static class Endpoints {
private List<String> toRemove;
private List<String> groupsToRemove;
2023-12-30 19:11:27 +00:00
}
@Data
2023-08-26 17:30:49 +01:00
public static class Metrics {
private Boolean enabled;
}
2023-12-30 19:11:27 +00:00
@Data
2023-08-26 17:30:49 +01:00
public static class AutomaticallyGenerated {
@ToString.Exclude private String key;
2024-10-14 22:34:41 +01:00
private String UUID;
}
2023-12-30 19:11:27 +00:00
@Data
public static class EnterpriseEdition {
2024-10-14 22:34:41 +01:00
private boolean enabled;
@ToString.Exclude private String key;
2024-10-14 22:34:41 +01:00
private int maxUsers;
private CustomMetadata customMetadata = new CustomMetadata();
2023-12-30 19:11:27 +00:00
@Data
public static class CustomMetadata {
private boolean autoUpdateMetadata;
private String author;
private String creator;
private String producer;
2023-12-30 19:11:27 +00:00
public String getCreator() {
return creator == null || creator.trim().isEmpty() ? "Stirling-PDF" : creator;
}
public String getProducer() {
return producer == null || producer.trim().isEmpty() ? "Stirling-PDF" : producer;
}
2023-08-26 17:30:49 +01:00
}
}
}