|
@@ -0,0 +1,63 @@
|
|
|
+package org.robert.printer.auth;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+
|
|
|
+public class Certificate {
|
|
|
+
|
|
|
+ private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+
|
|
|
+ private String fingerprint;
|
|
|
+ private String commonName;
|
|
|
+ private String organization;
|
|
|
+ private Date validFrom;
|
|
|
+ private Date validTo;
|
|
|
+
|
|
|
+ private boolean valid = false;
|
|
|
+
|
|
|
+ public static final Certificate UNKNOWN;
|
|
|
+ public static final Certificate EXPIRED;
|
|
|
+ public static final Certificate UNSIGNED;
|
|
|
+
|
|
|
+ static {
|
|
|
+ HashMap<String,String> map = new HashMap<String, String>();
|
|
|
+ map.put("fingerprint", "UNKNOWN REQUEST");
|
|
|
+ map.put("commonName", "An anonymous request");
|
|
|
+ map.put("organization", "Unknown");
|
|
|
+ map.put("validFrom", "0000-00-00 00:00:00");
|
|
|
+ map.put("validTo", "0000-00-00 00:00:00");
|
|
|
+ map.put("valid", "false");
|
|
|
+ UNKNOWN = Certificate.loadCertificate(map);
|
|
|
+
|
|
|
+ map.put("fingerprint", "EXPIRED REQUEST");
|
|
|
+ map.put("commonName", ""); //filled in per request
|
|
|
+ map.put("organization", ""); //filled in per request
|
|
|
+ EXPIRED = Certificate.loadCertificate(map);
|
|
|
+
|
|
|
+ map.put("fingerprint", "UNSIGNED REQUEST");
|
|
|
+ UNSIGNED = Certificate.loadCertificate(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Certificate loadCertificate(HashMap<String,String> data) {
|
|
|
+ Certificate cert = new Certificate();
|
|
|
+
|
|
|
+ cert.fingerprint = data.get("fingerprint");
|
|
|
+ cert.commonName = data.get("commonName");
|
|
|
+ cert.organization = data.get("organization");
|
|
|
+
|
|
|
+ try {
|
|
|
+ cert.validFrom = cert.dateFormat.parse(data.get("validFrom"));
|
|
|
+ cert.validTo = cert.dateFormat.parse(data.get("validTo"));
|
|
|
+ }
|
|
|
+ catch(Exception e) {
|
|
|
+ cert.validFrom = new Date(0);
|
|
|
+ cert.validTo = new Date(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ cert.valid = Boolean.parseBoolean(data.get("valid"));
|
|
|
+
|
|
|
+ return cert;
|
|
|
+ }
|
|
|
+}
|