Skip to content

Commit 054cd3d

Browse files
committed
2270: Added new dep, implemented functionality to init the DB in postgres, more refactoring
1 parent e32e5d9 commit 054cd3d

File tree

9 files changed

+173
-138
lines changed

9 files changed

+173
-138
lines changed

build.gradle

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ repositories {
3939
maven { url "https://jitpack.io" }
4040
maven { url "https://build.shibboleth.net/nexus/content/repositories/releases/" }
4141
maven {
42-
url 'https://build.shibboleth.net/maven/releases'
42+
url "https://build.shibboleth.net/maven/releases"
4343
}
4444
}
4545

@@ -98,7 +98,7 @@ launch4j {
9898

9999
spotless {
100100
java {
101-
target project.fileTree('src/main/java')
101+
target project.fileTree("src/main/java")
102102

103103
googleJavaFormat("1.22.0").aosp().reorderImports(false)
104104

@@ -111,7 +111,7 @@ spotless {
111111
}
112112

113113
//gradleLint {
114-
// rules=['unused-dependency']
114+
// rules=["unused-dependency"]
115115
// }
116116
tasks.wrapper {
117117
gradleVersion = "8.7"
@@ -129,15 +129,15 @@ dependencies {
129129
implementation("io.github.pixee:java-security-toolkit:1.2.0")
130130

131131
// implementation "org.yaml:snakeyaml:2.2"
132-
implementation 'com.github.Carleslc.Simple-YAML:Simple-Yaml:1.8.4'
132+
implementation "com.github.Carleslc.Simple-YAML:Simple-Yaml:1.8.4"
133133

134134
// Exclude Tomcat and include Jetty
135135
implementation("org.springframework.boot:spring-boot-starter-web:$springBootVersion")
136136
implementation "org.springframework.boot:spring-boot-starter-jetty:$springBootVersion"
137137

138138
implementation "org.springframework.boot:spring-boot-starter-thymeleaf:$springBootVersion"
139-
implementation 'com.posthog.java:posthog:1.1.1'
140-
implementation 'com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20240325.1'
139+
implementation "com.posthog.java:posthog:1.1.1"
140+
implementation "com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20240325.1"
141141

142142

143143
if (System.getenv("DOCKER_ENABLE_SECURITY") != "false") {
@@ -147,8 +147,9 @@ dependencies {
147147
implementation "org.springframework.boot:spring-boot-starter-oauth2-client:$springBootVersion"
148148

149149
implementation "org.springframework.session:spring-session-core:$springBootVersion"
150-
151-
implementation 'com.unboundid.product.scim2:scim2-sdk-client:2.3.5'
150+
implementation "org.springframework:spring-jdbc"
151+
152+
implementation "com.unboundid.product.scim2:scim2-sdk-client:2.3.5"
152153
// Don't upgrade h2database
153154
runtimeOnly "org.postgresql:postgresql:42.7.4"
154155
constraints {
@@ -157,8 +158,8 @@ dependencies {
157158
implementation "org.opensaml:opensaml-saml-impl:$openSamlVersion"
158159
}
159160
implementation "org.springframework.security:spring-security-saml2-service-provider:$springSecuritySamlVersion"
160-
// implementation 'org.springframework.security:spring-security-core:$springSecuritySamlVersion'
161-
implementation 'com.coveo:saml-client:5.0.0'
161+
// implementation "org.springframework.security:spring-security-core:$springSecuritySamlVersion"
162+
implementation "com.coveo:saml-client:5.0.0"
162163

163164

164165
}
@@ -207,13 +208,13 @@ dependencies {
207208
}
208209

209210
// https://mvnrepository.com/artifact/technology.tabula/tabula
210-
implementation ('technology.tabula:tabula:1.0.5') {
211+
implementation ("technology.tabula:tabula:1.0.5") {
211212
exclude group: "org.slf4j", module: "slf4j-simple"
212213
exclude group: "org.bouncycastle", module: "bcprov-jdk15on"
213214
exclude group: "com.google.code.gson", module: "gson"
214215
}
215216

216-
implementation 'org.apache.pdfbox:jbig2-imageio:3.0.4'
217+
implementation "org.apache.pdfbox:jbig2-imageio:3.0.4"
217218

218219
implementation "org.bouncycastle:bcprov-jdk18on:$bouncycastleVersion"
219220
implementation "org.bouncycastle:bcpkix-jdk18on:$bouncycastleVersion"
@@ -231,7 +232,7 @@ dependencies {
231232
compileOnly "org.projectlombok:lombok:$lombokVersion"
232233
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
233234

234-
testRuntimeOnly 'org.mockito:mockito-inline:5.2.0'
235+
testRuntimeOnly "org.mockito:mockito-inline:5.2.0"
235236
}
236237

237238
tasks.withType(JavaCompile).configureEach {

src/main/java/stirling/software/SPDF/SPdfApplication.java

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
import java.nio.file.Files;
66
import java.nio.file.Path;
77
import java.nio.file.Paths;
8-
import java.sql.Connection;
9-
import java.sql.DriverManager;
10-
import java.sql.ResultSet;
11-
import java.sql.SQLException;
12-
import java.sql.Statement;
138
import java.util.Collections;
149
import java.util.HashMap;
1510
import java.util.Map;
@@ -72,61 +67,6 @@ private static boolean isPortAvailable(int port) {
7267
}
7368
}
7469

75-
@PostConstruct
76-
public void initDB() {
77-
Connection connection = null;
78-
Statement statement = null;
79-
try {
80-
logger.debug("Creating database...");
81-
ApplicationProperties.Datasource datasource =
82-
applicationProperties.getSystem().getDatasource();
83-
84-
if (datasource != null) {
85-
connection =
86-
DriverManager.getConnection(
87-
datasource.getUrl(),
88-
datasource.getUsername(),
89-
datasource.getPassword());
90-
statement = connection.createStatement();
91-
statement.executeQuery(
92-
"SELECT count(*) FROM pg_database WHERE datname = 'database_name'");
93-
ResultSet resultSet = statement.getResultSet();
94-
resultSet.next();
95-
int count = resultSet.getInt(1);
96-
97-
if (count <= 0) {
98-
statement.executeUpdate("CREATE DATABASE stirling-pdf-DB");
99-
statement.executeUpdate(
100-
"CREATE ROLE "
101-
+ datasource.getUsername()
102-
+ " ADMIN WITH PASSWORD '"
103-
+ datasource.getPassword()
104-
+ "'");
105-
statement.executeUpdate("SET ROLE " + datasource.getUsername());
106-
logger.debug("Database created.");
107-
} else {
108-
logger.debug("Database already exists.");
109-
}
110-
}
111-
112-
} catch (SQLException e) {
113-
logger.error(e.toString());
114-
} finally {
115-
try {
116-
if (statement != null) {
117-
statement.close();
118-
logger.debug("Closed Statement.");
119-
}
120-
if (connection != null) {
121-
logger.debug("Closed Connection.");
122-
connection.close();
123-
}
124-
} catch (SQLException e) {
125-
logger.error(e.toString());
126-
}
127-
}
128-
}
129-
13070
@PostConstruct
13171
public void init() {
13272
baseUrlStatic = this.baseUrl;

src/main/java/stirling/software/SPDF/config/interfaces/DatabaseBackupInterface.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
import stirling.software.SPDF.utils.FileInfo;
77

88
public interface DatabaseBackupInterface {
9+
void initDatabase();
10+
911
void exportDatabase() throws IOException;
1012

11-
boolean importDatabase();
13+
void importDatabase();
1214

1315
boolean hasBackup();
1416

src/main/java/stirling/software/SPDF/config/security/InitialSecuritySetup.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ public class InitialSecuritySetup {
2020

2121
@Autowired private ApplicationProperties applicationProperties;
2222

23-
// todo: wip add Postgres here
2423
@Autowired private DatabaseBackupInterface databaseBackupHelper;
2524

2625
@PostConstruct
2726
public void init() throws IllegalArgumentException, IOException {
27+
databaseBackupHelper.initDatabase();
28+
2829
if (databaseBackupHelper.hasBackup() && !userService.hasUsers()) {
2930
databaseBackupHelper.importDatabase();
3031
} else if (!userService.hasUsers()) {

0 commit comments

Comments
 (0)