|
|
@ -9,6 +9,8 @@ import static java.util.Optional.empty; |
|
|
|
|
|
|
|
|
|
|
|
import de.srsoftware.oidc.api.*; |
|
|
|
import de.srsoftware.oidc.api.*; |
|
|
|
import de.srsoftware.oidc.api.data.*; |
|
|
|
import de.srsoftware.oidc.api.data.*; |
|
|
|
|
|
|
|
import jakarta.mail.Authenticator; |
|
|
|
|
|
|
|
import jakarta.mail.PasswordAuthentication; |
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
|
import java.io.FileNotFoundException; |
|
|
|
import java.io.FileNotFoundException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
@ -37,6 +39,7 @@ public class FileStore implements AuthorizationService, ClientService, SessionSe |
|
|
|
private Map<String, Client> clients = new HashMap<>(); |
|
|
|
private Map<String, Client> clients = new HashMap<>(); |
|
|
|
private Map<String, User> accessTokens = new HashMap<>(); |
|
|
|
private Map<String, User> accessTokens = new HashMap<>(); |
|
|
|
private Map<String, Authorization> authCodes = new HashMap<>(); |
|
|
|
private Map<String, Authorization> authCodes = new HashMap<>(); |
|
|
|
|
|
|
|
private Authenticator auth; |
|
|
|
|
|
|
|
|
|
|
|
public FileStore(File storage, PasswordHasher<String> passwordHasher) throws IOException { |
|
|
|
public FileStore(File storage, PasswordHasher<String> passwordHasher) throws IOException { |
|
|
|
this.storageFile = storage.toPath(); |
|
|
|
this.storageFile = storage.toPath(); |
|
|
@ -48,9 +51,10 @@ public class FileStore implements AuthorizationService, ClientService, SessionSe |
|
|
|
Files.writeString(storageFile, "{}"); |
|
|
|
Files.writeString(storageFile, "{}"); |
|
|
|
} |
|
|
|
} |
|
|
|
json = new JSONObject(Files.readString(storageFile)); |
|
|
|
json = new JSONObject(Files.readString(storageFile)); |
|
|
|
|
|
|
|
auth = null; // lazy init!
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private FileStore save() { |
|
|
|
public FileStore save() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
Files.writeString(storageFile, json.toString(2)); |
|
|
|
Files.writeString(storageFile, json.toString(2)); |
|
|
|
return this; |
|
|
|
return this; |
|
|
@ -319,6 +323,19 @@ public class FileStore implements AuthorizationService, ClientService, SessionSe |
|
|
|
|
|
|
|
|
|
|
|
/*** MailConfig implementation ***/ |
|
|
|
/*** MailConfig implementation ***/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public Authenticator authenticator() { |
|
|
|
|
|
|
|
if (auth == null) { |
|
|
|
|
|
|
|
auth = new Authenticator() { |
|
|
|
|
|
|
|
// override the getPasswordAuthentication method
|
|
|
|
|
|
|
|
protected PasswordAuthentication getPasswordAuthentication() { |
|
|
|
|
|
|
|
return new PasswordAuthentication(senderAddress(), senderPassword()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return auth; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String mailConfig(String key) { |
|
|
|
private String mailConfig(String key) { |
|
|
|
var config = json.getJSONObject(MAILCONFIG); |
|
|
|
var config = json.getJSONObject(MAILCONFIG); |
|
|
|
if (config.has(key)) return config.getString(key); |
|
|
|
if (config.has(key)) return config.getString(key); |
|
|
@ -328,71 +345,71 @@ public class FileStore implements AuthorizationService, ClientService, SessionSe |
|
|
|
private FileStore mailConfig(String key, Object newValue) { |
|
|
|
private FileStore mailConfig(String key, Object newValue) { |
|
|
|
var config = json.getJSONObject(MAILCONFIG); |
|
|
|
var config = json.getJSONObject(MAILCONFIG); |
|
|
|
config.put(key, newValue); |
|
|
|
config.put(key, newValue); |
|
|
|
|
|
|
|
auth = null; |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String smtpHost() { |
|
|
|
public String smtpHost() { |
|
|
|
return mailConfig("smtp_host"); |
|
|
|
return mailConfig(SMTP_HOST); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public MailConfig smtpHost(String newValue) { |
|
|
|
public MailConfig smtpHost(String newValue) { |
|
|
|
return mailConfig("smtp_host", newValue); |
|
|
|
return mailConfig(SMTP_HOST, newValue); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public int smtpPort() { |
|
|
|
public int smtpPort() { |
|
|
|
try { |
|
|
|
var config = json.getJSONObject(MAILCONFIG); |
|
|
|
return Integer.parseInt(mailConfig("smtp_port")); |
|
|
|
return config.has(SMTP_PORT) ? config.getInt(SMTP_PORT) : 0; |
|
|
|
} catch (NumberFormatException nfe) { |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public MailConfig smtpPort(int newValue) { |
|
|
|
public MailConfig smtpPort(int newValue) { |
|
|
|
return mailConfig("smtp_port", newValue); |
|
|
|
return mailConfig(SMTP_PORT, newValue); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String senderAddress() { |
|
|
|
public String senderAddress() { |
|
|
|
return mailConfig("sender_address"); |
|
|
|
return mailConfig(SMTP_USER); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public MailConfig senderAddress(String newValue) { |
|
|
|
public MailConfig senderAddress(String newValue) { |
|
|
|
return mailConfig("sender_address", newValue); |
|
|
|
return mailConfig(SMTP_USER, newValue); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String senderPassword() { |
|
|
|
public String senderPassword() { |
|
|
|
return mailConfig("smtp_password"); |
|
|
|
return mailConfig(SMTP_PASSWORD); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public MailConfig senderPassword(String newValue) { |
|
|
|
public MailConfig senderPassword(String newValue) { |
|
|
|
return mailConfig("smtp_password", newValue); |
|
|
|
return mailConfig(SMTP_PASSWORD, newValue); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean startTls() { |
|
|
|
public boolean startTls() { |
|
|
|
return "true".equals(mailConfig("start_tls")); |
|
|
|
var config = json.getJSONObject(MAILCONFIG); |
|
|
|
|
|
|
|
return config.has(START_TLS) ? config.getBoolean(START_TLS) : false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public MailConfig startTls(boolean newValue) { |
|
|
|
public MailConfig startTls(boolean newValue) { |
|
|
|
return mailConfig("start_tls", newValue); |
|
|
|
return mailConfig(START_TLS, newValue); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean smtpAuth() { |
|
|
|
public boolean smtpAuth() { |
|
|
|
return "true".equals(mailConfig("smtp_auth")); |
|
|
|
var config = json.getJSONObject(MAILCONFIG); |
|
|
|
|
|
|
|
return config.has(SMTP_AUTH) ? config.getBoolean(SMTP_AUTH) : false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public MailConfig smtpAuth(boolean newValue) { |
|
|
|
public MailConfig smtpAuth(boolean newValue) { |
|
|
|
return mailConfig("smtp_auth", newValue); |
|
|
|
return mailConfig(SMTP_AUTH, newValue); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|