Changeset 1282 for trunk


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.

Location:
trunk/src/org/expeditee
Files:
1 edited
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               
  • trunk/src/org/expeditee/gui/Browser.java

    r1281 r1282  
    3232import org.expeditee.actions.Simple;
    3333import org.expeditee.agents.mail.MailSession;
     34import org.expeditee.auth.AuthenticatorBrowser;
    3435import org.expeditee.core.BlockingRunnable;
    3536import org.expeditee.core.Colour;
     
    204205                if (Boolean.getBoolean("auth")) {
    205206                        try {
    206                                 org.expeditee.auth.Authenticator.getInstance();
    207                                 _initComplete = true;
    208                                 return;
     207                                _theBrowser = AuthenticatorBrowser.getInstance();
    209208                        } catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException | ClassNotFoundException | SQLException e) {
    210209                                e.printStackTrace();
    211210                        }
    212                 }
    213                 _theBrowser = new Browser();
     211                } else {
     212                        _theBrowser = new Browser();
     213                }               
    214214
    215215                EcosystemManager.getGraphicsManager().requestFocus();
    216216               
     217                // Java's way of getting access to internet.  Authenticating the user with their proxy username and password.
    217218                Authenticator.setDefault(proxyAuth);
    218219               
Note: See TracChangeset for help on using the changeset viewer.