source: trunk/src/org/expeditee/auth/Actions.java@ 1384

Last change on this file since 1384 was 1384, checked in by bln4, 5 years ago

Instructions for sending your contact details to a user can now be obtained by running the action on the multiuser1 frame.

File size: 26.6 KB
Line 
1package org.expeditee.auth;
2
3import java.awt.Desktop;
4import java.io.File;
5import java.io.FileNotFoundException;
6import java.io.IOException;
7import java.nio.file.Files;
8import java.nio.file.Path;
9import java.nio.file.Paths;
10import java.nio.file.StandardCopyOption;
11import java.security.InvalidKeyException;
12import java.security.KeyFactory;
13import java.security.KeyStoreException;
14import java.security.NoSuchAlgorithmException;
15import java.security.PrivateKey;
16import java.security.PublicKey;
17import java.security.SecureRandom;
18import java.security.cert.CertificateException;
19import java.security.spec.InvalidKeySpecException;
20import java.security.spec.PKCS8EncodedKeySpec;
21import java.sql.SQLException;
22import java.text.ParseException;
23import java.util.Base64;
24import java.util.Collection;
25import java.util.HashMap;
26import java.util.List;
27import java.util.Map;
28import java.util.Optional;
29import java.util.Random;
30import java.util.Scanner;
31import java.util.stream.Collectors;
32
33import javax.crypto.BadPaddingException;
34import javax.crypto.IllegalBlockSizeException;
35import javax.crypto.NoSuchPaddingException;
36import javax.crypto.SecretKey;
37import javax.crypto.spec.SecretKeySpec;
38
39import org.expeditee.agents.ExistingFramesetException;
40import org.expeditee.agents.InvalidFramesetNameException;
41import org.expeditee.auth.account.Authenticate;
42import org.expeditee.auth.account.Authenticate.AuthenticationResult;
43import org.expeditee.auth.account.Create;
44import org.expeditee.auth.account.Create.CreateResult;
45import org.expeditee.auth.account.Password;
46import org.expeditee.auth.mail.Mail;
47import org.expeditee.auth.mail.Mail.MailEntry;
48import org.expeditee.auth.mail.gui.MailBay;
49import org.expeditee.auth.tags.AuthenticationTag;
50import org.expeditee.gio.gesture.StandardGestureActions;
51import org.expeditee.gui.DisplayController;
52import org.expeditee.gui.Frame;
53import org.expeditee.gui.FrameIO;
54import org.expeditee.gui.MessageBay;
55import org.expeditee.items.Item;
56import org.expeditee.items.Text;
57import org.expeditee.settings.UserSettings;
58import org.expeditee.settings.identity.secrets.KeyList;
59import org.expeditee.stats.Formatter;
60import org.ngikm.cryptography.CryptographyConstants;
61
62public class Actions implements CryptographyConstants {
63
64 // Start Debug Actions
65 public static void SendTestMessage(String colleagueName) throws InvalidKeySpecException, NoSuchAlgorithmException, FileNotFoundException, KeyStoreException, CertificateException, ClassNotFoundException, IOException, SQLException {
66 String time = org.expeditee.stats.Formatter.getDateTime();
67 String sender = UserSettings.UserName.get();
68 String topic = "Test Message";
69 String message = "This is a test message.";
70 Map<String, String> options = new HashMap<String, String>();
71 options.put("Neat", "Beep");
72 MailEntry mail = new MailEntry(time, sender, colleagueName, topic, message, options);
73 Mail.sendMail(mail, colleagueName);
74 MessageBay.displayMessage("Test message sent.");
75 }
76
77 public static void SendTestMessageHemi(String param) {
78 String time = Formatter.getDateTime();
79 String sender = UserSettings.UserName.get();
80 String recipient = param.split(" ")[0];
81 String message = param.split(" ")[1];
82 Map<String, String> options = new HashMap<String, String>();
83 options.put("Accept", "beep");
84 options.put("Reject", "beep");
85 MailEntry mail = new MailEntry(time, sender, recipient, "Have a key", message, options);
86 Mail.sendMail(mail, recipient);
87 MessageBay.displayMessage("Test message sent.");
88 }
89
90 public static void SendTestOneOffMessage(String colleagueName) {
91 String time = Formatter.getDateTime();
92 String sender = UserSettings.UserName.get();
93 String topic = "Test Message";
94 String message = "This is a test message.";
95 Map<String, String> options = new HashMap<String, String>();
96 options.put("Neat", "Beep");
97 MailEntry mail = new MailEntry(time, sender, colleagueName, topic, message, options);
98 Random rand = new SecureRandom();
99 byte[] key = new byte[16];
100 rand.nextBytes(key);
101 System.out.println(Base64.getEncoder().encodeToString(key));
102 Mail.sendOneOffMail(mail, colleagueName, key);
103 }
104
105 private static String userbackup = "authadmin";
106 public static void ToggleAuth() {
107 String backup = UserSettings.UserName.get();
108 UserSettings.UserName.set(userbackup);
109 userbackup = backup;
110 }
111 // End Debug Actions
112
113 // Start Misc Auth Actions
114 /**
115 * Action ran by user to read a message using a single use distributed Symmetric key
116 * @param cursor The content on the cursor should be a text item whose content is the
117 * Symmetric key to use, represented as a Base64 encoded string.
118 * @param actionItem The action item will contain the encrypted message in its data.
119 */
120 public static void AuthOneOffSecureMessage(Text cursor, Text actionItem) {
121 byte[] keyBytes = Base64.getDecoder().decode(cursor.getText());
122 SecretKey key = new SecretKeySpec(keyBytes, SymmetricAlgorithm);
123 List<String> data = actionItem.getData();
124 Mail.decryptOneOffSecureMessage(key, data);
125 StandardGestureActions.Refresh();
126 }
127
128 /**
129 * Display Expeditee Mail
130 * @throws IOException
131 * @throws SQLException
132 * @throws ClassNotFoundException
133 * @throws CertificateException
134 * @throws NoSuchAlgorithmException
135 * @throws FileNotFoundException
136 * @throws KeyStoreException
137 * @throws ParseException
138 * @throws InvalidKeySpecException
139 * @throws BadPaddingException
140 * @throws IllegalBlockSizeException
141 * @throws NoSuchPaddingException
142 * @throws InvalidKeyException
143 */
144 public static void ToggleBay() throws KeyStoreException, FileNotFoundException, NoSuchAlgorithmException, CertificateException, ClassNotFoundException, SQLException, IOException, ParseException, InvalidKeySpecException, InvalidKeyException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException {
145 if (!AuthenticatorBrowser.isAuthenticated()) return;
146 if (!DisplayController.isMailMode()) {
147 MailBay.ensureLink();
148 Mail.clear();
149 String keyEncoded = KeyList.PrivateKey.get().getData().get(0);
150 byte[] keyBytes = Base64.getDecoder().decode(keyEncoded);
151 PrivateKey key = KeyFactory.getInstance(AsymmetricAlgorithm).generatePrivate(new PKCS8EncodedKeySpec(keyBytes));
152 Mail.checkMail(key);
153 }
154 DisplayController.ToggleMailMode();
155 }
156
157 /**
158 * Action used to navigate the authorised user back to their desktop.
159 */
160 public static void AuthGoToDesktop() {
161 if (AuthenticatorBrowser.Authenticated) {
162 DisplayController.setCurrentFrame(FrameIO.LoadFrame(UserSettings.HomeFrame.get()), true);
163 } else {
164 MessageBay.displayMessage("Please Login to proceed to your home frame.");
165 DisplayController.setCurrentFrame(FrameIO.LoadFrame("authentication1"), true);
166 }
167 }
168
169 /**
170 * Action used to navigate to multiuser1 (multiuser abilities) if authenticated and authentication1 (login) is not so.
171 */
172 public static void AuthGotoAccountManagement() {
173 if (AuthenticatorBrowser.Authenticated) {
174 DisplayController.setCurrentFrame(FrameIO.LoadFrame("multiuser1"), true);
175 } else {
176 MessageBay.displayMessage("Please Login to proceed to account managment.");
177 DisplayController.setCurrentFrame(FrameIO.LoadFrame("authentication1"), true);
178 }
179 }
180
181 /**
182 * Gets all items on a specified frame that contain the specified data.
183 */
184 public static Collection<Item> getByData(Frame frame, String data) {
185 Collection<Item> allItems = frame.getAllItems();
186 allItems.removeIf(i -> i.getData() == null || !i.hasData(data));
187 return allItems;
188 }
189
190 /**
191 * Gets all items on a specified frame that contains the specified content.
192 */
193 public static Collection<Item> getByContent(Frame frame, String content) {
194 Collection<Item> allItems = frame.getAllItems();
195 allItems.removeIf(i -> i.getText().compareTo(content) != 0);
196 return allItems;
197 }
198 // End Misc Auth Actions
199
200 // Start Making Contacts Actions
201 public static void AuthDistributeContactDetails() {
202 MessageBay.displayMessage(
203 "To receive directions on distributing your contact details to someone, attach their username to your cursor and run this action again."
204 );
205 }
206 public static String AuthDistributeContactDetails(String username) {
207 StringBuilder sb = new StringBuilder();
208 String nl = System.getProperty("line.separator");
209 String me = UserSettings.UserName.get();
210 Path profilePath = Paths.get(FrameIO.PROFILE_PATH).resolve(me);
211 try {
212 Desktop.getDesktop().open(profilePath.toFile());
213 sb.append("1. We have opened your profile directory for you. Tab to it and right click on the " + me + "-credentials directory." + nl);
214 } catch (IOException e) {
215 sb.append("1. Open your profile directory (" + profilePath + ") and right click on the " + me + "-credentials directory." + nl);
216 }
217
218 sb.append("2. Click on 'Share with Google Drive'." + nl);
219 sb.append("3. Enter " + username + "'s in the text box." + nl);
220 sb.append("4. Click on the button to the right of the text box in order to set the share to 'View Only'." + nl);
221 sb.append("5. Optionally add a note for " + username + " to read. Click the send button.");
222
223 return sb.toString();
224 }
225 // End Making Contacts Actions
226
227 // Start Regain Account Access Actions
228 /**
229 * Action used to start the process of formalising the password recovery process.
230 * @throws SQLException
231 * @throws IOException
232 * @throws ClassNotFoundException
233 * @throws CertificateException
234 * @throws NoSuchAlgorithmException
235 * @throws FileNotFoundException
236 * @throws KeyStoreException
237 * @throws InvalidKeySpecException
238 */
239 public static void AuthSubmitTrustedUsersPasswordRecovery() throws InvalidKeySpecException, NoSuchAlgorithmException, KeyStoreException, FileNotFoundException, CertificateException, ClassNotFoundException, IOException, SQLException {
240 Frame currentFrame = DisplayController.getCurrentFrame();
241 Collection<Text> textItems = currentFrame.getTextItems();
242
243 if (!AuthenticatorBrowser.Authenticated) {
244 MessageBay.errorMessage("You must be logged in to perform this action.");
245 return;
246 }
247
248 Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.TrustedUserOne, AuthenticationTag.TrustedUserTwo);
249 if (userdata.isPresent()) {
250 Map<AuthenticationTag, String> userData = userdata.get();
251 String colleagueOne = userData.get(AuthenticationTag.TrustedUserOne);
252 String colleagueTwo = userData.get(AuthenticationTag.TrustedUserTwo);
253 AuthSubmitTrustedUsersPasswordRecovery(colleagueOne, colleagueTwo);
254// Path colleagueOnePath = Paths.get(FrameIO.CONTACTS_PATH).resolve(colleagueOne + "-credentials");
255// Path colleagueTwoPath = Paths.get(FrameIO.CONTACTS_PATH).resolve(colleagueTwo + "-credentials");
256// if (!colleagueOnePath.toFile().exists()) {
257// MessageBay.errorMessage("Your nominated trusted user: " + colleagueOne + " must exist in your contacts.");
258// } else if (!colleagueTwoPath.toFile().exists()) {
259// MessageBay.errorMessage("Your nominated trusted user: " + colleagueTwo + " must exist in your contacts.");
260// } else {
261// userData.put(AuthenticationTag.Username, UserSettings.UserName.get());
262// boolean success = submitTrustedUsersPasswordRecovery(userData);
263// if (success) {
264// Collection<Item> toShow = getByData(currentFrame, "ShowOnProgress");
265// for (Item i: toShow) {
266// i.setVisible(true);
267// }
268// currentFrame.change();
269// MessageBay.displayMessage("-------Messages sent-------");
270// }
271// FrameIO.SaveFrame(currentFrame);
272// DisplayController.requestRefresh(false);
273// }
274 }
275 }
276
277 /**
278 * Action ran by user to specify who their password colleagues are. These are the
279 * individuals who will be consulted if and when the user needs to regain access
280 * to their account.
281 * @param colleagueOne
282 * @param colleagueTwo
283 */
284 public static void AuthSubmitTrustedUsersPasswordRecovery(String colleagueOne, String colleagueTwo) {
285 Password.setPWColleagues(colleagueOne, colleagueTwo);
286 }
287
288 /**
289 * Action ran by user to oblige with a request from colleague who has nominated the
290 * user as a pw colleague. Will email (not Expeditee mail) the colleague the password
291 * share that the user has stored on their secrets frame.
292 * @param colleagueName
293 */
294 public static void AuthEmailPasswordShare(String colleagueName) {
295 Password.emailPasswordShare(colleagueName);
296 }
297
298 /**
299 * Action ran by user to regain access to their account by providing:
300 * their username
301 * two password shares obtained from pw colleagues
302 * their desired new password
303 */
304 public static void AuthRegainAccountAccess() {
305 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
306 Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false,
307 AuthenticationTag.Username, AuthenticationTag.NewPassword, AuthenticationTag.NewPasswordAgain,
308 AuthenticationTag.PasswordSliceOne, AuthenticationTag.PasswordSliceTwo);
309 if (userdata.isPresent()) {
310 // Confirm new requested passwords match
311 Map<AuthenticationTag, String> userData = userdata.get();
312 if (!userData.get(AuthenticationTag.NewPassword).equals(userData.get(AuthenticationTag.NewPasswordAgain))) {
313 MessageBay.errorMessage("The passwords you have provided do not match.");
314 return;
315 }
316
317 Password.regainAccountAccess(userData);
318 }
319 }
320
321 /**
322 * Actions used to generate and deliver an intergalactic number to a users public email
323 * address after they have began the password recovery process.
324 */
325 public static void AuthDistributeIntergalacticNumber() {
326 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
327 Optional<Map<AuthenticationTag, String>> userdata =
328 AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username);
329 if (userdata.isPresent()) {
330 Map<AuthenticationTag, String> userData = userdata.get();
331 String username = userData.get(AuthenticationTag.Username);
332 String email = getEmailFromUsername(username);
333 userData.put(AuthenticationTag.Email, email);
334 Password.generateAndDeliverIntergalacticNumber(userData);
335 MessageBay.displayMessage("A identity number has been sent to the email "
336 + "associated with your account. Enter it below to proceed.");
337 }
338 }
339
340 /**
341 * Action used by user to submit their intergalactic number along with their username
342 * in order to confirm that they own the public email address registered to their account.
343 * This is part of the process of recoverying access to an account.
344 */
345 public static void AuthSubmitIntergalacticNumber() {
346 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
347 Optional<Map<AuthenticationTag, String>> userdata =
348 AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username,
349 AuthenticationTag.IntergalacticNumber);
350 if (userdata.isPresent()) {
351 Password.confirmIntergalacticNumberAndAlertTrustedUsers(userdata.get());
352 }
353 }
354 // End Regain Account Access Actions
355
356 // Start Create Account Actions
357 /**
358 * Action used to created a new user account.
359 * Attempts to use content from text items on frame, will default to java properties if they cannot be found.
360 * Will fail if it cannot find content from text items on frame and all required java properties are not present.
361 * @throws SQLException
362 * @throws IOException
363 * @throws ExistingFramesetException
364 * @throws InvalidFramesetNameException
365 * @throws ClassNotFoundException
366 * @throws FileNotFoundException
367 * @throws CertificateException
368 * @throws NoSuchAlgorithmException
369 * @throws KeyStoreException
370 * @throws BadPaddingException
371 * @throws IllegalBlockSizeException
372 * @throws NoSuchPaddingException
373 * @throws InvalidKeySpecException
374 * @throws InvalidKeyException
375 * @throws ParseException
376 * @throws Exception
377 */
378 public static void AuthCreateAccount() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, ClassNotFoundException, InvalidFramesetNameException, ExistingFramesetException, IOException, SQLException, InvalidKeyException, InvalidKeySpecException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, ParseException {
379 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
380 Optional<Map<AuthenticationTag, String>> userdata =
381 AuthenticationTag.fetchUserData(textItems, false,
382 AuthenticationTag.Username,
383 AuthenticationTag.Password,
384 AuthenticationTag.PasswordAgain,
385 AuthenticationTag.Email,
386 AuthenticationTag.EmailAgain);
387
388 if (userdata.isPresent()) {
389 Map<AuthenticationTag, String> userData = userdata.get();
390
391 // A profile already existing with 'username' means an account cannot be created with that username.
392 if (FrameIO.getProfilesList().contains(userData.get(AuthenticationTag.Username))) {
393 MessageBay.errorMessage("A Expeditee profile with this username already exists, please choose another.");
394 return;
395 }
396
397 // The chosen username must be a valid frameset name.
398 if (!FrameIO.isValidFramesetName(userData.get(AuthenticationTag.Username))) {
399 MessageBay.errorMessage("The provided username must begin and end with a letter and contain only letters and numbers inbetween, please choose another.");
400 return;
401 }
402
403 // The passwords provided must match
404 if (userData.get(AuthenticationTag.Password).compareTo(userData.get(AuthenticationTag.PasswordAgain)) != 0) {
405 MessageBay.errorMessage("The provided passwords do not match, please fix this and try again.");
406 return;
407 }
408
409 // The emails provided must match
410 if (userData.get(AuthenticationTag.Email).compareTo(userData.get(AuthenticationTag.EmailAgain)) != 0) {
411 MessageBay.errorMessage("The provided emails do not match, please fix this and try again.");
412 return;
413 }
414
415 CreateResult result = Create.createAccount(userData);
416 if (result == CreateResult.SuccessCreateAccount) {
417 Authenticate.login(userData);
418 AuthenticatorBrowser.Authenticated = true;
419 } else {
420 MessageBay.errorMessage(result.toString());
421 }
422 } else {
423 MessageBay.errorMessage("Please fill out all the supplied text boxes.");
424 }
425 }
426 // End Create Account Actions
427
428 // Start Account Login Actions
429 /**
430 * Action used to start authentication as a specified user.
431 * Attempts to use content from text items on frame, will default to java properties if they cannot be found.
432 * Will fail if it cannot find content from text items on frame and all required java properties are not present.
433 * @throws Exception
434 */
435 public static void AuthLogin() {
436 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
437 Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username, AuthenticationTag.Password);
438 if (userdata.isPresent()) {
439 AuthenticationResult result = Authenticate.login(userdata.get());
440 if (result == AuthenticationResult.SuccessLogin) {
441 MessageBay.displayMessage(result.toString());
442 AuthenticatorBrowser.Authenticated = true;
443 } else {
444 MessageBay.errorMessage(result.toString());
445 }
446 } else {
447 MessageBay.errorMessage("Please fill out all the supplied text boxes.");
448 }
449 }
450
451 /**
452 * Action used by the user to log out of their account.
453 */
454 public static void AuthLogout() {
455 MessageBay.displayMessage(Authenticate.logout().toString());
456 }
457 // End Account Login Actions
458
459 // Start Change Access Actions
460 /**
461 * Action used to change the currently authenticated users password.
462 * Attempts to use content from text items on frame, will default to java properties if they cannot be found.
463 * Will fail if it cannot find content from text items on frame and all required java properties are not present.
464 * Will fail if no user is currently logged in.
465 * @throws IOException
466 * @throws CertificateException
467 * @throws FileNotFoundException
468 * @throws KeyStoreException
469 * @throws NoSuchAlgorithmException
470 * @throws SQLException
471 * @throws ClassNotFoundException
472 */
473 public static void AuthChangePassword() throws NoSuchAlgorithmException, KeyStoreException, FileNotFoundException, CertificateException, IOException, ClassNotFoundException, SQLException {
474 final Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
475
476 if (!AuthenticatorBrowser.Authenticated) {
477 MessageBay.errorMessage("You must be logged in to perform this action.");
478 } else {
479 final Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Password, AuthenticationTag.NewPassword, AuthenticationTag.NewPasswordAgain);
480 if (userdata.isPresent()) {
481 final Map<AuthenticationTag, String> userData = userdata.get();
482 if (userData.get(AuthenticationTag.NewPassword).compareTo(userData.get(AuthenticationTag.NewPasswordAgain)) != 0) {
483 MessageBay.errorMessage("The provided passwords do not match, please fix this and try again.");
484 } else {
485 userData.put(AuthenticationTag.Username, UserSettings.UserName.get());
486 Password.changePassword(userData);
487 }
488 } else {
489 MessageBay.errorMessage("Please fill out all the supplied text boxes.");
490 }
491 }
492 }
493 // End Change Access Actions
494
495 // Start Private Helper Functions.
496 /**
497 * Gets the public email address associated with the specified username.
498 * @param username
499 * @return
500 */
501 private static String getEmailFromUsername(String username) {
502 Path credentialsDirPath = Paths.get(FrameIO.PROFILE_PATH).resolve(username).resolve(username + "-credentials");
503 Path credentialsFilePath = credentialsDirPath.resolve("credentials.inf");
504 String fileName = null;
505 if (credentialsFilePath.toFile().exists()) {
506 try (Scanner in = new Scanner(credentialsFilePath)) {
507 fileName = in.nextLine();
508 } catch (IOException e) {
509 MessageBay.errorMessage("Unable to locate public email for specified user, are they registered on this computer?");
510 return null;
511 }
512 } else {
513 MessageBay.errorMessage("Unable to locate public email for specified user, are they registered on this computer?");
514 return null;
515 }
516
517 int number = Integer.parseInt(fileName.replace(".exp", ""));
518 Frame credentialsFrame = FrameIO.LoadFrame(username + number, FrameIO.PROFILE_PATH);
519 Collection<Text> textItems = credentialsFrame.getTextItems();
520 textItems.removeIf(text -> !text.getText().startsWith("Email: "));
521 if (textItems.isEmpty()) {
522 MessageBay.errorMessage("Unable to locate public email for specified user, are they registered on this computer?");
523 return null;
524 } else {
525 Text emailText = textItems.iterator().next();
526 String email = emailText.getText().replace("Email: ", "");
527 return email;
528 }
529 }
530 // End Private Helper Functions.
531
532 // Start Future Functionality
533 public static void AuthShareFrameset() throws IOException {
534 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
535
536 Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Frameset);
537 if (userdata.isPresent()) {
538 Map<AuthenticationTag, String> userData = userdata.get();
539 FrameIO.SuspendCache();
540 Frame toShare = FrameIO.LoadFrame(userData.get(AuthenticationTag.Frameset) + 1);
541 FrameIO.ResumeCache();
542
543 if (toShare == null) {
544 MessageBay.errorMessage("Insufficient information provided to complete this action.");
545 return;
546 }
547
548 shareFrameset(toShare);
549 }
550 }
551
552 /*
553 * Function to share a specified frameset.
554 * Currently, this moves the frameset to the 'Shared By Me' directory and then relies on the user to use Google Drive functionality to share it appropriately.
555 */
556 private static void shareFrameset(Frame toShare) throws IOException {
557 File destinationDir = new File(FrameIO.SHARED_FRAMESETS_PATH + File.separator + toShare.getFramesetName());
558 File sourceDir = new File(toShare.getFramesetPath());
559
560 if (destinationDir.exists()) {
561 MessageBay.errorMessage("A frameset by this name already exists.");
562 return;
563 }
564
565 destinationDir.mkdir();
566 List<Path> files = Files.walk(sourceDir.toPath()).collect(Collectors.toList());
567 Files.move(files.get(0), destinationDir.toPath(), StandardCopyOption.ATOMIC_MOVE);
568
569 MessageBay.displayMessage("The frameset " + toShare.getFramesetName() + " has been moved to " + destinationDir + ". Google Drive functionality can now be used to share it with colleagues.");
570 }
571
572 /*
573 * Function to submit a request to specified contacts to be the current users pw colleagues.
574 */
575 @SuppressWarnings("unused")
576 private static boolean submitTrustedUsersPasswordRecovery(Map<AuthenticationTag, String> userData) throws InvalidKeySpecException, NoSuchAlgorithmException, KeyStoreException, FileNotFoundException, CertificateException, ClassNotFoundException, IOException, SQLException {
577 String colleagueOne = userData.get(AuthenticationTag.TrustedUserOne);
578 String colleagueTwo = userData.get(AuthenticationTag.TrustedUserTwo);
579 PublicKey colleagueOneKey = AuthenticatorBrowser.getInstance().getPublicKey(colleagueOne);
580 PublicKey colleagueTwoKey = AuthenticatorBrowser.getInstance().getPublicKey(colleagueTwo);
581 if (colleagueOneKey == null) {
582 MessageBay.errorMessage("Unable to get public key for colleague: " + colleagueOne);
583 return false;
584 } else if (colleagueTwoKey == null) {
585 MessageBay.errorMessage("Unable to get public key for colleague: " + colleagueTwo);
586 return false;
587 } else {
588 String time = org.expeditee.stats.Formatter.getDateTime();
589 String sender = userData.get(AuthenticationTag.Username);
590 String topic = "You have received a request for cooperation from your colleague " + sender;
591 String message = "Should " + sender + " forget their password, they would like your help recoverying it.";
592 Map<String, String> arguments = new HashMap<String, String>();
593 arguments.put("I agree to assist " + sender + " if they loose access to their account.", "AuthConfirmPasswordColleagueRelationship " + sender);
594 arguments.put("I wish to excuse myself from this responsibility.", "AuthDenyPasswordColleagueRelationship " + sender);
595 MailEntry mail = new MailEntry(time, sender, colleagueOne, topic, message, arguments);
596 Mail.sendMail(mail, colleagueOne);
597 mail = new MailEntry(time, sender, colleagueTwo, topic, message, arguments);
598 Mail.sendMail(mail, colleagueTwo);
599 AuthenticatorBrowser.getInstance().markRequestedColleagues(UserSettings.UserName.get());
600 return true;
601 }
602 }
603 // End Future Functionality
604}
Note: See TracBrowser for help on using the repository browser.