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 {
12 private User target, supporter;
14 private String ticket;
16 public SupportedUser(User target, User supporter, String ticket) {
17 this.supporter = supporter;
22 public boolean setName(Name newName) throws GigiApiException {
23 if (newName.equals(target.getName())) {
26 writeSELog("SE Name change");
27 target.setName(newName);
31 public boolean setDob(Date dob) throws GigiApiException {
32 if (dob.toString().equals(target.getDoB().toString())) {
35 writeSELog("SE dob change");
40 public void revokeAllCertificates() throws GigiApiException {
41 writeSELog("SE Revoke certificates");
42 Certificate[] certs = target.getCertificates(false);
43 // TODO Check for open jobs!
44 for (int i = 0; i < certs.length; i++) {
45 if (certs[i].getStatus() == CertificateStatus.ISSUED) {
51 private void writeSELog(String type) throws GigiApiException {
53 throw new GigiApiException("No ticket set!");
55 GigiPreparedStatement prep = DatabaseConnection.getInstance().prepare("INSERT INTO adminLog SET uid=?, admin=?, type=?, information=?");
56 prep.setInt(1, target.getId());
57 prep.setInt(2, supporter.getId());
58 prep.setString(3, type);
59 prep.setString(4, ticket);
64 return target.getId();
67 public Certificate[] getCertificates(boolean includeRevoked) {
68 return target.getCertificates(includeRevoked);
71 public String getTicket() {
75 public User getTargetUser() {
79 public void submitSupportAction() throws GigiApiException {
80 target.rawUpdateUserData();