fixed creation of first user upon database initalization
This commit is contained in:
@@ -40,9 +40,7 @@
|
|||||||
<Route path="/user/:user_id/edit" component={UserEdit} />
|
<Route path="/user/:user_id/edit" component={UserEdit} />
|
||||||
<Route path="/user/oidc/add" component={EditService} />
|
<Route path="/user/oidc/add" component={EditService} />
|
||||||
<Route path="/user/oidc/edit/:serviceName" component={EditService} />
|
<Route path="/user/oidc/edit/:serviceName" component={EditService} />
|
||||||
<Route>
|
<Route component={User} />
|
||||||
<p>Page not found</p>
|
|
||||||
</Route>
|
|
||||||
{:else}
|
{:else}
|
||||||
<Login />
|
<Login />
|
||||||
<Route path="/oidc_callback" component={Callback} />
|
<Route path="/oidc_callback" component={Callback} />
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* © SRSoftware 2025 */
|
||||||
package de.srsoftware.umbrella.message;
|
package de.srsoftware.umbrella.message;
|
||||||
|
|
||||||
import de.srsoftware.umbrella.core.BaseHandler;
|
import de.srsoftware.umbrella.core.BaseHandler;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* © SRSoftware 2025 */
|
||||||
package de.srsoftware.umbrella.message;
|
package de.srsoftware.umbrella.message;
|
||||||
|
|
||||||
public class MessageSystem {
|
public class MessageSystem {
|
||||||
|
|||||||
@@ -1,16 +1,6 @@
|
|||||||
/* © SRSoftware 2025 */
|
/* © SRSoftware 2025 */
|
||||||
package de.srsoftware.umbrella.message;
|
package de.srsoftware.umbrella.message;
|
||||||
|
|
||||||
import de.srsoftware.umbrella.core.UmbrellaException;
|
|
||||||
import de.srsoftware.umbrella.user.model.UmbrellaUser;
|
|
||||||
import de.srsoftware.umbrella.message.model.Settings;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static de.srsoftware.tools.jdbc.Condition.equal;
|
import static de.srsoftware.tools.jdbc.Condition.equal;
|
||||||
import static de.srsoftware.tools.jdbc.Query.*;
|
import static de.srsoftware.tools.jdbc.Query.*;
|
||||||
import static de.srsoftware.umbrella.core.Constants.*;
|
import static de.srsoftware.umbrella.core.Constants.*;
|
||||||
@@ -19,6 +9,15 @@ import static java.lang.System.Logger.Level.ERROR;
|
|||||||
import static java.lang.System.Logger.Level.WARNING;
|
import static java.lang.System.Logger.Level.WARNING;
|
||||||
import static java.text.MessageFormat.format;
|
import static java.text.MessageFormat.format;
|
||||||
|
|
||||||
|
import de.srsoftware.umbrella.core.UmbrellaException;
|
||||||
|
import de.srsoftware.umbrella.message.model.Settings;
|
||||||
|
import de.srsoftware.umbrella.user.model.UmbrellaUser;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class SqliteMessageDb implements MessageDb{
|
public class SqliteMessageDb implements MessageDb{
|
||||||
private static final System.Logger LOG = System.getLogger(SqliteMessageDb.class.getSimpleName());
|
private static final System.Logger LOG = System.getLogger(SqliteMessageDb.class.getSimpleName());
|
||||||
private final Connection db;
|
private final Connection db;
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import de.srsoftware.umbrella.user.api.UserDb;
|
|||||||
import de.srsoftware.umbrella.user.model.*;
|
import de.srsoftware.umbrella.user.model.*;
|
||||||
import de.srsoftware.umbrella.user.model.Session;
|
import de.srsoftware.umbrella.user.model.Session;
|
||||||
import de.srsoftware.umbrella.user.model.UmbrellaUser;
|
import de.srsoftware.umbrella.user.model.UmbrellaUser;
|
||||||
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@@ -159,8 +158,17 @@ CREATE TABLE IF NOT EXISTS {0} (
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long count = 0L;
|
||||||
try {
|
try {
|
||||||
Query.insertInto(TABLE_USERS,LOGIN,PASS,THEME,SETTINGS).values("admin", hasher.hash("admin",null),"default",null).execute(db);
|
ResultSet rs = select("COUNT(*)").from(TABLE_USERS).exec(db);
|
||||||
|
if (rs.next()) count = rs.getLong(1);
|
||||||
|
rs.close();
|
||||||
|
} catch (SQLException ignored) {
|
||||||
|
// go on with table creation
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (count<1) insertInto(TABLE_USERS,LOGIN,PASS,THEME,SETTINGS).values("admin", hasher.hash("admin",null),"default",null).execute(db);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOG.log(ERROR,"Failed to create first user…");
|
LOG.log(ERROR,"Failed to create first user…");
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|||||||
@@ -1,19 +1,15 @@
|
|||||||
/* © SRSoftware 2025 */
|
/* © SRSoftware 2025 */
|
||||||
package de.srsoftware.umbrella.web;
|
package de.srsoftware.umbrella.web;
|
||||||
|
|
||||||
import static de.srsoftware.tools.Optionals.nullable;
|
|
||||||
import static java.lang.System.Logger.Level.DEBUG;
|
import static java.lang.System.Logger.Level.DEBUG;
|
||||||
import static java.lang.System.Logger.Level.WARNING;
|
import static java.lang.System.Logger.Level.WARNING;
|
||||||
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
|
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
|
||||||
|
|
||||||
import com.sun.net.httpserver.HttpExchange;
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
import de.srsoftware.tools.Path;
|
import de.srsoftware.tools.Path;
|
||||||
import de.srsoftware.tools.PathHandler;
|
|
||||||
import de.srsoftware.umbrella.core.BaseHandler;
|
import de.srsoftware.umbrella.core.BaseHandler;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class WebHandler extends BaseHandler {
|
public class WebHandler extends BaseHandler {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user