]> WPIA git - gigi.git/blob - src/org/cacert/gigi/dbObjects/SupportedUser.java
FIX: Only revoke issued certs
[gigi.git] / src / org / cacert / gigi / dbObjects / SupportedUser.java
1 package org.cacert.gigi.dbObjects;
2
3 import java.sql.Date;
4
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;
9
10 public class SupportedUser {
11
12     private User target, supporter;
13
14     private String ticket;
15
16     public SupportedUser(User target, User supporter, String ticket) {
17         this.supporter = supporter;
18         this.target = target;
19         this.ticket = ticket;
20     }
21
22     public boolean setName(Name newName) throws GigiApiException {
23         if (newName.equals(target.getName())) {
24             return false;
25         }
26         writeSELog("SE Name change");
27         target.setName(newName);
28         return true;
29     }
30
31     public boolean setDob(Date dob) throws GigiApiException {
32         if (dob.toString().equals(target.getDoB().toString())) {
33             return false;
34         }
35         writeSELog("SE dob change");
36         target.setDoB(dob);
37         return true;
38     }
39
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) {
46                 certs[i].revoke();
47             }
48         }
49     }
50
51     private void writeSELog(String type) throws GigiApiException {
52         if (ticket == null) {
53             throw new GigiApiException("No ticket set!");
54         }
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);
60         prep.executeUpdate();
61     }
62
63     public int getId() {
64         return target.getId();
65     }
66
67     public Certificate[] getCertificates(boolean includeRevoked) {
68         return target.getCertificates(includeRevoked);
69     }
70
71     public String getTicket() {
72         return ticket;
73     }
74
75     public User getTargetUser() {
76         return target;
77     }
78
79     public void submitSupportAction() throws GigiApiException {
80         target.rawUpdateUserData();
81     }
82
83 }