Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
public class CwsEmailerService implements InitializingBean {

private static final Logger log = LoggerFactory.getLogger(CwsEmailerService.class);

@Value("${cws.admin.firstname}") private String prop_cwsAdminFirstName;
@Value("${cws.admin.lastname}") private String prop_cwsAdminLastName;
@Value("${cws.admin.email}") private String prop_cwsAdminEmail;
@Value("${cws.notification.emails}") private String prop_cwsNotificationEmails;
@Value("${cws.smtp.hostname}") private String prop_cwsSMTPHostname;
@Value("${cws.smtp.port}") private String prop_cwsSMTPPort;
Expand Down Expand Up @@ -43,14 +45,14 @@ public void sendEmail(

email.setHostName(prop_cwsSMTPHostname); // TODO: make this configurable as well?
email.setSmtpPort(Integer.parseInt(prop_cwsSMTPPort));
email.setFrom("cws_admin@locahost");
email.setFrom(prop_cwsAdminEmail);
email.setSubject(emailSubject);

for (String recip : recipients) {
email.addTo(recip.trim());
log.debug("About to send email to " + recip + "...");
}

log.debug("From: " + prop_cwsAdminEmail + " (" + prop_cwsAdminLastName + ", " + prop_cwsAdminFirstName + ")");
log.debug(" +-----------------------------------------------");
log.debug(" | SUBJECT : " + emailSubject);
log.debug(" | BODY : " + emailBody);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class CwsEngineProcessApplication extends SpringServletProcessApplication
//@Autowired private ExternalTaskService externalTaskService;

@Value("${camunda.executor.service.max.pool.size}") private Integer EXEC_SERVICE_MAX_POOL_SIZE;
@Value("${cws.admin.email}") private String cwsAdminEmail;
@Value("${cws.smtp.hostname}") private String cwsSMTPHostname;
@Value("${cws.smtp.port}") private String cwsSMTPPort;
@Value("${send.user.task.assignment.emails}") private String sendUserTaskAssignmentEmails;
Expand Down Expand Up @@ -465,8 +466,7 @@ public void notify(final DelegateExecution execution) throws Exception {
}
};
}



