From e6b4685659840b339366658415660edd3f5f4edf Mon Sep 17 00:00:00 2001 From: Dmitry Telegin Date: Wed, 15 Jan 2020 15:12:16 +0300 Subject: [PATCH] KEYCLOAK-12689 - Improvements for camelCase config properties --- .../quarkus/MicroProfileConfigProvider.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/quarkus/extensions/src/main/java/org/keycloak/provider/quarkus/MicroProfileConfigProvider.java b/quarkus/extensions/src/main/java/org/keycloak/provider/quarkus/MicroProfileConfigProvider.java index b6e7d78539..be8d8aff8b 100644 --- a/quarkus/extensions/src/main/java/org/keycloak/provider/quarkus/MicroProfileConfigProvider.java +++ b/quarkus/extensions/src/main/java/org/keycloak/provider/quarkus/MicroProfileConfigProvider.java @@ -104,10 +104,31 @@ public class MicroProfileConfigProvider implements Config.ConfigProvider { } private T getValue(String key, Class clazz, T defaultValue) { - T value = config.getOptionalValue(prefix + "." + key, clazz).orElse(defaultValue); - return value; + String property = prefix + "." + key; + return config.getOptionalValue(toDashCase(property), clazz) + .orElseGet(() -> config.getOptionalValue(property, clazz) + .orElse(defaultValue)); } } + private static String toDashCase(String s) { + + StringBuilder sb = new StringBuilder(s.length()); + boolean l = false; + + for (int i = 0; i < s.length(); i++) { + char c = s.charAt(i); + if (l && Character.isUpperCase(c)) { + sb.append('-'); + c = Character.toLowerCase(c); + l = false; + } else { + l = Character.isLowerCase(c); + } + sb.append(c); + } + return sb.toString(); + } + }