Ignore:
Timestamp:
05/07/19 14:08:23 (5 years ago)
Author:
bln4
Message:

Fixes to permission on items.

File:
1 edited

Legend:

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

    r1348 r1357  
    2222import java.util.Collection;
    2323import java.util.HashMap;
     24import java.util.Iterator;
    2425import java.util.List;
    2526import java.util.Map;
     
    3839import org.expeditee.auth.account.Authenticate.AuthenticationResult;
    3940import org.expeditee.auth.account.Create;
     41import org.expeditee.auth.account.Create.CreateResult;
    4042import org.expeditee.auth.account.Password;
    4143import org.expeditee.auth.gui.MailBay;
     
    4951import org.expeditee.items.Text;
    5052import org.expeditee.settings.UserSettings;
     53import org.expeditee.settings.identity.passwordrecovery.Colleagues;
    5154import org.expeditee.settings.identity.secrets.KeyList;
    5255import org.expeditee.stats.Formatter;
     
    7881                Mail.sendMail(mail, recipient);
    7982                MessageBay.displayMessage("Test message sent.");
     83        }
     84        public static void SetPWColleagues(String colleagueOne, String colleagueTwo) {
     85                Colleagues.Colleague_One.set(colleagueOne);
     86                Colleagues.Colleague_Two.set(colleagueTwo);
     87                Colleagues.Colleague_One_Email.set("[email protected]");
     88                Colleagues.Colleague_Two_Email.set("[email protected]");
    8089        }
    8190       
     
    181190                        }
    182191                       
    183                         Create.createAccount(userData);
    184                         Authenticate.login(userData);
    185                         AuthenticatorBrowser.Authenticated = true;
     192                        CreateResult result = Create.createAccount(userData);
     193                        if (result == CreateResult.SuccessCreateAccount) {
     194                                Authenticate.login(userData);
     195                                AuthenticatorBrowser.Authenticated = true;
     196                        } else {
     197                                MessageBay.errorMessage(result.toString());
     198                        }
    186199                } else {
    187200                        MessageBay.errorMessage("Please fill out all the supplied text boxes.");
     
    196209         */
    197210        public static void AuthLogin() {
    198                 final Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
    199                 final Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username, AuthenticationTag.Password);
     211                Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
     212                Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username, AuthenticationTag.Password);
    200213                if (userdata.isPresent()) {
    201214                        AuthenticationResult result = Authenticate.login(userdata.get());
    202215                        if (result == AuthenticationResult.SuccessLogin) {
    203216                                MessageBay.displayMessage(result.toString());
     217                                AuthenticatorBrowser.Authenticated = true;
    204218                        } else {
    205219                                MessageBay.errorMessage(result.toString());
    206220                        }
    207                         //login(userdata.get());
    208                         AuthenticatorBrowser.Authenticated = true;
    209221                } else {
    210222                        MessageBay.errorMessage("Please fill out all the supplied text boxes.");
     
    258270        }
    259271       
    260         public static void AuthResetPasswordPt1() {
     272        public static void AuthDistributeIntergalacticNumber() {
    261273                Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
    262                 Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username);
     274                Optional<Map<AuthenticationTag, String>> userdata =
     275                                AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username);
    263276                if (userdata.isPresent()) {
    264277                        Map<AuthenticationTag, String> userData = userdata.get();
     
    267280                        userData.put(AuthenticationTag.Email, email);
    268281                        Password.generateAndDeliverIntergalacticNumber(userData);
    269                         MessageBay.displayMessage("A Intergalactic number has been sent to the email associated with your account.  Enter it below to proceed.");
    270                 }
    271         }
    272        
    273         public static void AuthResetPasswordPt2() {
     282                        MessageBay.displayMessage("A identity number has been sent to the email "
     283                                        + "associated with your account.  Enter it below to proceed.");
     284                }
     285        }
     286       
     287        public static void AuthSubmitIntergalacticNumber() {
    274288                Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
    275                 Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username,
    276                                 AuthenticationTag.IntergalacticNumber, AuthenticationTag.NewPassword, AuthenticationTag.NewPasswordAgain);
     289                Optional<Map<AuthenticationTag, String>> userdata =
     290                                AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username,
     291                                                AuthenticationTag.IntergalacticNumber);
    277292                if (userdata.isPresent()) {
    278                         Map<AuthenticationTag, String> userData = userdata.get();
    279                         String username = userData.get(AuthenticationTag.Username);
    280                         String email = getEmailFromUsername(username);
    281                         userData.put(AuthenticationTag.Email, email);
    282                         Password.confirmIntergalacticNumberAndGenerateSubstituteAccount(userData);
     293                        Map<AuthenticationTag, String> tags = userdata.get();
     294                        String username = tags.get(AuthenticationTag.Username);
     295                        String intergalacticNumber = tags.get(AuthenticationTag.IntergalacticNumber);
     296                        boolean match = false;
     297                        try {
     298                                match = AuthenticatorBrowser.getInstance().confirmIntergalaticNumber(username, intergalacticNumber);
     299                        } catch (NoSuchAlgorithmException | KeyStoreException | CertificateException | ClassNotFoundException
     300                                        | IOException | SQLException e) {
     301                                e.printStackTrace();
     302                                return;
     303                        }
     304                        if (!match) {
     305                                MessageBay.errorMessage("The provided identity number does not match the one stored on file.");
     306                                return;
     307                        }
     308                        String[] colleagues = getPasswordColleaguesFromUsername(username);
     309                        Password.confirmIntergalacticNumberAndAlertColleagues(userdata.get(), colleagues);
    283310                }
    284311        }
    285312       
    286313        private static String getEmailFromUsername(String username) {
    287                 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
    288314                Path credentialsDirPath = Paths.get(FrameIO.PROFILE_PATH).resolve(username).resolve(username + "-credentials");
    289315                Path credentialsFilePath = credentialsDirPath.resolve("credentials.inf");
     
    303329                int number = Integer.parseInt(fileName.replace(".exp", ""));
    304330                Frame credentialsFrame = FrameIO.LoadFrame(username + number, FrameIO.PROFILE_PATH);
    305                 textItems = credentialsFrame.getTextItems();
     331                Collection<Text> textItems = credentialsFrame.getTextItems();
    306332                textItems.removeIf(text -> !text.getText().startsWith("Email: "));
    307333                if (textItems.isEmpty()) {
     
    313339                        return email;
    314340                }
     341        }
     342       
     343        private static String[] getPasswordColleaguesFromUsername(String username) {
     344                Path credentialsDirPath = Paths.get(FrameIO.PROFILE_PATH).resolve(username).resolve(username + "-credentials");
     345                Path credentialsFilePath = credentialsDirPath.resolve("pwcolleagues.inf");
     346                String fileName = null;
     347                if (credentialsFilePath.toFile().exists()) {
     348                        try (Scanner in = new Scanner(credentialsFilePath)) {
     349                                fileName = in.nextLine();
     350                        } catch (IOException e) {
     351                                MessageBay.errorMessage("Unable to password colleague frame for specified user, are they registered on this computer?");
     352                                return null;
     353                        }
     354                } else {
     355                        MessageBay.errorMessage("Unable to password colleague frame for specified user, are they registered on this computer?");
     356                        return null;
     357                }
     358               
     359                int number = Integer.parseInt(fileName.replace(".exp", ""));
     360                Frame pwColleagueFrame = FrameIO.LoadFrame(username + number, FrameIO.PROFILE_PATH);
     361                Collection<Text> textItems = pwColleagueFrame.getTextItems();
     362                textItems.removeIf(text -> !text.getText().startsWith("Colleague"));
     363               
     364                String[] ret = new String[4];
     365                Iterator<Text> it = textItems.iterator();
     366                while(it.hasNext()) {
     367                        String content = it.next().getText().toLowerCase().trim();
     368                        if (content.contains("colleague_one:")) {
     369                                ret[0] = content.replace("colleague_one:", "").trim();
     370                        } else if (content.contains("colleague_two:")) {
     371                                ret[1] = content.replace("colleague_two:", "").trim();
     372                        } else if (content.contains("colleague_one_email:")) {
     373                                ret[2] = content.replace("colleague_one_email:", "").trim();
     374                        } else if (content.contains("colleague_two_email:")) {
     375                                ret[3] = content.replace("colleague_two_email:", "").trim();
     376                        }
     377                }
     378                return ret;
    315379        }
    316380       
Note: See TracChangeset for help on using the changeset viewer.