Ignore:
Timestamp:
03/25/19 14:33:31 (5 years ago)
Author:
bln4
Message:

On profile creation a new parameter has been introducted. By passing a map, the user is able to nominate settings frames for which to be notified of their construction.

The above functionalty has been used to programmatically establish the frame number for a users credentials frame.

On user account creation, the users credential frame is migrated to the <username>-credentials folder and a redirect is setup. Functionality for doing this has been generisised and placed in FrameIO.

Location:
trunk/src/org/expeditee/auth
Files:
3 edited

Legend:

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

    r1263 r1270  
    3232import java.util.Optional;
    3333import java.util.Random;
     34import java.util.function.Consumer;
    3435import java.util.stream.Collectors;
    3536
     
    6768
    6869public class Actions implements CryptographyConstants {
    69                
     70       
     71        //Debug Functions
    7072        public static void SendTestMessage(String colleagueName) throws InvalidKeySpecException, NoSuchAlgorithmException, FileNotFoundException, KeyStoreException, CertificateException, ClassNotFoundException, IOException, SQLException {
    7173                String time = org.expeditee.stats.Formatter.getDateTime();
     
    7981                Path outbox = Paths.get(FrameIO.PROFILE_PATH).resolve(sender).resolve(sender + "-credentials");
    8082                Mail.sendMail(mail, publicKey, outbox);
     83        }
     84        private static String userbackup = "authadmin";
     85        public static void ToggleAuth() {
     86                String backup = UserSettings.UserName.get();
     87                UserSettings.UserName.set(userbackup);
     88                userbackup = backup;
    8189        }
    8290       
     
    394402                initialSettings.put("org.expeditee.gui.folders.FolderSettings.AudioDirs", FolderSettings.AudioDirs);
    395403               
     404                // Record the credentials frame number
     405                Map<String, Consumer<Frame>> notifiers = new HashMap<String, Consumer<Frame>>();
     406                notifiers.put(Constants.SETTINGS_AUTH, frame -> {
     407                        Authenticator.CREDENTIALS_FRAME = frame.getNumber();
     408                        Collection<Text> textItems = frame.getTextItems();
     409                        for (Text t: textItems) {
     410                                if (t.getText().equals("Secrets")) {
     411                                        t.setPermission(new PermissionPair(UserAppliedPermission.followLinks, UserAppliedPermission.denied));
     412                                        break;
     413                                }
     414                        }
     415                });
     416               
    396417                // Create users profile
    397                 Frame profile = FrameIO.CreateNewProfile(username, initialSettings);
     418                Frame profile = FrameIO.CreateNewProfile(username, initialSettings, notifiers);
    398419                int lastNumber = FrameIO.getLastNumber(profile.getFramesetName());
    399420                for (int i = 1; i <= lastNumber; i++) {
     
    407428                        f.getAllItems().stream().forEach(item -> item.setOwner(username));
    408429                        f.setChanged(true);
    409                         f.setEncryptionLabel("Profile");
     430                        if (f.getNumber() != Authenticator.CREDENTIALS_FRAME) {
     431                                f.setEncryptionLabel("Profile");
     432                        }
    410433                        Collection<Item> secretsLink = getByContent(f, "Secrets");
    411434                        Collection<Item> publicKeyItem = getByContent(f, "PublicKey");
    412435                        if (!secretsLink.isEmpty() && !publicKeyItem.isEmpty()) {
    413436                                //Then we are on credentials frame
    414                                 secretsLink.forEach(text -> text.setPermission(new PermissionPair(UserAppliedPermission.full, UserAppliedPermission.none)));
    415437                                f.addToData("MultiuserCredentials");
    416438                        }
     
    421443                        FrameIO.SaveFrame(f);
    422444                        KeyList.PersonalKey.setSetting(backupPersonalKey);
     445                }
     446               
     447                if (Authenticator.CREDENTIALS_FRAME == -1) {
     448                        System.err.println("authActions::Unable to establish credentials frame for new profile frame.  Account creation failed.");
     449                        return;
    423450                }
    424451               
     
    436463                out.flush();
    437464                out.close();
     465                //      migrate credentials frame
     466                Frame credentialsFrame = FrameIO.LoadFrame(username + Authenticator.CREDENTIALS_FRAME);
     467                FrameIO.migrateFrame(credentialsFrame, Paths.get(credentialsDir.getAbsolutePath()).resolve(Authenticator.CREDENTIALS_FRAME + ".exp"));
    438468                //      outbox
    439469                Connection c = DriverManager.getConnection("jdbc:sqlite:" + credentialsDir.getAbsolutePath() + File.separator + "expmail.db");
  • trunk/src/org/expeditee/auth/Authenticator.java

    r1267 r1270  
    6464       
    6565        // The frame number of the frame containing the current authenticated users public key.
    66         public static int CREDENTIALS_FRAME = 13;
     66        public static int CREDENTIALS_FRAME = -1;
    6767        public static final String ADMINACCOUNT = "authadmin";
    6868       
  • trunk/src/org/expeditee/auth/tags/Constants.java

    r1243 r1270  
    1919        public static final String SETTINGS_USER_SETTINGS_PROFILE_NAME = "settings.UserSettings.ProfileName";
    2020        public static final String SETTINGS_USER_SETTINGS_USER_NAME = "settings.UserSettings.UserName";
     21        public static final String SETTINGS_AUTH = "settings.identity";
    2122        public static final String SETTINGS_AUTH_EMAIL = "settings.identity.Email";
    2223        public static final String SETTINGS_AUTH_PUBLIC_KEY = "settings.identity.PublicKey";
Note: See TracChangeset for help on using the changeset viewer.