X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2FdbObjects%2FCertificateProfile.java;h=0e6f29bac09b0dec6f641910a6414e2d4c0e8c00;hp=43c1dd5ca3831d70161b25f23d6a7a03ff49d790;hb=dc10b875c132eb7840a6b9827ec93916076d34f7;hpb=95840660b28dce27a38ed7de0b66634ec7f38ba2 diff --git a/src/org/cacert/gigi/dbObjects/CertificateProfile.java b/src/org/cacert/gigi/dbObjects/CertificateProfile.java index 43c1dd5c..0e6f29ba 100644 --- a/src/org/cacert/gigi/dbObjects/CertificateProfile.java +++ b/src/org/cacert/gigi/dbObjects/CertificateProfile.java @@ -22,9 +22,9 @@ public class CertificateProfile implements IdCachable { private final String visibleName; - private static HashMap byName = new HashMap<>(); + private static final Map byName; - private static HashMap byId = new HashMap<>(); + private static final Map byId; private final Map pt; @@ -176,15 +176,19 @@ public class CertificateProfile implements IdCachable { } static { + final HashMap myName = new HashMap(); + final HashMap myId = new HashMap(); + for (File f : new File("config/profiles").listFiles()) { Properties p = new Properties(); try { p.load(new FileInputStream(f)); } catch (IOException e) { - e.printStackTrace(); + throw new Error("Unable to load profile from " + f.getName(), e); } + String[] parts = f.getName().split("\\.")[0].split("-", 2); - GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT keyname, include, requires, name FROM `profiles` WHERE id=?"); + GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT `keyname`, `include`, `requires`, `name` FROM `profiles` WHERE `id`=?"); ps.setInt(1, Integer.parseInt(parts[0])); GigiResultSet rs = ps.executeQuery(); @@ -199,7 +203,7 @@ public class CertificateProfile implements IdCachable { throw new Error("Config error. Certificate Profile mismatch"); } } else { - GigiPreparedStatement insert = DatabaseConnection.getInstance().prepare("INSERT INTO `profiles` SET keyname=?, include=?, requires=?, name=?, id=?"); + GigiPreparedStatement insert = DatabaseConnection.getInstance().prepare("INSERT INTO `profiles` SET `keyname`=?, `include`=?, `requires`=?, `name`=?, `id`=?"); insert.setString(1, parts[1]); insert.setString(2, p.getProperty("include")); insert.setString(3, p.getProperty("requires", "")); @@ -207,16 +211,18 @@ public class CertificateProfile implements IdCachable { insert.setInt(5, Integer.parseInt(parts[0])); insert.execute(); } - } - GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT id, keyname, name, requires, include FROM `profiles`"); + + GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT `id`, `keyname`, `name`, `requires`, `include` FROM `profiles`"); GigiResultSet rs = ps.executeQuery(); while (rs.next()) { CertificateProfile cp = new CertificateProfile(rs.getInt("id"), rs.getString("keyName"), rs.getString("name"), rs.getString("requires"), rs.getString("include")); - byId.put(cp.getId(), cp); - byName.put(cp.getKeyName(), cp); + myId.put(cp.getId(), cp); + myName.put(cp.getKeyName(), cp); } + byName = Collections.unmodifiableMap(myName); + byId = Collections.unmodifiableMap(myId); } public static CertificateProfile getById(int id) { @@ -231,18 +237,27 @@ public class CertificateProfile implements IdCachable { return byId.values().toArray(new CertificateProfile[byId.size()]); } - public boolean canBeIssuedBy(User u) { + public boolean canBeIssuedBy(CertificateOwner owner, User actor) { + if (pt.containsKey("orga")) { + if ( !(owner instanceof Organisation)) { + return false; + } + } else { + if (owner instanceof Organisation) { + return false; + } + } for (String s : req) { if (s.equals("points>=50")) { - if (u.getAssurancePoints() < 50) { + if (actor.getAssurancePoints() < 50) { return false; } } else if (s.equals("points>=100")) { - if (u.getAssurancePoints() < 100) { + if (actor.getAssurancePoints() < 100) { return false; } } else if (s.equals("codesign")) { - if (u.isInGroup(Group.CODESIGNING)) { + if (actor.isInGroup(Group.CODESIGNING)) { return false; } } else { @@ -252,4 +267,5 @@ public class CertificateProfile implements IdCachable { } return true; } + }