X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2FdbObjects%2FDomain.java;h=00f51c1fe87df68cf050dd3020c49bbc7e245f9f;hb=81c4fd845d05491068c306af961d1784e92b67a9;hp=13ee9f350762832541ed8fdb71756f1a12f4f43a;hpb=12c6327bdc31d1f1d50159de69641d878827dddf;p=gigi.git diff --git a/src/org/cacert/gigi/dbObjects/Domain.java b/src/org/cacert/gigi/dbObjects/Domain.java index 13ee9f35..00f51c1f 100644 --- a/src/org/cacert/gigi/dbObjects/Domain.java +++ b/src/org/cacert/gigi/dbObjects/Domain.java @@ -1,6 +1,7 @@ package org.cacert.gigi.dbObjects; import java.io.IOException; +import java.io.InputStream; import java.net.IDN; import java.util.Arrays; import java.util.Collections; @@ -17,7 +18,7 @@ import org.cacert.gigi.database.GigiResultSet; import org.cacert.gigi.dbObjects.DomainPingConfiguration.PingType; import org.cacert.gigi.util.PublicSuffixes; -public class Domain implements IdCachable { +public class Domain implements IdCachable, Verifyable { public class DomainPingExecution { @@ -70,8 +71,8 @@ public class Domain implements IdCachable { private static final Set IDNEnabledTLDs; static { Properties CPS = new Properties(); - try { - CPS.load(Domain.class.getResourceAsStream("CPS.properties")); + try (InputStream resourceAsStream = Domain.class.getResourceAsStream("CPS.properties")) { + CPS.load(resourceAsStream); IDNEnabledTLDs = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(CPS.getProperty("IDN-enabled").split(",")))); } catch (IOException e) { throw new Error(e); @@ -93,7 +94,7 @@ public class Domain implements IdCachable { } public Domain(User owner, String suffix) throws GigiApiException { - checkCertifyableDomain(suffix, owner.isInGroup(Group.getByString("codesign"))); + checkCertifyableDomain(suffix, owner.isInGroup(Group.CODESIGNING)); this.owner = owner; this.suffix = suffix; @@ -168,10 +169,10 @@ public class Domain implements IdCachable { } public void insert() throws GigiApiException { - if (id != 0) { - throw new GigiApiException("already inserted."); - } synchronized (Domain.class) { + if (id != 0) { + throw new GigiApiException("already inserted."); + } checkInsert(suffix); GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO `domains` SET memid=?, domain=?"); ps.setInt(1, owner.getId()); @@ -232,7 +233,7 @@ public class Domain implements IdCachable { configs = null; } - public void verify(String hash) throws GigiApiException { + public synchronized void verify(String hash) throws GigiApiException { GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE domainPinglog SET state='success' WHERE challenge=? AND configId IN (SELECT id FROM pingconfig WHERE domainId=?)"); ps.setString(1, hash); ps.setInt(2, id); @@ -270,4 +271,16 @@ public class Domain implements IdCachable { return em; } + public static int searchUserIdByDomain(String domain) { + GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT memid FROM domains WHERE domain = ?"); + ps.setString(1, domain); + GigiResultSet res = ps.executeQuery(); + res.beforeFirst(); + if (res.next()) { + return res.getInt(1); + } else { + return -1; + } + } + }