From d4fa3bd9dd48f4d5e26850a23f5ba48a9c10ad64 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Thu, 5 Jun 2014 15:02:07 +0200 Subject: LDAP refactored behind interfaces. All functions of LDAP now hidden behind interfaces: Authenticator, Lookup and NextKeyManager (LDAP property storage was already a ClusterStorage). Gateway holds additional objects, and Fixes #26 #191. Refs #27 (needs additional work for read perms and auth tokens) --- src/main/java/com/c2kernel/process/Bootstrap.java | 45 ++++++++++++----------- 1 file changed, 24 insertions(+), 21 deletions(-) (limited to 'src/main/java/com/c2kernel/process/Bootstrap.java') diff --git a/src/main/java/com/c2kernel/process/Bootstrap.java b/src/main/java/com/c2kernel/process/Bootstrap.java index f273c5d..bcc5e68 100644 --- a/src/main/java/com/c2kernel/process/Bootstrap.java +++ b/src/main/java/com/c2kernel/process/Bootstrap.java @@ -1,8 +1,8 @@ package com.c2kernel.process; import java.net.InetAddress; -import java.util.Enumeration; import java.util.HashMap; +import java.util.Iterator; import java.util.Set; import java.util.StringTokenizer; @@ -10,6 +10,7 @@ import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.XMLUnit; import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.entity.proxy.AgentProxy; import com.c2kernel.entity.proxy.ItemProxy; import com.c2kernel.events.Event; import com.c2kernel.events.History; @@ -22,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.LDAPLookup; +import com.c2kernel.lookup.Lookup; import com.c2kernel.lookup.Path; import com.c2kernel.lookup.RolePath; import com.c2kernel.persistency.ClusterStorage; @@ -47,6 +48,7 @@ public class Bootstrap { static DomainPath thisServerPath; static HashMap resHandlerCache = new HashMap(); + static HashMap systemAgents = new HashMap(); /** * Run everything without timing-out the service wrapper @@ -71,7 +73,7 @@ public class Bootstrap Logger.msg("Bootstrap.run() - Initialising Server Item Workflow"); initServerItemWf(); - // register modules + Gateway.getModuleManager().setUser(systemAgents.get("system")); Gateway.getModuleManager().registerModules(); Logger.msg("Bootstrap.run() - Bootstrapping complete"); @@ -120,13 +122,13 @@ public class Bootstrap // Find or create Item for Resource DomainPath modDomPath = typeImpHandler.getPath(itemName, ns); ItemProxy thisProxy; - Enumeration en = Gateway.getLDAPLookup().search(typeImpHandler.getTypeRoot(), itemName); - if (!en.hasMoreElements()) { + Iterator en = Gateway.getLookup().search(typeImpHandler.getTypeRoot(), itemName); + if (!en.hasNext()) { Logger.msg("Bootstrap.verifyResource() - "+typeImpHandler.getName()+" "+itemName+" not found. Creating new."); thisProxy = createResourceItem(typeImpHandler, itemName, layer, ns); } else { - DomainPath path = (DomainPath)en.nextElement(); + DomainPath path = (DomainPath)en.next(); thisProxy = Gateway.getProxyManager().getProxy(path); // Verify module property and location @@ -160,8 +162,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.getLDAPLookup().add(modDomPath); - Gateway.getLDAPLookup().delete(path); + Gateway.getLookup().add(modDomPath); + Gateway.getLookup().delete(path); } } @@ -261,12 +263,12 @@ public class Bootstrap } - ItemPath entityPath = Gateway.getLDAPLookup().getNextKeyManager().generateNextEntityKey(); + ItemPath entityPath = Gateway.getNextKeyManager().generateNextEntityKey(); Gateway.getCorbaServer().createEntity(entityPath); - Gateway.getLDAPLookup().add(entityPath); + Gateway.getLookup().add(entityPath); DomainPath newDomPath = impHandler.getPath(itemName, ns); newDomPath.setEntity(entityPath); - Gateway.getLDAPLookup().add(newDomPath); + Gateway.getLookup().add(newDomPath); ItemProxy newItemProxy = Gateway.getProxyManager().getProxy(entityPath); newItemProxy.initialise( 1, props, ca, null); return newItemProxy; @@ -277,9 +279,9 @@ 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."); - LDAPLookup lookup = Gateway.getLDAPLookup(); + Lookup lookup = Gateway.getLookup(); try { - lookup.getRoleManager().getAgentPath(name); + systemAgents.put(name, Gateway.getProxyManager().getAgentProxy(lookup.getAgentPath(name))); Logger.msg(3, "Bootstrap.checkAgent() - User '"+name+"' found."); return; } catch (ObjectNotFoundException ex) { } @@ -287,23 +289,24 @@ public class Bootstrap RolePath rolePath; try { - rolePath = lookup.getRoleManager().getRolePath(role); + rolePath = lookup.getRolePath(role); } catch (ObjectNotFoundException ex) { - rolePath = lookup.getRoleManager().createRole(role, joblist); + rolePath = lookup.createRole(role, joblist); } try { - ItemPath entityPath = lookup.getNextKeyManager().generateNextEntityKey(); + ItemPath entityPath = Gateway.getNextKeyManager().generateNextEntityKey(); AgentPath agentPath = new AgentPath(entityPath.getSysKey(), name); agentPath.setPassword(pass); Gateway.getCorbaServer().createEntity(agentPath); - Gateway.getLDAPLookup().add(agentPath); + Gateway.getLookup().add(agentPath); // assign admin role Logger.msg("Bootstrap.checkAgent() - Assigning role '"+role+"'"); rolePath.addAgent(agentPath); Gateway.getStorage().put(agentPath.getSysKey(), new Property("Name", name, true), null); Gateway.getStorage().put(agentPath.getSysKey(), new Property("Type", "Agent", false), null); + systemAgents.put(name, Gateway.getProxyManager().getAgentProxy(agentPath)); Logger.msg("Bootstrap.checkAgent() - Done"); } catch (Exception ex) { Logger.error("Unable to create "+name+" user."); @@ -335,11 +338,11 @@ public class Bootstrap serverEntity = thisServerPath.getEntity(); } catch (ObjectNotFoundException ex) { Logger.msg("Creating server item "+thisServerPath); - serverEntity = Gateway.getLDAPLookup().getNextKeyManager().generateNextEntityKey(); + serverEntity = Gateway.getNextKeyManager().generateNextEntityKey(); Gateway.getCorbaServer().createEntity(serverEntity); - Gateway.getLDAPLookup().add(serverEntity); + Gateway.getLookup().add(serverEntity); thisServerPath.setEntity(serverEntity); - Gateway.getLDAPLookup().add(thisServerPath); + Gateway.getLookup().add(thisServerPath); } Gateway.getStorage().put(serverEntity.getSysKey(), new Property("Name", serverName, false), null); Gateway.getStorage().put(serverEntity.getSysKey(), new Property("Type", "Server", false), null); @@ -359,7 +362,7 @@ public class Bootstrap PredefinedStepContainer predef = (PredefinedStepContainer)wf.search("workflow/predefined"); wf.getChildGraphModel().removeVertex(predef); wf.addChild(new ServerPredefinedStepContainer(), predef.getCentrePoint()); - wf.initialise(thisServerPath.getSysKey(), Gateway.getLDAPLookup().getRoleManager().getAgentPath("system")); + wf.initialise(thisServerPath.getSysKey(), systemAgents.get("system").getPath()); Gateway.getStorage().put(thisServerPath.getSysKey(), wf, null); } } -- cgit v1.2.3