From cedb32b6b7a799ef4142b418e64d3538cf604af1 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Thu, 5 Jun 2014 14:13:37 +0200 Subject: Recreate old Authenticator interface as 'ProxyLogin' Server boots with new lookup interface. --- .../com/c2kernel/entity/proxy/ProxyManager.java | 22 ++++++++++++++-------- .../com/c2kernel/lookup/ldap/LDAPAuthManager.java | 12 ++++++++++-- .../java/com/c2kernel/lookup/ldap/LDAPLookup.java | 17 +++++++++++------ .../com/c2kernel/lookup/ldap/LDAPLookupUtils.java | 4 ++-- .../c2kernel/lookup/ldap/LDAPNextKeyManager.java | 15 ++++++++++----- .../java/com/c2kernel/lookup/ldap/LDAPPathSet.java | 5 +++-- src/main/java/com/c2kernel/process/Bootstrap.java | 9 ++++++--- .../java/com/c2kernel/process/ClientShell.java | 4 ++-- src/main/java/com/c2kernel/process/Gateway.java | 10 ++++++---- .../java/com/c2kernel/process/UserCodeProcess.java | 8 ++++---- .../com/c2kernel/process/auth/ConsoleAuth.java | 4 ++-- .../java/com/c2kernel/process/auth/ProxyLogin.java | 12 ++++++++++++ .../java/com/c2kernel/process/module/Module.java | 9 +++++---- .../com/c2kernel/process/module/ModuleManager.java | 12 +++++++++--- .../com/c2kernel/process/module/ModuleScript.java | 11 +---------- .../java/com/c2kernel/scripting/ScriptConsole.java | 10 +--------- .../java/com/c2kernel/utils/ObjectProperties.java | 10 ++++++++-- 17 files changed, 106 insertions(+), 68 deletions(-) create mode 100644 src/main/java/com/c2kernel/process/auth/ProxyLogin.java (limited to 'src/main/java/com/c2kernel') diff --git a/src/main/java/com/c2kernel/entity/proxy/ProxyManager.java b/src/main/java/com/c2kernel/entity/proxy/ProxyManager.java index 9503e54..2b2e0e9 100644 --- a/src/main/java/com/c2kernel/entity/proxy/ProxyManager.java +++ b/src/main/java/com/c2kernel/entity/proxy/ProxyManager.java @@ -156,7 +156,7 @@ public class ProxyManager **************************************************************************/ private ItemProxy createProxy( org.omg.CORBA.Object ior, int systemKey, - boolean isItem ) + boolean isAgent ) throws ObjectNotFoundException { @@ -164,13 +164,13 @@ public class ProxyManager Logger.msg(5, "ProxyManager::creating proxy on Item " + systemKey); - if( isItem ) + if( isAgent ) { - newProxy = new ItemProxy(ior, systemKey); + newProxy = new AgentProxy(ior, systemKey); } else { - newProxy = new AgentProxy(ior, systemKey); + newProxy = new ItemProxy(ior, systemKey); } // subscribe to changes from server @@ -194,7 +194,7 @@ public class ProxyManager **************************************************************************/ private ItemProxy getProxy( org.omg.CORBA.Object ior, int systemKey, - boolean isItem ) + boolean isAgent ) throws ObjectNotFoundException { Integer key = new Integer(systemKey); @@ -205,7 +205,7 @@ public class ProxyManager newProxy = proxyPool.get(key); if (newProxy == null) { // create a new one - newProxy = createProxy(ior, systemKey, isItem ); + newProxy = createProxy(ior, systemKey, isAgent ); proxyPool.put(key, newProxy); } return newProxy; @@ -224,12 +224,18 @@ public class ProxyManager //convert namePath to dn format Logger.msg(8,"ProxyManager::getProxy(" + path.toString() + ")"); - boolean isItem = !(path.getEntity() instanceof AgentPath); + boolean isAgent = (path.getEntity() instanceof AgentPath); return getProxy( Gateway.getLookup().resolve(path), path.getSysKey(), - isItem ); + isAgent ); } + + public AgentProxy getAgentProxy( AgentPath path ) + throws ObjectNotFoundException + { + return (AgentProxy) getProxy(path); + } /************************************************************************** * void reportCurrentProxies() diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPAuthManager.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPAuthManager.java index 20d16c3..4c26de6 100644 --- a/src/main/java/com/c2kernel/lookup/ldap/LDAPAuthManager.java +++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPAuthManager.java @@ -26,7 +26,8 @@ public class LDAPAuthManager implements Authenticator { ldapProps.mUser = ""; ldapProps.mPassword = ""; mLDAPConn = LDAPLookupUtils.createConnection(ldapProps); - LDAPLookup anonLookup = new LDAPLookup(ldapProps, this); + LDAPLookup anonLookup = new LDAPLookup(ldapProps); + anonLookup.open(this); String agentDN = anonLookup.getFullDN(anonLookup.getAgentPath(agentName)); //found agentDN, try to log in with it @@ -47,10 +48,17 @@ public class LDAPAuthManager implements Authenticator { @Override public boolean authenticate(String resource) throws InvalidDataException, ObjectNotFoundException { + ldapProps = new LDAPProperties(Gateway.getProperties()); + if (ldapProps.mUser == null || ldapProps.mUser.length()==0 || ldapProps.mPassword == null || ldapProps.mPassword.length()==0) throw new InvalidDataException("LDAP root user properties not found in config."); - return authenticate(null, ldapProps.mUser, ldapProps.mPassword); + try { + mLDAPConn = LDAPLookupUtils.createConnection(ldapProps); + return true; + } catch (LDAPException e) { + return false; + } } @Override diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java index a5624b1..a96a46b 100644 --- a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java +++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPLookup.java @@ -66,7 +66,7 @@ public class LDAPLookup implements Lookup * * @param props The LDAP properties object that extracts LDAP connection properties from the global c2kprops */ - public LDAPLookup(LDAPProperties props, LDAPAuthManager auth) throws LDAPException + public LDAPLookup(LDAPProperties props) { Logger.msg(8,"LDAPLookup - initialising."); @@ -80,10 +80,15 @@ public class LDAPLookup implements Lookup } + public LDAPLookup() { + this(new LDAPProperties(Gateway.getProperties())); + } + @Override public void open(Authenticator auth) { mLDAPAuth = (LDAPAuthManager)auth; mNextKeyManager = new LDAPNextKeyManager(mLDAPAuth, "cn=last,"+mItemTypeRoot); + Gateway.getProperties().setProperty("NextKeyManager", mNextKeyManager); Logger.msg(7, "LDAP.useOldProps="+Gateway.getProperties().getBoolean("LDAP.useOldProps", false)); mPropManager = new LDAPPropertyManager(this, mLDAPAuth); } @@ -330,7 +335,7 @@ public class LDAPLookup implements Lookup { LDAPSearchResults res = mLDAPAuth.getAuthObject().search(startDN, scope, filter,attr,false,searchCons); - return new LDAPPathSet(res); + return new LDAPPathSet(res, this); } catch (LDAPException ex) { @@ -439,7 +444,7 @@ public class LDAPLookup implements Lookup (LDAPLookupUtils.existsAttributeValue(entry,"objectclass","cristalcontext") && dn.endsWith(mDomainTypeRoot))) { DomainPath domainPath = new DomainPath(); - domainPath.setPath(getPathComponents(dn)); + domainPath.setPath(getPathComponents(dn.substring(0, dn.lastIndexOf(mDomainTypeRoot)))); thisPath = domainPath; } else if (LDAPLookupUtils.existsAttributeValue(entry,"objectclass","cristalentity") || @@ -451,7 +456,7 @@ public class LDAPLookup implements Lookup entityPath = new ItemPath(entityKey); else { entityPath = new ItemPath(); - entityPath.setPath(getPathComponents(dn)); + entityPath.setPath(getPathComponents(dn.substring(0, dn.lastIndexOf(mItemTypeRoot)))); } thisPath = entityPath; } @@ -497,7 +502,7 @@ public class LDAPLookup implements Lookup @Override public Object resolve(Path path) throws ObjectNotFoundException { - return resolveObject(getDN(path)); + return resolveObject(getFullDN(path)); } @Override @@ -709,7 +714,7 @@ public class LDAPLookup implements Lookup String filter = "(&(objectclass=cristalagent)(uid="+agentName+"))"; Iterator res = search(mItemTypeRoot,LDAPConnection.SCOPE_SUB,filter,searchCons); if (!res.hasNext()) - throw new ObjectNotFoundException("Agent not found"); + throw new ObjectNotFoundException("Agent not found: "+agentName, ""); Path result = res.next(); if (result instanceof AgentPath) return (AgentPath)result; diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java index 6ff6b2f..e1c8ac4 100644 --- a/src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java +++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPLookupUtils.java @@ -39,7 +39,7 @@ final public class LDAPLookupUtils LDAPEntry thisEntry = ld.read(dn,searchCons); if (thisEntry != null) return thisEntry; } catch (LDAPException ex) { - throw new ObjectNotFoundException("LDAP Exception: "+ex.getMessage(), ""); + throw new ObjectNotFoundException("LDAP Exception for dn:"+dn+": \n"+ex.getMessage(), ""); } throw new ObjectNotFoundException(dn+" does not exist", ""); @@ -315,7 +315,7 @@ final public class LDAPLookupUtils public static String escapeDN (String name) { //From RFC 2253 and the / character for JNDI - + if (name == null) return null; String escapedStr = new String(name); //Backslash is both a Java and an LDAP escape character, so escape it first diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPNextKeyManager.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPNextKeyManager.java index fdd565a..4db8a49 100644 --- a/src/main/java/com/c2kernel/lookup/ldap/LDAPNextKeyManager.java +++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPNextKeyManager.java @@ -6,6 +6,7 @@ import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.InvalidItemPathException; import com.c2kernel.lookup.ItemPath; import com.c2kernel.persistency.ClusterStorageException; +import com.c2kernel.persistency.NextKeyManager; import com.c2kernel.process.Gateway; import com.c2kernel.utils.Logger; import com.novell.ldap.LDAPEntry; @@ -20,7 +21,7 @@ import com.novell.ldap.LDAPEntry; **************************************************************************/ // public static final String codeRevision = "$Revision: 1.2 $ $Date: 2005/04/27 13:47:24 $ $Author: abranson $"; -public class LDAPNextKeyManager { +public class LDAPNextKeyManager implements NextKeyManager { LDAPAuthManager ldap; String lastKeyPath; @@ -31,7 +32,8 @@ public class LDAPNextKeyManager { this.lastKeyPath = lastKeyPath; } - public synchronized ItemPath generateNextEntityKey() + @Override + public synchronized ItemPath generateNextEntityKey() throws ObjectCannotBeUpdated, ObjectNotFoundException { ItemPath lastKey = getLastEntityPath(); @@ -57,18 +59,21 @@ public class LDAPNextKeyManager { return lastKey; } - public synchronized AgentPath generateNextAgentKey() + @Override + public synchronized AgentPath generateNextAgentKey() throws ObjectCannotBeUpdated, ObjectNotFoundException { ItemPath newEntity = generateNextEntityKey(); return new AgentPath(newEntity); } - public void writeLastEntityKey(int sysKey) throws ObjectCannotBeUpdated, ObjectNotFoundException { + @Override + public void writeLastEntityKey(int sysKey) throws ObjectCannotBeUpdated, ObjectNotFoundException { LDAPEntry lastKeyEntry = LDAPLookupUtils.getEntry(ldap.getAuthObject(),lastKeyPath); LDAPLookupUtils.setAttributeValue(ldap.getAuthObject(), lastKeyEntry,"intsyskey",Integer.toString(sysKey)); } - public ItemPath getLastEntityPath() throws ObjectNotFoundException + @Override + public ItemPath getLastEntityPath() throws ObjectNotFoundException { LDAPEntry lastKeyEntry = LDAPLookupUtils.getEntry(ldap.getAuthObject(),lastKeyPath); String lastKey = LDAPLookupUtils.getFirstAttributeValue(lastKeyEntry,"intsyskey"); diff --git a/src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java b/src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java index 5c46073..806976d 100644 --- a/src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java +++ b/src/main/java/com/c2kernel/lookup/ldap/LDAPPathSet.java @@ -27,9 +27,10 @@ public class LDAPPathSet implements Iterator { public LDAPPathSet(LDAPLookup ldap) { // empty this.ldap = ldap; results = null; - } + } - public LDAPPathSet(LDAPSearchResults results) { + public LDAPPathSet(LDAPSearchResults results, LDAPLookup ldap) { + this.ldap = ldap; this.results = results; } diff --git a/src/main/java/com/c2kernel/process/Bootstrap.java b/src/main/java/com/c2kernel/process/Bootstrap.java index 25ea512..bcc5e68 100644 --- a/src/main/java/com/c2kernel/process/Bootstrap.java +++ b/src/main/java/com/c2kernel/process/Bootstrap.java @@ -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; @@ -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"); @@ -279,7 +281,7 @@ public class Bootstrap Logger.msg(1, "Bootstrap.checkAgent() - Checking for existence of '"+name+"' user."); Lookup lookup = Gateway.getLookup(); try { - lookup.getAgentPath(name); + systemAgents.put(name, Gateway.getProxyManager().getAgentProxy(lookup.getAgentPath(name))); Logger.msg(3, "Bootstrap.checkAgent() - User '"+name+"' found."); return; } catch (ObjectNotFoundException ex) { } @@ -304,6 +306,7 @@ public class Bootstrap 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."); @@ -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.getLookup().getAgentPath("system")); + wf.initialise(thisServerPath.getSysKey(), systemAgents.get("system").getPath()); Gateway.getStorage().put(thisServerPath.getSysKey(), wf, null); } } diff --git a/src/main/java/com/c2kernel/process/ClientShell.java b/src/main/java/com/c2kernel/process/ClientShell.java index 6a620d8..b6afb2c 100644 --- a/src/main/java/com/c2kernel/process/ClientShell.java +++ b/src/main/java/com/c2kernel/process/ClientShell.java @@ -3,7 +3,7 @@ package com.c2kernel.process; import java.util.Scanner; import com.c2kernel.entity.proxy.AgentProxy; -import com.c2kernel.process.auth.Authenticator; +import com.c2kernel.process.auth.ProxyLogin; import com.c2kernel.scripting.Script; public class ClientShell extends StandardClient { @@ -40,7 +40,7 @@ public class ClientShell extends StandardClient { Gateway.init(readC2KArgs(args)); String authClassName = Gateway.getProperties().getProperty("cli.auth"); Class authClass = Gateway.getResource().getClassForName(authClassName); - Authenticator auth = (Authenticator)authClass.newInstance(); + ProxyLogin auth = (ProxyLogin)authClass.newInstance(); AgentProxy user = auth.authenticate(Gateway.getProperties().getProperty("Name")); ClientShell shell = new ClientShell(user); shell.run(); diff --git a/src/main/java/com/c2kernel/process/Gateway.java b/src/main/java/com/c2kernel/process/Gateway.java index 0c97a77..af24fe2 100644 --- a/src/main/java/com/c2kernel/process/Gateway.java +++ b/src/main/java/com/c2kernel/process/Gateway.java @@ -136,9 +136,6 @@ public class Gateway Language.isTranlated=true; Language.mTableOfTranslation = FileStringUtility.loadLanguageFile(languageFile); } - - // if client, run module startup scripts. Otherwise bootstrap will do it after all imports - if (!AbstractMain.runningAsWrapper) mModules.runScripts("startup"); } /** @@ -215,7 +212,7 @@ public class Gateway } catch (Exception ex) { Logger.error(ex); - throw new InvalidDataException("Cannot authenticate. Name and/or password invalid.", ""); + throw new InvalidDataException("Cannot connect server process. Please check config.", ""); } @@ -250,6 +247,11 @@ public class Gateway AgentPath agentPath = mLookup.getAgentPath(agentName); AgentProxy userProxy = (AgentProxy) mProxyManager.getProxy(agentPath); userProxy.setAuthObj(auth); + + // Run module startup scripts. Server does this during bootstrap + mModules.setUser(userProxy); + mModules.runScripts("startup"); + return userProxy; } diff --git a/src/main/java/com/c2kernel/process/UserCodeProcess.java b/src/main/java/com/c2kernel/process/UserCodeProcess.java index 47742aa..0d35025 100644 --- a/src/main/java/com/c2kernel/process/UserCodeProcess.java +++ b/src/main/java/com/c2kernel/process/UserCodeProcess.java @@ -9,8 +9,8 @@ import com.c2kernel.common.InvalidTransitionException; import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.entity.agent.Job; import com.c2kernel.entity.proxy.AgentProxy; -import com.c2kernel.entity.proxy.ProxyObserver; import com.c2kernel.entity.proxy.MemberSubscription; +import com.c2kernel.entity.proxy.ProxyObserver; import com.c2kernel.persistency.ClusterStorage; import com.c2kernel.scripting.ErrorInfo; import com.c2kernel.scripting.ScriptErrorException; @@ -38,12 +38,12 @@ public class UserCodeProcess extends StandardClient implements ProxyObserver errors = new HashMap(); HashMap jobs; - public UserCodeProcess(String agentName, String agentPass) { + public UserCodeProcess(String agentName, String agentPass, String resource) { // login - try for a while in case server hasn't imported our user yet for (int i=1;i<6;i++) { try { Logger.msg("Login attempt "+i+" of 5"); - agent = Gateway.connect(agentName, agentPass); + agent = Gateway.connect(agentName, agentPass, resource); break; } catch (Exception ex) { Logger.error("Could not log in."); @@ -209,7 +209,7 @@ public class UserCodeProcess extends StandardClient implements ProxyObserver modules = new ArrayList(); HashMap modulesXML = new HashMap(); Properties props = new Properties(); + AgentProxy user; boolean isServer; OutcomeValidator moduleValidator; @@ -110,6 +112,10 @@ public class ModuleManager { if (!allDepsPresent) Logger.die("Unmet module dependencies. Cannot continue"); } + public void setUser(AgentProxy user) { + this.user = user; + } + public String getModuleVersions() { StringBuffer ver = new StringBuffer(); for (Module thisMod : modules) { @@ -127,7 +133,7 @@ public class ModuleManager { public void runScripts(String event) { for (Module thisMod : modules) { try { - thisMod.runScript(event, isServer); + thisMod.runScript(event, user, isServer); } catch (ScriptingEngineException e) { Logger.error(e); Logger.die(e.getMessage()); @@ -152,7 +158,7 @@ public class ModuleManager { try { String nsReset = Gateway.getProperties().getProperty("Module."+thisMod.ns+".reset"); boolean thisReset = nsReset == null?reset:nsReset.equals("true"); - thisMod.importAll(serverEntity, modulesXML.get(thisMod.ns), thisReset); + thisMod.importAll(serverEntity, user, modulesXML.get(thisMod.ns), thisReset); } catch (Exception e) { Logger.error(e); throw new ModuleException("Error importing items for module "+thisMod.getName()); @@ -160,7 +166,7 @@ public class ModuleManager { Logger.msg("Module "+thisMod.getName()+" registered"); try { - thisMod.runScript("startup", true); + thisMod.runScript("startup", user, true); } catch (ScriptingEngineException e) { Logger.error(e); throw new ModuleException("Error in startup script for module "+thisMod.getName()); diff --git a/src/main/java/com/c2kernel/process/module/ModuleScript.java b/src/main/java/com/c2kernel/process/module/ModuleScript.java index e948996..f16f390 100644 --- a/src/main/java/com/c2kernel/process/module/ModuleScript.java +++ b/src/main/java/com/c2kernel/process/module/ModuleScript.java @@ -1,7 +1,6 @@ package com.c2kernel.process.module; import com.c2kernel.entity.proxy.AgentProxy; -import com.c2kernel.process.Gateway; import com.c2kernel.scripting.Script; import com.c2kernel.scripting.ScriptingEngineException; @@ -23,16 +22,8 @@ public class ModuleScript { this.script = script; } - public Script getScript(String ns) throws ScriptingEngineException { - AgentProxy user = Gateway.getCurrentUser(); - try { - if (user == null) user = (AgentProxy)Gateway.getProxyManager().getProxy( - Gateway.getLookup().getAgentPath("system")); - } catch (Exception ex) { - throw new ScriptingEngineException("System agent unavailable"); - } + public Script getScript(String ns, AgentProxy user) throws ScriptingEngineException { return new Script(lang, ns+" "+target+" "+event, script, user); - } public boolean shouldRun(String event, boolean isServer) { diff --git a/src/main/java/com/c2kernel/scripting/ScriptConsole.java b/src/main/java/com/c2kernel/scripting/ScriptConsole.java index a98ab57..a01e25f 100644 --- a/src/main/java/com/c2kernel/scripting/ScriptConsole.java +++ b/src/main/java/com/c2kernel/scripting/ScriptConsole.java @@ -16,7 +16,6 @@ import javax.script.ScriptEngine; import org.tanukisoftware.wrapper.WrapperManager; -import com.c2kernel.entity.proxy.AgentProxy; import com.c2kernel.process.Gateway; import com.c2kernel.utils.Logger; import com.c2kernel.utils.server.SocketHandler; @@ -138,16 +137,9 @@ public class ScriptConsole implements SocketHandler { // get system objects try { Logger.addLogStream(output, 0); - AgentProxy user = Gateway.getCurrentUser(); - try { - if (user == null) user = (AgentProxy)Gateway.getProxyManager().getProxy( - Gateway.getLookup().getAgentPath("system")); - } catch (Exception ex) { - output.println("System agent unavailable"); - } Script context; try { - context = new Script("javascript", user, output); + context = new Script("javascript", null, output); } catch (Exception ex) { output.println("Error initializing console script context"); ex.printStackTrace(output); diff --git a/src/main/java/com/c2kernel/utils/ObjectProperties.java b/src/main/java/com/c2kernel/utils/ObjectProperties.java index 1e9db8b..731b009 100644 --- a/src/main/java/com/c2kernel/utils/ObjectProperties.java +++ b/src/main/java/com/c2kernel/utils/ObjectProperties.java @@ -151,11 +151,17 @@ public class ObjectProperties extends Properties { } } - public Object getInstance(String propName) throws InstantiationException, IllegalAccessException, ClassNotFoundException { - Object prop = getObject(propName); + public Object getInstance(String propName, Object defaultVal) throws InstantiationException, IllegalAccessException, ClassNotFoundException { + Object prop = getObject(propName, defaultVal); + if (prop == null || prop.equals("")) + throw new InstantiationException("Property '"+propName+"' was not defined. Cannot instantiate."); if (prop instanceof String) return Class.forName((String)prop).newInstance(); return prop; + } + + public Object getInstance(String propName) throws InstantiationException, IllegalAccessException, ClassNotFoundException { + return getInstance(propName, null); } } -- cgit v1.2.3