/**
* Helper method to get procDefKey from execution object, using multiple methods.
*/
Expand Down Expand Up @@ -520,14 +520,15 @@ private void emailUserTaskAssignment(

email.setHostName(cwsSMTPHostname);
email.setSmtpPort(Integer.parseInt(cwsSMTPPort));
email.setFrom("cws_admin@localhost"); // TODO: make this configurable as well?
email.setFrom(cwsAdminEmail);
email.setSubject(emailSubject);

for (String recip : recipients) {
email.addTo(recip.trim());
log.debug("About to send email to " + recip + "...");
}


log.debug(" FROM : " + cwsAdminEmail);
log.debug(" SUBJECT: " + emailSubject);
log.debug(" BODY : " + emailBody);

Expand Down
160 changes: 153 additions & 7 deletions cws-installer/src/main/java/jpl/cws/task/CwsInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@
import static jpl.cws.task.CwsInstallerUtils.writeToFile;
import static jpl.cws.task.UnzipUtility.unzipFile;

import java.lang.*;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import java.nio.file.Files;
import java.io.StringReader;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import org.w3c.dom.*;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
Expand Down Expand Up @@ -2110,9 +2129,11 @@ private static void updateFiles() throws IOException {
content = content.replace("__CWS_ADMIN_EMAIL__", cws_user_email);
}
else {
content = content.replace("__CWS_ADMIN_FIRSTNAME__", "N/A");
content = content.replace("__CWS_ADMIN_LASTNAME__", "N/A");
content = content.replace("__CWS_ADMIN_EMAIL__", "N/A");
Path pluginBeanFilePath = Paths.get(config_work_dir + SEP + "tomcat_conf" + SEP + "ldap_plugin_bean.xml");
String[] identityAttr = getIdentityPluginAttribute(pluginBeanFilePath, cws_user, cws_ldap_url);
content = content.replace("__CWS_ADMIN_FIRSTNAME__", identityAttr[0]);
content = content.replace("__CWS_ADMIN_LASTNAME__", identityAttr[1]);
content = content.replace("__CWS_ADMIN_EMAIL__", identityAttr[2]);
}
writeToFile(filePath, content);
copy(
Expand Down Expand Up @@ -2189,6 +2210,19 @@ private static void updateWorkerProperties() throws IOException {
content = content.replace("__CWS_TOMCAT_WEBAPPS__", cws_tomcat_webapps);
content = content.replace("__CWS_AUTH_SCHEME__", cws_auth_scheme);
content = content.replace("__STARTUP_AUTOREGISTER_PROCESS_DEFS__", startup_autoregister_process_defs);

if (cws_auth_scheme.equalsIgnoreCase("CAMUNDA")) {
content = content.replace("__CWS_ADMIN_FIRSTNAME__", cws_user_firstname);
content = content.replace("__CWS_ADMIN_LASTNAME__", cws_user_lastname);
content = content.replace("__CWS_ADMIN_EMAIL__", cws_user_email);
} else {
Path pluginBeanFilePath = Paths.get(config_work_dir + SEP + "tomcat_conf" + SEP + "ldap_plugin_bean.xml");
String[] identityAttr = getIdentityPluginAttribute(pluginBeanFilePath, cws_user, cws_ldap_url);
content = content.replace("__CWS_ADMIN_FIRSTNAME__", identityAttr[0]);
content = content.replace("__CWS_ADMIN_LASTNAME__", identityAttr[1]);
content = content.replace("__CWS_ADMIN_EMAIL__", identityAttr[2]);
}

content = content.replace("__CWS_NOTIFICATION_EMAILS__", cws_notification_emails);
content = content.replace("__CWS_TOKEN_EXPIRATION_HOURS__", cws_token_expiration_hours);
content = content.replace("__CWS_SMTP_HOSTNAME__", cws_smtp_hostname);
Expand Down Expand Up @@ -2290,6 +2324,19 @@ private static void updateCwsUiProperties() throws IOException {
content = content.replace("__CWS_TOMCAT_HOME__", cws_tomcat_root);
content = content.replace("__CWS_TOMCAT_WEBAPPS__", cws_tomcat_webapps);
content = content.replace("__CWS_PROJECT_WEBAPP_ROOT__", (cws_project_webapp_root == null || cws_project_webapp_root.equals("none")) ? "" : cws_project_webapp_root);

if (cws_auth_scheme.equalsIgnoreCase("CAMUNDA")) {
content = content.replace("__CWS_ADMIN_FIRSTNAME__", cws_user_firstname);
content = content.replace("__CWS_ADMIN_LASTNAME__", cws_user_lastname);
content = content.replace("__CWS_ADMIN_EMAIL__", cws_user_email);
} else {
Path pluginBeanFilePath = Paths.get(config_work_dir + SEP + "tomcat_conf" + SEP + "ldap_plugin_bean.xml");
String[] identityAttr = getIdentityPluginAttribute(pluginBeanFilePath, cws_user, cws_ldap_url);
content = content.replace("__CWS_ADMIN_FIRSTNAME__", identityAttr[0]);
content = content.replace("__CWS_ADMIN_LASTNAME__", identityAttr[1]);
content = content.replace("__CWS_ADMIN_EMAIL__", identityAttr[2]);
}

content = content.replace("__CWS_NOTIFICATION_EMAILS__", cws_notification_emails);
content = content.replace("__CWS_TOKEN_EXPIRATION_HOURS__", cws_token_expiration_hours);
content = content.replace("__CWS_SMTP_HOSTNAME__", cws_smtp_hostname);
Expand Down Expand Up @@ -2371,6 +2418,9 @@ private static void updateCwsUiConfig() throws IOException {
if (elasticsearch_use_auth.equalsIgnoreCase("Y")) {
content = content.replace("__ES_USERNAME__", elasticsearch_username);
content = content.replace("__ES_PASSWORD__", elasticsearch_password);
} else {
content = content.replace("__ES_USERNAME__", "na");
content = content.replace("__ES_PASSWORD__", "na");
}
content = content.replace("__CWS_HISTORY_DAYS_TO_LIVE__", history_days_to_live);
writeToFile(path, content);
Expand Down Expand Up @@ -2424,6 +2474,92 @@ private static void updateCwsUiConfig() throws IOException {
}


private static String[] getIdentityPluginAttribute(Path beanFilePath, String user, String ldapURL) throws IOException {
//
// Get identity plugin properties and attributes
//
String propertyBase = "";
String propertySearchBase = "";
String[] identityAttributes = new String[3];
String[] attributeFilter = {"givenName", "sn", "mail"};

try {
String fileContent = new String(Files.readAllBytes(beanFilePath));
String repl = "";
String replContent = fileContent.substring(0, fileContent.indexOf("<bean id=\"ldapIdentityProviderPlugin\""));
fileContent = fileContent.replace(replContent, repl);

// Turn file content from string to document
String xmlContent = fileContent;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
builder = factory.newDocumentBuilder();
Document docx = builder.parse(new InputSource(new StringReader(xmlContent)));

NodeList bean = docx.getElementsByTagName("property");

for(int i = 0; i < bean.getLength(); i++) {
Element beanElement = (Element) bean.item(i);
if (beanElement.getAttribute("name").equalsIgnoreCase("baseDn")) {
if (beanElement.getAttribute("value").equals("")) {
propertyBase = beanElement.getTextContent();
} else {
propertyBase = beanElement.getAttribute("value");
}
}
if (beanElement.getAttribute("name").equalsIgnoreCase("userSearchBase")) {
if (beanElement.getAttribute("value").equals("")) {
propertySearchBase = beanElement.getTextContent();
} else {
propertySearchBase = beanElement.getAttribute("value");
}
}
}

Hashtable env = new Hashtable();
String cxtFactory = "com.sun.jndi.ldap.LdapCtxFactory";
env.put(Context.INITIAL_CONTEXT_FACTORY, cxtFactory);
env.put(Context.PROVIDER_URL, ldapURL);
DirContext dirCxt = new InitialDirContext(env);

String base = propertySearchBase + "," + propertyBase;

SearchControls ctrl = new SearchControls();
ctrl.setReturningAttributes(attributeFilter);
ctrl.setSearchScope(SearchControls.SUBTREE_SCOPE);

String filter = "(&(uid=" + user + "))";
NamingEnumeration results = dirCxt.search(base, filter, ctrl);
while (results.hasMore()) {
SearchResult result = (SearchResult) results.next();
Attributes attrs = result.getAttributes();
// First name attribute - givenName
Attribute attr = attrs.get("givenName");
identityAttributes[0] = attr.get().toString();
// Last name attribute - sn
attr = attrs.get("sn");
identityAttributes[1] = attr.get().toString();
// Email attribute - mail
attr = attrs.get("mail");
identityAttributes[2] = attr.get().toString();
}
dirCxt.close();
} catch (Exception e) {
print("+----------------------------------------------------------------------------------+");
print("CWS Installer ERROR: LDAP API failed to retrieve CWS user's " + Arrays.toString(attributeFilter));
print(" to set in CWS properties files and utilize for CWS services. Make sure 'ldap_plugin_bean.xml' is ");
print(" properly configured. Refer to the template /tomcat_conf/ldap_plugin_bean.xml");
print("ERROR: " + e);
print("+----------------------------------------------------------------------------------+");
// JNDI LDAP retrieval failed.
identityAttributes[0] = "__CWS_ADMIN_FIRSTNAME__";
identityAttributes[1] = "__CWS_ADMIN_LASTNAME__";
identityAttributes[2] = "__CWS_ADMIN_EMAIL__";
}
return identityAttributes;
}


private static String updateIdentityPluginContent(String content) throws IOException {
//
// Update identity plugin content
Expand Down Expand Up @@ -2534,7 +2670,7 @@ private static void installLogstash() throws IOException {
Paths.get(logstash_root + SEP + "cws-logstash.conf"));
}

private static void writeOutConfigurationFile() {
private static void writeOutConfigurationFile() throws IOException {
InstallerPresets presets = CwsInstallerUtils.getInstallerPresets();

setPreset("hostname", this_hostname);
Expand All @@ -2547,9 +2683,19 @@ private static void writeOutConfigurationFile() {
setPreset("database_username", cws_db_username);
setPreset("database_password", cws_db_password);
setPreset("admin_user", cws_user);
setPreset("admin_firstname", cws_user_firstname);
setPreset("admin_lastname", cws_user_lastname);
setPreset("admin_email", cws_user_email);

if (cws_auth_scheme.equalsIgnoreCase("CAMUNDA")) {
setPreset("admin_firstname", cws_user_firstname);
setPreset("admin_lastname", cws_user_lastname);
setPreset("admin_email", cws_user_email);
} else {
Path pluginBeanFilePath = Paths.get(config_work_dir + SEP + "tomcat_conf" + SEP + "ldap_plugin_bean.xml");
String[] identityAttr = getIdentityPluginAttribute(pluginBeanFilePath, cws_user, cws_ldap_url);
setPreset("admin_firstname", identityAttr[0]);
setPreset("admin_lastname", identityAttr[1]);
setPreset("admin_email", identityAttr[2]);
}

setPreset("cws_web_port", cws_tomcat_connector_port);
setPreset("cws_ssl_port", cws_tomcat_ssl_port);
setPreset("cws_ajp_port", cws_tomcat_ajp_port);
Expand Down
3 changes: 3 additions & 0 deletions install/cws-engine/cws-engine.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ user.task.assignment.subject=__CWS_TASK_ASSIGNMENT_SUBJ__
user.task.assignment.body=__CWS_TASK_ASSIGNMENT_BODY__
cws.engine.jobexecutor.enabled=__CWS_ENGINE_JOBEXECUTOR_ENABLED__
startup.autoregister.proces.defs=__STARTUP_AUTOREGISTER_PROCESS_DEFS__
cws.admin.firstname=__CWS_ADMIN_FIRSTNAME__
cws.admin.lastname=__CWS_ADMIN_LASTNAME__
cws.admin.email=__CWS_ADMIN_EMAIL__
cws.notification.emails=__CWS_NOTIFICATION_EMAILS__
cws.token.expiration.hours=__CWS_TOKEN_EXPIRATION_HOURS__
cws.smtp.hostname=__CWS_SMTP_HOSTNAME__
Expand Down
3 changes: 3 additions & 0 deletions install/cws-ui/cws-ui.properties
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ cws.broker.obj.name=cws-broker:brokerName=cwsConsoleBroker,type=Broker

cws.auth.scheme=__CWS_AUTH_SCHEME__

cws.admin.firstname=__CWS_ADMIN_FIRSTNAME__
cws.admin.lastname=__CWS_ADMIN_LASTNAME__
cws.admin.email=__CWS_ADMIN_EMAIL__
cws.notification.emails=__CWS_NOTIFICATION_EMAILS__
cws.token.expiration.hours=__CWS_TOKEN_EXPIRATION_HOURS__

Expand Down