Joaquín Reñé
2025-10-07 146a0fb8b0e90f9196e569152f649baf60d6cc8f
securis/src/main/java/net/curisit/securis/ioc/SecurisModule.java
....@@ -1,3 +1,6 @@
1
+/*
2
+* Copyright @ 2013 CurisTEC, S.A.S. All Rights Reserved.
3
+*/
14 package net.curisit.securis.ioc;
25
36 import java.io.File;
....@@ -18,6 +21,25 @@
1821 import com.google.inject.AbstractModule;
1922 import com.google.inject.Provides;
2023
24
+/**
25
+* SecurisModule
26
+* <p>
27
+* Guice module that provides application-level infrastructural dependencies
28
+* (base URI, app directories, DB files list, support email/hash, etc.).
29
+* <p>
30
+* Configuration:
31
+* - Reads server port from /securis-server.properties (key: "port").
32
+* - Defaults to port 9997 when not present or on read errors.
33
+* - Constructs base URI as http://0.0.0.0:{port}/ with UriBuilder.
34
+* - Creates working directories under ${user.home}/.SeCuris on demand.
35
+*
36
+* Security note:
37
+* - getPassword/getFilePassword are simple helpers; secrets should be
38
+* managed via a secure vault/env vars in production.
39
+*
40
+* @author JRA
41
+* Last reviewed by JRA on Oct 7, 2025.
42
+*/
2143 public class SecurisModule extends AbstractModule {
2244
2345 private static final int DEFAULT_PORT = 9997;
....@@ -25,28 +47,51 @@
2547
2648 private static final Logger LOG = LogManager.getLogger(SecurisModule.class);
2749
50
+ /** configure<p>Currently no explicit bindings; providers below supply instances. */
2851 @Override
29
- protected void configure() {
52
+ protected void configure() { }
3053
31
- }
32
-
54
+ /**
55
+ * getPassword<p>
56
+ * Composite password (example use with encrypted H2 URL).
57
+ *
58
+ * @return concatenated password string
59
+ */
3360 public String getPassword() {
3461 return getFilePassword() + " " + "53curi5";
3562 }
3663
64
+ /**
65
+ * getFilePassword<p>
66
+ * Standalone file password (for H2 CIPHER).
67
+ *
68
+ * @return file password string
69
+ */
3770 public String getFilePassword() {
3871 return "cur151T";
3972 }
4073
74
+ /**
75
+ * getUrl<p>
76
+ * H2 JDBC URL with AES cipher pointing to {appDir}/db/securis.
77
+ *
78
+ * @param appDir application working directory
79
+ * @return JDBC URL (H2)
80
+ */
4181 public String getUrl(File appDir) {
4282 return String.format("jdbc:h2:%s/db/securis;CIPHER=AES", appDir.getAbsolutePath());
4383 }
4484
85
+ /**
86
+ * getBaseURI<p>
87
+ * Provide the base URI for the HTTP server using configured or default port.
88
+ *
89
+ * @return base URI (http://0.0.0.0:{port}/)
90
+ */
4591 @Named("base-uri")
4692 @Provides
4793 @ApplicationScoped
4894 public URI getBaseURI() {
49
- // Read from configuration, where?
5095 try {
5196 String url = MessageFormat.format("http://{0}/", "0.0.0.0");
5297 LOG.debug("Server url{}", url);
....@@ -56,33 +101,46 @@
56101 }
57102 }
58103
104
+ /**
105
+ * getPort<p>
106
+ * Read port from properties file or return default.
107
+ *
108
+ * @return HTTP port
109
+ */
59110 private int getPort() {
60111 Integer port;
61112 Properties prop = new Properties();
62113 try {
63114 prop.load(getClass().getResourceAsStream(PROPERTIES_FILE_NAME));
64115 port = Integer.valueOf(prop.getProperty("port"));
65
- if (port == null) {
66
- return DEFAULT_PORT;
67
- } else {
68
- return port;
69
- }
116
+ return (port == null ? DEFAULT_PORT : port);
70117 } catch (Exception ex) {
71118 return DEFAULT_PORT;
72119 }
73120 }
74121
122
+ /**
123
+ * getAppDbFiles<p>
124
+ * List of SQL files to initialize the application DB.
125
+ *
126
+ * @return list of classpath resource paths
127
+ */
75128 protected List<String> getAppDbFiles() {
76
-
77129 return Arrays.asList("/db/schema.sql");
78130 }
79131
132
+ /**
133
+ * getTemporaryDir<p>
134
+ * Provide a temp directory inside the app working dir (.TEMP).
135
+ * Creates it if missing and marks for deletion on exit.
136
+ *
137
+ * @return temp directory or null if creation failed
138
+ */
80139 @Named("temporary-dir")
81140 @Provides
82141 @ApplicationScoped
83142 public File getTemporaryDir() {
84
- String tmp = getAppDir().getAbsolutePath();
85
- tmp += File.separator + ".TEMP";
143
+ String tmp = getAppDir().getAbsolutePath() + File.separator + ".TEMP";
86144 File ftmp = new File(tmp);
87145 if (!ftmp.exists()) {
88146 if (!ftmp.mkdirs()) {
....@@ -94,14 +152,18 @@
94152 return ftmp;
95153 }
96154
155
+ /**
156
+ * getAppDir<p>
157
+ * Provide the app working directory under ${user.home}/.SeCuris (creates if missing).
158
+ *
159
+ * @return working directory or null if creation failed
160
+ */
97161 @Named("app-dir")
98162 @Provides
99163 @ApplicationScoped
100164 public File getAppDir() {
101165 String appDir = System.getProperty("user.home", System.getProperty("user.dir"));
102
- if (appDir == null) {
103
- appDir = ".";
104
- }
166
+ if (appDir == null) appDir = ".";
105167 appDir += File.separator + ".SeCuris";
106168 File fAppDir = new File(appDir);
107169 if (!fAppDir.exists()) {
....@@ -113,6 +175,12 @@
113175 return fAppDir;
114176 }
115177
178
+ /**
179
+ * getSupportEmail<p>
180
+ * Provide support email address.
181
+ *
182
+ * @return email
183
+ */
116184 @Named("support-email")
117185 @Provides
118186 @ApplicationScoped
....@@ -120,6 +188,12 @@
120188 return "support@curisit.net";
121189 }
122190
191
+ /**
192
+ * getHashLogo<p>
193
+ * Provide a static content hash for the logo (cache-busting or integrity).
194
+ *
195
+ * @return hex SHA-256
196
+ */
123197 @Named("hash-logo")
124198 @Provides
125199 @ApplicationScoped
....@@ -127,11 +201,17 @@
127201 return "1b42616809d4cd8ccf109e3c30d0ab25067f160b30b7354a08ddd563de0096ba";
128202 }
129203
204
+ /**
205
+ * getDbFiles<p>
206
+ * Provide DB initialization files list (delegates to {@link #getAppDbFiles()}).
207
+ *
208
+ * @return list of SQL resource paths
209
+ */
130210 @Named("db-files")
131211 @Provides
132212 @ApplicationScoped
133213 public List<String> getDbFiles() {
134214 return getAppDbFiles();
135215 }
136
-
137216 }
217
+