From d01289c0683a8a70e24754cdc1e442151fdbc9d3 Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Mon, 5 Aug 2024 00:27:09 +0200 Subject: [PATCH] refactored classes and modules, fixed decoding bug Signed-off-by: Stephan Richter --- .../build.gradle | 1 + .../main/java/de/srsoftware/http}/Cookie.java | 2 +- .../java/de/srsoftware/http}/PathHandler.java | 5 ++-- .../de/srsoftware/http}/SessionToken.java | 2 +- .../oidc/api/AuthorizationService.java | 16 ++++++++++++ .../oidc/api/ClaimAuthorizationService.java | 12 --------- .../de/srsoftware/oidc/api/ClientService.java | 1 + .../de/srsoftware/oidc/api/Constants.java | 1 - .../srsoftware/oidc/api/SessionService.java | 2 ++ .../de/srsoftware/oidc/api/UserService.java | 1 + .../oidc/api/{ => data}/AuthResult.java | 2 +- .../oidc/api/{ => data}/Authorization.java | 2 +- .../oidc/api/{ => data}/AuthorizedScopes.java | 2 +- .../oidc/api/{ => data}/Client.java | 2 +- .../oidc/api/{ => data}/Permission.java | 2 +- .../oidc/api/{ => data}/Session.java | 2 +- .../srsoftware/oidc/api/{ => data}/User.java | 2 +- de.srsoftware.oidc.app/build.gradle | 1 + .../de/srsoftware/oidc/app/Application.java | 4 +-- de.srsoftware.oidc.backend/build.gradle | 4 +-- .../oidc/backend/ClientController.java | 13 ++++++---- .../srsoftware/oidc/backend/Controller.java | 6 ++--- .../oidc/backend/KeyStoreController.java | 2 +- .../oidc/backend/TokenController.java | 25 +++++++++++++------ .../oidc/backend/UserController.java | 6 +++-- .../oidc/backend/WellKnownController.java | 2 +- .../oidc/datastore/file/FileStore.java | 7 +++--- de.srsoftware.oidc.web/build.gradle | 1 + .../java/de/srsoftware/oidc/web/Forward.java | 2 +- .../de/srsoftware/oidc/web/StaticPages.java | 2 +- settings.gradle | 6 ++--- 31 files changed, 82 insertions(+), 56 deletions(-) rename {de.srsoftware.cookies => de.srsoftware.http}/build.gradle (88%) rename {de.srsoftware.cookies/src/main/java/de/srsoftware/cookies => de.srsoftware.http/src/main/java/de/srsoftware/http}/Cookie.java (97%) rename {de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api => de.srsoftware.http/src/main/java/de/srsoftware/http}/PathHandler.java (98%) rename {de.srsoftware.cookies/src/main/java/de/srsoftware/cookies => de.srsoftware.http/src/main/java/de/srsoftware/http}/SessionToken.java (95%) create mode 100644 de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/AuthorizationService.java delete mode 100644 de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/ClaimAuthorizationService.java rename de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/{ => data}/AuthResult.java (80%) rename de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/{ => data}/Authorization.java (74%) rename de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/{ => data}/AuthorizedScopes.java (80%) rename de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/{ => data}/Client.java (97%) rename de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/{ => data}/Permission.java (64%) rename de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/{ => data}/Session.java (76%) rename de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/{ => data}/User.java (98%) diff --git a/de.srsoftware.cookies/build.gradle b/de.srsoftware.http/build.gradle similarity index 88% rename from de.srsoftware.cookies/build.gradle rename to de.srsoftware.http/build.gradle index f2eceda..64fed60 100644 --- a/de.srsoftware.cookies/build.gradle +++ b/de.srsoftware.http/build.gradle @@ -12,6 +12,7 @@ repositories { dependencies { testImplementation platform('org.junit:junit-bom:5.10.0') testImplementation 'org.junit.jupiter:junit-jupiter' + implementation 'org.json:json:20240303' implementation project(':de.srsoftware.utils') } diff --git a/de.srsoftware.cookies/src/main/java/de/srsoftware/cookies/Cookie.java b/de.srsoftware.http/src/main/java/de/srsoftware/http/Cookie.java similarity index 97% rename from de.srsoftware.cookies/src/main/java/de/srsoftware/cookies/Cookie.java rename to de.srsoftware.http/src/main/java/de/srsoftware/http/Cookie.java index 2c42e62..85d490f 100644 --- a/de.srsoftware.cookies/src/main/java/de/srsoftware/cookies/Cookie.java +++ b/de.srsoftware.http/src/main/java/de/srsoftware/http/Cookie.java @@ -1,5 +1,5 @@ /* © SRSoftware 2024 */ -package de.srsoftware.cookies; +package de.srsoftware.http; import static de.srsoftware.utils.Optionals.nullable; import static java.lang.System.Logger.Level.*; diff --git a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/PathHandler.java b/de.srsoftware.http/src/main/java/de/srsoftware/http/PathHandler.java similarity index 98% rename from de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/PathHandler.java rename to de.srsoftware.http/src/main/java/de/srsoftware/http/PathHandler.java index 1fced82..2f63002 100644 --- a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/PathHandler.java +++ b/de.srsoftware.http/src/main/java/de/srsoftware/http/PathHandler.java @@ -1,7 +1,7 @@ /* © SRSoftware 2024 */ -package de.srsoftware.oidc.api; +package de.srsoftware.http; + -import static de.srsoftware.oidc.api.Constants.AUTHORIZATION; import static de.srsoftware.utils.Optionals.nullable; import static java.lang.System.Logger.Level.*; import static java.net.HttpURLConnection.*; @@ -16,6 +16,7 @@ import java.util.stream.Stream; import org.json.JSONObject; public abstract class PathHandler implements HttpHandler { + public static final String AUTHORIZATION = "Authorization"; public static final String CONTENT_TYPE = "Content-Type"; public static final String DELETE = "DELETE"; private static final String FORWARDED_HOST = "x-forwarded-host"; diff --git a/de.srsoftware.cookies/src/main/java/de/srsoftware/cookies/SessionToken.java b/de.srsoftware.http/src/main/java/de/srsoftware/http/SessionToken.java similarity index 95% rename from de.srsoftware.cookies/src/main/java/de/srsoftware/cookies/SessionToken.java rename to de.srsoftware.http/src/main/java/de/srsoftware/http/SessionToken.java index d274bf7..a28e0a0 100644 --- a/de.srsoftware.cookies/src/main/java/de/srsoftware/cookies/SessionToken.java +++ b/de.srsoftware.http/src/main/java/de/srsoftware/http/SessionToken.java @@ -1,5 +1,5 @@ /* © SRSoftware 2024 */ -package de.srsoftware.cookies; +package de.srsoftware.http; import com.sun.net.httpserver.HttpExchange; diff --git a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/AuthorizationService.java b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/AuthorizationService.java new file mode 100644 index 0000000..788a360 --- /dev/null +++ b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/AuthorizationService.java @@ -0,0 +1,16 @@ +/* © SRSoftware 2024 */ +package de.srsoftware.oidc.api; + +import de.srsoftware.oidc.api.data.AuthResult; +import de.srsoftware.oidc.api.data.Authorization; +import de.srsoftware.oidc.api.data.Client; +import de.srsoftware.oidc.api.data.User; +import java.time.Instant; +import java.util.Collection; +import java.util.Optional; + +public interface AuthorizationService { + AuthorizationService authorize(User user, Client client, Collection scopes, Instant expiration); + Optional consumeAuthorization(String authCode); + AuthResult getAuthorization(User user, Client client, Collection scopes); +} diff --git a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/ClaimAuthorizationService.java b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/ClaimAuthorizationService.java deleted file mode 100644 index bf9d7f9..0000000 --- a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/ClaimAuthorizationService.java +++ /dev/null @@ -1,12 +0,0 @@ -/* © SRSoftware 2024 */ -package de.srsoftware.oidc.api; - -import java.time.Instant; -import java.util.Collection; -import java.util.Optional; - -public interface ClaimAuthorizationService { - ClaimAuthorizationService authorize(User user, Client client, Collection scopes, Instant expiration); - Optional consumeAuthorization(String authCode); - AuthResult getAuthorization(User user, Client client, Collection scopes); -} diff --git a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/ClientService.java b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/ClientService.java index 5216f7e..f050599 100644 --- a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/ClientService.java +++ b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/ClientService.java @@ -1,6 +1,7 @@ /* © SRSoftware 2024 */ package de.srsoftware.oidc.api; +import de.srsoftware.oidc.api.data.Client; import java.util.List; import java.util.Optional; diff --git a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Constants.java b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Constants.java index ecf933f..95ad9eb 100644 --- a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Constants.java +++ b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Constants.java @@ -6,7 +6,6 @@ public class Constants { public static final String ACCESS_TOKEN = "access_token"; public static final String APP_NAME = "LightOIDC"; public static final String AUTH_CODE = "authorization_code"; - public static final String AUTHORIZATION = "Authorization"; public static final String AUTHORZED = "authorized"; public static final String BEARER = "Bearer"; public static final String CAUSE = "cause"; diff --git a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/SessionService.java b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/SessionService.java index 8aa563a..f1b8332 100644 --- a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/SessionService.java +++ b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/SessionService.java @@ -1,6 +1,8 @@ /* © SRSoftware 2024 */ package de.srsoftware.oidc.api; +import de.srsoftware.oidc.api.data.Session; +import de.srsoftware.oidc.api.data.User; import java.time.Duration; import java.util.Optional; diff --git a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/UserService.java b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/UserService.java index 32e349c..b9122d5 100644 --- a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/UserService.java +++ b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/UserService.java @@ -1,6 +1,7 @@ /* © SRSoftware 2024 */ package de.srsoftware.oidc.api; +import de.srsoftware.oidc.api.data.User; import java.util.List; import java.util.Optional; diff --git a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/AuthResult.java b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/data/AuthResult.java similarity index 80% rename from de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/AuthResult.java rename to de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/data/AuthResult.java index f1ebaaf..992d78c 100644 --- a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/AuthResult.java +++ b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/data/AuthResult.java @@ -1,5 +1,5 @@ /* © SRSoftware 2024 */ -package de.srsoftware.oidc.api; +package de.srsoftware.oidc.api.data; import java.util.Set; diff --git a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Authorization.java b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/data/Authorization.java similarity index 74% rename from de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Authorization.java rename to de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/data/Authorization.java index dfdc76d..c935976 100644 --- a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Authorization.java +++ b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/data/Authorization.java @@ -1,5 +1,5 @@ /* © SRSoftware 2024 */ -package de.srsoftware.oidc.api; +package de.srsoftware.oidc.api.data; public record Authorization(String clientId, String userId, AuthorizedScopes scopes) { } \ No newline at end of file diff --git a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/AuthorizedScopes.java b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/data/AuthorizedScopes.java similarity index 80% rename from de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/AuthorizedScopes.java rename to de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/data/AuthorizedScopes.java index 03ebcb4..2570948 100644 --- a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/AuthorizedScopes.java +++ b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/data/AuthorizedScopes.java @@ -1,5 +1,5 @@ /* © SRSoftware 2024 */ -package de.srsoftware.oidc.api; +package de.srsoftware.oidc.api.data; import java.time.Instant; import java.util.Set; diff --git a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Client.java b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/data/Client.java similarity index 97% rename from de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Client.java rename to de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/data/Client.java index ef38b6a..4d36b25 100644 --- a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Client.java +++ b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/data/Client.java @@ -1,5 +1,5 @@ /* © SRSoftware 2024 */ -package de.srsoftware.oidc.api; +package de.srsoftware.oidc.api.data; import static de.srsoftware.oidc.api.Constants.*; diff --git a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Permission.java b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/data/Permission.java similarity index 64% rename from de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Permission.java rename to de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/data/Permission.java index e673e1e..aa3a017 100644 --- a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Permission.java +++ b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/data/Permission.java @@ -1,4 +1,4 @@ /* © SRSoftware 2024 */ -package de.srsoftware.oidc.api; +package de.srsoftware.oidc.api.data; public enum Permission { MANAGE_CLIENTS } diff --git a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Session.java b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/data/Session.java similarity index 76% rename from de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Session.java rename to de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/data/Session.java index 3c98cdc..f39d6ea 100644 --- a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/Session.java +++ b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/data/Session.java @@ -1,5 +1,5 @@ /* © SRSoftware 2024 */ -package de.srsoftware.oidc.api; +package de.srsoftware.oidc.api.data; import java.time.Instant; diff --git a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/User.java b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/data/User.java similarity index 98% rename from de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/User.java rename to de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/data/User.java index ecb29bc..bbec403 100644 --- a/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/User.java +++ b/de.srsoftware.oidc.api/src/main/java/de/srsoftware/oidc/api/data/User.java @@ -1,5 +1,5 @@ /* © SRSoftware 2024 */ -package de.srsoftware.oidc.api; +package de.srsoftware.oidc.api.data; import java.util.*; diff --git a/de.srsoftware.oidc.app/build.gradle b/de.srsoftware.oidc.app/build.gradle index b5da0a5..a712306 100644 --- a/de.srsoftware.oidc.app/build.gradle +++ b/de.srsoftware.oidc.app/build.gradle @@ -12,6 +12,7 @@ repositories { dependencies { testImplementation platform('org.junit:junit-bom:5.10.0') testImplementation 'org.junit.jupiter:junit-jupiter' + implementation project(':de.srsoftware.http') implementation project(':de.srsoftware.logging') implementation project(':de.srsoftware.oidc.api') implementation project(':de.srsoftware.oidc.backend') 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 c3c10b4..4ecd1e3 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 @@ -3,7 +3,7 @@ package de.srsoftware.oidc.app; import static de.srsoftware.oidc.api.Constants.*; -import static de.srsoftware.oidc.api.Permission.MANAGE_CLIENTS; +import static de.srsoftware.oidc.api.data.Permission.MANAGE_CLIENTS; import static de.srsoftware.utils.Optionals.emptyIfBlank; import static de.srsoftware.utils.Paths.configDir; import static de.srsoftware.utils.Strings.uuid; @@ -16,7 +16,7 @@ import com.sun.net.httpserver.HttpServer; import de.srsoftware.logging.ColorLogger; import de.srsoftware.oidc.api.KeyManager; import de.srsoftware.oidc.api.KeyStorage; -import de.srsoftware.oidc.api.User; +import de.srsoftware.oidc.api.data.User; import de.srsoftware.oidc.backend.*; import de.srsoftware.oidc.datastore.file.FileStore; import de.srsoftware.oidc.datastore.file.PlaintextKeyStore; diff --git a/de.srsoftware.oidc.backend/build.gradle b/de.srsoftware.oidc.backend/build.gradle index 2218230..b88ca24 100644 --- a/de.srsoftware.oidc.backend/build.gradle +++ b/de.srsoftware.oidc.backend/build.gradle @@ -12,9 +12,9 @@ repositories { dependencies { testImplementation platform('org.junit:junit-bom:5.10.0') testImplementation 'org.junit.jupiter:junit-jupiter' - implementation project(':de.srsoftware.cookies') - implementation project(':de.srsoftware.oidc.api') + implementation project(':de.srsoftware.http') implementation project(':de.srsoftware.logging') + implementation project(':de.srsoftware.oidc.api') implementation project(':de.srsoftware.utils') implementation 'org.json:json:20240303' implementation 'org.bitbucket.b_c:jose4j:0.9.6' 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 bf98340..b14083f 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 @@ -2,12 +2,15 @@ package de.srsoftware.oidc.backend; import static de.srsoftware.oidc.api.Constants.*; -import static de.srsoftware.oidc.api.Permission.MANAGE_CLIENTS; +import static de.srsoftware.oidc.api.data.Permission.MANAGE_CLIENTS; import static de.srsoftware.utils.Optionals.emptyIfBlank; import static java.net.HttpURLConnection.*; import com.sun.net.httpserver.HttpExchange; import de.srsoftware.oidc.api.*; +import de.srsoftware.oidc.api.data.AuthorizedScopes; +import de.srsoftware.oidc.api.data.Client; +import de.srsoftware.oidc.api.data.Session; import de.srsoftware.utils.Optionals; import java.io.IOException; import java.time.Instant; @@ -16,11 +19,11 @@ import java.util.*; import org.json.JSONObject; public class ClientController extends Controller { - private static final System.Logger LOG = System.getLogger(ClientController.class.getSimpleName()); - private final ClaimAuthorizationService authorizations; - private final ClientService clients; + private static final System.Logger LOG = System.getLogger(ClientController.class.getSimpleName()); + private final AuthorizationService authorizations; + private final ClientService clients; - public ClientController(ClaimAuthorizationService authorizationService, ClientService clientService, SessionService sessionService) { + public ClientController(AuthorizationService authorizationService, ClientService clientService, SessionService sessionService) { super(sessionService); authorizations = authorizationService; clients = clientService; diff --git a/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/Controller.java b/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/Controller.java index 2fcdd9b..e0d253f 100644 --- a/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/Controller.java +++ b/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/Controller.java @@ -2,10 +2,10 @@ package de.srsoftware.oidc.backend; import com.sun.net.httpserver.HttpExchange; -import de.srsoftware.cookies.SessionToken; -import de.srsoftware.oidc.api.PathHandler; -import de.srsoftware.oidc.api.Session; +import de.srsoftware.http.PathHandler; +import de.srsoftware.http.SessionToken; import de.srsoftware.oidc.api.SessionService; +import de.srsoftware.oidc.api.data.Session; import java.util.Optional; public abstract class Controller extends PathHandler { diff --git a/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/KeyStoreController.java b/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/KeyStoreController.java index 3fe5623..eb7c58e 100644 --- a/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/KeyStoreController.java +++ b/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/KeyStoreController.java @@ -2,9 +2,9 @@ package de.srsoftware.oidc.backend; import com.sun.net.httpserver.HttpExchange; +import de.srsoftware.http.PathHandler; import de.srsoftware.oidc.api.KeyManager; import de.srsoftware.oidc.api.KeyStorage; -import de.srsoftware.oidc.api.PathHandler; import java.io.IOException; import org.jose4j.jwk.JsonWebKey; import org.jose4j.jwk.PublicJsonWebKey; diff --git a/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/TokenController.java b/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/TokenController.java index 2a2ac4b..ac58d21 100644 --- a/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/TokenController.java +++ b/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/TokenController.java @@ -4,11 +4,13 @@ package de.srsoftware.oidc.backend; import static de.srsoftware.oidc.api.Constants.*; import static de.srsoftware.oidc.api.Constants.ERROR; import static de.srsoftware.utils.Optionals.emptyIfBlank; -import static java.lang.System.Logger.Level.*; import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED; import com.sun.net.httpserver.HttpExchange; +import de.srsoftware.http.PathHandler; import de.srsoftware.oidc.api.*; +import de.srsoftware.oidc.api.data.Client; +import de.srsoftware.oidc.api.data.User; import java.io.IOException; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; @@ -23,13 +25,13 @@ import org.json.JSONObject; public class TokenController extends PathHandler { public record Configuration(String issuer, int tokenExpirationMinutes) { } - private final ClientService clients; - private final ClaimAuthorizationService authorizations; - private final UserService users; - private final KeyManager keyManager; - private Configuration config; + private final ClientService clients; + private final AuthorizationService authorizations; + private final UserService users; + private final KeyManager keyManager; + private Configuration config; - public TokenController(ClaimAuthorizationService authorizationService, ClientService clientService, KeyManager keyManager, UserService userService, Configuration configuration) { + public TokenController(AuthorizationService authorizationService, ClientService clientService, KeyManager keyManager, UserService userService, Configuration configuration) { authorizations = authorizationService; clients = clientService; this.keyManager = keyManager; @@ -37,8 +39,15 @@ public class TokenController extends PathHandler { config = configuration; } + private String decode(String urlencoded) { + return URLDecoder.decode(urlencoded, StandardCharsets.UTF_8); + } + private Map deserialize(String body) { - return Arrays.stream(body.split("&")).map(s -> s.split("=")).collect(Collectors.toMap(arr -> arr[0], arr -> arr[1])); + return Arrays + .stream(body.split("&")) // + .map(s -> s.split("=")) + .collect(Collectors.toMap(arr -> decode(arr[0]), arr -> decode(arr[1]))); } @Override 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 ec4f15c..d4ad046 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 @@ -1,12 +1,14 @@ /* © SRSoftware 2024 */ package de.srsoftware.oidc.backend; -import static de.srsoftware.oidc.api.User.*; +import static de.srsoftware.oidc.api.data.User.*; import static java.net.HttpURLConnection.*; import com.sun.net.httpserver.HttpExchange; -import de.srsoftware.cookies.SessionToken; +import de.srsoftware.http.SessionToken; import de.srsoftware.oidc.api.*; +import de.srsoftware.oidc.api.data.Session; +import de.srsoftware.oidc.api.data.User; import java.io.IOException; import java.util.Map; import java.util.Optional; diff --git a/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/WellKnownController.java b/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/WellKnownController.java index 1291481..ce90443 100644 --- a/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/WellKnownController.java +++ b/de.srsoftware.oidc.backend/src/main/java/de/srsoftware/oidc/backend/WellKnownController.java @@ -3,7 +3,7 @@ package de.srsoftware.oidc.backend; import com.sun.net.httpserver.HttpExchange; -import de.srsoftware.oidc.api.PathHandler; +import de.srsoftware.http.PathHandler; import java.io.IOException; import java.util.Map; 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 4f94b02..f4e5368 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 @@ -1,13 +1,14 @@ /* © SRSoftware 2024 */ package de.srsoftware.oidc.datastore.file; /* © SRSoftware 2024 */ import static de.srsoftware.oidc.api.Constants.EXPIRATION; -import static de.srsoftware.oidc.api.User.*; +import static de.srsoftware.oidc.api.data.User.*; import static de.srsoftware.utils.Optionals.nullable; import static de.srsoftware.utils.Strings.uuid; import static java.lang.System.Logger.Level.WARNING; import static java.util.Optional.empty; import de.srsoftware.oidc.api.*; +import de.srsoftware.oidc.api.data.*; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -19,7 +20,7 @@ import java.time.temporal.ChronoUnit; import java.util.*; import org.json.JSONObject; -public class FileStore implements ClaimAuthorizationService, ClientService, SessionService, UserService { +public class FileStore implements AuthorizationService, ClientService, SessionService, UserService { private static final String AUTHORIZATIONS = "authorizations"; private static final String CLIENTS = "clients"; private static final String CODES = "codes"; @@ -273,7 +274,7 @@ public class FileStore implements ClaimAuthorizationService, ClientService, Sess } @Override - public ClaimAuthorizationService authorize(User user, Client client, Collection scopes, Instant expiration) { + public AuthorizationService authorize(User user, Client client, Collection scopes, Instant expiration) { LOG.log(WARNING, "{0}.authorize({1}, {2}, {3}, {4}) not implemented", getClass().getSimpleName(), user.realName(), client.name(), scopes, expiration); var authorizations = json.getJSONObject(AUTHORIZATIONS); if (!authorizations.has(user.uuid())) authorizations.put(user.uuid(), new JSONObject()); diff --git a/de.srsoftware.oidc.web/build.gradle b/de.srsoftware.oidc.web/build.gradle index f56e27a..8bd2c6a 100644 --- a/de.srsoftware.oidc.web/build.gradle +++ b/de.srsoftware.oidc.web/build.gradle @@ -13,6 +13,7 @@ dependencies { testImplementation platform('org.junit:junit-bom:5.10.0') testImplementation 'org.junit.jupiter:junit-jupiter' implementation project(':de.srsoftware.oidc.api') + implementation project(':de.srsoftware.http') } test { diff --git a/de.srsoftware.oidc.web/src/main/java/de/srsoftware/oidc/web/Forward.java b/de.srsoftware.oidc.web/src/main/java/de/srsoftware/oidc/web/Forward.java index 718e1dd..779461b 100644 --- a/de.srsoftware.oidc.web/src/main/java/de/srsoftware/oidc/web/Forward.java +++ b/de.srsoftware.oidc.web/src/main/java/de/srsoftware/oidc/web/Forward.java @@ -4,7 +4,7 @@ package de.srsoftware.oidc.web; import static java.lang.System.Logger.Level.INFO; import com.sun.net.httpserver.HttpExchange; -import de.srsoftware.oidc.api.PathHandler; +import de.srsoftware.http.PathHandler; import java.io.IOException; public class Forward extends PathHandler { diff --git a/de.srsoftware.oidc.web/src/main/java/de/srsoftware/oidc/web/StaticPages.java b/de.srsoftware.oidc.web/src/main/java/de/srsoftware/oidc/web/StaticPages.java index 47851bb..26deaa1 100644 --- a/de.srsoftware.oidc.web/src/main/java/de/srsoftware/oidc/web/StaticPages.java +++ b/de.srsoftware.oidc.web/src/main/java/de/srsoftware/oidc/web/StaticPages.java @@ -5,7 +5,7 @@ import static java.lang.System.Logger.Level.*; import static java.util.Optional.empty; import com.sun.net.httpserver.HttpExchange; -import de.srsoftware.oidc.api.PathHandler; +import de.srsoftware.http.PathHandler; import java.io.FileNotFoundException; import java.io.IOException; import java.net.MalformedURLException; diff --git a/settings.gradle b/settings.gradle index 8f326cf..30b85e8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,10 +1,10 @@ rootProject.name = 'LightOIDC' +include 'de.srsoftware.http' +include 'de.srsoftware.logging' include 'de.srsoftware.oidc.api' include 'de.srsoftware.oidc.app' -include 'de.srsoftware.oidc.web' include 'de.srsoftware.oidc.backend' include 'de.srsoftware.oidc.datastore.file' -include 'de.srsoftware.cookies' -include 'de.srsoftware.logging' +include 'de.srsoftware.oidc.web' include 'de.srsoftware.utils'