Browse Source

improved UI

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
Stephan Richter 6 months ago
parent
commit
8cccd8b4e8
  1. 10
      de.srsoftware.http/src/main/java/de/srsoftware/http/PathHandler.java
  2. 12
      de.srsoftware.oidc.app/src/main/java/de/srsoftware/oidc/app/Application.java
  3. 2
      de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/ClientController.java
  4. 89
      de.srsoftware.oidc.datastore.sqlite/src/main/java/de/srsoftware/oidc/datastore/sqlite/SqliteMailConfig.java
  5. 4
      de.srsoftware.oidc.web/src/main/resources/de/reset.html
  6. 5
      de.srsoftware.oidc.web/src/main/resources/en/reset.html
  7. 12
      de.srsoftware.oidc.web/src/main/resources/en/scripts/index.js
  8. 12
      de.srsoftware.oidc.web/src/main/resources/en/scripts/reset.js
  9. 1
      settings.gradle

10
de.srsoftware.http/src/main/java/de/srsoftware/http/PathHandler.java

@ -76,9 +76,9 @@ public abstract class PathHandler implements HttpHandler {
String method = ex.getRequestMethod(); String method = ex.getRequestMethod();
LOG.log(INFO, "{0} {1}", method, path); LOG.log(INFO, "{0} {1}", method, path);
boolean ignored = switch (method) { boolean ignored = switch (method) {
case DELETE -> doDelete(path,ex); case DELETE -> doDelete(path, ex);
case GET -> doGet(path,ex); case GET -> doGet(path, ex);
case POST -> doPost(path,ex); case POST -> doPost(path, ex);
default -> false; default -> false;
}; };
ex.getResponseBody().close(); ex.getResponseBody().close();
@ -86,7 +86,7 @@ public abstract class PathHandler implements HttpHandler {
public String relativePath(HttpExchange ex) { public String relativePath(HttpExchange ex) {
var requestPath = ex.getRequestURI().toString(); var requestPath = ex.getRequestURI().toString();
for (var path : paths){ for (var path : paths) {
if (requestPath.startsWith(path)) { if (requestPath.startsWith(path)) {
requestPath = requestPath.substring(path.length()); requestPath = requestPath.substring(path.length());
break; break;
@ -198,4 +198,4 @@ public abstract class PathHandler implements HttpHandler {
public static String url(HttpExchange ex) { public static String url(HttpExchange ex) {
return hostname(ex) + ex.getRequestURI(); return hostname(ex) + ex.getRequestURI();
} }
} }

12
de.srsoftware.oidc.app/src/main/java/de/srsoftware/oidc/app/Application.java

@ -106,7 +106,7 @@ public class Application {
private static AuthorizationService setupAuthService(Configuration config, Path defaultFile, FileStoreProvider fileStoreProvider) throws SQLException { private static AuthorizationService setupAuthService(Configuration config, Path defaultFile, FileStoreProvider fileStoreProvider) throws SQLException {
var authServiceLocation = new File(config.getOrDefault("auth_store", defaultFile)); var authServiceLocation = new File(config.getOrDefault("auth_store", defaultFile));
return switch (extension(authServiceLocation)){ return switch (extension(authServiceLocation)) {
case "db", "sqlite", "sqlite3" -> new SqliteAuthService(connectionProvider.get(authServiceLocation)); case "db", "sqlite", "sqlite3" -> new SqliteAuthService(connectionProvider.get(authServiceLocation));
default -> fileStoreProvider.get(authServiceLocation); default -> fileStoreProvider.get(authServiceLocation);
}; };
@ -114,7 +114,7 @@ public class Application {
private static SessionService setupSessionService(Configuration config, Path defaultFile, FileStoreProvider fileStoreProvider) throws SQLException { private static SessionService setupSessionService(Configuration config, Path defaultFile, FileStoreProvider fileStoreProvider) throws SQLException {
var sessionStore = new File(config.getOrDefault("session_storage", defaultFile)); var sessionStore = new File(config.getOrDefault("session_storage", defaultFile));
return switch (extension(sessionStore)){ return switch (extension(sessionStore)) {
case "db", "sqlite", "sqlite3" -> new SqliteSessionService(connectionProvider.get(sessionStore)); case "db", "sqlite", "sqlite3" -> new SqliteSessionService(connectionProvider.get(sessionStore));
default -> fileStoreProvider.get(sessionStore); default -> fileStoreProvider.get(sessionStore);
}; };
@ -122,7 +122,7 @@ public class Application {
private static MailConfig setupMailConfig(Configuration config, Path defaultFile, FileStoreProvider fileStoreProvider) throws SQLException { private static MailConfig setupMailConfig(Configuration config, Path defaultFile, FileStoreProvider fileStoreProvider) throws SQLException {
var mailConfigLocation = new File(config.getOrDefault("mail_config_storage", defaultFile)); var mailConfigLocation = new File(config.getOrDefault("mail_config_storage", defaultFile));
var mailConfig = switch (extension(mailConfigLocation)){ var mailConfig = switch (extension(mailConfigLocation)) {
case "db", "sqlite", "sqlite3" -> new SqliteMailConfig(connectionProvider.get(mailConfigLocation)); case "db", "sqlite", "sqlite3" -> new SqliteMailConfig(connectionProvider.get(mailConfigLocation));
default -> fileStoreProvider.get(mailConfigLocation); default -> fileStoreProvider.get(mailConfigLocation);
}; };
@ -138,8 +138,8 @@ public class Application {
private static UserService setupUserService(Configuration config, Path defaultFile, FileStoreProvider fileStoreProvider, UuidHasher passHasher) throws SQLException { private static UserService setupUserService(Configuration config, Path defaultFile, FileStoreProvider fileStoreProvider, UuidHasher passHasher) throws SQLException {
var userStorageLocation = new File(config.getOrDefault("user_storage", defaultFile)); var userStorageLocation = new File(config.getOrDefault("user_storage", defaultFile));
var userService = switch (extension(userStorageLocation).toLowerCase()){ var userService = switch (extension(userStorageLocation).toLowerCase()) {
case "db", "sqlite", "sqlite3" -> new SqliteUserService(connectionProvider.get(userStorageLocation),passHasher); case "db", "sqlite", "sqlite3" -> new SqliteUserService(connectionProvider.get(userStorageLocation), passHasher);
default -> fileStoreProvider.get(userStorageLocation); default -> fileStoreProvider.get(userStorageLocation);
}; };
@ -196,5 +196,5 @@ public class Application {
} }
return map; return map;
} }
} }

2
de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/ClientController.java

@ -158,7 +158,7 @@ public class ClientController extends Controller {
.stream() .stream()
.map(clients::getClient) .map(clients::getClient)
.flatMap(Optional::stream) .flatMap(Optional::stream)
.sorted(Comparator.comparing(Client::name)) .sorted(Comparator.comparing(Client::name, String.CASE_INSENSITIVE_ORDER))
.map(Client::safeMap) .map(Client::safeMap)
.toList(); .toList();
return sendContent(ex, Map.of(AUTHORZED, authorizedClients, NAME, user.realName())); return sendContent(ex, Map.of(AUTHORZED, authorizedClients, NAME, user.realName()));

89
de.srsoftware.oidc.datastore.sqlite/src/main/java/de/srsoftware/oidc/datastore/sqlite/SqliteMailConfig.java

@ -76,84 +76,83 @@ public class SqliteMailConfig extends SqliteStore implements MailConfig {
stmt.setInt(1, ++currentVersion); stmt.setInt(1, ++currentVersion);
stmt.execute(); stmt.execute();
conn.commit(); conn.commit();
} } catch (Exception e) {
catch (Exception e) {
conn.rollback(); conn.rollback();
LOG.log(System.Logger.Level.ERROR, "Failed to update at {} = {}", STORE_VERSION, currentVersion); LOG.log(System.Logger.Level.ERROR, "Failed to update at {} = {}", STORE_VERSION, currentVersion);
break; break;
} }
} }
conn.setAutoCommit(true); conn.setAutoCommit(true);
} }
@Override @Override
public String smtpHost() { public String smtpHost() {
return smtpHost; return smtpHost;
} }
@Override @Override
public MailConfig smtpHost(String newValue) { public MailConfig smtpHost(String newValue) {
smtpHost = newValue; smtpHost = newValue;
return this; return this;
} }
@Override @Override
public int smtpPort() { public int smtpPort() {
return smtpPort; return smtpPort;
} }
@Override @Override
public MailConfig smtpPort(int newValue) { public MailConfig smtpPort(int newValue) {
smtpPort = newValue; smtpPort = newValue;
return this; return this;
} }
@Override @Override
public String senderAddress() { public String senderAddress() {
return senderAddress; return senderAddress;
} }
@Override @Override
public MailConfig senderAddress(String newValue) { public MailConfig senderAddress(String newValue) {
senderAddress = newValue; senderAddress = newValue;
return this; return this;
} }
@Override @Override
public String senderPassword() { public String senderPassword() {
return password; return password;
} }
@Override @Override
public MailConfig senderPassword(String newValue) { public MailConfig senderPassword(String newValue) {
password = newValue; password = newValue;
return this; return this;
} }
@Override @Override
public boolean startTls() { public boolean startTls() {
return startTls; return startTls;
} }
@Override @Override
public boolean smtpAuth() { public boolean smtpAuth() {
return smtpAuth; return smtpAuth;
} }
@Override @Override
public MailConfig startTls(boolean newValue) { public MailConfig startTls(boolean newValue) {
startTls = newValue; startTls = newValue;
return this; return this;
} }
@Override @Override
public MailConfig smtpAuth(boolean newValue) { public MailConfig smtpAuth(boolean newValue) {
smtpAuth = newValue; smtpAuth = newValue;
return this; return this;
} }
@Override @Override
public Authenticator authenticator() { public Authenticator authenticator() {
if (auth == null) { if (auth == null) {
auth = new Authenticator() { auth = new Authenticator() {
// override the getPasswordAuthentication method // override the getPasswordAuthentication method
@ -163,10 +162,10 @@ public Authenticator authenticator() {
}; };
} }
return auth; return auth;
} }
@Override @Override
public MailConfig save() { public MailConfig save() {
try { try {
var stmt = conn.prepareStatement(SAVE_MAILCONFIG); var stmt = conn.prepareStatement(SAVE_MAILCONFIG);
for (var entry : map().entrySet()) { for (var entry : map().entrySet()) {
@ -179,5 +178,5 @@ public MailConfig save() {
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
} }

4
de.srsoftware.oidc.web/src/main/resources/de/reset.html

@ -42,6 +42,10 @@
<th>Error</th> <th>Error</th>
<td class="warning">Zugriffs-Token gefunden, ist aber ungültig!</td> <td class="warning">Zugriffs-Token gefunden, ist aber ungültig!</td>
</tr> </tr>
<tr id="other_error" style="display: none">
<th>Error</th>
<td class="warning" id="other_error_text">Unbekannter Fehler!</td>
</tr>
<tr> <tr>
<td></td> <td></td>
<td><button id="passBtn" type="button" onClick="updatePass()">Aktualisieren</button></td> <td><button id="passBtn" type="button" onClick="updatePass()">Aktualisieren</button></td>

5
de.srsoftware.oidc.web/src/main/resources/en/reset.html

@ -42,6 +42,11 @@
<th>Error</th> <th>Error</th>
<td class="warning">I received an access token, but it is invalid!</td> <td class="warning">I received an access token, but it is invalid!</td>
</tr> </tr>
<tr id="other_error" style="display: none">
<th>Error</th>
<td class="warning" id="other_error_text">Unknown error!</td>
</tr>
<tr> <tr>
<td></td> <td></td>
<td><button id="passBtn" type="button" onClick="updatePass()">Update</button></td> <td><button id="passBtn" type="button" onClick="updatePass()">Update</button></td>

12
de.srsoftware.oidc.web/src/main/resources/en/scripts/index.js

@ -11,12 +11,18 @@ function handleDash(response){
var clients = data.authorized; var clients = data.authorized;
var content = document.getElementById('content'); var content = document.getElementById('content');
var any = false; var any = false;
var lastLetter = null;
for (let id in clients){ for (let id in clients){
var client = clients[id]; var client = clients[id];
if (client.landing_page){ if (client.landing_page){
var div = document.createElement("div"); var initialLetter = client.name.charAt(0).toUpperCase();
div.innerHTML = `<button onclick="window.location.href='${client.landing_page}';">${client.name}</button>`; if (initialLetter != lastLetter) {
content.append(div); if (lastLetter) content.append(document.createElement("br"));
lastLetter = initialLetter;
}
var span = document.createElement("span");
span.innerHTML = `<button onclick="window.location.href='${client.landing_page}';">${client.name}</button>`;
content.append(span);
any = true; any = true;
} }
} }

12
de.srsoftware.oidc.web/src/main/resources/en/scripts/reset.js

@ -10,10 +10,14 @@ function handlePasswordResponse(response){
} else { } else {
setText('passBtn', 'Update failed!'); setText('passBtn', 'Update failed!');
response.text().then(text => { response.text().then(text => {
if (text == 'invalid token') show('invalid_token'); if (text == 'invalid token') show('invalid_token'); else
if (text == 'token missing') show('missing_token'); if (text == 'token missing') show('missing_token'); else
if (text == 'password mismatch') show('password_mismatch'); if (text == 'password mismatch') show('password_mismatch'); else
if (text == 'weak password') show('weak_password'); if (text == 'weak password') show('weak_password'); else {
setText('other_error_text',text);
show('other_error');
}
}); });
} }
enable('passBtn'); enable('passBtn');

1
settings.gradle

@ -9,4 +9,5 @@ include 'de.srsoftware.oidc.datastore.encrypted'
include 'de.srsoftware.oidc.datastore.file' include 'de.srsoftware.oidc.datastore.file'
include 'de.srsoftware.oidc.web' include 'de.srsoftware.oidc.web'
include 'de.srsoftware.utils' include 'de.srsoftware.utils'
include 'de.srsoftware.slf4j2syslog'

Loading…
Cancel
Save