overhauling constants, working on translations

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-01-15 13:58:50 +01:00
parent 669853352e
commit 0d1cdd35d1
103 changed files with 2161 additions and 1207 deletions

View File

@@ -5,12 +5,12 @@ public class Paths {
private Paths(){}
public static final String CALLBACK = "callback";
public static final String CONNECTED = "connected";
public static final String CREATE = "create";
public static final String DASH = "dash";
public static final String IMPERSONATE = "impersonate";
public static final String INSTALL = "install";
public static final String JAVASCRIPT = "js";
public static final String LOGIN = "login";
public static final String MENU = "menu";
public static final String MODULES = "modules";
public static final String NOTIFY = "notify";

View File

@@ -5,14 +5,16 @@ import static de.srsoftware.tools.MimeType.MIME_FORM_URL;
import static de.srsoftware.tools.Optionals.*;
import static de.srsoftware.tools.Strings.uuid;
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
import static de.srsoftware.umbrella.core.Constants.*;
import static de.srsoftware.umbrella.core.Constants.CODE;
import static de.srsoftware.umbrella.core.Constants.TOKEN;
import static de.srsoftware.umbrella.core.ModuleRegistry.postBox;
import static de.srsoftware.umbrella.core.Paths.*;
import static de.srsoftware.umbrella.core.ResponseCode.*;
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_SERVER_ERROR;
import static de.srsoftware.umbrella.core.Util.*;
import static de.srsoftware.umbrella.core.constants.Field.*;
import static de.srsoftware.umbrella.core.constants.Field.PASSWORD;
import static de.srsoftware.umbrella.core.constants.Field.REDIRECT;
import static de.srsoftware.umbrella.core.constants.Field.STATE;
import static de.srsoftware.umbrella.core.constants.Field.USER;
import static de.srsoftware.umbrella.core.constants.Path.*;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
import static de.srsoftware.umbrella.user.Constants.*;
import static de.srsoftware.umbrella.user.Paths.*;
@@ -28,11 +30,12 @@ import static java.util.Optional.empty;
import com.sun.net.httpserver.HttpExchange;
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.ModuleRegistry;
import de.srsoftware.umbrella.core.api.UserService;
import de.srsoftware.umbrella.core.constants.Field;
import de.srsoftware.umbrella.core.constants.Path;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.core.model.*;
import de.srsoftware.umbrella.user.api.LoginServiceDb;
@@ -83,14 +86,14 @@ public class UserModule extends BaseHandler implements UserService {
public UserModule(Configuration config) throws UmbrellaException {
super();
var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingConfigException(CONFIG_DATABASE));
var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingConfig(CONFIG_DATABASE));
// may be splitted in separate db files later
logins = new SqliteDB(connect(dbFile));
users = new SqliteDB(connect(dbFile));
ModuleRegistry.add(this);
}
private boolean deleteOIDC(HttpExchange ex, UmbrellaUser user, Path path) throws IOException {
private boolean deleteOIDC(HttpExchange ex, UmbrellaUser user, de.srsoftware.tools.Path path) throws IOException {
var head = path.pop();
try {
return switch (head) {
@@ -122,8 +125,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())) throw missingFieldException(FOREIGN_ID);
if (!(json.has(SERVICE_ID) && json.get(SERVICE_ID) instanceof String serviceId && !serviceId.isBlank())) throw missingFieldException(SERVICE_ID);
if (!(json.has(FOREIGN_ID) && json.get(FOREIGN_ID) instanceof String foreignId && !foreignId.isBlank())) throw missingField(FOREIGN_ID);
if (!(json.has(SERVICE_ID) && json.get(SERVICE_ID) instanceof String serviceId && !serviceId.isBlank())) throw missingField(SERVICE_ID);
try {
@@ -164,7 +167,7 @@ public class UserModule extends BaseHandler implements UserService {
}
@Override
public boolean doDelete(Path path, HttpExchange ex) throws IOException {
public boolean doDelete(de.srsoftware.tools.Path path, HttpExchange ex) throws IOException {
try {
var user = loadUser(ex);
addCors(ex);
@@ -177,7 +180,7 @@ public class UserModule extends BaseHandler implements UserService {
}
@Override
public boolean doGet(Path path, HttpExchange ex) throws IOException {
public boolean doGet(de.srsoftware.tools.Path path, HttpExchange ex) throws IOException {
var sessionToken = SessionToken.from(ex).map(Token::of);
try {
var user = loadUser(sessionToken);
@@ -203,7 +206,7 @@ public class UserModule extends BaseHandler implements UserService {
}
public boolean doPatch(Path path, HttpExchange ex) throws IOException {
public boolean doPatch(de.srsoftware.tools.Path path, HttpExchange ex) throws IOException {
addCors(ex);
String head = null;
try {
@@ -212,7 +215,7 @@ public class UserModule extends BaseHandler implements UserService {
long userId;
if (head == null || head.isBlank()) return sendContent(ex, HTTP_UNPROCESSABLE,"User id missing!");
if (requestingUser.isEmpty()) return unauthorized(ex);
if (PASSWORD.equals(head)) return patchPassword(ex,requestingUser.get());
if (Path.PASSWORD.equals(head)) return patchPassword(ex,requestingUser.get());
if (OIDC.equals(head)) return patchService(ex,path.pop(),requestingUser.get());
userId = Long.parseLong(head);
DbUser editedUser = (DbUser) loadUser(userId);
@@ -236,7 +239,7 @@ public class UserModule extends BaseHandler implements UserService {
}
@Override
public boolean doPost(Path path, HttpExchange ex) throws IOException {
public boolean doPost(de.srsoftware.tools.Path path, HttpExchange ex) throws IOException {
addCors(ex);
var head = path.pop();
Long targetId = null;
@@ -249,7 +252,7 @@ public class UserModule extends BaseHandler implements UserService {
case CREATE -> postCreate(ex);
case OIDC -> postOIDC(ex, path);
case IMPERSONATE -> impersonate(ex, targetId);
case LOGIN -> postLogin(ex);
case Path.LOGIN -> postLogin(ex);
case SEARCH -> postSearch(ex);
case RESET_PW -> postResetPassword(ex);
case null, default -> super.doPost(path,ex);
@@ -273,16 +276,16 @@ public class UserModule extends BaseHandler implements UserService {
LOG.log(WARNING, "Request does not seem to contain JSON data!", e);
return sendContent(ex,HTTP_BAD_REQUEST,"Request does not seem to contain JSON data!");
}
if (!params.has(CODE)) return sendContent(ex,HTTP_BAD_REQUEST,"missing auth code");
if (!params.has(Field.CODE)) return sendContent(ex,HTTP_BAD_REQUEST,"missing auth code");
if (!params.has(STATE)) return sendContent(ex,HTTP_BAD_REQUEST,"no state submitted");
var code = params.getString(CODE);
var code = params.getString(Field.CODE);
var state = stateMap.remove(params.getString(STATE));
if (state == null) return sendContent(ex,HTTP_BAD_REQUEST,"no state submitted");
var redirect = url(ex).replaceAll("/api/.*","/oidc_callback");
var location = state.config.getString(TOKEN_ENDPOINT);
try {
var data = Map.of(GRANT_TYPE,AUTHORIZATION_CODE, CODE,code,REDIRECT_URI,redirect,CLIENT_ID,state.loginService.clientId(),CLIENT_SECRET,state.loginService.clientSecret());
var data = Map.of(GRANT_TYPE,AUTHORIZATION_CODE, Field.CODE,code,REDIRECT_URI,redirect,CLIENT_ID,state.loginService.clientId(),CLIENT_SECRET,state.loginService.clientSecret());
var resp = request(location,data,MIME_FORM_URL,state.loginService.basicAuth());
if (!(resp instanceof JSONObject json)) return sendContent(ex,HTTP_BAD_REQUEST,format("{0} did not return JSON!",location));
if (!json.has(ID_TOKEN)) return sendContent(ex,HTTP_FAILED_DEPENDENCY,"Missing ID token token exchange failed!");
@@ -321,13 +324,13 @@ public class UserModule extends BaseHandler implements UserService {
}
private boolean getOIDC(HttpExchange ex, UmbrellaUser user, Path path) throws IOException, UmbrellaException {
private boolean getOIDC(HttpExchange ex, UmbrellaUser user, de.srsoftware.tools.Path path) throws IOException, UmbrellaException {
var head = path.pop();
return switch (head){
case BUTTONS -> getOidcButtons(ex);
case LIST -> getServiceList(ex,user);
case CONNECTED -> getConnectedServices(ex,user);
case REDIRECT -> getOidcRedirect(ex,path.pop());
case Path.REDIRECT -> getOidcRedirect(ex,path.pop());
case null -> super.doGet(path,ex);
default -> getOIDC(ex,user,head);
};
@@ -370,7 +373,7 @@ public class UserModule extends BaseHandler implements UserService {
var clientId = loginService.clientId();
var state = UUID.randomUUID().toString();
stateMap.put(state, State.of(loginService, config));
return sendContent(ex,Map.of(OIDC_CALLBACK, callback, AUTH_ENDPOINT, authEndpoint, SCOPE, OIDC_SCOPE, CLIENT_ID, clientId, RESPONSE_TYPE, CODE, STATE, state));
return sendContent(ex,Map.of(OIDC_CALLBACK, callback, AUTH_ENDPOINT, authEndpoint, SCOPE, OIDC_SCOPE, CLIENT_ID, clientId, RESPONSE_TYPE, Field.CODE, STATE, state));
} catch (UmbrellaException e){
return send(ex,e);
}
@@ -429,9 +432,9 @@ public class UserModule extends BaseHandler implements UserService {
}
private boolean postOIDC(HttpExchange ex, Path path) throws IOException {
private boolean postOIDC(HttpExchange ex, de.srsoftware.tools.Path path) throws IOException {
return switch (path.pop()){
case TOKEN -> exchangeToken(ex);
case Path.TOKEN -> exchangeToken(ex);
case null, default -> super.doPost(path,ex);
};
}
@@ -462,10 +465,10 @@ public class UserModule extends BaseHandler implements UserService {
private boolean patchService(HttpExchange ex, String serviceName, UmbrellaUser requestingUser) throws IOException, UmbrellaException {
if (!(requestingUser instanceof DbUser user && user.permissions().contains(MANAGE_LOGIN_SERVICES))) throw forbidden("You are not allowed to manage that service!");
var json = json(ex);
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);
if (!json.has(NAME) || !(json.get(NAME) instanceof String name) || name.isBlank()) throw missingField(NAME);
if (!json.has(URL) || !(json.get(URL) instanceof String url) || url.isBlank()) throw missingField(URL);
if (!json.has(CLIENT_ID) || !(json.get(CLIENT_ID) instanceof String clientId) || clientId.isBlank()) throw missingField(CLIENT_ID);
if (!json.has(CLIENT_SECRET) || !(json.get(CLIENT_SECRET) instanceof String secret) || secret.isBlank()) throw missingField(CLIENT_SECRET);
var service = logins.save(new LoginService(name,url,clientId,secret, DEFAULT_FIELD));
return sendContent(ex,service.toMap());
}

View File

@@ -1,7 +1,7 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.user.model;
import static de.srsoftware.umbrella.core.Constants.USER_ID;
import static de.srsoftware.umbrella.core.constants.Field.USER_ID;
import static de.srsoftware.umbrella.user.Constants.*;
import de.srsoftware.tools.Mappable;

View File

@@ -3,8 +3,8 @@ package de.srsoftware.umbrella.user.model;
import static de.srsoftware.tools.Strings.base64;
import static de.srsoftware.umbrella.core.Constants.NAME;
import static de.srsoftware.umbrella.core.Constants.URL;
import static de.srsoftware.umbrella.core.constants.Field.NAME;
import static de.srsoftware.umbrella.core.constants.Field.URL;
import static de.srsoftware.umbrella.user.Constants.*;
import static java.nio.charset.StandardCharsets.UTF_8;

View File

@@ -4,19 +4,25 @@ package de.srsoftware.umbrella.user.sqlite;
import static de.srsoftware.tools.jdbc.Condition.*;
import static de.srsoftware.tools.jdbc.Query.*;
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
import static de.srsoftware.umbrella.core.Constants.*;
import static de.srsoftware.umbrella.core.Errors.*;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException;
import static de.srsoftware.umbrella.core.constants.Field.*;
import static de.srsoftware.umbrella.core.constants.Field.SETTINGS;
import static de.srsoftware.umbrella.core.constants.Field.TYPE;
import static de.srsoftware.umbrella.core.constants.Text.*;
import static de.srsoftware.umbrella.core.constants.Text.USERS;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.failedToLoadObject;
import static de.srsoftware.umbrella.core.model.Translatable.t;
import static de.srsoftware.umbrella.user.Constants.*;
import static de.srsoftware.umbrella.user.model.DbUser.ADMIN_PERMISSIONS;
import static java.lang.System.Logger.Level.*;
import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
import static java.text.MessageFormat.format;
import static java.time.ZoneOffset.UTC;
import de.srsoftware.tools.PasswordHasher;
import de.srsoftware.tools.jdbc.Query;
import de.srsoftware.umbrella.core.BaseDb;
import de.srsoftware.umbrella.core.constants.Text;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.core.model.*;
import de.srsoftware.umbrella.user.BadHasher;
@@ -55,7 +61,7 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute();
stmt.close();
} catch (SQLException e) {
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_LOGIN_SERVICES).causedBy(e);
throw failedToCreateTable(TABLE_LOGIN_SERVICES).causedBy(e);
}
createTable = """
@@ -68,7 +74,7 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute();
stmt.close();
} catch (SQLException e) {
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_SERVICE_IDS_USERS).causedBy(e);
throw failedToCreateTable(TABLE_SERVICE_IDS_USERS).causedBy(e);
}
createTable = """
@@ -81,7 +87,7 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute();
stmt.close();
} catch (SQLException e) {
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_TOKEN_USES).causedBy(e);
throw failedToCreateTable(TABLE_TOKEN_USES).causedBy(e);
}
}
@@ -105,11 +111,11 @@ CREATE TABLE IF NOT EXISTS {0} (
private void createLanguageColumn() {
var sql = "ALTER TABLE {0} ADD COLUMN {1} VARCHAR(10)";
try {
var stmt = db.prepareStatement(format(sql,TABLE_USERS,LANGUAGE));
var stmt = db.prepareStatement(format(sql,TABLE_USERS, LANGUAGE));
stmt.execute();
stmt.close();
} catch (SQLException e) {
throw databaseException(FAILED_TO_ADD_COLUMN,LANGUAGE,TABLE_USERS).causedBy(e);
throw databaseException(FAILED_TO_ADD_COLUMN, NAME, LANGUAGE, TABLE,TABLE_USERS).causedBy(e);
}
}
@@ -139,8 +145,7 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR,ERROR_FAILED_CREATE_TABLE,TABLE_USERS,e);
throw new RuntimeException(e);
throw failedToCreateTable(TABLE_USERS);
}
long count = 0L;
@@ -153,9 +158,9 @@ CREATE TABLE IF NOT EXISTS {0} (
}
try {
if (count<1) insertInto(TABLE_USERS,LOGIN,PASS,THEME,SETTINGS).values("admin", hasher.hash("admin",null),"default",null).execute(db);
if (count<1) insertInto(TABLE_USERS, LOGIN, PASS,THEME, SETTINGS).values("admin", hasher.hash("admin",null),"default",null).execute(db);
} catch (SQLException e) {
throw databaseException(FAILED_TO_STORE_ENTITY,"first user");
throw failedToStoreObject(t("first user")).causedBy(e);
}
createTable = """
@@ -169,7 +174,7 @@ CREATE TABLE IF NOT EXISTS {0} (
stmt.execute();
stmt.close();
} catch (SQLException e) {
throw databaseException(FAILED_TO_CREATE_TABLE,TABLE_USERS).causedBy(e);
throw failedToCreateTable(TABLE_USERS).causedBy(e);
}
}
@@ -178,7 +183,7 @@ CREATE TABLE IF NOT EXISTS {0} (
try {
Query.delete().from(TABLE_USERS).where(ID,equal(userId)).execute(db);
} catch (SQLException e) {
throw databaseException(FAILED_TO_DROP_ENTITY,"user "+userId).causedBy(e);
throw failedToDropObject(t(USER_WITH_ID, ID,userId)).causedBy(e);
}
return userId;
}
@@ -189,7 +194,7 @@ CREATE TABLE IF NOT EXISTS {0} (
Query.delete().from(TABLE_LOGIN_SERVICES).where(NAME,equal(serviceName)).execute(db);
Query.delete().from(TABLE_SERVICE_IDS_USERS).where(SERVICE_ID,like(serviceName+":%")).execute(db);
} catch (SQLException e) {
throw databaseException(FAILED_TO_DROP_ENTITY,serviceName).causedBy(e);
throw failedToDropObject(t(SERVICE_WITH_ID,ID,serviceName)).causedBy(e);
}
return serviceName;
}
@@ -214,7 +219,7 @@ CREATE TABLE IF NOT EXISTS {0} (
try {
return Query.delete().from(TABLE_TOKENS).where(TOKEN, equal(token)).execute(db);
} catch (SQLException e){
throw databaseException(FAILED_TO_DROP_ENTITY,"session token").causedBy(e);
throw failedToDropObject(t("session token")).causedBy(e);
}
}
@@ -226,7 +231,7 @@ CREATE TABLE IF NOT EXISTS {0} (
LOG.log(DEBUG,"Extended session of user {0} until {1}",session.user().name(),then());
return session.extended(newExpiration);
} catch (SQLException e) {
throw databaseException(FAILED_TO_UPDATE_ENTITY,session.token()).causedBy(e);
throw databaseException(FAILED_TO_UPDATE_OBJECT, OBJECT,session.token()).causedBy(e);
}
}
@@ -245,7 +250,7 @@ CREATE TABLE IF NOT EXISTS {0} (
insertInto(TABLE_TOKENS, USER_ID, TOKEN, EXPIRATION).values(session.user().id(),session.token(),session.expiration().getEpochSecond()).execute(db);
return session;
} catch (SQLException e) {
throw databaseException(FAILED_TO_LOAD_ENTITIES_OF_OWNER,"session",user.name()).causedBy(e);
throw databaseException(FAILED_TO_LOAD_ENTITIES_OF_OWNER, TYPE,t(SESSION), OWNER,user.name()).causedBy(e);
}
}
@@ -259,7 +264,7 @@ CREATE TABLE IF NOT EXISTS {0} (
} catch (SQLException sqle){
LOG.log(WARNING,"Failed to load user_id for '{0}' @ '{1}'!",foreignUserId,loginService);
}
if (userId == null) throw databaseException(FAILED_TO_LOAD_ENTITIES_OF_OWNER,foreignUserId,loginService);
if (userId == null) throw databaseException(FAILED_TO_LOAD_ENTITIES_OF_OWNER, TYPE, t(USER_WITH_ID, ID,foreignUserId), OWNER,loginService);
return userId;
}
@@ -278,7 +283,7 @@ CREATE TABLE IF NOT EXISTS {0} (
}
rs.close();
} catch (SQLException e) {
throw databaseException(FAILED_TO_LIST_ENTITIES,USERS).causedBy(e);
throw databaseException(FAILED_TO_LIST_ENTITIES,t(USERS)).causedBy(e);
}
return list;
}
@@ -292,7 +297,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return list;
} catch (SQLException e) {
throw databaseException(FAILED_TO_LOAD_ENTITIES_OF_OWNER,"service ids","user "+userId).causedBy(e);
throw databaseException(FAILED_TO_LOAD_ENTITIES_OF_OWNER, TYPE,"service ids", OWNER, t(USER_WITH_ID, ID,userId)).causedBy(e);
}
}
@@ -304,7 +309,7 @@ CREATE TABLE IF NOT EXISTS {0} (
while (rs.next()) list.add(toLoginService(rs));
rs.close();
} catch (SQLException e){
throw databaseException(FAILED_TO_LIST_ENTITIES,TABLE_LOGIN_SERVICES).causedBy(e);
throw databaseException(FAILED_TO_LIST_ENTITIES, TYPE,TABLE_LOGIN_SERVICES).causedBy(e);
}
return list;
}
@@ -317,7 +322,7 @@ CREATE TABLE IF NOT EXISTS {0} (
if (rs.next()) loginService = toLoginService(rs);
rs.close();
} catch (SQLException e) {
throw databaseException(FAILED_TO_LOAD_ENTITY,"login service").causedBy(e);
throw databaseException(FAILED_TO_LOAD_OBJECT, OBJECT,t(LOGIN_SERVICE)).causedBy(e);
}
if (loginService == null) throw new UmbrellaException(500,"Failed to load login service \"{0}\"!",name);
return loginService;
@@ -334,7 +339,7 @@ CREATE TABLE IF NOT EXISTS {0} (
} catch (SQLException e) {
LOG.log(WARNING,"Failed to load user for \"{0}\"!",email);
}
if (user == null) throw databaseException(FAILED_TO_LOAD_ENTITY_BY_ID,USER,email);
if (user == null) throw failedToLoadObject(Text.USER,email);
return user;
}
@@ -349,7 +354,7 @@ CREATE TABLE IF NOT EXISTS {0} (
} catch (SQLException e) {
LOG.log(WARNING,"Failed to load user \"{0}\"!",id);
}
if (user == null) throw databaseException(FAILED_TO_LOAD_ENTITY_BY_ID,USER,id);
if (user == null) throw failedToLoadObject(t(Text.USER),id);
return user;
}
@@ -364,7 +369,7 @@ CREATE TABLE IF NOT EXISTS {0} (
} catch (SQLException e) {
LOG.log(WARNING,"Failed to load user for session {0}!",session.token());
}
if (user == null) throw databaseException(FAILED_TO_LOAD_ENTITY_BY_ID,USER,session.token());
if (user == null) throw failedToLoadObject(t(Text.USER),session.token());
return user;
}
@@ -390,7 +395,7 @@ CREATE TABLE IF NOT EXISTS {0} (
} catch (SQLException e) {
LOG.log(WARNING,"Failed to load user \"{0}\"!",key,e);
}
if (user == null) throw new UmbrellaException(HTTP_UNAUTHORIZED,FAILED_TO_LOAD_ENTITY_BY_ID,USER,key);
if (user == null) throw unauthorized(FAILED_TO_LOAD_OBJECT_BY_ID, OBJECT,t(Text.USER), ID,key);
return user;
}
@@ -400,14 +405,14 @@ CREATE TABLE IF NOT EXISTS {0} (
dropExpiredSessions();
Session session = null;
try {
var rs = select(ALL).from(TABLE_TOKENS).leftJoin(USER_ID,TABLE_USERS,ID).where(TOKEN,equal(token)).exec(db);
var rs = select(ALL).from(TABLE_TOKENS).leftJoin(USER_ID,TABLE_USERS, ID).where(TOKEN,equal(token)).exec(db);
if (rs.next()) session = new Session(toUser(rs),token,Instant.ofEpochSecond(rs.getLong(EXPIRATION)));
rs.close();
} catch (SQLException e) {
LOG.log(WARNING,"Failed to request session ({0}) from database",token);
throw new UmbrellaException(500,"Failed to request session ({0}) from database",token);
}
if (session == null) throw databaseException(FAILED_TO_LOAD_ENTITY_BY_ID,"session",token);
if (session == null) throw failedToLoadObject("session",token);
return session;
}
@@ -420,7 +425,7 @@ CREATE TABLE IF NOT EXISTS {0} (
try {
insertInto(TABLE_SERVICE_IDS_USERS, SERVICE_ID, USER_ID).values(assignment.loginService()+":"+assignment.foreingId(),assignment.userId()).execute(db).close();
} catch (SQLException e) {
throw databaseException(FAILED_TO_STORE_ENTITY,"user assignment").causedBy(e);
throw failedToStoreObject("user assignment").causedBy(e);
}
return assignment;
}
@@ -434,7 +439,7 @@ CREATE TABLE IF NOT EXISTS {0} (
.execute(db)
.close();
} catch (SQLException e){
throw databaseException(FAILED_TO_STORE_ENTITY,"login service data").causedBy(e);
throw failedToStoreObject("login service data").causedBy(e);
}
return service;
}
@@ -445,7 +450,7 @@ CREATE TABLE IF NOT EXISTS {0} (
Long id = user.id();
var email = user.email() == null ? null : user.email().toString();
if (id<1){
insertInto(TABLE_USERS,LOGIN, PASS, THEME, EMAIL, LANGUAGE)
insertInto(TABLE_USERS, LOGIN, PASS, THEME, EMAIL, LANGUAGE)
.values(user.name(), user.hashedPassword(), user.theme(), email, user.language())
.execute(db)
.close();
@@ -456,7 +461,7 @@ CREATE TABLE IF NOT EXISTS {0} (
.close();
}
} catch (SQLException e) {
throw databaseException(FAILED_TO_STORE_ENTITY,"user data").causedBy(e);
throw failedToStoreObject("user data").causedBy(e);
}
return user;
}
@@ -473,7 +478,7 @@ CREATE TABLE IF NOT EXISTS {0} (
rs.close();
return users;
} catch (SQLException e){
throw databaseException(FAILED_TO_SEARCH_DB,USERS).causedBy(e);
throw failedToSearchDb(t(USERS)).causedBy(e);
}
}
@@ -524,7 +529,7 @@ CREATE TABLE IF NOT EXISTS {0} (
.execute(db);
return assignment;
} catch (SQLException e) {
throw databaseException(FAILED_TO_DROP_ENTITY_OF_ENTITY,"foreign id",assignment.foreingId(),"service",assignment.loginService()).causedBy(e);
throw failedToDropObjectFromObject("foreign id",assignment.foreingId(),"service",assignment.loginService()).causedBy(e);
}
}
}