]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/dbObjects/Domain.java
FIX: coverity resource leaks.
[gigi.git] / src / org / cacert / gigi / dbObjects / Domain.java
index 13ee9f350762832541ed8fdb71756f1a12f4f43a..9df2e4822c7f33eae8cc8f1003011e8a44078c4e 100644 (file)
@@ -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;
@@ -70,8 +71,8 @@ public class Domain implements IdCachable {
     private static final Set<String> 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());
@@ -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;
+        }
+    }
+
 }