From c307102e338d99a76d22ba521e469a6c34e8c770 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 2 Apr 2015 20:38:50 +0200 Subject: [PATCH] [Minor] added ComponentContainer.getRealm(Certificate) - instead of throwing an exception if the realm property is missing on the certificate, we first see if the default realm is available --- .../java/li/strolch/agent/api/ComponentContainer.java | 4 ++-- .../li/strolch/agent/impl/ComponentContainerImpl.java | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/li.strolch.agent/src/main/java/li/strolch/agent/api/ComponentContainer.java b/li.strolch.agent/src/main/java/li/strolch/agent/api/ComponentContainer.java index 27d89b6f5..ccd113fb2 100644 --- a/li.strolch.agent/src/main/java/li/strolch/agent/api/ComponentContainer.java +++ b/li.strolch.agent/src/main/java/li/strolch/agent/api/ComponentContainer.java @@ -65,8 +65,8 @@ public interface ComponentContainer { * @return the {@link StrolchRealm} * * @throws StrolchException - * if the user does not have a {@link StrolchConstants#PROP_REALM} property configured, or if the realm - * does not exist with the found value + * if the user does not have a {@link StrolchConstants#PROP_REALM} property configured, and the default + * realm is not configured, or if the realm does not exist with the found value */ public abstract StrolchRealm getRealm(Certificate certificate) throws StrolchException; 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 206fbb4e8..7defa4f79 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 @@ -114,9 +114,13 @@ public class ComponentContainerImpl implements ComponentContainer { String realmName = certificate.getProperty(StrolchConstants.PROP_REALM); if (StringHelper.isEmpty(realmName)) { - String msg = "The User {0} is missing the property {1}"; - throw new StrolchException( - MessageFormat.format(msg, certificate.getUsername(), StrolchConstants.PROP_REALM)); + 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, StrolchConstants.DEFAULT_REALM)); + } } try {