I tried not passing in the password by commenting out the line but I got a DOes not authenticate error. Below is my code.
null;IDfClient client = DfClient.getLocalClient();
sMgr = client.newSessionManager();IDfLoginInfo login =
new DfLoginInfo();login.setUser(superuser
);
login.setPassword(password);
sMgr.setIdentity(currentDocbase, login);IDfSession session =
sMgr.getSession(currentDocbase);
That code needs to be in a method and run in the Method Server. That is flexible in that you can escalate the permissions as you want in you business code but it takes a big amount of work to set up:
I use the following class as a base for dm_method invocation (CollectionBlock is a class that iterates over a collection, calling processCurrent(), and ensures the collection is closed in the end):
public abstract class MethodInvoker { public abstract String getMethod(IDfSession session) throws DfException; public abstract String getArguments(IDfSession session) throws DfException; public abstract void handleFailure(int retVal) throws DfException; protected class ProcessResultsBlock extends CollectionBlock { @Override protected void processCurrent(IDfCollection collection) throws DfException { boolean failed = collection.getBoolean("launch_failed"); int retVal = collection.getInt("method_return_val"); if (failed) { handleFailure(retVal); } } } public MethodInvoker() { super(); } public void invokeMethod(IDfSession session) throws DfException { checkResults(createCommand(session, getArguments(session)).execute(session)); } private IDfApplyDoMethod createCommand(IDfSession session, String args) throws DfException { IDfApplyDoMethod command = (IDfApplyDoMethod) DfAdminCommand.getCommand(IDfAdminCommand.APPLY_DO_METHOD); command.setMethod(getMethod(session)); command.setArguments(args); command.setLaunchAsync(false); command.setRunAsServer(true); return command; } private void checkResults(IDfCollection results) throws DfException { new ProcessResultsBlock().execute(results); } }
Note: You can start the method server in debug mode (uncomment the relevant line in the bin/run.bat) and debug the code remotly by attaching the debugger in the 8787 port (default value).
If you implement your code using IDmMethod class, you dont have worry about passing in the username. The install owner will come from parameters that the server will pass to the method as part of the execute method:
public void execute(Map params, OutputStream ostream) throws Exception