summaryrefslogtreecommitdiffstats
path: root/pki/base/common/src/com/netscape/cms/jobs/RenewalNotificationJob.java
diff options
context:
space:
mode:
authorAde Lee <alee@redhat.com>2012-01-11 12:57:53 -0500
committerAde Lee <alee@redhat.com>2012-01-11 13:49:04 -0500
commit10cfe7756e967ac91c66d33b392aeab9cf3780fb (patch)
treed5ac9b58442265d2ce5ef60e31f041ddacba1b4f /pki/base/common/src/com/netscape/cms/jobs/RenewalNotificationJob.java
parentedcb24f65cc3700e75d0a1d14dc2483f210b0ee4 (diff)
downloadpki-10cfe7756e967ac91c66d33b392aeab9cf3780fb.tar.gz
pki-10cfe7756e967ac91c66d33b392aeab9cf3780fb.tar.xz
pki-10cfe7756e967ac91c66d33b392aeab9cf3780fb.zip
Formatting (no line wrap in comments or code)
Diffstat (limited to 'pki/base/common/src/com/netscape/cms/jobs/RenewalNotificationJob.java')
-rw-r--r--pki/base/common/src/com/netscape/cms/jobs/RenewalNotificationJob.java297
1 files changed, 152 insertions, 145 deletions
diff --git a/pki/base/common/src/com/netscape/cms/jobs/RenewalNotificationJob.java b/pki/base/common/src/com/netscape/cms/jobs/RenewalNotificationJob.java
index 8649cf23a..2a3fffed3 100644
--- a/pki/base/common/src/com/netscape/cms/jobs/RenewalNotificationJob.java
+++ b/pki/base/common/src/com/netscape/cms/jobs/RenewalNotificationJob.java
@@ -17,7 +17,6 @@
// --- END COPYRIGHT BLOCK ---
package com.netscape.cms.jobs;
-
import java.io.IOException;
import java.text.DateFormat;
import java.util.Calendar;
@@ -49,12 +48,11 @@ import com.netscape.certsrv.notification.IMailNotification;
import com.netscape.certsrv.request.IRequest;
import com.netscape.certsrv.request.RequestId;
-
/**
- * A job for the Jobs Scheduler. This job checks in the internal ldap
+ * A job for the Jobs Scheduler. This job checks in the internal ldap
* db for certs about to expire within the next configurable days and
* sends email notifications to the appropriate recipients.
- *
+ *
* the $TOKENS that are available for the this jobs's summary outer form are:<br
>
* <UL>
@@ -79,14 +77,14 @@ import com.netscape.certsrv.request.RequestId;
* <LI>$HttpHost
* <LI>$HttpPort
* </UL>
- *
+ *
* @version $Revision$, $Date$
* @see com.netscape.certsrv.jobs.IJob
* @see com.netscape.cms.jobs.AJobBase
*/
-public class RenewalNotificationJob
- extends AJobBase
- implements IJob, Runnable, IExtendedPluginInfo {
+public class RenewalNotificationJob
+ extends AJobBase
+ implements IJob, Runnable, IExtendedPluginInfo {
// config parameters...
public static final String PROP_CRON = "cron";
@@ -98,14 +96,14 @@ public class RenewalNotificationJob
/**
* This job will send notification at this much time before the
- * enpiration date
+ * enpiration date
*/
public static final String PROP_NOTIFYTRIGGEROFFSET =
- "notifyTriggerOffset";
+ "notifyTriggerOffset";
/**
* This job will stop sending notification this much time after
- * the expiration date
+ * the expiration date
*/
public static final String PROP_NOTIFYENDOFFSET = "notifyEndOffset";
@@ -113,13 +111,13 @@ public class RenewalNotificationJob
* sender email address as appeared on the notification email
*/
public static final String PROP_SENDEREMAIL =
- "senderEmail";
+ "senderEmail";
/**
* email subject line as appeared on the notification email
*/
public static final String PROP_EMAILSUBJECT =
- "emailSubject";
+ "emailSubject";
/**
* location of the template file used for email notification
@@ -149,7 +147,7 @@ public class RenewalNotificationJob
/**
* location of the template file for each item appeared on the
- * notification summary
+ * notification summary
*/
public static final String PROP_SUMMARY_ITEMTEMPLATE = "summary.itemTemplate";
@@ -159,44 +157,44 @@ public class RenewalNotificationJob
* for instances of this implementation can be configured through the
* console.
*/
- protected static String[] mConfigParams =
- new String[] {
- "enabled",
- PROP_CRON,
- PROP_PROFILE_ID,
- PROP_NOTIFYTRIGGEROFFSET,
- PROP_NOTIFYENDOFFSET,
- PROP_SENDEREMAIL,
- PROP_EMAILSUBJECT,
- PROP_EMAILTEMPLATE,
- "summary.enabled",
- PROP_SUMMARY_RECIPIENTEMAIL,
- PROP_SUMMARY_SENDEREMAIL,
- PROP_SUMMARY_SUBJECT,
- PROP_SUMMARY_ITEMTEMPLATE,
- PROP_SUMMARY_TEMPLATE,
+ protected static String[] mConfigParams =
+ new String[] {
+ "enabled",
+ PROP_CRON,
+ PROP_PROFILE_ID,
+ PROP_NOTIFYTRIGGEROFFSET,
+ PROP_NOTIFYENDOFFSET,
+ PROP_SENDEREMAIL,
+ PROP_EMAILSUBJECT,
+ PROP_EMAILTEMPLATE,
+ "summary.enabled",
+ PROP_SUMMARY_RECIPIENTEMAIL,
+ PROP_SUMMARY_SENDEREMAIL,
+ PROP_SUMMARY_SUBJECT,
+ PROP_SUMMARY_ITEMTEMPLATE,
+ PROP_SUMMARY_TEMPLATE,
};
-
+
protected ICertificateRepository mCertDB = null;
protected ICertificateAuthority mCA = null;
protected boolean mSummary = false;
protected String mEmailSender = null;
protected String mEmailSubject = null;
protected String mEmailTemplateName = null;
- protected String mSummaryItemTemplateName = null;
- protected String mSummaryTemplateName = null;
+ protected String mSummaryItemTemplateName = null;
+ protected String mSummaryTemplateName = null;
protected boolean mSummaryHTML = false;
protected boolean mHTML = false;
protected String mHttpHost = null;
protected String mHttpPort = null;
- private int mPreDays = 0;
- private long mPreMS = 0;
- private int mPostDays = 0;
- private long mPostMS = 0;
- private int mMaxNotifyCount = 1;
- private String[] mProfileId = null;
+ private int mPreDays = 0;
+ private long mPreMS = 0;
+ private int mPostDays = 0;
+ private long mPostMS = 0;
+ private int mMaxNotifyCount = 1;
+ private String[] mProfileId = null;
/* Vector of extendedPluginInfo strings */
protected static Vector mExtendedPluginInfo = null;
@@ -207,8 +205,8 @@ public class RenewalNotificationJob
/**
* class constructor
- */
- public RenewalNotificationJob () {
+ */
+ public RenewalNotificationJob() {
}
/**
@@ -217,48 +215,49 @@ public class RenewalNotificationJob
public String[] getExtendedPluginInfo(Locale locale) {
String s[] = {
IExtendedPluginInfo.HELP_TEXT +
- "; A job that checks for expiring or expired certs" +
- "notifyTriggerOffset before and notifyEndOffset after " +
- "the expiration date",
-
- PROP_PROFILE_ID + ";string;Specify the ID of the profile which "+
- "approved the certificates that are about to expire. For multiple "+
- "profiles, each entry is separated by white space. For example, " +
- "if the administrator just wants to give automated notification " +
- "when the SSL server certificates are about to expire, then "+
- "he should enter \"caServerCert caAgentServerCert\" in the profileId textfield. "+
- "Blank field means all profiles.",
+ "; A job that checks for expiring or expired certs" +
+ "notifyTriggerOffset before and notifyEndOffset after " +
+ "the expiration date",
+
+ PROP_PROFILE_ID + ";string;Specify the ID of the profile which " +
+ "approved the certificates that are about to expire. For multiple " +
+ "profiles, each entry is separated by white space. For example, " +
+ "if the administrator just wants to give automated notification " +
+ "when the SSL server certificates are about to expire, then " +
+ "he should enter \"caServerCert caAgentServerCert\" in the profileId textfield. " +
+ "Blank field means all profiles.",
PROP_NOTIFYTRIGGEROFFSET + ";number,required;How long (in days) before " +
- "certificate expiration will the first notification " +
- "be sent",
+ "certificate expiration will the first notification " +
+ "be sent",
PROP_NOTIFYENDOFFSET + ";number,required;How long (in days) after " +
- "certificate expiration will notifications " +
- "continue to be resent if certificate is not renewed",
+ "certificate expiration will notifications " +
+ "continue to be resent if certificate is not renewed",
PROP_CRON + ";string,required;Format: minute hour dayOfMonth Mmonth " +
- "dayOfWeek. Use '*' for 'every'. For dayOfWeek, 0 is Sunday",
+ "dayOfWeek. Use '*' for 'every'. For dayOfWeek, 0 is Sunday",
PROP_SENDEREMAIL + ";string,required;Specify the address to be used " +
- "as the email's 'sender'. Bounces go to this address.",
+ "as the email's 'sender'. Bounces go to this address.",
PROP_EMAILSUBJECT + ";string,required;Email subject",
PROP_EMAILTEMPLATE + ";string,required;Fully qualified pathname of " +
- "template file of email to be sent",
+ "template file of email to be sent",
"enabled;boolean;Enable this plugin",
"summary.enabled;boolean;Enabled sending of summaries",
PROP_SUMMARY_SENDEREMAIL + ";string,required;Sender email address of summary",
PROP_SUMMARY_RECIPIENTEMAIL + ";string,required;Who should receive summaries",
PROP_SUMMARY_SUBJECT + ";string,required;Subject of summary email",
PROP_SUMMARY_TEMPLATE + ";string,required;Fully qualified pathname of " +
- "template file of email to be sent",
+ "template file of email to be sent",
PROP_SUMMARY_ITEMTEMPLATE + ";string,required;Fully qualified pathname of " +
- "file with template to be used for each summary item",
+ "file with template to be used for each summary item",
IExtendedPluginInfo.HELP_TOKEN +
- ";configuration-jobrules-renewalnotification",
+ ";configuration-jobrules-renewalnotification",
};
return s;
}
-
+
/**
* Initialize from the configuration file.
+ *
* @param id String name of this instance
* @param implName string name of this implementation
* @param config configuration store for this instance
@@ -289,10 +288,10 @@ public class RenewalNotificationJob
mJobCron = scheduler.createJobCron(mCron);
}
-
+
/**
* finds out which cert needs notification and notifies the
- * responsible parties
+ * responsible parties
*/
public void run() {
// for forming renewal URL at template
@@ -301,7 +300,7 @@ public class RenewalNotificationJob
// read from the configuration file
try {
- mPreDays = mConfig.getInteger(PROP_NOTIFYTRIGGEROFFSET, 30); // in days
+ mPreDays = mConfig.getInteger(PROP_NOTIFYTRIGGEROFFSET, 30); // in days
mPostDays = mConfig.getInteger(PROP_NOTIFYENDOFFSET, 15); // in days
mEmailSender = mConfig.getString(PROP_SENDEREMAIL);
@@ -314,19 +313,19 @@ public class RenewalNotificationJob
if (sc.getBoolean(PROP_ENABLED, false)) {
mSummary = true;
mSummaryItemTemplateName =
- mConfig.getString(PROP_SUMMARY_ITEMTEMPLATE);
+ mConfig.getString(PROP_SUMMARY_ITEMTEMPLATE);
mSummarySenderEmail =
- mConfig.getString(PROP_SUMMARY_SENDEREMAIL);
+ mConfig.getString(PROP_SUMMARY_SENDEREMAIL);
mSummaryReceiverEmail =
- mConfig.getString(PROP_SUMMARY_RECIPIENTEMAIL);
+ mConfig.getString(PROP_SUMMARY_RECIPIENTEMAIL);
mSummaryMailSubject =
- mConfig.getString(PROP_SUMMARY_SUBJECT);
+ mConfig.getString(PROP_SUMMARY_SUBJECT);
mSummaryTemplateName =
- mConfig.getString(PROP_SUMMARY_TEMPLATE);
+ mConfig.getString(PROP_SUMMARY_TEMPLATE);
} else {
mSummary = false;
}
-
+
long msperday = 86400 * 1000;
long mspredays = mPreDays;
long mspostdays = mPostDays;
@@ -347,9 +346,9 @@ public class RenewalNotificationJob
* if notified successfully, mark "STATUS_SUCCESS",
* else, if notified unsuccessfully, mark "STATUS_FAILURE".
*/
-
+
/* 1) make target notAfter string */
-
+
Date expiryDate = null;
Date stopDate = null;
@@ -360,13 +359,13 @@ public class RenewalNotificationJob
expiryDate = new Date(expiryMS);
stopDate = new Date(stopMS);
-
+
// All cert records which:
// 1) expire before the deadline
// 2) have not already been renewed
// filter format:
// (& (notafter<='time')(!(certAutoRenew=DONE))(!certAutoRenew=DISABLED))
-
+
StringBuffer f = new StringBuffer();
String profileId = "";
try {
@@ -374,24 +373,24 @@ public class RenewalNotificationJob
} catch (EBaseException ee) {
}
- if (profileId != null && profileId.length() > 0) {
+ if (profileId != null && profileId.length() > 0) {
StringTokenizer tokenizer = new StringTokenizer(profileId);
int num = tokenizer.countTokens();
mProfileId = new String[num];
- for (int i=0; i<num; i++)
+ for (int i = 0; i < num; i++)
mProfileId[i] = tokenizer.nextToken();
}
f.append("(&");
if (mProfileId != null) {
if (mProfileId.length == 1)
- f.append("("+ICertRecord.ATTR_META_INFO+ "=" +
- ICertRecord.META_PROFILE_ID +":"+mProfileId[0]+")");
+ f.append("(" + ICertRecord.ATTR_META_INFO + "=" +
+ ICertRecord.META_PROFILE_ID + ":" + mProfileId[0] + ")");
else {
f.append("(|");
- for (int i=0; i<mProfileId.length; i++) {
- f.append("("+ICertRecord.ATTR_META_INFO+ "=" +
- ICertRecord.META_PROFILE_ID +":"+mProfileId[i]+")");
+ for (int i = 0; i < mProfileId.length; i++) {
+ f.append("(" + ICertRecord.ATTR_META_INFO + "=" +
+ ICertRecord.META_PROFILE_ID + ":" + mProfileId[i] + ")");
}
f.append(")");
}
@@ -407,7 +406,7 @@ public class RenewalNotificationJob
String filter = f.toString();
String emailTemplate =
- getTemplateContent(mEmailTemplateName);
+ getTemplateContent(mEmailTemplateName);
mHTML = mMailHTML;
@@ -415,7 +414,7 @@ public class RenewalNotificationJob
String summaryItemTemplate = null;
if (mSummary == true) {
- summaryItemTemplate =
+ summaryItemTemplate =
getTemplateContent(mSummaryItemTemplateName);
}
@@ -423,7 +422,7 @@ public class RenewalNotificationJob
CertRecProcessor cp = new CertRecProcessor(this, emailTemplate, summaryItemTemplate, ic);
//CertRecordList list = mCertDB.findCertRecordsInList(filter, null, "serialno", 5);
//list.processCertRecords(0, list.getSize() - 1, cp);
-
+
Enumeration en = mCertDB.findCertRecs(filter);
while (en.hasMoreElements()) {
@@ -436,36 +435,36 @@ public class RenewalNotificationJob
log(ILogger.LL_FAILURE, CMS.getLogMessage("JOBS_FAILED_PROCESS", e.toString()));
}
}
-
+
// Now send the summary
if (mSummary == true) {
try {
String summaryTemplate =
- getTemplateContent(mSummaryTemplateName);
+ getTemplateContent(mSummaryTemplateName);
mSummaryHTML = mMailHTML;
buildContentParams(IEmailFormProcessor.TOKEN_ID,
- mId);
+ mId);
buildContentParams(IEmailFormProcessor.TOKEN_SUMMARY_ITEM_LIST,
- ic.mItemListContent);
+ ic.mItemListContent);
buildContentParams(IEmailFormProcessor.TOKEN_SUMMARY_TOTAL_NUM,
- String.valueOf(ic.mNumFail + ic.mNumSuccessful));
- buildContentParams(IEmailFormProcessor.TOKEN_SUMMARY_SUCCESS_NUM,
- String.valueOf(ic.mNumSuccessful));
+ String.valueOf(ic.mNumFail + ic.mNumSuccessful));
+ buildContentParams(IEmailFormProcessor.TOKEN_SUMMARY_SUCCESS_NUM,
+ String.valueOf(ic.mNumSuccessful));
buildContentParams(IEmailFormProcessor.TOKEN_SUMMARY_FAILURE_NUM,
- String.valueOf(ic.mNumFail));
+ String.valueOf(ic.mNumFail));
buildContentParams(IEmailFormProcessor.TOKEN_EXECUTION_TIME,
- nowString);
-
+ nowString);
+
IEmailFormProcessor summaryEmfp = CMS.getEmailFormProcessor();
- String summaryContent =
- summaryEmfp.getEmailContent(summaryTemplate,
- mContentParams);
+ String summaryContent =
+ summaryEmfp.getEmailContent(summaryTemplate,
+ mContentParams);
if (summaryContent == null) {
log(ILogger.LL_FAILURE, CMS.getLogMessage("JOBS_SUMMARY_CONTENT_NULL"));
@@ -490,38 +489,43 @@ public class RenewalNotificationJob
/**
* get instance id.
+ *
* @return a String identifier
*/
public String getId() {
return mId;
}
-
+
/**
* set instance id.
+ *
* @param id String id of the instance
*/
public void setId(String id) {
mId = id;
}
-
+
/**
* get cron string associated with this job
+ *
* @return a JobCron object that represents the schedule of this job
*/
public IJobCron getJobCron() {
return mJobCron;
}
-
+
/**
* gets the plugin name of this job.
+ *
* @return a String that is the name of this implementation
*/
public String getImplName() {
return mImplName;
}
-
+
/**
* Gets the configuration substore used by this job
+ *
* @return configuration store
*/
public IConfigStore getConfigStore() {
@@ -529,11 +533,11 @@ public class RenewalNotificationJob
}
protected void mailUser(String subject,
- String msg,
- String sender,
- IRequest req,
- ICertRecord cr)
- throws IOException, ENotificationException, EBaseException {
+ String msg,
+ String sender,
+ IRequest req,
+ ICertRecord cr)
+ throws IOException, ENotificationException, EBaseException {
IMailNotification mn = CMS.getMailNotification();
@@ -568,13 +572,18 @@ public class RenewalNotificationJob
mn.setTo(rcp);
- if (sender != null) mn.setFrom(sender);
- else mn.setFrom("nobody");
+ if (sender != null)
+ mn.setFrom(sender);
+ else
+ mn.setFrom("nobody");
- if (subject != null) mn.setSubject(subject);
- else mn.setFrom("Important message from Certificate Authority");
+ if (subject != null)
+ mn.setSubject(subject);
+ else
+ mn.setFrom("Important message from Certificate Authority");
- if (mHTML == true) mn.setContentType("text/html");
+ if (mHTML == true)
+ mn.setContentType("text/html");
String failedString = null;
@@ -584,10 +593,10 @@ public class RenewalNotificationJob
}
/**
- * Returns a list of configuration parameter names.
- * The list is passed to the configuration console so instances of
+ * Returns a list of configuration parameter names.
+ * The list is passed to the configuration console so instances of
* this implementation can be configured through the console.
- *
+ *
* @return String array of configuration parameter names.
*/
public String[] getConfigParams() {
@@ -595,15 +604,14 @@ public class RenewalNotificationJob
}
}
-
class CertRecProcessor implements IElementProcessor {
protected RenewalNotificationJob mJob;
protected String mEmailTemplate;
protected String mSummaryItemTemplate;
protected ItemCounter mIC;
- public CertRecProcessor(RenewalNotificationJob job, String emailTemplate,
- String summaryItemTemplate, ItemCounter ic) {
+ public CertRecProcessor(RenewalNotificationJob job, String emailTemplate,
+ String summaryItemTemplate, ItemCounter ic) {
mJob = job;
mEmailTemplate = emailTemplate;
mSummaryItemTemplate = summaryItemTemplate;
@@ -621,9 +629,9 @@ class CertRecProcessor implements IElementProcessor {
if (cr != null) {
mJob.buildItemParams(cr.getCertificate());
mJob.buildItemParams(IEmailFormProcessor.TOKEN_HTTP_HOST,
- mJob.mHttpHost);
+ mJob.mHttpHost);
mJob.buildItemParams(IEmailFormProcessor.TOKEN_HTTP_PORT, mJob.mHttpPort);
-
+
MetaInfo metaInfo = null;
metaInfo = (MetaInfo) cr.get(ICertRecord.ATTR_META_INFO);
@@ -632,10 +640,10 @@ class CertRecProcessor implements IElementProcessor {
numFailCounted = true;
if (mJob.mSummary == true)
mJob.buildItemParams(IEmailFormProcessor.TOKEN_STATUS,
- AJobBase.STATUS_FAILURE);
- mJob.log(ILogger.LL_FAILURE,
- CMS.getLogMessage("JOBS_GET_CERT_ERROR",
- cr.getCertificate().getSerialNumber().toString(16)));
+ AJobBase.STATUS_FAILURE);
+ mJob.log(ILogger.LL_FAILURE,
+ CMS.getLogMessage("JOBS_GET_CERT_ERROR",
+ cr.getCertificate().getSerialNumber().toString(16)));
} else {
ridString = (String) metaInfo.get(ICertRecord.META_REQUEST_ID);
}
@@ -645,54 +653,54 @@ class CertRecProcessor implements IElementProcessor {
if (ridString != null) {
RequestId rid = new RequestId(ridString);
-
+
try {
req = mJob.mCA.getRequestQueue().findRequest(rid);
} catch (Exception e) {
// it is ok not to be able to get the request. The main reason
// to get the request is to retrieve the requestor's email.
// We can retrieve the email from the CertRecord.
- CMS.debug("huh RenewalNotificationJob Exception: "+e.toString());
+ CMS.debug("huh RenewalNotificationJob Exception: " + e.toString());
}
if (req != null)
mJob.buildItemParams(req);
} // ridString != null
- try {
+ try {
// send mail to user
-
+
IEmailFormProcessor emfp = CMS.getEmailFormProcessor();
String message = emfp.getEmailContent(mEmailTemplate,
mJob.mItemParams);
mJob.mailUser(mJob.mEmailSubject,
- message,
- mJob.mEmailSender,
- req,
- cr);
-
+ message,
+ mJob.mEmailSender,
+ req,
+ cr);
+
mJob.buildItemParams(IEmailFormProcessor.TOKEN_STATUS,
- AJobBase.STATUS_SUCCESS);
-
+ AJobBase.STATUS_SUCCESS);
+
mIC.mNumSuccessful++;
-
+
} catch (Exception e) {
- CMS.debug("RenewalNotificationJob Exception: "+e.toString());
+ CMS.debug("RenewalNotificationJob Exception: " + e.toString());
mJob.buildItemParams(IEmailFormProcessor.TOKEN_STATUS, AJobBase.STATUS_FAILURE);
mJob.log(ILogger.LL_FAILURE, e.toString(), ILogger.L_MULTILINE);
if (numFailCounted == false) {
mIC.mNumFail++;
}
}
-
+
if (mJob.mSummary == true) {
IEmailFormProcessor summaryItemEmfp =
- CMS.getEmailFormProcessor();
- String c =
- summaryItemEmfp.getEmailContent(mSummaryItemTemplate,
- mJob.mItemParams);
-
+ CMS.getEmailFormProcessor();
+ String c =
+ summaryItemEmfp.getEmailContent(mSummaryItemTemplate,
+ mJob.mItemParams);
+
if (mIC.mItemListContent == null) {
mIC.mItemListContent = c;
} else {
@@ -702,7 +710,6 @@ class CertRecProcessor implements IElementProcessor {
}
}
-
class ItemCounter {
public int mNumSuccessful = 0;
public int mNumFail = 0;