2023-08-26 17:30:49 +01:00
|
|
|
package stirling.software.SPDF.model;
|
|
|
|
|
2024-05-12 19:58:34 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collection;
|
2023-08-27 00:39:22 +01:00
|
|
|
import java.util.List;
|
2024-05-12 19:58:34 +02:00
|
|
|
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-09-13 16:42:38 +01:00
|
|
|
import lombok.Data;
|
|
|
|
import lombok.ToString;
|
2023-08-26 17:30:49 +01:00
|
|
|
import stirling.software.SPDF.config.YamlPropertySourceFactory;
|
2024-06-15 14:15:09 +02:00
|
|
|
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)
|
2024-09-13 16:42:38 +01:00
|
|
|
@Data
|
2023-08-26 17:30:49 +01:00
|
|
|
public class ApplicationProperties {
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2024-09-13 16:42:38 +01: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
|
|
|
|
2024-09-13 16:42:38 +01:00
|
|
|
@Data
|
2023-08-26 22:33:23 +01:00
|
|
|
public static class AutoPipeline {
|
|
|
|
private String outputFolder;
|
2024-09-13 16:42:38 +01:00
|
|
|
}
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2024-09-13 16:42:38 +01: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
|
|
|
}
|
|
|
|
|
2024-09-13 16:42:38 +01:00
|
|
|
@Data
|
2023-08-26 17:30:49 +01:00
|
|
|
public static class Security {
|
|
|
|
private Boolean enableLogin;
|
|
|
|
private Boolean csrfDisabled;
|
2024-09-13 16:42:38 +01:00
|
|
|
private InitialLogin initialLogin = new InitialLogin();
|
|
|
|
private OAUTH2 oauth2 = new OAUTH2();
|
2023-12-29 20:48:21 +00:00
|
|
|
private int loginAttemptCount;
|
|
|
|
private long loginResetTimeMinutes;
|
2024-06-15 14:15:09 +02:00
|
|
|
private String loginMethod = "all";
|
|
|
|
|
2024-09-13 16:42:38 +01:00
|
|
|
@Data
|
2023-09-29 23:58:37 +01:00
|
|
|
public static class InitialLogin {
|
|
|
|
private String username;
|
2024-09-13 16:42:38 +01:00
|
|
|
@ToString.Exclude private String password;
|
2023-12-30 19:11:27 +00:00
|
|
|
}
|
2024-04-29 15:01:22 -06:00
|
|
|
|
2024-09-13 16:42:38 +01:00
|
|
|
@Data
|
2024-04-29 15:01:22 -06:00
|
|
|
public static class OAUTH2 {
|
2024-05-25 18:19:03 +02:00
|
|
|
private Boolean enabled = false;
|
2024-04-29 15:01:22 -06:00
|
|
|
private String issuer;
|
|
|
|
private String clientId;
|
2024-09-13 16:42:38 +01:00
|
|
|
@ToString.Exclude private String clientSecret;
|
2024-05-25 18:19:03 +02:00
|
|
|
private Boolean autoCreateUser = false;
|
2024-08-16 12:57:37 +02:00
|
|
|
private Boolean blockRegistration = false;
|
2024-05-12 19:58:34 +02:00
|
|
|
private String useAsUsername;
|
2024-05-25 18:19:03 +02:00
|
|
|
private Collection<String> scopes = new ArrayList<>();
|
2024-05-12 19:58:34 +02:00
|
|
|
private String provider;
|
2024-05-25 18:19:03 +02:00
|
|
|
private Client client = new Client();
|
2024-05-12 19:58:34 +02:00
|
|
|
|
2024-05-25 18:19:03 +02:00
|
|
|
public void setScopes(String scopes) {
|
2024-05-12 19:58:34 +02:00
|
|
|
List<String> scopesList =
|
2024-05-25 18:19:03 +02:00
|
|
|
Arrays.stream(scopes.split(","))
|
2024-05-12 19:58:34 +02:00
|
|
|
.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) {
|
2024-09-13 16:42:38 +01:00
|
|
|
return value != null && !value.trim().isEmpty();
|
2024-05-25 18:19:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean isValid(Collection<String> value, String name) {
|
2024-09-13 16:42:38 +01:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2024-09-13 16:42:38 +01:00
|
|
|
@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();
|
|
|
|
|
2024-06-15 14:15:09 +02:00
|
|
|
public Provider get(String registrationId) throws UnsupportedProviderException {
|
2024-06-06 21:03:06 +02:00
|
|
|
switch (registrationId.toLowerCase()) {
|
2024-05-30 09:42:23 +01:00
|
|
|
case "google":
|
2024-05-25 18:19:03 +02:00
|
|
|
return getGoogle();
|
|
|
|
case "github":
|
|
|
|
return getGithub();
|
|
|
|
case "keycloak":
|
|
|
|
return getKeycloak();
|
|
|
|
default:
|
2024-09-13 16:42:38 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-13 16:42:38 +01:00
|
|
|
@Data
|
2023-08-26 17:30:49 +01:00
|
|
|
public static class System {
|
|
|
|
private String defaultLocale;
|
|
|
|
private Boolean googlevisibility;
|
2024-04-21 13:15:18 +02:00
|
|
|
private boolean showUpdate;
|
|
|
|
private Boolean showUpdateOnlyAdmin;
|
2024-04-27 11:03:57 +01:00
|
|
|
private boolean customHTMLFiles;
|
2024-08-15 11:43:56 +02:00
|
|
|
private String tessdataDir;
|
2023-12-26 20:10:37 +00:00
|
|
|
private Boolean enableAlphaFunctionality;
|
2023-12-30 19:11:27 +00:00
|
|
|
}
|
|
|
|
|
2024-09-13 16:42:38 +01: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() {
|
2024-09-13 16:42:38 +01:00
|
|
|
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() {
|
2024-09-13 16:42:38 +01:00
|
|
|
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() {
|
2024-09-13 16:42:38 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-09-13 16:42:38 +01: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
|
|
|
}
|
|
|
|
|
2024-09-13 16:42:38 +01: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
|
|
|
|
2024-09-13 16:42:38 +01:00
|
|
|
@Data
|
2023-08-26 17:30:49 +01:00
|
|
|
public static class AutomaticallyGenerated {
|
2024-09-13 16:42:38 +01:00
|
|
|
@ToString.Exclude private String key;
|
|
|
|
}
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2024-09-13 16:42:38 +01:00
|
|
|
@Data
|
|
|
|
public static class EnterpriseEdition {
|
|
|
|
@ToString.Exclude private String key;
|
|
|
|
private CustomMetadata customMetadata = new CustomMetadata();
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2024-09-13 16:42:38 +01: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
|
|
|
|
2024-09-13 16:42:38 +01: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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|