From 99ce15a0f4f9fe891a1d60fb441c2f43e34685ad Mon Sep 17 00:00:00 2001 From: Hylke van der Schaaf Date: Thu, 10 Oct 2024 09:39:35 +0200 Subject: [PATCH] Cleaned up code --- .../auth/keycloak/DatabaseHandler.java | 13 +-- .../auth/keycloak/KeycloakAuthProvider.java | 73 ++-------------- .../auth/keycloak/KeycloakFilter.java | 4 +- .../auth/keycloak/KeycloakSettings.java | 85 +++++++++++++++++++ .../auth/keycloak/UserRoleDecoderDflt.java | 8 +- .../ilt/frostserver/auth/keycloak/Utils.java | 16 ++-- .../frostserver/model/CollectionsHelper.java | 4 +- .../ilt/frostserver/model/EntityType.java | 8 +- .../iosb/ilt/frostserver/service/Service.java | 5 +- .../frostserver/settings/MqttSettings.java | 3 +- .../http/common/HttpRequestDecoder.java | 2 +- .../frostserver/http/common/ServletMain.java | 1 + .../statests/f01auth/AbstractAuthTests.java | 6 -- .../ilt/statests/util/mqtt/MqttHelper2.java | 1 + .../plugin/openapi/spec/OpenApiGenerator.java | 2 +- .../plugin/projects/ProjectRoleDecoder.java | 10 +-- 16 files changed, 134 insertions(+), 107 deletions(-) create mode 100644 FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/KeycloakSettings.java diff --git a/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/DatabaseHandler.java b/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/DatabaseHandler.java index 0108c7359..192f6a35f 100644 --- a/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/DatabaseHandler.java +++ b/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/DatabaseHandler.java @@ -17,9 +17,9 @@ */ package de.fraunhofer.iosb.ilt.frostserver.auth.keycloak; -import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakAuthProvider.TAG_USER_CACHE_CLEANUP_INTERVAL; -import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakAuthProvider.TAG_USER_CACHE_LIFETIME; -import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakAuthProvider.TAG_USER_ROLE_DECODER_CLASS; +import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakSettings.TAG_USER_CACHE_CLEANUP_INTERVAL; +import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakSettings.TAG_USER_CACHE_LIFETIME; +import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakSettings.TAG_USER_ROLE_DECODER_CLASS; import static de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.utils.ConnectionUtils.TAG_DB_URL; import de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.utils.ConnectionUtils; @@ -87,8 +87,8 @@ public static DatabaseHandler getInstance(CoreSettings coreSettings) { private DatabaseHandler(CoreSettings coreSettings) { authSettings = coreSettings.getAuthSettings(); connectionUrl = authSettings.get(TAG_DB_URL, ConnectionUtils.class); - String userRoleDecoderClass = authSettings.get(TAG_USER_ROLE_DECODER_CLASS, KeycloakAuthProvider.class); - String lifeTimeString = authSettings.get(TAG_USER_CACHE_LIFETIME, KeycloakAuthProvider.class); + String userRoleDecoderClass = authSettings.get(TAG_USER_ROLE_DECODER_CLASS, KeycloakSettings.class); + String lifeTimeString = authSettings.get(TAG_USER_CACHE_LIFETIME, KeycloakSettings.class); lifetime = Duration.parse(lifeTimeString); try { Class urdClass = Class.forName(userRoleDecoderClass); @@ -97,7 +97,7 @@ private DatabaseHandler(CoreSettings coreSettings) { } catch (ReflectiveOperationException ex) { LOGGER.error("Could not create UserRoleDecoder: Class '{}' could not be instantiated", userRoleDecoderClass, ex); } - String cleanupIntervalString = authSettings.get(TAG_USER_CACHE_CLEANUP_INTERVAL, KeycloakAuthProvider.class); + String cleanupIntervalString = authSettings.get(TAG_USER_CACHE_CLEANUP_INTERVAL, KeycloakSettings.class); cleanupIntervalMs = Duration.parse(cleanupIntervalString).toMillis(); } @@ -169,6 +169,7 @@ private void cleanupSleep() { Thread.sleep(cleanupIntervalMs); } catch (InterruptedException ex) { LOGGER.trace("Rude Wakeup.", ex); + Thread.currentThread().interrupt(); } } diff --git a/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/KeycloakAuthProvider.java b/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/KeycloakAuthProvider.java index 93303c752..45aeac221 100644 --- a/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/KeycloakAuthProvider.java +++ b/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/KeycloakAuthProvider.java @@ -17,19 +17,18 @@ */ package de.fraunhofer.iosb.ilt.frostserver.auth.keycloak; +import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakSettings.TAG_MAX_CLIENTS_PER_USER; +import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakSettings.TAG_MAX_PASSWORD_LENGTH; +import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakSettings.TAG_MAX_USERNAME_LENGTH; +import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakSettings.TAG_REGISTER_USER_LOCALLY; import static de.fraunhofer.iosb.ilt.frostserver.settings.CoreSettings.TAG_AUTHENTICATE_ONLY; import static de.fraunhofer.iosb.ilt.frostserver.settings.CoreSettings.TAG_AUTH_ROLE_ADMIN; import static de.fraunhofer.iosb.ilt.frostserver.util.user.UserData.MAX_PASSWORD_LENGTH; import static de.fraunhofer.iosb.ilt.frostserver.util.user.UserData.MAX_USERNAME_LENGTH; -import de.fraunhofer.iosb.ilt.frostclient.settings.annotation.SensitiveValue; import de.fraunhofer.iosb.ilt.frostserver.service.InitResult; -import de.fraunhofer.iosb.ilt.frostserver.settings.ConfigDefaults; import de.fraunhofer.iosb.ilt.frostserver.settings.CoreSettings; import de.fraunhofer.iosb.ilt.frostserver.settings.Settings; -import de.fraunhofer.iosb.ilt.frostserver.settings.annotation.DefaultValue; -import de.fraunhofer.iosb.ilt.frostserver.settings.annotation.DefaultValueBoolean; -import de.fraunhofer.iosb.ilt.frostserver.settings.annotation.DefaultValueInt; import de.fraunhofer.iosb.ilt.frostserver.util.AuthProvider; import de.fraunhofer.iosb.ilt.frostserver.util.LiquibaseUser; import de.fraunhofer.iosb.ilt.frostserver.util.exception.UpgradeFailedException; @@ -57,62 +56,8 @@ * * @author scf */ -public class KeycloakAuthProvider implements AuthProvider, LiquibaseUser, ConfigDefaults { +public class KeycloakAuthProvider implements AuthProvider, LiquibaseUser { - @DefaultValue("") - @SensitiveValue - public static final String TAG_KEYCLOAK_CONFIG = "keycloakConfig"; - - @DefaultValue("") - public static final String TAG_KEYCLOAK_CONFIG_FILE = "keycloakConfigFile"; - - /** - * The URL on the Keycloak server that can be used to download the Keycloak - * config file. Usually this URL is in the form of: - * https://keycloak.example.com/auth/realms/[realm]/clients-registrations/install/[clientId] - */ - @DefaultValue("") - public static final String TAG_KEYCLOAK_CONFIG_URL = "keycloakConfigUrl"; - - /** - * If the client has "access-type" set to "confidential" then a secret is - * required to download the configuration. This secret can be found in the - * configuration itself, in Keycloak. - */ - @DefaultValue("") - @SensitiveValue - public static final String TAG_KEYCLOAK_CONFIG_SECRET = "keycloakConfigSecret"; - - @DefaultValueInt(10) - public static final String TAG_MAX_CLIENTS_PER_USER = "maxClientsPerUser"; - - @DefaultValueBoolean(false) - public static final String TAG_REGISTER_USER_LOCALLY = "registerUserLocally"; - - @DefaultValue("USERS") - public static final String TAG_USER_TABLE = "userTable"; - - @DefaultValue("USER_NAME") - public static final String TAG_USERNAME_COLUMN = "usernameColumn"; - - @DefaultValueInt(MAX_PASSWORD_LENGTH) - public static final String TAG_MAX_PASSWORD_LENGTH = "maxPasswordLength"; - - @DefaultValueInt(MAX_USERNAME_LENGTH) - public static final String TAG_MAX_USERNAME_LENGTH = "maxUsernameLength"; - - @DefaultValue("de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.UserRoleDecoderDflt") - public static final String TAG_USER_ROLE_DECODER_CLASS = "userRoleDecoderClass"; - - @DefaultValue("PT5M") - public static final String TAG_USER_CACHE_LIFETIME = "userCacheLifetime"; - - @DefaultValue("PT5S") - public static final String TAG_USER_CACHE_CLEANUP_INTERVAL = "userCacheCleanupInterval"; - - /** - * The logger for this class. - */ private static final Logger LOGGER = LoggerFactory.getLogger(KeycloakAuthProvider.class); /** @@ -148,10 +93,10 @@ public InitResult init(CoreSettings coreSettings) { OPTIONS.put("keycloak-config-file", FROST_SERVER_KEYCLOAKJSON); final Settings authSettings = coreSettings.getAuthSettings(); roleAdmin = authSettings.get(TAG_AUTH_ROLE_ADMIN, CoreSettings.class); - maxClientsPerUser = authSettings.getInt(TAG_MAX_CLIENTS_PER_USER, getClass()); - maxPassLength = authSettings.getInt(TAG_MAX_PASSWORD_LENGTH, getClass()); - maxNameLength = authSettings.getInt(TAG_MAX_USERNAME_LENGTH, getClass()); - registerUserLocally = authSettings.getBoolean(TAG_REGISTER_USER_LOCALLY, KeycloakAuthProvider.class); + maxClientsPerUser = authSettings.getInt(TAG_MAX_CLIENTS_PER_USER, KeycloakSettings.class); + maxPassLength = authSettings.getInt(TAG_MAX_PASSWORD_LENGTH, KeycloakSettings.class); + maxNameLength = authSettings.getInt(TAG_MAX_USERNAME_LENGTH, KeycloakSettings.class); + registerUserLocally = authSettings.getBoolean(TAG_REGISTER_USER_LOCALLY, KeycloakSettings.class); authenticateOnly = authSettings.getBoolean(TAG_AUTHENTICATE_ONLY, CoreSettings.class); if (registerUserLocally) { DatabaseHandler.init(coreSettings); diff --git a/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/KeycloakFilter.java b/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/KeycloakFilter.java index 123457fdb..c9c937ef5 100644 --- a/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/KeycloakFilter.java +++ b/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/KeycloakFilter.java @@ -17,7 +17,7 @@ */ package de.fraunhofer.iosb.ilt.frostserver.auth.keycloak; -import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakAuthProvider.TAG_REGISTER_USER_LOCALLY; +import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakSettings.TAG_REGISTER_USER_LOCALLY; import static de.fraunhofer.iosb.ilt.frostserver.settings.CoreSettings.TAG_AUTHENTICATE_ONLY; import static de.fraunhofer.iosb.ilt.frostserver.settings.CoreSettings.TAG_AUTH_ALLOW_ANON_READ; import static de.fraunhofer.iosb.ilt.frostserver.settings.CoreSettings.TAG_AUTH_ROLE_ADMIN; @@ -99,7 +99,7 @@ public void init(FilterConfig filterConfig) throws ServletException { roleMappings = AuthUtils.loadRoleMapping(authSettings); roleAdmin = authSettings.get(TAG_AUTH_ROLE_ADMIN, CoreSettings.class); authenticateOnly = authSettings.getBoolean(TAG_AUTHENTICATE_ONLY, CoreSettings.class); - registerUserLocally = authSettings.getBoolean(TAG_REGISTER_USER_LOCALLY, KeycloakAuthProvider.class); + registerUserLocally = authSettings.getBoolean(TAG_REGISTER_USER_LOCALLY, KeycloakSettings.class); if (registerUserLocally) { databaseHandler = DatabaseHandler.getInstance(coreSettings); } diff --git a/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/KeycloakSettings.java b/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/KeycloakSettings.java new file mode 100644 index 000000000..e819a877c --- /dev/null +++ b/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/KeycloakSettings.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2024 Fraunhofer Institut IOSB, Fraunhoferstr. 1, D 76131 + * Karlsruhe, Germany. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ +package de.fraunhofer.iosb.ilt.frostserver.auth.keycloak; + +import static de.fraunhofer.iosb.ilt.frostserver.util.user.UserData.MAX_PASSWORD_LENGTH; +import static de.fraunhofer.iosb.ilt.frostserver.util.user.UserData.MAX_USERNAME_LENGTH; + +import de.fraunhofer.iosb.ilt.frostclient.settings.annotation.SensitiveValue; +import de.fraunhofer.iosb.ilt.frostserver.settings.ConfigDefaults; +import de.fraunhofer.iosb.ilt.frostserver.settings.annotation.DefaultValue; +import de.fraunhofer.iosb.ilt.frostserver.settings.annotation.DefaultValueBoolean; +import de.fraunhofer.iosb.ilt.frostserver.settings.annotation.DefaultValueInt; + +/** + * Holds the settigs for the Keycloak Auth Provider. + */ +public class KeycloakSettings implements ConfigDefaults { + + @DefaultValue("") + @SensitiveValue + public static final String TAG_KEYCLOAK_CONFIG = "keycloakConfig"; + + @DefaultValue("") + public static final String TAG_KEYCLOAK_CONFIG_FILE = "keycloakConfigFile"; + + /** + * The URL on the Keycloak server that can be used to download the Keycloak + * config file. Usually this URL is in the form of: + * https://keycloak.example.com/auth/realms/[realm]/clients-registrations/install/[clientId] + */ + @DefaultValue("") + public static final String TAG_KEYCLOAK_CONFIG_URL = "keycloakConfigUrl"; + + /** + * If the client has "access-type" set to "confidential" then a secret is + * required to download the configuration. This secret can be found in the + * configuration itself, in Keycloak. + */ + @DefaultValue("") + @SensitiveValue + public static final String TAG_KEYCLOAK_CONFIG_SECRET = "keycloakConfigSecret"; + + @DefaultValueInt(10) + public static final String TAG_MAX_CLIENTS_PER_USER = "maxClientsPerUser"; + + @DefaultValueBoolean(false) + public static final String TAG_REGISTER_USER_LOCALLY = "registerUserLocally"; + + @DefaultValue("USERS") + public static final String TAG_USER_TABLE = "userTable"; + + @DefaultValue("USER_NAME") + public static final String TAG_USERNAME_COLUMN = "usernameColumn"; + + @DefaultValueInt(MAX_PASSWORD_LENGTH) + public static final String TAG_MAX_PASSWORD_LENGTH = "maxPasswordLength"; + + @DefaultValueInt(MAX_USERNAME_LENGTH) + public static final String TAG_MAX_USERNAME_LENGTH = "maxUsernameLength"; + + @DefaultValue("de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.UserRoleDecoderDflt") + public static final String TAG_USER_ROLE_DECODER_CLASS = "userRoleDecoderClass"; + + @DefaultValue("PT5M") + public static final String TAG_USER_CACHE_LIFETIME = "userCacheLifetime"; + + @DefaultValue("PT5S") + public static final String TAG_USER_CACHE_CLEANUP_INTERVAL = "userCacheCleanupInterval"; + +} diff --git a/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/UserRoleDecoderDflt.java b/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/UserRoleDecoderDflt.java index 408b03023..e4f3a5941 100644 --- a/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/UserRoleDecoderDflt.java +++ b/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/UserRoleDecoderDflt.java @@ -17,8 +17,8 @@ */ package de.fraunhofer.iosb.ilt.frostserver.auth.keycloak; -import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakAuthProvider.TAG_USERNAME_COLUMN; -import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakAuthProvider.TAG_USER_TABLE; +import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakSettings.TAG_USERNAME_COLUMN; +import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakSettings.TAG_USER_TABLE; import de.fraunhofer.iosb.ilt.frostserver.settings.CoreSettings; import de.fraunhofer.iosb.ilt.frostserver.settings.Settings; @@ -40,8 +40,8 @@ public class UserRoleDecoderDflt implements UserRoleDecoder { @Override public void init(CoreSettings coreSettings) { Settings authSettings = coreSettings.getAuthSettings(); - userTable = authSettings.get(TAG_USER_TABLE, KeycloakAuthProvider.class); - usernameColumn = authSettings.get(TAG_USERNAME_COLUMN, KeycloakAuthProvider.class); + userTable = authSettings.get(TAG_USER_TABLE, KeycloakSettings.class); + usernameColumn = authSettings.get(TAG_USERNAME_COLUMN, KeycloakSettings.class); } @Override diff --git a/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/Utils.java b/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/Utils.java index 53e97590c..09f0aa99c 100644 --- a/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/Utils.java +++ b/FROST-Server.Auth.Keycloak/src/main/java/de/fraunhofer/iosb/ilt/frostserver/auth/keycloak/Utils.java @@ -17,10 +17,10 @@ */ package de.fraunhofer.iosb.ilt.frostserver.auth.keycloak; -import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakAuthProvider.TAG_KEYCLOAK_CONFIG; -import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakAuthProvider.TAG_KEYCLOAK_CONFIG_FILE; -import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakAuthProvider.TAG_KEYCLOAK_CONFIG_SECRET; -import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakAuthProvider.TAG_KEYCLOAK_CONFIG_URL; +import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakSettings.TAG_KEYCLOAK_CONFIG; +import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakSettings.TAG_KEYCLOAK_CONFIG_FILE; +import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakSettings.TAG_KEYCLOAK_CONFIG_SECRET; +import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakSettings.TAG_KEYCLOAK_CONFIG_URL; import de.fraunhofer.iosb.ilt.frostserver.settings.CoreSettings; import de.fraunhofer.iosb.ilt.frostserver.settings.Settings; @@ -78,7 +78,7 @@ public static interface MethodRoleMapper { */ public static String getKeycloakConfig(CoreSettings coreSettings) { Settings authSettings = coreSettings.getAuthSettings(); - String keycloakConfig = authSettings.get(TAG_KEYCLOAK_CONFIG, ""); + String keycloakConfig = authSettings.get(TAG_KEYCLOAK_CONFIG, KeycloakSettings.class); if (!StringHelper.isNullOrEmpty(keycloakConfig)) { return keycloakConfig; } @@ -99,7 +99,7 @@ public static String getKeycloakConfig(CoreSettings coreSettings) { * @return the contents of the config file. */ private static String getKeycloakConfigFromFile(Settings authSettings) { - String keycloakConfigFile = authSettings.get(TAG_KEYCLOAK_CONFIG_FILE, ""); + String keycloakConfigFile = authSettings.get(TAG_KEYCLOAK_CONFIG_FILE, KeycloakSettings.class); if (StringHelper.isNullOrEmpty(keycloakConfigFile)) { return ""; } @@ -120,11 +120,11 @@ private static String getKeycloakConfigFromFile(Settings authSettings) { * @return the contents of the config file. */ private static String getKeycloakConfigFromServer(Settings authSettings) { - String keycloakConfigUrl = authSettings.get(TAG_KEYCLOAK_CONFIG_URL, ""); + String keycloakConfigUrl = authSettings.get(TAG_KEYCLOAK_CONFIG_URL, KeycloakSettings.class); if (StringHelper.isNullOrEmpty(keycloakConfigUrl)) { return ""; } - String keycloakConfigSecret = authSettings.get(TAG_KEYCLOAK_CONFIG_SECRET, ""); + String keycloakConfigSecret = authSettings.get(TAG_KEYCLOAK_CONFIG_SECRET, KeycloakSettings.class); LOGGER.info("Fetching Keycloak config from server: {}", keycloakConfigUrl); try (CloseableHttpClient client = HttpClients.createSystem()) { diff --git a/FROST-Server.Core.Model/src/main/java/de/fraunhofer/iosb/ilt/frostserver/model/CollectionsHelper.java b/FROST-Server.Core.Model/src/main/java/de/fraunhofer/iosb/ilt/frostserver/model/CollectionsHelper.java index 728637940..8a09bc512 100644 --- a/FROST-Server.Core.Model/src/main/java/de/fraunhofer/iosb/ilt/frostserver/model/CollectionsHelper.java +++ b/FROST-Server.Core.Model/src/main/java/de/fraunhofer/iosb/ilt/frostserver/model/CollectionsHelper.java @@ -72,7 +72,7 @@ public static Object getFrom(final Map map, final List p return getFrom((Object) map, path); } - public static Object getFrom(final ComplexValue cv, final List path) { + public static Object getFrom(final ComplexValue cv, final List path) { return getFrom((Object) cv, path); } @@ -83,7 +83,7 @@ private static Object getFrom(final Object mapOrList, final List path) { String key = path.get(idx); if (currentEntry instanceof Map map) { currentEntry = map.get(key); - } else if (currentEntry instanceof ComplexValue cv) { + } else if (currentEntry instanceof ComplexValue cv) { currentEntry = cv.getProperty(key); } else if (currentEntry instanceof List list) { try { diff --git a/FROST-Server.Core.Model/src/main/java/de/fraunhofer/iosb/ilt/frostserver/model/EntityType.java b/FROST-Server.Core.Model/src/main/java/de/fraunhofer/iosb/ilt/frostserver/model/EntityType.java index 033fbfc79..ace1bf364 100644 --- a/FROST-Server.Core.Model/src/main/java/de/fraunhofer/iosb/ilt/frostserver/model/EntityType.java +++ b/FROST-Server.Core.Model/src/main/java/de/fraunhofer/iosb/ilt/frostserver/model/EntityType.java @@ -289,7 +289,7 @@ public Property getProperty(String name) { } public EntityPropertyMain getEntityProperty(String name) { - Property property = propertiesByName.get(name); + Property property = propertiesByName.get(name); if (property instanceof EntityPropertyMain entityPropertyMain) { return entityPropertyMain; } @@ -297,7 +297,7 @@ public EntityPropertyMain getEntityProperty(String name) { } public NavigationPropertyMain getNavigationProperty(String name) { - Property property = propertiesByName.get(name); + Property property = propertiesByName.get(name); if (property instanceof NavigationPropertyMain navigationPropertyMain) { return navigationPropertyMain; } @@ -305,7 +305,7 @@ public NavigationPropertyMain getNavigationProperty(String name) { } public NavigationPropertyEntity getNavigationPropertyEntity(String name) { - Property property = propertiesByName.get(name); + Property property = propertiesByName.get(name); if (property instanceof NavigationPropertyEntity npe) { return npe; } @@ -313,7 +313,7 @@ public NavigationPropertyEntity getNavigationPropertyEntity(String name) { } public NavigationPropertyEntitySet getNavigationPropertyEntitySet(String name) { - Property property = propertiesByName.get(name); + Property property = propertiesByName.get(name); if (property instanceof NavigationPropertyEntitySet npes) { return npes; } diff --git a/FROST-Server.Core/src/main/java/de/fraunhofer/iosb/ilt/frostserver/service/Service.java b/FROST-Server.Core/src/main/java/de/fraunhofer/iosb/ilt/frostserver/service/Service.java index 40e8aa10b..346910062 100644 --- a/FROST-Server.Core/src/main/java/de/fraunhofer/iosb/ilt/frostserver/service/Service.java +++ b/FROST-Server.Core/src/main/java/de/fraunhofer/iosb/ilt/frostserver/service/Service.java @@ -64,7 +64,6 @@ import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; -import java.net.URL; import java.security.Principal; import java.util.ArrayList; import java.util.Collections; @@ -937,8 +936,8 @@ private LinkData parseForRefWithId(ServiceRequest request, ResourcePath path, Pa if (!targetUrl.startsWith(serviceRootUrl)) { try { // id is a relative url, resolve against the request url. - URL requestUrl = new URL(serviceRootUrl + '/' + versionUrl + request.getUrlPath()); - targetUrl = new URL(requestUrl, targetUrl).toString(); + URI requestUri = URI.create(serviceRootUrl + '/' + versionUrl + request.getUrlPath()); + targetUrl = requestUri.resolve(targetUrl).toURL().toString(); } catch (MalformedURLException ex) { return LinkData.error("Failed to parse URL in $id: " + ex.getMessage()); } diff --git a/FROST-Server.Core/src/main/java/de/fraunhofer/iosb/ilt/frostserver/settings/MqttSettings.java b/FROST-Server.Core/src/main/java/de/fraunhofer/iosb/ilt/frostserver/settings/MqttSettings.java index 64b209f10..0e3d78b1a 100644 --- a/FROST-Server.Core/src/main/java/de/fraunhofer/iosb/ilt/frostserver/settings/MqttSettings.java +++ b/FROST-Server.Core/src/main/java/de/fraunhofer/iosb/ilt/frostserver/settings/MqttSettings.java @@ -25,6 +25,7 @@ import de.fraunhofer.iosb.ilt.frostserver.settings.annotation.DefaultValueBoolean; import de.fraunhofer.iosb.ilt.frostserver.settings.annotation.DefaultValueInt; import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; @@ -199,7 +200,7 @@ private void searchExposedEndpoints(CoreSettings coreSettings) { } else { String serviceRootUrl = coreSettings.getQueryDefaults().getServiceRootUrl(); try { - URL serviceRoot = new URL(serviceRootUrl); + URL serviceRoot = URI.create(serviceRootUrl).toURL(); List genEndpoints = new ArrayList<>(); genEndpoints.add("mqtt://" + serviceRoot.getHost() + ":" + getPort()); endpoints = Collections.unmodifiableList(genEndpoints); diff --git a/FROST-Server.HTTP.Common/src/main/java/de/fraunhofer/iosb/ilt/frostserver/http/common/HttpRequestDecoder.java b/FROST-Server.HTTP.Common/src/main/java/de/fraunhofer/iosb/ilt/frostserver/http/common/HttpRequestDecoder.java index 00bc3482e..f13dc46d4 100644 --- a/FROST-Server.HTTP.Common/src/main/java/de/fraunhofer/iosb/ilt/frostserver/http/common/HttpRequestDecoder.java +++ b/FROST-Server.HTTP.Common/src/main/java/de/fraunhofer/iosb/ilt/frostserver/http/common/HttpRequestDecoder.java @@ -188,7 +188,7 @@ private String generateRootUrl(HttpServletRequest request, Version version, Stri } return xfProto + "://" + xfHost + ":" + xfPort + basePath; } else { - final StringBuffer requestURL = request.getRequestURL(); + final String requestURL = request.getRequestURL().toString(); int versionIdx = requestURL.indexOf(version.urlPart); return requestURL.substring(0, versionIdx - 1); } diff --git a/FROST-Server.HTTP.Common/src/main/java/de/fraunhofer/iosb/ilt/frostserver/http/common/ServletMain.java b/FROST-Server.HTTP.Common/src/main/java/de/fraunhofer/iosb/ilt/frostserver/http/common/ServletMain.java index 2638dc667..5e0cce558 100644 --- a/FROST-Server.HTTP.Common/src/main/java/de/fraunhofer/iosb/ilt/frostserver/http/common/ServletMain.java +++ b/FROST-Server.HTTP.Common/src/main/java/de/fraunhofer/iosb/ilt/frostserver/http/common/ServletMain.java @@ -146,6 +146,7 @@ protected void doPut(HttpServletRequest request, HttpServletResponse response) { processRequest(request, response); } + @Override protected void doPatch(HttpServletRequest request, HttpServletResponse response) { processRequest(request, response); } diff --git a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/f01auth/AbstractAuthTests.java b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/f01auth/AbstractAuthTests.java index 5095d56eb..66168b6da 100644 --- a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/f01auth/AbstractAuthTests.java +++ b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/f01auth/AbstractAuthTests.java @@ -79,9 +79,6 @@ public abstract class AbstractAuthTests extends AbstractTestClass { protected static SensorThingsService serviceRead; protected static SensorThingsService serviceAnon; private static EntityHelper2 ehAdmin; - private static EntityHelper2 ehWrite; - private static EntityHelper2 ehRead; - private static EntityHelper2 ehAnon; private final boolean anonymousReadAllowed; private final AuthTestHelper ath; @@ -103,9 +100,6 @@ protected void setUpVersion() { serviceRead = getServiceRead(); serviceAnon = getServiceAnonymous(); ehAdmin = new EntityHelper2(serviceAdmin); - ehWrite = new EntityHelper2(serviceWrite); - ehRead = new EntityHelper2(serviceRead); - ehAnon = new EntityHelper2(serviceAnon); mqttHelperAdmin = new MqttHelper2(serviceAdmin, serverSettings.getMqttUrl(), serverSettings.getMqttTimeOutMs()); mqttHelperWrite = new MqttHelper2(serviceWrite, serverSettings.getMqttUrl(), serverSettings.getMqttTimeOutMs()); mqttHelperRead = new MqttHelper2(serviceRead, serverSettings.getMqttUrl(), serverSettings.getMqttTimeOutMs()); diff --git a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/util/mqtt/MqttHelper2.java b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/util/mqtt/MqttHelper2.java index 0f0227ab1..492baf0b1 100644 --- a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/util/mqtt/MqttHelper2.java +++ b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/util/mqtt/MqttHelper2.java @@ -151,6 +151,7 @@ public void executeRequest(MqttAction ma) { executor.shutdownNow(); } MqttManager.clearTestSubscriptionListeners(); + Assertions.assertFalse(ma.topics.isEmpty(), "No topics to test?"); for (TestSubscription tl : ma.topics) { Assertions.assertTrue( tl.checkAllReceived(mqttTimeoutMs), diff --git a/Plugins/OpenApi/src/main/java/de/fraunhofer/iosb/ilt/frostserver/plugin/openapi/spec/OpenApiGenerator.java b/Plugins/OpenApi/src/main/java/de/fraunhofer/iosb/ilt/frostserver/plugin/openapi/spec/OpenApiGenerator.java index 6c68ada54..adcf93a17 100644 --- a/Plugins/OpenApi/src/main/java/de/fraunhofer/iosb/ilt/frostserver/plugin/openapi/spec/OpenApiGenerator.java +++ b/Plugins/OpenApi/src/main/java/de/fraunhofer/iosb/ilt/frostserver/plugin/openapi/spec/OpenApiGenerator.java @@ -393,7 +393,7 @@ private static void createEntitySchema(GeneratorContext context, EntityType enti for (Property property : entityType.getPropertySet()) { String propertyName = property.getJsonName(); - if (property instanceof EntityPropertyMain epm) { + if (property instanceof EntityPropertyMain epm) { if (epm.getAliases().contains("@iot.id")) { propertyName = version.getIdName(); } diff --git a/Plugins/Projects/src/main/java/de/fraunhofer/iosb/ilt/frostserver/plugin/projects/ProjectRoleDecoder.java b/Plugins/Projects/src/main/java/de/fraunhofer/iosb/ilt/frostserver/plugin/projects/ProjectRoleDecoder.java index d4d97bb7e..732135ff6 100644 --- a/Plugins/Projects/src/main/java/de/fraunhofer/iosb/ilt/frostserver/plugin/projects/ProjectRoleDecoder.java +++ b/Plugins/Projects/src/main/java/de/fraunhofer/iosb/ilt/frostserver/plugin/projects/ProjectRoleDecoder.java @@ -17,10 +17,10 @@ */ package de.fraunhofer.iosb.ilt.frostserver.plugin.projects; -import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakAuthProvider.TAG_USERNAME_COLUMN; -import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakAuthProvider.TAG_USER_TABLE; +import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakSettings.TAG_USERNAME_COLUMN; +import static de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakSettings.TAG_USER_TABLE; -import de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakAuthProvider; +import de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.KeycloakSettings; import de.fraunhofer.iosb.ilt.frostserver.auth.keycloak.UserRoleDecoder; import de.fraunhofer.iosb.ilt.frostserver.settings.ConfigDefaults; import de.fraunhofer.iosb.ilt.frostserver.settings.CoreSettings; @@ -68,8 +68,8 @@ public class ProjectRoleDecoder implements UserRoleDecoder, ConfigDefaults { @Override public void init(CoreSettings coreSettings) { final Settings authSettings = coreSettings.getAuthSettings(); - userTable = authSettings.get(TAG_USER_TABLE, KeycloakAuthProvider.class); - usernameColumn = authSettings.get(TAG_USERNAME_COLUMN, KeycloakAuthProvider.class); + userTable = authSettings.get(TAG_USER_TABLE, KeycloakSettings.class); + usernameColumn = authSettings.get(TAG_USERNAME_COLUMN, KeycloakSettings.class); uprInsertQuery = authSettings.get(TAG_UPR_INSERT_QUERY, ProjectRoleDecoder.class); uprCleanupQuery = authSettings.get(TAG_UPR_CLEANUP_QUERY, ProjectRoleDecoder.class); String projectRoleRegex = authSettings.get(TAG_ROLE_REGEX, ProjectRoleDecoder.class);