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

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