[Minor] added ComponentContainer.getRealm(Certificate)
This commit is contained in:
parent
22ddb3bd74
commit
e123cbf47d
|
@ -20,6 +20,7 @@ import java.util.Set;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.runtime.StrolchConstants;
|
import li.strolch.runtime.StrolchConstants;
|
||||||
import li.strolch.runtime.privilege.PrivilegeHandler;
|
import li.strolch.runtime.privilege.PrivilegeHandler;
|
||||||
|
import ch.eitchnet.privilege.model.Certificate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
@ -46,11 +47,27 @@ public interface ComponentContainer {
|
||||||
*
|
*
|
||||||
* @param realm
|
* @param realm
|
||||||
* the name of the {@link StrolchRealm} to return
|
* the name of the {@link StrolchRealm} to return
|
||||||
|
*
|
||||||
* @return the {@link StrolchRealm} with the given name
|
* @return the {@link StrolchRealm} with the given name
|
||||||
*
|
*
|
||||||
* @throws StrolchException
|
* @throws StrolchException
|
||||||
* if the {@link StrolchRealm} does not exist with the given name
|
* 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;
|
||||||
|
|
||||||
}
|
}
|
|
@ -30,6 +30,7 @@ import li.strolch.agent.api.StrolchAgent;
|
||||||
import li.strolch.agent.api.StrolchComponent;
|
import li.strolch.agent.api.StrolchComponent;
|
||||||
import li.strolch.agent.api.StrolchRealm;
|
import li.strolch.agent.api.StrolchRealm;
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
|
import li.strolch.runtime.StrolchConstants;
|
||||||
import li.strolch.runtime.configuration.ComponentConfiguration;
|
import li.strolch.runtime.configuration.ComponentConfiguration;
|
||||||
import li.strolch.runtime.configuration.RuntimeConfiguration;
|
import li.strolch.runtime.configuration.RuntimeConfiguration;
|
||||||
import li.strolch.runtime.configuration.StrolchConfiguration;
|
import li.strolch.runtime.configuration.StrolchConfiguration;
|
||||||
|
@ -39,6 +40,8 @@ import li.strolch.runtime.privilege.PrivilegeHandler;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import ch.eitchnet.privilege.model.Certificate;
|
||||||
|
import ch.eitchnet.utils.helper.StringHelper;
|
||||||
import ch.eitchnet.utils.helper.SystemHelper;
|
import ch.eitchnet.utils.helper.SystemHelper;
|
||||||
|
|
||||||
public class ComponentContainerImpl implements ComponentContainer {
|
public class ComponentContainerImpl implements ComponentContainer {
|
||||||
|
@ -106,6 +109,25 @@ public class ComponentContainerImpl implements ComponentContainer {
|
||||||
return getComponent(RealmHandler.class).getRealm(realm);
|
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<Class<?>, StrolchComponent> componentMap,
|
private void setupComponent(Map<Class<?>, StrolchComponent> componentMap,
|
||||||
Map<String, ComponentController> controllerMap, ComponentConfiguration componentConfiguration) {
|
Map<String, ComponentController> controllerMap, ComponentConfiguration componentConfiguration) {
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ public class StrolchConstants {
|
||||||
public static final String OBSERVER_HANDLER = ObserverHandler.class.getSimpleName();
|
public static final String OBSERVER_HANDLER = ObserverHandler.class.getSimpleName();
|
||||||
public static final String PRIVILEGE_HANDLER = "PrivilegeHandler";
|
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_REALM = "defaultRealm";
|
||||||
|
|
||||||
public static final String DEFAULT_XML_VERSION = "1.0"; //$NON-NLS-1$
|
public static final String DEFAULT_XML_VERSION = "1.0"; //$NON-NLS-1$
|
||||||
|
|
Loading…
Reference in New Issue