X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=util-testing%2Forg%2Fcacert%2Fgigi%2Fpages%2FManager.java;h=38b45f6eb11f6be12edeb5d69f5ee171e2d651df;hp=e4e3dbd41a05e0cb2fe534ffa2a7a6377832c3a0;hb=d7271af56f7c4f3381ea079f1be1a52124e1d241;hpb=0b0db3d1f59e3473fad2d8011f75552b7de1671e diff --git a/util-testing/org/cacert/gigi/pages/Manager.java b/util-testing/org/cacert/gigi/pages/Manager.java index e4e3dbd4..38b45f6e 100644 --- a/util-testing/org/cacert/gigi/pages/Manager.java +++ b/util-testing/org/cacert/gigi/pages/Manager.java @@ -7,6 +7,7 @@ import java.security.GeneralSecurityException; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.Signature; +import java.text.SimpleDateFormat; import java.util.Base64; import java.util.Calendar; import java.util.Date; @@ -14,9 +15,11 @@ import java.util.GregorianCalendar; 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; @@ -59,6 +62,20 @@ import sun.security.x509.X509Key; public class Manager extends Page { + public static String validVerificationDateString() { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Calendar c = Calendar.getInstance(); + c.setTimeInMillis(System.currentTimeMillis()); + c.add(Calendar.MONTH, -Notary.LIMIT_MAX_MONTHS_VERIFICATION + 1); + return sdf.format(new Date(c.getTimeInMillis())); + } + + public static Country getRandomCountry() { + List cc = Country.getCountries(); + int rnd = new Random().nextInt(cc.size()); + return cc.get(rnd); + } + public static final String PATH = "/manager"; private static HashMap dps; @@ -88,6 +105,28 @@ public class Manager extends Page { } } + 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.getDBName()); + 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]; @@ -116,7 +155,7 @@ public class Manager extends Page { ps.setInt(3, 100); ps.setString(4, "Manager init code"); ps.setString(5, "1990-01-01"); - ps.setString(6, Country.getRandomCountry().getCode()); + ps.setString(6, getRandomCountry().getCode()); ps.execute(); } return u; @@ -228,7 +267,7 @@ public class Manager extends Page { gc.setTimeInMillis(0); gc.set(1990, 0, 1); - Country country = Country.getRandomCountry(); + 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"), // @@ -253,6 +292,8 @@ public class Manager extends Page { User[] assurers = new User[25]; + User supporter; + @Override public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { if (req.getParameter("create") != null) { @@ -264,12 +305,16 @@ public class Manager extends Page { resp.getWriter().println("User not found."); return; } - if (req.getParameter("addpriv") != null) { - u.grantGroup(u, Group.getByString(req.getParameter("priv"))); - resp.getWriter().println("Privilege granted"); - } else { - u.revokeGroup(u, Group.getByString(req.getParameter("priv"))); - resp.getWriter().println("Privilege revoked"); + try { + if (req.getParameter("addpriv") != null) { + u.grantGroup(getSupporter(), Group.getByString(req.getParameter("priv"))); + resp.getWriter().println("Privilege granted"); + } else { + u.revokeGroup(getSupporter(), Group.getByString(req.getParameter("priv"))); + resp.getWriter().println("Privilege revoked"); + } + } catch (GigiApiException e) { + throw new Error(e); } } else if (req.getParameter("fetch") != null) { String mail = req.getParameter("femail"); @@ -318,7 +363,7 @@ public class Manager extends Page { 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, Country.getRandomCountry()); + Notary.assure(getAssurer(agentNumber), byEmail, byEmail.getPreferredName(), byEmail.getDoB(), currentVP, "Testmanager Verify up code", validVerificationDateString(), AssuranceType.FACE_TO_FACE, getRandomCountry()); agentNumber += 1; vp -= currentVP; } @@ -335,7 +380,7 @@ public class Manager extends Page { 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, Country.getRandomCountry()); + Notary.assure(byEmail, a, a.getNames()[0], a.getDoB(), 10, "Testmanager exp up code", validVerificationDateString(), AssuranceType.FACE_TO_FACE, getRandomCountry()); } } catch (GigiApiException e) { throw new Error(e); @@ -456,6 +501,7 @@ public class Manager extends Page { vars.put("reverificationDays", TimeConditions.getInstance().getVerificationLimitDays()); vars.put("verificationFreshMonths", TimeConditions.getInstance().getVerificationMonths()); vars.put("verificationMaxAgeMonths", TimeConditions.getInstance().getVerificationMaxAgeMonths()); + vars.put("emailPingMonths", TimeConditions.getInstance().getEmailPingMonths()); form.output(resp.getWriter(), getLanguage(req), vars); }