]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/pages/LoginPage.java
add: split API and add CATS import API
[gigi.git] / src / org / cacert / gigi / pages / LoginPage.java
index d25eacfb43bc0036aa4a8ae7c6fe9070a980b55f..58adcda2dacb1a3ab1aa3be2592f847554f58fde 100644 (file)
@@ -16,12 +16,14 @@ import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.database.GigiResultSet;
+import org.cacert.gigi.dbObjects.CertificateOwner;
 import org.cacert.gigi.dbObjects.Group;
 import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.template.Form;
 import org.cacert.gigi.util.AuthorizationContext;
 import org.cacert.gigi.util.PasswordHash;
+import org.cacert.gigi.util.ServerConstants;
 
 public class LoginPage extends Page {
 
@@ -52,7 +54,11 @@ public class LoginPage extends Page {
 
     @Override
     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
-        new LoginForm(req).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
+        if (req.getHeader("Host").equals(ServerConstants.getSecureHostNamePort())) {
+            resp.getWriter().println(getLanguage(req).getTranslation("Authentication with certificate failed. Try another certificate or use a password."));
+        } else {
+            new LoginForm(req).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
+        }
     }
 
     @Override
@@ -146,17 +152,12 @@ public class LoginPage extends Page {
         if ( !serial.matches("[A-Fa-f0-9]+")) {
             throw new Error("serial malformed.");
         }
-        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT `memid` FROM `certs` WHERE `serial`=? AND `disablelogin`='0' AND `revoked` is NULL");
-        ps.setString(1, serial.toLowerCase());
-        GigiResultSet rs = ps.executeQuery();
-        User user = null;
-        if (rs.next()) {
-            user = User.getById(rs.getInt(1));
-        } else {
-            System.out.println("User with serial " + serial + " not found.");
+
+        CertificateOwner o = CertificateOwner.getByEnabledSerial(serial);
+        if (o == null || !(o instanceof User)) {
+            return null;
         }
-        rs.close();
-        return user;
+        return (User) o;
     }
 
     public static X509Certificate getCertificateFromRequest(HttpServletRequest req) {
@@ -182,7 +183,7 @@ public class LoginPage extends Page {
     }
 
     @Override
-    public boolean isPermitted(User u) {
-        return u == null;
+    public boolean isPermitted(AuthorizationContext ac) {
+        return ac == null;
     }
 }