Ignore:
Timestamp:
04/05/19 10:24:27 (5 years ago)
Author:
bln4
Message:

Tidied up startup a bit, Authenticator class renamed to AuthenticatedBrowser to signify it is Browsers replacement when running in authentication mode.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/auth/AuthenticatorBrowser.java

    r1281 r1282  
    6969import org.ngikm.cryptography.CryptographyConstants;
    7070
    71 public final class Authenticator extends Browser implements CryptographyConstants {
     71public final class AuthenticatorBrowser extends Browser implements CryptographyConstants {
    7272       
    7373        // The frame number of the frame containing the current authenticated users public key.
     
    8383        private static final String KEYSTOREFILENAME = "keystore.ks" + File.separator;
    8484               
    85         private static Authenticator instance;
    86        
    87         public static Authenticator getInstance() throws KeyStoreException, FileNotFoundException, NoSuchAlgorithmException, CertificateException, IOException, ClassNotFoundException, SQLException {
    88                 if (instance == null) { instance = new Authenticator(); }
     85        private static AuthenticatorBrowser instance;
     86       
     87        public static AuthenticatorBrowser getInstance() throws KeyStoreException, FileNotFoundException, NoSuchAlgorithmException, CertificateException, IOException, ClassNotFoundException, SQLException {
     88                if (instance == null) { instance = new AuthenticatorBrowser(); }
    8989                return instance;
    9090        }
    9191       
    92         private Authenticator() throws KeyStoreException, FileNotFoundException, IOException, NoSuchAlgorithmException, CertificateException, ClassNotFoundException, SQLException {
     92        private AuthenticatorBrowser() throws KeyStoreException, FileNotFoundException, IOException, NoSuchAlgorithmException, CertificateException, ClassNotFoundException, SQLException {
    9393                super("Authentication");
    9494                UserSettings.setupDefaultFolders();
     
    101101                // Does the account Authentication.ADMINACCOUNT exist?
    102102                // If not then we have get the user to assign a password to it.
    103                 if (!keyStore.containsAlias(Authenticator.ADMINACCOUNT)) {
     103                if (!keyStore.containsAlias(AuthenticatorBrowser.ADMINACCOUNT)) {
    104104                        new File(FrameIO.PARENT_FOLDER).mkdirs();
    105105                        protectAdmin();
     
    136136                // class load database classes
    137137                Class.forName("org.sqlite.JDBC");
    138                 _theBrowser = this;
    139138        }
    140139
     
    227226                                        loadMailFromFile(dbFile);
    228227                                }
    229                                 Path timestamp = deaddropforcontactPath.resolve(UserSettings.UserName.get() + ".last-accessed");
    230                                 try(FileWriter out = new FileWriter(timestamp.toFile())) {
    231                                         out.write(Formatter.getDateTime() + System.getProperty("line.separator"));
    232                                 } catch (IOException e) {
    233                                         e.printStackTrace();
    234                                 }
    235228                                clearOldMailFromDatabase(deaddropforcontactPath);
    236229                        }
     230                }
     231        }
     232
     233        final void updateLastReadMailTime(Path deaddropforcontactPath) {
     234                Path timestamp = deaddropforcontactPath.resolve(UserSettings.UserName.get() + ".last-accessed");
     235                try(FileWriter out = new FileWriter(timestamp.toFile())) {
     236                        out.write(Formatter.getDateTime() + System.getProperty("line.separator"));
     237                } catch (IOException e) {
     238                        e.printStackTrace();
    237239                }
    238240        }
     
    257259               
    258260                if (dbFile == null || lastAccessedFile == null) {
    259                         System.err.println("Failed to clear old messages from database file.");
    260                         return; // Not the end of the world if we cannot clear out old messages.
     261                        return; // Not the end of the world if we cannot clear out old messages, these files may not be present yet if the others are recently new.
    261262                }
    262263               
     
    266267                        timestamp = format.parse(in.nextLine());
    267268                } catch (ParseException e) {
    268                         System.err.println("Failed to clear old messages from database file.");
    269                         return; // Not the end of the world if we cannot clear out old messages.
     269                        return; // Not the end of the world if we cannot clear out old messages, the database might be empty.
    270270                }
    271271               
Note: See TracChangeset for help on using the changeset viewer.