1 package org.cacert.gigi.dbObjects;
5 import org.cacert.gigi.GigiApiException;
6 import org.cacert.gigi.database.DatabaseConnection;
7 import org.cacert.gigi.database.GigiPreparedStatement;
8 import org.cacert.gigi.dbObjects.Certificate.CertificateStatus;
10 public class SupportedUser {
14 private User supporter;
16 private String ticket;
18 public SupportedUser(User target, User supporter, String ticket) {
19 this.supporter = supporter;
24 public boolean setName(Name newName) throws GigiApiException {
25 if (newName.equals(target.getName())) {
28 writeSELog("SE Name change");
29 target.setName(newName);
33 public boolean setDob(Date dob) throws GigiApiException {
34 if (dob.toString().equals(target.getDoB().toString())) {
37 writeSELog("SE dob change");
42 public void revokeAllCertificates() throws GigiApiException {
43 writeSELog("SE Revoke certificates");
44 Certificate[] certs = target.getCertificates(false);
45 // TODO Check for open jobs!
46 for (int i = 0; i < certs.length; i++) {
47 if (certs[i].getStatus() == CertificateStatus.ISSUED) {
53 private void writeSELog(String type) throws GigiApiException {
55 throw new GigiApiException("No ticket set!");
57 GigiPreparedStatement prep = DatabaseConnection.getInstance().prepare("INSERT INTO adminLog SET uid=?, admin=?, type=?, information=?");
58 prep.setInt(1, target.getId());
59 prep.setInt(2, supporter.getId());
60 prep.setString(3, type);
61 prep.setString(4, ticket);
66 return target.getId();
69 public Certificate[] getCertificates(boolean includeRevoked) {
70 return target.getCertificates(includeRevoked);
73 public String getTicket() {
77 public User getTargetUser() {
81 public void submitSupportAction() throws GigiApiException {
82 target.rawUpdateUserData();