From 77772fcc947af82343b088a987ca87c2c0d36168 Mon Sep 17 00:00:00 2001 From: Marten Date: Mon, 13 May 2019 16:33:46 +0200 Subject: [PATCH] added key value shorthand --- .../commons/security/CommonsPrincipal.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/commons-auth-adapter/src/main/java/io/rocketbase/commons/security/CommonsPrincipal.java b/commons-auth-adapter/src/main/java/io/rocketbase/commons/security/CommonsPrincipal.java index 694c32ea..ea4e9c9b 100644 --- a/commons-auth-adapter/src/main/java/io/rocketbase/commons/security/CommonsPrincipal.java +++ b/commons-auth-adapter/src/main/java/io/rocketbase/commons/security/CommonsPrincipal.java @@ -27,6 +27,18 @@ public static CommonsPrincipal getCurrent() { return null; } + /** + * @return the value of the given key when user is logged in and key exists
+ * key is stored internally in lowercase so that this function also lowers the given key... + */ + public String getCurrentKeyValue(String key) { + CommonsPrincipal current = getCurrent(); + if (current != null) { + return current.getKeyValues() != null ? current.getKeyValues().getOrDefault(key.toLowerCase(), null) : null; + } + return null; + } + @Override public String getName() { return getUsername();