import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
+import java.util.Random;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.cacert.gigi.dbObjects.Certificate;
import org.cacert.gigi.dbObjects.Certificate.CertificateStatus;
import org.cacert.gigi.dbObjects.CertificateOwner;
-import org.cacert.gigi.dbObjects.CountryCode;
-import org.cacert.gigi.dbObjects.CountryCode.CountryCodeType;
+import org.cacert.gigi.dbObjects.Country;
import org.cacert.gigi.dbObjects.Digest;
import org.cacert.gigi.dbObjects.Domain;
import org.cacert.gigi.dbObjects.DomainPingType;
public class Manager extends Page {
+ public static Country getRandomCountry() {
+ List<Country> cc = Country.getCountries();
+ int rnd = new Random().nextInt(cc.size());
+ return cc.get(rnd);
+ }
+
public static final String PATH = "/manager";
private static HashMap<DomainPingType, DomainPinger> dps;
}
}
+ public User getSupporter() {
+ if (supporter != null) {
+ return supporter;
+ }
+ try {
+ User u = createAssurer( -1);
+ if ( !u.isInGroup(Group.SUPPORTER)) {
+ try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `user_groups` SET `user`=?, `permission`=?::`userGroup`, `grantedby`=?")) {
+ ps.setInt(1, u.getId());
+ ps.setString(2, Group.SUPPORTER.getDatabaseName());
+ ps.setInt(3, u.getId());
+ ps.execute();
+ }
+ u.refreshGroups();
+ }
+ supporter = u;
+ } catch (ReflectiveOperationException | GigiApiException e) {
+ e.printStackTrace();
+ }
+ return supporter;
+ }
+
public User getAssurer(int i) {
if (assurers[i] != null) {
return assurers[i];
}
private User createAssurer(int i) throws GigiApiException, IllegalAccessException {
- try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, `points`=?, `location`=?, `date`=?")) {
+ try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, `points`=?, `location`=?, `date`=?, `country`=?")) {
String mail = "test-assurer" + i + "@example.com";
User u = User.getByEmail(mail);
if (u == null) {
ps.setInt(3, 100);
ps.setString(4, "Manager init code");
ps.setString(5, "1990-01-01");
+ ps.setString(6, getRandomCountry().getCode());
ps.execute();
}
return u;
Calendar gc = GregorianCalendar.getInstance();
gc.setTimeInMillis(0);
gc.set(1990, 0, 1);
- User u = new User(email, "xvXV12°§", new DayDate(gc.getTime().getTime()), Locale.ENGLISH, //
- new NamePart(NamePartType.FIRST_NAME, "Först"), new NamePart(NamePartType.FIRST_NAME, "Müddle"),//
+
+ Country country = getRandomCountry();
+
+ User u = new User(email, "xvXV12°§", new DayDate(gc.getTime().getTime()), Locale.ENGLISH, country, //
+ new NamePart(NamePartType.FIRST_NAME, "Först"), new NamePart(NamePartType.FIRST_NAME, "Müddle"), //
new NamePart(NamePartType.LAST_NAME, "Läst"), new NamePart(NamePartType.SUFFIX, "Süffix"));
EmailAddress ea = u.getEmails()[0];
verify(email, ea);
User[] assurers = new User[25];
+ User supporter;
+
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
if (req.getParameter("create") != null) {
return;
}
if (req.getParameter("addpriv") != null) {
- u.grantGroup(u, Group.getByString(req.getParameter("priv")));
+ try {
+ u.grantGroup(getSupporter(), Group.getByString(req.getParameter("priv")));
+ } catch (GigiApiException e) {
+ throw new Error(e);
+ }
resp.getWriter().println("Privilege granted");
} else {
u.revokeGroup(u, Group.getByString(req.getParameter("priv")));
if (vp < 10) {
currentVP = vp;
}
- Notary.assure(getAssurer(agentNumber), byEmail, byEmail.getPreferredName(), byEmail.getDoB(), currentVP, "Testmanager Verify up code", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS));
+ Notary.assure(getAssurer(agentNumber), byEmail, byEmail.getPreferredName(), byEmail.getDoB(), currentVP, "Testmanager Verify up code", "2014-11-06", AssuranceType.FACE_TO_FACE, getRandomCountry());
agentNumber += 1;
vp -= currentVP;
}
try {
for (int i = 0; i < 25; i++) {
User a = getAssurer(i);
- Notary.assure(byEmail, a, a.getNames()[0], a.getDoB(), 10, "Testmanager exp up code", "2014-11-06", AssuranceType.FACE_TO_FACE, CountryCode.getCountryCode("DE", CountryCodeType.CODE_2_CHARS));
+ Notary.assure(byEmail, a, a.getNames()[0], a.getDoB(), 10, "Testmanager exp up code", "2014-11-06", AssuranceType.FACE_TO_FACE, getRandomCountry());
}
} catch (GigiApiException e) {
throw new Error(e);