From 05a1b8ab22831aaa2ed69ff165d51c5497a65dde Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 11 Mar 2019 13:11:53 +0100 Subject: [PATCH] [New] Added .getRealm(), .getEmail(), .getLocator() on Certificate, User, UserRep --- .../agent/impl/ComponentContainerImpl.java | 7 +++-- .../li/strolch/runtime/StrolchConstants.java | 3 +- .../src/main/java/li/strolch/model/Tags.java | 3 ++ .../privilege/base/PrivilegeConstants.java | 4 +++ .../handler/MailUserChallengeHandler.java | 6 ++-- .../strolch/privilege/model/Certificate.java | 30 +++++++++++++++++++ .../li/strolch/privilege/model/UserRep.java | 30 +++++++++++++++++++ .../privilege/model/internal/User.java | 30 +++++++++++++++++++ 8 files changed, 106 insertions(+), 7 deletions(-) diff --git a/li.strolch.agent/src/main/java/li/strolch/agent/impl/ComponentContainerImpl.java b/li.strolch.agent/src/main/java/li/strolch/agent/impl/ComponentContainerImpl.java index 915544f65..f7e9b26cd 100644 --- a/li.strolch.agent/src/main/java/li/strolch/agent/impl/ComponentContainerImpl.java +++ b/li.strolch.agent/src/main/java/li/strolch/agent/impl/ComponentContainerImpl.java @@ -16,6 +16,7 @@ package li.strolch.agent.impl; import static li.strolch.model.Tags.AGENT; +import static li.strolch.runtime.StrolchConstants.PROP_REALM; import static li.strolch.runtime.StrolchConstants.SYSTEM_USER_AGENT; import static li.strolch.utils.helper.StringHelper.formatNanoDuration; @@ -112,14 +113,14 @@ public class ComponentContainerImpl implements ComponentContainer { @Override public StrolchRealm getRealm(Certificate certificate) throws StrolchException { - String realmName = certificate.getProperty(StrolchConstants.PROP_REALM); + String realmName = certificate.getRealm(); if (StringHelper.isEmpty(realmName)) { if (getRealmNames().contains(StrolchConstants.DEFAULT_REALM)) { realmName = StrolchConstants.DEFAULT_REALM; } else { String msg = "The User {0} is missing the property {1} and the Realm {2} can not be used as it does not exist!"; throw new StrolchException(MessageFormat - .format(msg, certificate.getUsername(), StrolchConstants.PROP_REALM, + .format(msg, certificate.getUsername(), PROP_REALM, StrolchConstants.DEFAULT_REALM)); } } @@ -129,7 +130,7 @@ public class ComponentContainerImpl implements ComponentContainer { } catch (StrolchException e) { String msg = "The User {0} has property {1} with value={2}, but the Realm does not eixst, or is not accessible by this user!"; throw new StrolchException( - MessageFormat.format(msg, certificate.getUsername(), StrolchConstants.PROP_REALM, realmName), e); + MessageFormat.format(msg, certificate.getUsername(), PROP_REALM, realmName), e); } } diff --git a/li.strolch.agent/src/main/java/li/strolch/runtime/StrolchConstants.java b/li.strolch.agent/src/main/java/li/strolch/runtime/StrolchConstants.java index 74b3182d6..1c1f7afaa 100644 --- a/li.strolch.agent/src/main/java/li/strolch/runtime/StrolchConstants.java +++ b/li.strolch.agent/src/main/java/li/strolch/runtime/StrolchConstants.java @@ -20,6 +20,7 @@ import static li.strolch.utils.helper.StringHelper.DOT; import li.strolch.agent.api.ObserverHandler; import li.strolch.model.StrolchModelConstants; import li.strolch.persistence.api.PersistenceHandler; +import li.strolch.privilege.base.PrivilegeConstants; import li.strolch.privilege.handler.PrivilegeHandler; /** @@ -35,7 +36,7 @@ public class StrolchConstants { public static final String PRIVILEGE_HANDLER = "PrivilegeHandler"; public static final String SYSTEM_USER_AGENT = "agent"; - public static final String PROP_REALM = "realm"; + public static final String PROP_REALM = PrivilegeConstants.REALM; public static final String DEFAULT_REALM = "defaultRealm"; public static final String DEFAULT_XML_VERSION = StrolchModelConstants.DEFAULT_XML_VERSION; diff --git a/li.strolch.model/src/main/java/li/strolch/model/Tags.java b/li.strolch.model/src/main/java/li/strolch/model/Tags.java index 0d02f8a6f..b2fa8e364 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/Tags.java +++ b/li.strolch.model/src/main/java/li/strolch/model/Tags.java @@ -134,6 +134,7 @@ public class Tags { // miscellaneous + public static final String MSG_TYPE = "msgType"; public static final String USERNAME = "username"; public static final String ELEMENTS = "elements"; public static final String NR_OF_ELEMENTS = "nrOfElements"; @@ -142,6 +143,8 @@ public class Tags { public static final String REALMS = "realms"; public static final String SIZE = "size"; public static final String EXCEPTION = "exception"; + public static final String FORMAT = "format"; + public static final String FLAT = "flat"; } public static class Audit { diff --git a/li.strolch.privilege/src/main/java/li/strolch/privilege/base/PrivilegeConstants.java b/li.strolch.privilege/src/main/java/li/strolch/privilege/base/PrivilegeConstants.java index 0dc02926d..b3b008f12 100644 --- a/li.strolch.privilege/src/main/java/li/strolch/privilege/base/PrivilegeConstants.java +++ b/li.strolch.privilege/src/main/java/li/strolch/privilege/base/PrivilegeConstants.java @@ -7,4 +7,8 @@ public class PrivilegeConstants { public static final int DEFAULT_KEY_LENGTH = 256; public static final int DEFAULT_SMALL_ITERATIONS = 10000; public static final int DEFAULT_ITERATIONS = 200000; + + public static final String REALM = "realm"; + public static final String LOCATION = "location"; + public static final String EMAIL = "email"; } diff --git a/li.strolch.privilege/src/main/java/li/strolch/privilege/handler/MailUserChallengeHandler.java b/li.strolch.privilege/src/main/java/li/strolch/privilege/handler/MailUserChallengeHandler.java index 0d0a8e35a..50fa24129 100644 --- a/li.strolch.privilege/src/main/java/li/strolch/privilege/handler/MailUserChallengeHandler.java +++ b/li.strolch.privilege/src/main/java/li/strolch/privilege/handler/MailUserChallengeHandler.java @@ -1,5 +1,7 @@ package li.strolch.privilege.handler; +import static li.strolch.privilege.base.PrivilegeConstants.EMAIL; + import java.text.MessageFormat; import li.strolch.privilege.model.internal.User; @@ -8,8 +10,6 @@ import li.strolch.utils.helper.StringHelper; public class MailUserChallengeHandler extends UserChallengeHandler { - private static final String EMAIL = "email"; - @Override public void sendChallengeToUser(User user, String challenge) { @@ -22,7 +22,7 @@ public class MailUserChallengeHandler extends UserChallengeHandler { sb.append(challenge); String text = sb.toString(); - String recipient = user.getProperty(EMAIL); + String recipient = user.getEmail(); if (StringHelper.isEmpty(recipient)) { String msg = "User {0} has no property {1}"; throw new RuntimeException(MessageFormat.format(msg, user.getUsername(), EMAIL)); diff --git a/li.strolch.privilege/src/main/java/li/strolch/privilege/model/Certificate.java b/li.strolch.privilege/src/main/java/li/strolch/privilege/model/Certificate.java index a9f60070a..c30a6a125 100644 --- a/li.strolch.privilege/src/main/java/li/strolch/privilege/model/Certificate.java +++ b/li.strolch.privilege/src/main/java/li/strolch/privilege/model/Certificate.java @@ -15,9 +15,12 @@ */ package li.strolch.privilege.model; +import static li.strolch.privilege.base.PrivilegeConstants.*; + import java.io.Serializable; import java.util.*; +import li.strolch.privilege.base.PrivilegeConstants; import li.strolch.privilege.base.PrivilegeException; import li.strolch.privilege.handler.PrivilegeHandler; import li.strolch.privilege.model.internal.User; @@ -166,6 +169,33 @@ public final class Certificate implements Serializable { return this.propertyMap.get(key); } + /** + * Returns the value of the property {@link PrivilegeConstants#REALM} + * + * @return the value of the property {@link PrivilegeConstants#REALM} + */ + public String getRealm() { + return getProperty(REALM); + } + + /** + * Returns the value of the property {@link PrivilegeConstants#LOCATION} + * + * @return the value of the property {@link PrivilegeConstants#LOCATION} + */ + public String getLocation() { + return getProperty(LOCATION); + } + + /** + * Returns the value of the property {@link PrivilegeConstants#EMAIL} + * + * @return the value of the property {@link PrivilegeConstants#EMAIL} + */ + public String getEmail() { + return getProperty(EMAIL); + } + public Locale getLocale() { return this.locale; } diff --git a/li.strolch.privilege/src/main/java/li/strolch/privilege/model/UserRep.java b/li.strolch.privilege/src/main/java/li/strolch/privilege/model/UserRep.java index 6db608723..18f258ed6 100644 --- a/li.strolch.privilege/src/main/java/li/strolch/privilege/model/UserRep.java +++ b/li.strolch.privilege/src/main/java/li/strolch/privilege/model/UserRep.java @@ -15,10 +15,13 @@ */ package li.strolch.privilege.model; +import static li.strolch.privilege.base.PrivilegeConstants.*; + import java.io.Serializable; import java.text.MessageFormat; import java.util.*; +import li.strolch.privilege.base.PrivilegeConstants; import li.strolch.privilege.base.PrivilegeException; import li.strolch.privilege.model.internal.Role; import li.strolch.privilege.model.internal.User; @@ -286,6 +289,33 @@ public class UserRep implements Serializable { return new HashMap<>(this.properties); } + /** + * Returns the value of the property {@link PrivilegeConstants#REALM} + * + * @return the value of the property {@link PrivilegeConstants#REALM} + */ + public String getRealm() { + return getProperty(REALM); + } + + /** + * Returns the value of the property {@link PrivilegeConstants#LOCATION} + * + * @return the value of the property {@link PrivilegeConstants#LOCATION} + */ + public String getLocation() { + return getProperty(LOCATION); + } + + /** + * Returns the value of the property {@link PrivilegeConstants#EMAIL} + * + * @return the value of the property {@link PrivilegeConstants#EMAIL} + */ + public String getEmail() { + return getProperty(EMAIL); + } + /** * Returns a string representation of this object displaying its concrete type and its values * diff --git a/li.strolch.privilege/src/main/java/li/strolch/privilege/model/internal/User.java b/li.strolch.privilege/src/main/java/li/strolch/privilege/model/internal/User.java index 76f3712be..1425ca48b 100644 --- a/li.strolch.privilege/src/main/java/li/strolch/privilege/model/internal/User.java +++ b/li.strolch.privilege/src/main/java/li/strolch/privilege/model/internal/User.java @@ -15,8 +15,11 @@ */ package li.strolch.privilege.model.internal; +import static li.strolch.privilege.base.PrivilegeConstants.*; + import java.util.*; +import li.strolch.privilege.base.PrivilegeConstants; import li.strolch.privilege.base.PrivilegeException; import li.strolch.privilege.model.UserRep; import li.strolch.privilege.model.UserState; @@ -279,6 +282,33 @@ public final class User { return this.propertyMap; } + /** + * Returns the value of the property {@link PrivilegeConstants#REALM} + * + * @return the value of the property {@link PrivilegeConstants#REALM} + */ + public String getRealm() { + return getProperty(REALM); + } + + /** + * Returns the value of the property {@link PrivilegeConstants#LOCATION} + * + * @return the value of the property {@link PrivilegeConstants#LOCATION} + */ + public String getLocation() { + return getProperty(LOCATION); + } + + /** + * Returns the value of the property {@link PrivilegeConstants#EMAIL} + * + * @return the value of the property {@link PrivilegeConstants#EMAIL} + */ + public String getEmail() { + return getProperty(EMAIL); + } + /** * @return a {@link UserRep} which is a representation of this object used to serialize and view on clients */