implemented document creation

this required a major refactoring of the object model
This commit is contained in:
2025-07-10 12:49:32 +02:00
parent 21812d2b42
commit 163bcebf4f
43 changed files with 345 additions and 153 deletions

View File

@@ -9,6 +9,5 @@ dependencies{
implementation("de.srsoftware:tools.optionals:1.0.0")
implementation("de.srsoftware:tools.util:2.0.3")
implementation("org.bitbucket.b_c:jose4j:0.9.6")
implementation("org.json:json:20240303")
implementation("org.xerial:sqlite-jdbc:3.49.0.0")
}

View File

@@ -12,6 +12,8 @@ import static de.srsoftware.umbrella.core.ResponseCode.*;
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_SERVER_ERROR;
import static de.srsoftware.umbrella.core.Util.open;
import static de.srsoftware.umbrella.core.Util.request;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingConfigException;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
import static de.srsoftware.umbrella.user.Constants.*;
import static de.srsoftware.umbrella.user.Paths.*;
import static de.srsoftware.umbrella.user.Paths.IMPERSONATE;
@@ -29,8 +31,8 @@ import de.srsoftware.configuration.Configuration;
import de.srsoftware.tools.Path;
import de.srsoftware.tools.SessionToken;
import de.srsoftware.umbrella.core.BaseHandler;
import de.srsoftware.umbrella.core.UmbrellaException;
import de.srsoftware.umbrella.core.api.UserService;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.core.model.EmailAddress;
import de.srsoftware.umbrella.core.model.Token;
import de.srsoftware.umbrella.core.model.UmbrellaUser;
@@ -84,7 +86,7 @@ public class UserModule extends BaseHandler implements UserService {
}
public UserModule(Configuration config, MessageSystem messageSystem) throws UmbrellaException {
var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> new UmbrellaException(ERROR_MISSING_CONFIG,CONFIG_DATABASE));
var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingConfigException(CONFIG_DATABASE));
// may be splitted in separate db files later
logins = new SqliteDB(connect(dbFile));
messages = messageSystem;
@@ -97,11 +99,15 @@ public class UserModule extends BaseHandler implements UserService {
private boolean deleteOIDC(HttpExchange ex, UmbrellaUser user, Path path) throws IOException {
var head = path.pop();
return switch (head){
case CONNECTED -> deleteServiceConnection(ex,user);
case null -> super.doGet(path,ex);
default -> deleteService(ex,user,head);
};
try {
return switch (head) {
case CONNECTED -> deleteServiceConnection(ex, user);
case null -> super.doGet(path, ex);
default -> deleteService(ex, user, head);
};
} catch (UmbrellaException e) {
return send(ex,e);
}
}
private boolean deleteService(HttpExchange ex, UmbrellaUser user, String serviceName) throws IOException {
@@ -114,7 +120,7 @@ public class UserModule extends BaseHandler implements UserService {
}
}
private boolean deleteServiceConnection(HttpExchange ex, UmbrellaUser user) throws IOException {
private boolean deleteServiceConnection(HttpExchange ex, UmbrellaUser user) throws IOException, UmbrellaException {
if (user == null) return sendContent(ex,HTTP_SERVER_ERROR,"Expected user object to be of type DbUser");
JSONObject json;
try {
@@ -123,8 +129,8 @@ public class UserModule extends BaseHandler implements UserService {
LOG.log(WARNING,"Request does not contain valid JSON",e);
return sendContent(ex,HTTP_FAILED_DEPENDENCY,"Request does not contain valid JSON");
}
if (!(json.has(FOREIGN_ID) && json.get(FOREIGN_ID) instanceof String foreignId && !foreignId.isBlank())) return sendContent(ex,HTTP_UNPROCESSABLE,format(ERROR_MISSING_FIELD,FOREIGN_ID));
if (!(json.has(SERVICE_ID) && json.get(SERVICE_ID) instanceof String serviceId && !serviceId.isBlank())) return sendContent(ex,HTTP_UNPROCESSABLE,format(ERROR_MISSING_FIELD,SERVICE_ID));
if (!(json.has(FOREIGN_ID) && json.get(FOREIGN_ID) instanceof String foreignId && !foreignId.isBlank())) throw missingFieldException(FOREIGN_ID);
if (!(json.has(SERVICE_ID) && json.get(SERVICE_ID) instanceof String serviceId && !serviceId.isBlank())) throw missingFieldException(SERVICE_ID);
try {
@@ -501,10 +507,10 @@ public class UserModule extends BaseHandler implements UserService {
if (!(requestingUser instanceof DbUser user && user.permissions().contains(MANAGE_LOGIN_SERVICES))) return forbidden(ex);
try {
var json = json(ex);
if (!json.has(NAME) || !(json.get(NAME) instanceof String name) || name.isBlank()) return sendContent(ex,HTTP_UNPROCESSABLE,format(ERROR_MISSING_FIELD,NAME));
if (!json.has(URL) || !(json.get(URL) instanceof String url) || url.isBlank()) return sendContent(ex,HTTP_UNPROCESSABLE,format(ERROR_MISSING_FIELD,URL));
if (!json.has(CLIENT_ID) || !(json.get(CLIENT_ID) instanceof String clientId) || clientId.isBlank()) return sendContent(ex,HTTP_UNPROCESSABLE,format(ERROR_MISSING_FIELD,CLIENT_ID));
if (!json.has(CLIENT_SECRET) || !(json.get(CLIENT_SECRET) instanceof String secret) || secret.isBlank()) return sendContent(ex,HTTP_UNPROCESSABLE,format(ERROR_MISSING_FIELD,CLIENT_SECRET));
if (!json.has(NAME) || !(json.get(NAME) instanceof String name) || name.isBlank()) throw missingFieldException(NAME);
if (!json.has(URL) || !(json.get(URL) instanceof String url) || url.isBlank()) throw missingFieldException(URL);
if (!json.has(CLIENT_ID) || !(json.get(CLIENT_ID) instanceof String clientId) || clientId.isBlank()) throw missingFieldException(CLIENT_ID);
if (!json.has(CLIENT_SECRET) || !(json.get(CLIENT_SECRET) instanceof String secret) || secret.isBlank()) throw missingFieldException(CLIENT_SECRET);
var service = logins.save(new LoginService(name,url,clientId,secret, DEFAULT_FIELD));
return sendContent(ex,service.toMap());
} catch (UmbrellaException e) {

View File

@@ -1,7 +1,7 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.user.api;
import de.srsoftware.umbrella.core.UmbrellaException;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.user.model.ForeignLogin;
import de.srsoftware.umbrella.user.model.LoginService;
import java.util.List;

View File

@@ -1,7 +1,7 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.user.api;
import de.srsoftware.umbrella.core.UmbrellaException;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.core.model.EmailAddress;
import de.srsoftware.umbrella.core.model.Session;
import de.srsoftware.umbrella.core.model.Token;

View File

@@ -12,7 +12,7 @@ import static java.text.MessageFormat.format;
import de.srsoftware.tools.PasswordHasher;
import de.srsoftware.tools.jdbc.Query;
import de.srsoftware.umbrella.core.UmbrellaException;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.core.model.EmailAddress;
import de.srsoftware.umbrella.core.model.Session;
import de.srsoftware.umbrella.core.model.Token;