Skip to content
Snippets Groups Projects
Commit 17b744c6 authored by Michael Burgardt's avatar Michael Burgardt Committed by Pierre Wolff
Browse files

ISSUE-203 Fix TemplateRenderer use and hide input

parent 141b7815
No related branches found
No related tags found
No related merge requests found
......@@ -12,8 +12,6 @@ import edu.kit.scc.webreg.service.mail.TemplateRenderer;
import edu.kit.scc.webreg.service.ssh.SshWorker;
import java.util.HashMap;
import java.util.Map;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* This workflow will evaluate a Velocity template (ssh_input_template)
......@@ -40,18 +38,13 @@ public class ScriptedLdapSshRegisterWorkflow extends ScriptedLdapRegisterWorkflo
String template = "";
try {
InitialContext ic = new InitialContext();
TemplateRenderer renderer = (TemplateRenderer) ic.lookup("global/bwreg/bwreg-service/TemplateRenderer!edu.kit.scc.webreg.service.mail.TemplateRenderer");
TemplateRenderer renderer = new TemplateRenderer();
renderer.init();
template = prop.readProp("ssh_input_template");
String input = renderer.evaluate(template, context);
SshWorker sshWorker = new SshWorker(prop, auditor);
sshWorker.sendInput(input);
} catch (NamingException ex) {
logger.error("Could not retrieve TemplateRenderer");
auditor.logAction("", "SSH SET USER PASSWORD", localUid, "Setting user password failed",
AuditStatus.FAIL);
throw new RegisterException(ex);
} catch (TemplateRenderingException ex) {
logger.error("Could not evaluate provided template: " + (template.isBlank() ? "template is empty" : template));
auditor.logAction("", "SSH SET USER PASSWORD", localUid, "Setting user password failed",
......@@ -62,6 +55,8 @@ public class ScriptedLdapSshRegisterWorkflow extends ScriptedLdapRegisterWorkflo
auditor.logAction("", "SSH SET USER PASSWORD", localUid, "Setting user password failed",
AuditStatus.FAIL);
throw new RegisterException(ex);
} catch (NullPointerException ex) {
throw new RegisterException(ex);
}
}
......
......@@ -90,15 +90,15 @@ public class SshWorker {
throw new IOException(response);
}
logger.info("Sending input to host response: {}", response);
auditor.logAction("", "SEND SSH INPUT", input,
"Input " + input + " send successfully to host " + sshHost,
auditor.logAction("", "SEND SSH INPUT", sshHost,
"Input send successfully to host " + sshHost,
AuditStatus.SUCCESS);
}
} catch (IOException e) {
logger.error("IOExcetion happened in SSH Session", e);
String message = "FAILED: Sending input " + input + " to " + sshHost
String message = "FAILED: Sending input to " + sshHost
+ " as " + sshUser + ": " + e.getMessage();
auditor.logAction("", "SEND SSH INPUT", input, "Sendind input failed",
auditor.logAction("", "SEND SSH INPUT", sshHost, "Sendind input failed",
AuditStatus.FAIL);
throw new RegisterException(message);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment