package org.cacert.gigi.dbObjects;
import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
import java.util.HashMap;
import java.util.Locale;
import org.cacert.gigi.GigiApiException;
import org.cacert.gigi.database.GigiPreparedStatement;
import org.cacert.gigi.dbObjects.Certificate.CertificateStatus;
-import org.cacert.gigi.email.SendMail;
import org.cacert.gigi.localisation.Language;
+import org.cacert.gigi.output.template.MailTemplate;
import org.cacert.gigi.output.template.Outputable;
import org.cacert.gigi.output.template.SprintfCommand;
import org.cacert.gigi.util.DayDate;
}
}
+ public void revokeCertificate(Certificate cert) throws GigiApiException {
+
+ // TODO Check for open jobs!
+ if (cert.getStatus() == CertificateStatus.ISSUED) {
+ writeSELog("SE Revoke certificate");
+ cert.revoke().waitFor(60000);
+ // send notification to support
+ String subject = "Revoke certificate";
+ Outputable message = SprintfCommand.createSimple("Certificate with serial number {0} for {1} <{2}>, has been revoked.", cert.getSerial(), target.getPreferredName().toString(), target.getEmail());
+ sendSupportNotification(subject, message);
+ // send notification to user
+ subject = "Revoke certificate";
+ message = SprintfCommand.createSimple("Certificate with serial number {0} with subject distinguished name {1} has been revoked.", cert.getSerial(), cert.getDistinguishedName());
+ sendSupportUserNotification(subject, message);
+ }
+ }
+
private void writeSELog(String type) throws GigiApiException {
if (ticket == null) {
throw new GigiApiException("No ticket set!");
return target;
}
- public void grant(Group toMod) {
+ public void grant(Group toMod) throws GigiApiException {
target.grantGroup(supporter, toMod);
}
target.revokeGroup(supporter, toMod);
}
+ private static final MailTemplate supportNotification = new MailTemplate(SupportedUser.class.getResource("SupportNotificationMail.templ"));
+
public void sendSupportNotification(String subject, Outputable message) {
try {
- StringWriter sw = new StringWriter();
- PrintWriter outMail = new PrintWriter(sw);
- outMail.print("Hi," + "\n\n");
- SprintfCommand.createSimple("supporter {0} triggered:", supporter.getPreferredName().toString()).output(outMail, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
- outMail.print("\n\n");
- message.output(outMail, Language.getInstance(Locale.ENGLISH), new HashMap<String, Object>());
- outMail.print("\n\n");
- outMail.print("RA DB");
- outMail.close();
- String supportemailaddress = "support@" + ServerConstants.getWwwHostName().replaceFirst("^www\\.", "");
- SendMail.getInstance().sendMail(supportemailaddress, "[" + this.getTicket() + "] RA DB " + subject, sw.toString(), supportemailaddress, null, null, null, null, false);
+ HashMap<String, Object> vars = new HashMap<>();
+ vars.put("supporter", supporter.getPreferredName().toString());
+ vars.put("action", message);
+ vars.put("ticket", this.getTicket());
+ vars.put("subject", subject);
+
+ String supportemailaddress = ServerConstants.getSupportMailAddress();
+ supportNotification.sendMail(Language.getInstance(Locale.ENGLISH), vars, supportemailaddress);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private static final MailTemplate supportUserNotification = new MailTemplate(SupportedUser.class.getResource("SupportUserNotificationMail.templ"));
+
+ public void sendSupportUserNotification(String subject, Outputable message) {
+ try {
+ HashMap<String, Object> vars = new HashMap<>();
+ vars.put("action", message);
+ vars.put("ticket", this.getTicket());
+ vars.put("subject", subject);
+
+ supportUserNotification.sendMail(Language.getInstance(Locale.ENGLISH), vars, target.getEmail());
} catch (IOException e) {
e.printStackTrace();
}