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 5b72787cb..27d89b6f5 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 @@ -20,6 +20,7 @@ import java.util.Set; import li.strolch.exception.StrolchException; import li.strolch.runtime.StrolchConstants; import li.strolch.runtime.privilege.PrivilegeHandler; +import ch.eitchnet.privilege.model.Certificate; /** * @author Robert von Burg @@ -46,11 +47,27 @@ public interface ComponentContainer { * * @param realm * the name of the {@link StrolchRealm} to return + * * @return the {@link StrolchRealm} with the given name * * @throws StrolchException * if the {@link StrolchRealm} does not exist with the given name */ - public abstract StrolchRealm getRealm(String realm); + public abstract StrolchRealm getRealm(String realm) throws StrolchException; + + /** + * Returns the default {@link StrolchRealm} for the user with the given {@link Certificate}. This is done by + * querying the property {@link StrolchConstants#PROP_REALM} from the certificate. + * + * @param certificate + * the {@link Certificate} from which to retrieve the name of the {@link StrolchRealm} to return + * + * @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 + */ + public abstract StrolchRealm getRealm(Certificate certificate) throws StrolchException; } \ No newline at end of file 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 9fb496679..206fbb4e8 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 @@ -30,6 +30,7 @@ import li.strolch.agent.api.StrolchAgent; import li.strolch.agent.api.StrolchComponent; import li.strolch.agent.api.StrolchRealm; import li.strolch.exception.StrolchException; +import li.strolch.runtime.StrolchConstants; import li.strolch.runtime.configuration.ComponentConfiguration; import li.strolch.runtime.configuration.RuntimeConfiguration; import li.strolch.runtime.configuration.StrolchConfiguration; @@ -39,6 +40,8 @@ import li.strolch.runtime.privilege.PrivilegeHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import ch.eitchnet.privilege.model.Certificate; +import ch.eitchnet.utils.helper.StringHelper; import ch.eitchnet.utils.helper.SystemHelper; public class ComponentContainerImpl implements ComponentContainer { @@ -106,6 +109,25 @@ public class ComponentContainerImpl implements ComponentContainer { return getComponent(RealmHandler.class).getRealm(realm); } + @Override + public StrolchRealm getRealm(Certificate certificate) throws StrolchException { + + 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)); + } + + try { + return getComponent(RealmHandler.class).getRealm(realmName); + } 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); + } + } + private void setupComponent(Map, StrolchComponent> componentMap, Map controllerMap, ComponentConfiguration componentConfiguration) { 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 2ed2a0842..3368f8b3b 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 @@ -31,6 +31,7 @@ public class StrolchConstants { public static final String OBSERVER_HANDLER = ObserverHandler.class.getSimpleName(); public static final String PRIVILEGE_HANDLER = "PrivilegeHandler"; + public static final String PROP_REALM = "realm"; public static final String DEFAULT_REALM = "defaultRealm"; public static final String DEFAULT_XML_VERSION = "1.0"; //$NON-NLS-1$