summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/process
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2014-06-30 23:03:03 +0200
committerAndrew Branson <andrew.branson@cern.ch>2014-06-30 23:03:03 +0200
commit2495be9ecfa8aea47e285f63b5bb27b0c133b1f8 (patch)
treed85f6df165386a86683de6ccee4c1767723573dd /src/main/java/com/c2kernel/process
parentdc2bbfdda8ee4f32937c3e91f77e52dc4501f0f1 (diff)
Separated modifying Lookup methods into LookupManager, which is only
present in a server process. This stops clients trying to write to the directory without relying on their permissions.
Diffstat (limited to 'src/main/java/com/c2kernel/process')
-rw-r--r--src/main/java/com/c2kernel/process/Bootstrap.java24
-rw-r--r--src/main/java/com/c2kernel/process/Gateway.java21
2 files changed, 34 insertions, 11 deletions
diff --git a/src/main/java/com/c2kernel/process/Bootstrap.java b/src/main/java/com/c2kernel/process/Bootstrap.java
index f32764c..bc93676 100644
--- a/src/main/java/com/c2kernel/process/Bootstrap.java
+++ b/src/main/java/com/c2kernel/process/Bootstrap.java
@@ -23,7 +23,7 @@ import com.c2kernel.lifecycle.instance.stateMachine.Transition;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.lookup.ItemPath;
-import com.c2kernel.lookup.Lookup;
+import com.c2kernel.lookup.LookupManager;
import com.c2kernel.lookup.Path;
import com.c2kernel.lookup.RolePath;
import com.c2kernel.persistency.ClusterStorage;
@@ -117,6 +117,7 @@ public class Bootstrap
public static DomainPath verifyResource(String ns, String itemName, Integer version, String itemType, String dataLocation, int layer, boolean reset) throws Exception {
if (version == null) version = 0;
+ LookupManager lookupManager = Gateway.getLookupManager();
ResourceImportHandler typeImpHandler = getHandler(itemType);
Logger.msg(1, "Bootstrap.verifyResource() - Verifying version "+version+" of "+typeImpHandler.getName()+" "+itemName);
@@ -163,8 +164,8 @@ public class Bootstrap
Logger.msg("Module item "+itemName+" found with path "+path.toString()+". Moving to "+modDomPath.toString());
modDomPath.setEntity(new ItemPath(thisProxy.getSystemKey()));
if (!modDomPath.exists())
- Gateway.getLookup().add(modDomPath);
- Gateway.getLookup().delete(path);
+ lookupManager.add(modDomPath);
+ lookupManager.delete(path);
}
}
@@ -252,6 +253,8 @@ public class Bootstrap
// create props
PropertyDescriptionList pdList = impHandler.getPropDesc();
PropertyArrayList props = new PropertyArrayList();
+ LookupManager lookupManager = Gateway.getLookupManager();
+
for (int i = 0; i < pdList.list.size(); i++) {
PropertyDescription pd = pdList.list.get(i);
String propName = pd.getName();
@@ -275,10 +278,10 @@ public class Bootstrap
ItemPath entityPath = Gateway.getNextKeyManager().generateNextEntityKey();
Gateway.getCorbaServer().createEntity(entityPath);
- Gateway.getLookup().add(entityPath);
+ lookupManager.add(entityPath);
DomainPath newDomPath = impHandler.getPath(itemName, ns);
newDomPath.setEntity(entityPath);
- Gateway.getLookup().add(newDomPath);
+ lookupManager.add(newDomPath);
ItemProxy newItemProxy = Gateway.getProxyManager().getProxy(entityPath);
newItemProxy.initialise( 1, props, ca, null);
return newItemProxy;
@@ -289,12 +292,14 @@ public class Bootstrap
**************************************************************************/
private static void checkAgent(String name, String pass, String role, boolean joblist) throws Exception {
Logger.msg(1, "Bootstrap.checkAgent() - Checking for existence of '"+name+"' user.");
- Lookup lookup = Gateway.getLookup();
+ LookupManager lookup = Gateway.getLookupManager();
+
try {
systemAgents.put(name, Gateway.getProxyManager().getAgentProxy(lookup.getAgentPath(name)));
Logger.msg(3, "Bootstrap.checkAgent() - User '"+name+"' found.");
return;
} catch (ObjectNotFoundException ex) { }
+
Logger.msg("Bootstrap.checkAgent() - User '"+name+"' not found. Creating.");
RolePath rolePath;
@@ -309,7 +314,7 @@ public class Bootstrap
AgentPath agentPath = new AgentPath(entityPath.getSysKey(), name);
agentPath.setPassword(pass);
Gateway.getCorbaServer().createEntity(agentPath);
- Gateway.getLookup().add(agentPath);
+ lookup.add(agentPath);
// assign admin role
Logger.msg("Bootstrap.checkAgent() - Assigning role '"+role+"'");
@@ -341,6 +346,7 @@ public class Bootstrap
}
public static void createServerItem() throws Exception {
+ LookupManager lookupManager = Gateway.getLookupManager();
String serverName = Gateway.getProperties().getProperty("ItemServer.name");
thisServerPath = new DomainPath("/servers/"+serverName);
ItemPath serverEntity;
@@ -350,9 +356,9 @@ public class Bootstrap
Logger.msg("Creating server item "+thisServerPath);
serverEntity = Gateway.getNextKeyManager().generateNextEntityKey();
Gateway.getCorbaServer().createEntity(serverEntity);
- Gateway.getLookup().add(serverEntity);
+ lookupManager.add(serverEntity);
thisServerPath.setEntity(serverEntity);
- Gateway.getLookup().add(thisServerPath);
+ lookupManager.add(thisServerPath);
}
Gateway.getStorage().put(serverEntity.getSysKey(), new Property("Name", serverName, false), null);
Gateway.getStorage().put(serverEntity.getSysKey(), new Property("Type", "Server", false), null);
diff --git a/src/main/java/com/c2kernel/process/Gateway.java b/src/main/java/com/c2kernel/process/Gateway.java
index 2499bf7..09700d6 100644
--- a/src/main/java/com/c2kernel/process/Gateway.java
+++ b/src/main/java/com/c2kernel/process/Gateway.java
@@ -9,6 +9,7 @@ import java.net.MalformedURLException;
import java.util.Enumeration;
import java.util.Properties;
+import com.c2kernel.common.CannotManageException;
import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.CorbaServer;
@@ -17,6 +18,7 @@ import com.c2kernel.entity.proxy.ProxyManager;
import com.c2kernel.entity.proxy.ProxyServer;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.Lookup;
+import com.c2kernel.lookup.LookupManager;
import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.persistency.NextKeyManager;
import com.c2kernel.persistency.TransactionManager;
@@ -58,6 +60,7 @@ public class Gateway
static private org.omg.CORBA.ORB mORB;
static private boolean orbDestroyed = false;
static private Lookup mLookup;
+ static private LookupManager mLookupManager = null;
static private NextKeyManager mNextKeyManager;
static private TransactionManager mStorage;
static private ProxyManager mProxyManager;
@@ -145,10 +148,16 @@ public class Gateway
*
* @throws InvalidDataException - error initialising
*/
- static public void startServer(Authenticator auth) throws InvalidDataException {
+ static public void startServer(Authenticator auth) throws InvalidDataException, CannotManageException {
try {
// check top level directory contexts
- mLookup.initializeDirectory();
+ if (mLookup instanceof LookupManager) {
+ mLookupManager = (LookupManager)mLookup;
+ mLookupManager.initializeDirectory();
+ }
+ else {
+ throw new CannotManageException("Lookup implementation is not a LookupManager. Cannot write to directory");
+ }
// init next key manager
mNextKeyManager = (NextKeyManager)mC2KProps.getInstance("NextKeyManager");
@@ -322,6 +331,14 @@ public class Gateway
return mLookup;
}
+ static public LookupManager getLookupManager() throws CannotManageException
+ {
+ if (mLookupManager == null)
+ throw new CannotManageException("No Lookup Manager created. Not a server process.", "");
+ else
+ return mLookupManager;
+ }
+
static public CorbaServer getCorbaServer()
{
return mCorbaServer;