implemented EncryptedMailConfig, needs testing
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -18,6 +18,7 @@ import de.srsoftware.logging.ColorLogger;
|
||||
import de.srsoftware.oidc.api.*;
|
||||
import de.srsoftware.oidc.api.data.User;
|
||||
import de.srsoftware.oidc.backend.*;
|
||||
import de.srsoftware.oidc.datastore.encrypted.EncryptedMailConfig;
|
||||
import de.srsoftware.oidc.datastore.file.FileStoreProvider;
|
||||
import de.srsoftware.oidc.datastore.file.PlaintextKeyStore;
|
||||
import de.srsoftware.oidc.datastore.sqlite.*;
|
||||
@@ -110,10 +111,19 @@ public class Application {
|
||||
|
||||
private static MailConfig setupMailConfig(Configuration config, Path defaultFile, FileStoreProvider fileStoreProvider) throws SQLException {
|
||||
var mailConfigLocation = new File(config.getOrDefault("mail_config_storage",defaultFile));
|
||||
return switch (extension(mailConfigLocation)){
|
||||
var mailConfig = switch (extension(mailConfigLocation)){
|
||||
case "db", "sqlite", "sqlite3" -> new SqliteMailConfig(connectionProvider.get(mailConfigLocation));
|
||||
default -> fileStoreProvider.get(mailConfigLocation);
|
||||
};
|
||||
|
||||
Optional<String> encryptionKey = config.get(ENCRYPTION_KEY);
|
||||
var salt = config.getOrDefault(SALT,uuid());
|
||||
|
||||
|
||||
if (encryptionKey.isPresent()){
|
||||
mailConfig = new EncryptedMailConfig(mailConfig,encryptionKey.get(),salt);
|
||||
}
|
||||
return mailConfig;
|
||||
}
|
||||
|
||||
private static UserService setupUserService(Configuration config, Path defaultFile, FileStoreProvider fileStoreProvider, UuidHasher passHasher) throws SQLException {
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
/* © SRSoftware 2024 */
|
||||
package de.srsoftware.oidc.app;
|
||||
|
||||
import static java.util.Optional.empty;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class Configuration {
|
||||
@@ -30,6 +33,17 @@ public class Configuration {
|
||||
return json.getString(key);
|
||||
}
|
||||
|
||||
public <T> Optional<T> get(String key) {
|
||||
if (!json.has(key)) return empty();
|
||||
var o = json.get(key);
|
||||
try {
|
||||
@SuppressWarnings("unchecked") var result = (T)o;
|
||||
return Optional.of(result);
|
||||
} catch (Exception e) {
|
||||
return empty();
|
||||
}
|
||||
}
|
||||
|
||||
public Configuration save() {
|
||||
try {
|
||||
Files.writeString(storageFile, json.toString(2));
|
||||
|
||||
Reference in New Issue
Block a user