diff --git a/config/formatting.xml b/config/formatting.xml
deleted file mode 100644
index 5fbd51e..0000000
--- a/config/formatting.xml
+++ /dev/null
@@ -1,337 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/de.srsoftware.oidc.api/build.gradle b/de.srsoftware.oidc.api/build.gradle
index 1a11b90..155010e 100644
--- a/de.srsoftware.oidc.api/build.gradle
+++ b/de.srsoftware.oidc.api/build.gradle
@@ -6,7 +6,7 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter'
implementation 'de.srsoftware:tools.optionals:1.0.0'
- implementation 'de.srsoftware:tools.util:1.0.2'
+ implementation 'de.srsoftware:tools.util:1.0.3'
implementation 'org.bitbucket.b_c:jose4j:0.9.6'
implementation 'org.json:json:20240303'
implementation 'com.sun.mail:jakarta.mail:2.0.1'
diff --git a/de.srsoftware.oidc.app/build.gradle.kts b/de.srsoftware.oidc.app/build.gradle.kts
index 6baa74b..2eb579d 100644
--- a/de.srsoftware.oidc.app/build.gradle.kts
+++ b/de.srsoftware.oidc.app/build.gradle.kts
@@ -2,10 +2,10 @@ description = "SRSoftware OIDC: app"
dependencies{
implementation("org.json:json:20240303")
- implementation("de.srsoftware:tools.http:1.0.0")
+ implementation("de.srsoftware:tools.http:1.0.1")
implementation("de.srsoftware:tools.logging:1.0.0")
implementation("de.srsoftware:tools.optionals:1.0.0")
- implementation("de.srsoftware:tools.util:1.0.2")
+ implementation("de.srsoftware:tools.util:1.0.3")
implementation(project(":de.srsoftware.oidc.api"))
implementation(project(":de.srsoftware.oidc.backend"))
implementation(project(":de.srsoftware.oidc.datastore.encrypted"))
diff --git a/de.srsoftware.oidc.app/src/main/java/de/srsoftware/oidc/app/Application.java b/de.srsoftware.oidc.app/src/main/java/de/srsoftware/oidc/app/Application.java
index 740beb3..a73af90 100644
--- a/de.srsoftware.oidc.app/src/main/java/de/srsoftware/oidc/app/Application.java
+++ b/de.srsoftware.oidc.app/src/main/java/de/srsoftware/oidc/app/Application.java
@@ -46,11 +46,11 @@ public class Application {
public static final String ROOT = "/";
public static final String STATIC_PATH = "/web";
- private static final String BASE_PATH = "basePath";
- private static final String FAVICON = "/favicon.ico";
- private static final String INDEX = STATIC_PATH + "/index.html";
- private static final String WELL_KNOWN = "/.well-known";
- private static System.Logger LOG = new ColorLogger("Application").setLogLevel(DEBUG);
+ private static final String BASE_PATH = "basePath";
+ private static final String FAVICON = "/favicon.ico";
+ private static final String INDEX = STATIC_PATH + "/index.html";
+ private static final String WELL_KNOWN = "/.well-known";
+ private static final System.Logger LOG = new ColorLogger("Application").setLogLevel(DEBUG);
public static void main(String[] args) throws Exception {
var argMap = map(args);
diff --git a/de.srsoftware.oidc.backend/build.gradle.kts b/de.srsoftware.oidc.backend/build.gradle.kts
index aad3421..cd45bee 100644
--- a/de.srsoftware.oidc.backend/build.gradle.kts
+++ b/de.srsoftware.oidc.backend/build.gradle.kts
@@ -2,9 +2,9 @@ description = "SRSoftware OIDC: backend"
dependencies{
implementation("com.sun.mail:jakarta.mail:2.0.1")
- implementation("de.srsoftware:tools.http:1.0.0")
+ implementation("de.srsoftware:tools.http:1.0.1")
implementation("de.srsoftware:tools.optionals:1.0.0")
- implementation("de.srsoftware:tools.util:1.0.2")
+ implementation("de.srsoftware:tools.util:1.0.3")
implementation("org.bitbucket.b_c:jose4j:0.9.6")
implementation("org.json:json:20240303")
diff --git a/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/ClientController.java b/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/ClientController.java
index 465472e..0f1f0da 100644
--- a/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/ClientController.java
+++ b/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/ClientController.java
@@ -42,15 +42,15 @@ public class ClientController extends Controller {
var user = optUser.get();
var json = json(ex);
var state = json.has(STATE) ? json.getString(STATE) : null;
- if (!json.has(CLIENT_ID)) return badRequest(ex, Error.message(ERROR_MISSING_PARAMETER, PARAM, CLIENT_ID, STATE, state));
+ if (!json.has(CLIENT_ID)) return badRequest(ex, Error.of(ERROR_MISSING_PARAMETER).addData(PARAM, CLIENT_ID, STATE, state));
var clientId = json.getString(CLIENT_ID);
var optClient = clients.getClient(clientId);
- if (optClient.isEmpty()) return badRequest(ex, Error.message(ERROR_UNKNOWN_CLIENT, CLIENT_ID, clientId, STATE, state));
+ if (optClient.isEmpty()) return badRequest(ex, Error.of(ERROR_UNKNOWN_CLIENT).addData(CLIENT_ID, clientId, STATE, state));
for (String param : List.of(SCOPE, RESPONSE_TYPE, REDIRECT_URI)) {
- if (!json.has(param)) return badRequest(ex, Error.message(ERROR_MISSING_PARAMETER, PARAM, param, STATE, state));
+ if (!json.has(param)) return badRequest(ex, Error.of(ERROR_MISSING_PARAMETER).addData(PARAM, param, STATE, state));
}
var scopes = toList(json, SCOPE);
- if (!scopes.contains(OPENID)) return badRequest(ex, Error.message(ERROR_MISSING_PARAMETER, PARAM, "Scope: openid", STATE, state));
+ if (!scopes.contains(OPENID)) return badRequest(ex, Error.of(ERROR_MISSING_PARAMETER).addData(PARAM, "Scope: openid", STATE, state));
var responseTypes = toList(json, RESPONSE_TYPE);
var types = 0;
for (var responseType : responseTypes) {
@@ -60,15 +60,15 @@ public class ClientController extends Controller {
types++;
break;
default:
- return badRequest(ex, Error.message(ERROR_UNSUPPORTED_RESPONSE_TYPE, RESPONSE_TYPE, responseType, STATE, state));
+ return badRequest(ex, Error.of(ERROR_UNSUPPORTED_RESPONSE_TYPE).addData(RESPONSE_TYPE, responseType, STATE, state));
}
}
- if (types < 1) return badRequest(ex, Error.message(ERROR_MISSING_CODE_RESPONSE_TYPE, STATE, state));
+ if (types < 1) return badRequest(ex, Error.of(ERROR_MISSING_CODE_RESPONSE_TYPE).addData(STATE, state));
var client = optClient.get();
var redirect = json.getString(REDIRECT_URI);
- if (!client.redirectUris().contains(redirect)) return badRequest(ex, Error.message(ERROR_INVALID_REDIRECT, REDIRECT_URI, redirect, STATE, state));
+ if (!client.redirectUris().contains(redirect)) return badRequest(ex, Error.of(ERROR_INVALID_REDIRECT).addData(REDIRECT_URI, redirect, STATE, state));
if (json.has(AUTHORZED)) { // user did consent
var authorized = json.getJSONObject(AUTHORZED);
diff --git a/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/UserController.java b/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/UserController.java
index 611b32e..a3382e0 100644
--- a/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/UserController.java
+++ b/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/UserController.java
@@ -14,7 +14,7 @@ import de.srsoftware.oidc.api.*;
import de.srsoftware.oidc.api.data.Permission;
import de.srsoftware.oidc.api.data.Session;
import de.srsoftware.oidc.api.data.User;
-import de.srsoftware.tools.Payload;
+import de.srsoftware.tools.Content;
import de.srsoftware.tools.Result;
import de.srsoftware.tools.SessionToken;
import jakarta.mail.*;
@@ -198,7 +198,7 @@ public class UserController extends Controller {
var trust = body.has(TRUST) && body.getBoolean(TRUST);
Result result = users.login(username, password);
- if (result instanceof Payload user) return sendUserAndCookie(ex, sessions.createSession(user.get(), trust), user.get());
+ if (result instanceof Content user) return sendUserAndCookie(ex, sessions.createSession(user.get(), trust), user.get());
return sendContent(ex, HTTP_UNAUTHORIZED, result);
}
@@ -261,8 +261,6 @@ public class UserController extends Controller {
message.setContent(multipart);
Transport.send(message);
- } catch (AddressException e) {
- throw new RuntimeException(e);
} catch (MessagingException e) {
throw new RuntimeException(e);
}
diff --git a/de.srsoftware.oidc.datastore.encrypted/build.gradle.kts b/de.srsoftware.oidc.datastore.encrypted/build.gradle.kts
index 78332cf..115944b 100644
--- a/de.srsoftware.oidc.datastore.encrypted/build.gradle.kts
+++ b/de.srsoftware.oidc.datastore.encrypted/build.gradle.kts
@@ -3,7 +3,7 @@ description = "SRSoftware OIDC: encrypted datastore module"
dependencies{
implementation("com.sun.mail:jakarta.mail:2.0.1")
implementation("de.srsoftware:tools.optionals:1.0.0")
- implementation("de.srsoftware:tools.util:1.0.2")
+ implementation("de.srsoftware:tools.util:1.0.3")
implementation(project(":de.srsoftware.oidc.api"))
testImplementation(project(":de.srsoftware.oidc.api","testBundle"))
diff --git a/de.srsoftware.oidc.datastore.encrypted/src/main/java/de/srsoftware/oidc/datastore/encrypted/EncryptedUserService.java b/de.srsoftware.oidc.datastore.encrypted/src/main/java/de/srsoftware/oidc/datastore/encrypted/EncryptedUserService.java
index e7a0c34..0e552e1 100644
--- a/de.srsoftware.oidc.datastore.encrypted/src/main/java/de/srsoftware/oidc/datastore/encrypted/EncryptedUserService.java
+++ b/de.srsoftware.oidc.datastore.encrypted/src/main/java/de/srsoftware/oidc/datastore/encrypted/EncryptedUserService.java
@@ -8,9 +8,9 @@ import static java.util.Optional.empty;
import de.srsoftware.oidc.api.UserService;
import de.srsoftware.oidc.api.data.AccessToken;
import de.srsoftware.oidc.api.data.User;
+import de.srsoftware.tools.Content;
import de.srsoftware.tools.Error;
import de.srsoftware.tools.PasswordHasher;
-import de.srsoftware.tools.Payload;
import de.srsoftware.tools.Result;
import java.util.*;
@@ -98,25 +98,25 @@ public class EncryptedUserService extends EncryptedConfig implements UserService
@Override
public Result login(String username, String password) {
- if (username == null || username.isBlank()) return Error.message(ERROR_NO_USERNAME);
+ if (username == null || username.isBlank()) return Error.of(ERROR_NO_USERNAME);
var optLock = getLock(username);
if (optLock.isPresent()) {
var lock = optLock.get();
LOG.log(WARNING, "{0} is locked after {1} failed logins. Lock will be released at {2}", username, lock.attempts(), lock.releaseTime());
- return Error.message(ERROR_LOCKED, ATTEMPTS, lock.attempts(), RELEASE, lock.releaseTime());
+ return new Error(ERROR_LOCKED).addData(ATTEMPTS, lock.attempts(), RELEASE, lock.releaseTime());
}
for (var encryptedUser : backend.list()) {
var decryptedUser = decrypt(encryptedUser);
var match = List.of(decryptedUser.username(), decryptedUser.realName(), decryptedUser.email()).contains(username);
if (match && hasher.matches(password, decryptedUser.hashedPassword())) {
this.unlock(username);
- return Payload.of(decryptedUser);
+ return Content.of(decryptedUser);
}
}
var lock = lock(username);
LOG.log(WARNING, "Login failed for {0} → locking account until {1}", username, lock.releaseTime());
- return Error.message(ERROR_LOGIN_FAILED, RELEASE, lock.releaseTime());
+ return new Error(ERROR_LOGIN_FAILED).addData(RELEASE, lock.releaseTime());
}
@Override
diff --git a/de.srsoftware.oidc.datastore.encrypted/src/test/java/de/srsoftware/oidc/datastore/encrypted/EncryptedUserServiceTest.java b/de.srsoftware.oidc.datastore.encrypted/src/test/java/de/srsoftware/oidc/datastore/encrypted/EncryptedUserServiceTest.java
index bf2f011..fe68158 100644
--- a/de.srsoftware.oidc.datastore.encrypted/src/test/java/de/srsoftware/oidc/datastore/encrypted/EncryptedUserServiceTest.java
+++ b/de.srsoftware.oidc.datastore.encrypted/src/test/java/de/srsoftware/oidc/datastore/encrypted/EncryptedUserServiceTest.java
@@ -8,9 +8,9 @@ import static java.lang.System.Logger.Level.WARNING;
import de.srsoftware.oidc.api.*;
import de.srsoftware.oidc.api.data.AccessToken;
import de.srsoftware.oidc.api.data.User;
+import de.srsoftware.tools.Content;
import de.srsoftware.tools.Error;
import de.srsoftware.tools.PasswordHasher;
-import de.srsoftware.tools.Payload;
import de.srsoftware.tools.Result;
import java.io.File;
import java.util.*;
@@ -19,10 +19,10 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
public class EncryptedUserServiceTest extends UserServiceTest {
- private static final System.Logger LOG = System.getLogger(EncryptedUserServiceTest.class.getSimpleName());
- private class InMemoryUserService implements UserService {
+ private static final System.Logger LOG = System.getLogger(EncryptedUserServiceTest.class.getSimpleName());
+ private static class InMemoryUserService implements UserService {
private final PasswordHasher hasher;
- private HashMap users = new HashMap<>();
+ private final HashMap users = new HashMap<>();
public InMemoryUserService(PasswordHasher hasher) {
this.hasher = hasher;
@@ -76,19 +76,19 @@ public class EncryptedUserServiceTest extends UserServiceTest {
if (optLock.isPresent()) {
var lock = optLock.get();
LOG.log(WARNING, "{} is locked after {} failed logins. Lock will be released at {}", username, lock.attempts(), lock.releaseTime());
- return Error.message(ERROR_LOCKED, ATTEMPTS, lock.attempts(), RELEASE, lock.releaseTime());
+ return new Error(ERROR_LOCKED).addData(ATTEMPTS, lock.attempts(), RELEASE, lock.releaseTime());
}
for (var entry : users.entrySet()) {
var user = entry.getValue();
if (user.username().equals(username) && passwordMatches(password, user)) {
unlock(username);
- return Payload.of(user);
+ return Content.of(user);
}
}
var lock = lock(username);
LOG.log(WARNING, "Login failed for {0} → locking account until {1}", username, lock.releaseTime());
- return Error.message(ERROR_LOGIN_FAILED, RELEASE, lock.releaseTime());
+ return new Error(ERROR_LOGIN_FAILED).addData(RELEASE, lock.releaseTime());
}
@Override
@@ -109,20 +109,21 @@ public class EncryptedUserServiceTest extends UserServiceTest {
return this;
}
}
- private File storage = new File("/tmp/" + UUID.randomUUID());
+ private final File storage = new File("/tmp/" + UUID.randomUUID());
private UserService userService;
- private String key, salt;
@AfterEach
public void tearDown() {
- if (storage.exists()) storage.delete();
+ if (storage.exists()) {
+ var ignored = storage.delete();
+ }
}
@BeforeEach
public void setup() {
tearDown();
- key = uuid();
- salt = uuid();
+ String key = uuid();
+ String salt = uuid();
InMemoryUserService backend = new InMemoryUserService(hasher());
userService = new EncryptedUserService(backend, key, salt, hasher());
}
diff --git a/de.srsoftware.oidc.datastore.file/build.gradle.kts b/de.srsoftware.oidc.datastore.file/build.gradle.kts
index 79d50dc..c1cad1b 100644
--- a/de.srsoftware.oidc.datastore.file/build.gradle.kts
+++ b/de.srsoftware.oidc.datastore.file/build.gradle.kts
@@ -3,7 +3,7 @@ description = "SRSoftware OIDC: file datastore module"
dependencies{
implementation("com.sun.mail:jakarta.mail:2.0.1")
implementation("de.srsoftware:tools.optionals:1.0.0")
- implementation("de.srsoftware:tools.util:1.0.2")
+ implementation("de.srsoftware:tools.util:1.0.3")
implementation("org.json:json:20240303")
implementation(project(":de.srsoftware.oidc.api"))
diff --git a/de.srsoftware.oidc.datastore.file/src/main/java/de/srsoftware/oidc/datastore/file/FileStore.java b/de.srsoftware.oidc.datastore.file/src/main/java/de/srsoftware/oidc/datastore/file/FileStore.java
index 91727c6..8571c14 100644
--- a/de.srsoftware.oidc.datastore.file/src/main/java/de/srsoftware/oidc/datastore/file/FileStore.java
+++ b/de.srsoftware.oidc.datastore.file/src/main/java/de/srsoftware/oidc/datastore/file/FileStore.java
@@ -10,9 +10,9 @@ import static java.util.Optional.empty;
import de.srsoftware.oidc.api.*;
import de.srsoftware.oidc.api.data.*;
+import de.srsoftware.tools.Content;
import de.srsoftware.tools.Error;
import de.srsoftware.tools.PasswordHasher;
-import de.srsoftware.tools.Payload;
import de.srsoftware.tools.Result;
import jakarta.mail.Authenticator;
import jakarta.mail.PasswordAuthentication;
@@ -181,13 +181,13 @@ public class FileStore implements AuthorizationService, ClientService, SessionSe
@Override
public Result login(String username, String password) {
- if (!json.has(USERS)) return Error.message(ERROR_LOGIN_FAILED);
- if (username == null || username.isBlank()) return Error.message(ERROR_NO_USERNAME);
+ if (!json.has(USERS)) return Error.of(ERROR_LOGIN_FAILED);
+ if (username == null || username.isBlank()) return Error.of(ERROR_NO_USERNAME);
var optLock = getLock(username);
if (optLock.isPresent()) {
var lock = optLock.get();
LOG.log(WARNING, "{0} is locked after {1} failed logins. Lock will be released at {2}", username, lock.attempts(), lock.releaseTime());
- return Error.message(ERROR_LOCKED, ATTEMPTS, lock.attempts(), RELEASE, lock.releaseTime());
+ return new Error(ERROR_LOCKED).addData(ATTEMPTS, lock.attempts(), RELEASE, lock.releaseTime());
}
try {
var users = json.getJSONObject(USERS);
@@ -198,14 +198,14 @@ public class FileStore implements AuthorizationService, ClientService, SessionSe
var loadedUser = User.of(userData, userId).filter(u -> passwordMatches(password, u));
if (loadedUser.isPresent()) {
unlock(username);
- return Payload.of(loadedUser.get());
+ return Content.of(loadedUser.get());
}
}
var lock = lock(username);
LOG.log(WARNING, "Login failed for {0} → locking account until {1}", username, lock.releaseTime());
- return Error.message(ERROR_LOGIN_FAILED, RELEASE, lock.releaseTime());
+ return new Error(ERROR_LOGIN_FAILED).addData(RELEASE, lock.releaseTime());
} catch (Exception e) {
- return Error.message(ERROR_LOGIN_FAILED);
+ return Error.of(ERROR_LOGIN_FAILED);
}
}
diff --git a/de.srsoftware.oidc.web/build.gradle.kts b/de.srsoftware.oidc.web/build.gradle.kts
index d0131c6..a2057ed 100644
--- a/de.srsoftware.oidc.web/build.gradle.kts
+++ b/de.srsoftware.oidc.web/build.gradle.kts
@@ -1,7 +1,7 @@
description = "SRSoftware OIDC: web module"
dependencies{
- implementation("de.srsoftware:tools.http:1.0.0")
+ implementation("de.srsoftware:tools.http:1.0.1")
implementation(project(":de.srsoftware.oidc.api"))
}
diff --git a/de.srsoftware.oidc.web/src/main/resources/en/scripts/authorization.js b/de.srsoftware.oidc.web/src/main/resources/en/scripts/authorization.js
index bfbd20d..79ec741 100644
--- a/de.srsoftware.oidc.web/src/main/resources/en/scripts/authorization.js
+++ b/de.srsoftware.oidc.web/src/main/resources/en/scripts/authorization.js
@@ -52,10 +52,10 @@ function handleResponse(response){
response.json().then(json => {
console.log("handleResponse → error",json);
if (json.error) show(json.error);
- if (json.metadata.client_id) setText('client_id',json.metadata.client_id);
- if (json.metadata.parameter) setText('parameter',json.metadata.parameter);
- if (json.metadata.redirect_uri) setText('redirect_uri',json.metadata.redirect_uri);
- if (json.metadata.response_type)setText('response_type',json.metadata.response_type)
+ if (json.data.client_id) setText('client_id',json.data.client_id);
+ if (json.data.parameter) setText('parameter',json.data.parameter);
+ if (json.data.redirect_uri) setText('redirect_uri',json.data.redirect_uri);
+ if (json.data.response_type)setText('response_type',json.data.response_type)
});
/*if (json.error != "invalid_request_uri"){
var url = params.get('redirect_uri') + '?' + new URLSearchParams(json).toString();
diff --git a/de.srsoftware.oidc.web/src/main/resources/en/scripts/login.js b/de.srsoftware.oidc.web/src/main/resources/en/scripts/login.js
index 2534b2c..1f20763 100644
--- a/de.srsoftware.oidc.web/src/main/resources/en/scripts/login.js
+++ b/de.srsoftware.oidc.web/src/main/resources/en/scripts/login.js
@@ -19,7 +19,7 @@ function handleLogin(response){
response.json().then(body => setTimeout(doRedirect,100));
} else {
response.json().then(json => {
- if (json.metadata.release) get('release').innerHTML = new Date(json.metadata.release).toLocaleString();
+ if (json.data.release) get('release').innerHTML = new Date(json.data.release).toLocaleString();
show(json.error);
});
}