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

Last change on this file since 1484 was 1484, checked in by bnemhaus, 4 years ago

Added minor feedback for some long time running actions.

File size: 26.6 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 Text displayMessage = MessageBay.displayMessage("Action processing....");
320 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
321 Optional<Map<AuthenticationTag, String>> userdata =
322 AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username);
323 if (userdata.isPresent()) {
324 Map<AuthenticationTag, String> userData = userdata.get();
325 String username = userData.get(AuthenticationTag.Username);
326 String email = getEmailFromUsername(username);
327 userData.put(AuthenticationTag.Email, email);
328 Password.generateAndDeliverIntergalacticNumber(userData);
329 MessageBay.displayMessage("An identity number has been sent to the email "
330 + "associated with your account. Enter it below to proceed.");
331 }
332 displayMessage.setText(displayMessage.getText() + "..Done");
333 }
334
335 /**
336 * Action used by user to submit their intergalactic number along with their username
337 * in order to confirm that they own the public email address registered to their account.
338 * This is part of the process of recoverying access to an account.
339 */
340 public static void AuthSubmitIntergalacticNumber() {
341 Text displayMessage = MessageBay.displayMessage("Action processing....");
342 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
343 Optional<Map<AuthenticationTag, String>> userdata =
344 AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username,
345 AuthenticationTag.IntergalacticNumber);
346 if (userdata.isPresent()) {
347 Password.confirmIntergalacticNumberAndAlertTrustedUsers(userdata.get());
348 }
349 displayMessage.setText(displayMessage.getText() + "..Done");
350 }
351 // End Regain Account Access Actions
352
353 // Start Create Account Actions
354 /**
355 * Action used to created a new user account.
356 * Attempts to use content from text items on frame, will default to java properties if they cannot be found.
357 * Will fail if it cannot find content from text items on frame and all required java properties are not present.
358 * @throws SQLException
359 * @throws IOException
360 * @throws ExistingFramesetException
361 * @throws InvalidFramesetNameException
362 * @throws ClassNotFoundException
363 * @throws FileNotFoundException
364 * @throws CertificateException
365 * @throws NoSuchAlgorithmException
366 * @throws KeyStoreException
367 * @throws BadPaddingException
368 * @throws IllegalBlockSizeException
369 * @throws NoSuchPaddingException
370 * @throws InvalidKeySpecException
371 * @throws InvalidKeyException
372 * @throws ParseException
373 * @throws Exception
374 */
375 public static void AuthCreateAccount() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, ClassNotFoundException, InvalidFramesetNameException, ExistingFramesetException, IOException, SQLException, InvalidKeyException, InvalidKeySpecException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, ParseException {
376 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
377 Optional<Map<AuthenticationTag, String>> userdata =
378 AuthenticationTag.fetchUserData(textItems, false,
379 AuthenticationTag.Username,
380 AuthenticationTag.Password,
381 AuthenticationTag.PasswordAgain,
382 AuthenticationTag.Email,
383 AuthenticationTag.EmailAgain);
384
385 if (userdata.isPresent()) {
386 Map<AuthenticationTag, String> userData = userdata.get();
387
388 // A profile already existing with 'username' means an account cannot be created with that username.
389 if (FrameIO.getProfilesList().contains(userData.get(AuthenticationTag.Username))) {
390 MessageBay.errorMessage("A Expeditee profile with this username already exists, please choose another.");
391 return;
392 }
393
394 // The chosen username must be a valid frameset name.
395 if (!FrameIO.isValidFramesetName(userData.get(AuthenticationTag.Username))) {
396 MessageBay.errorMessage("The provided username must begin and end with a letter and contain only letters and numbers inbetween, please choose another.");
397 return;
398 }
399
400 // The passwords provided must match
401 if (userData.get(AuthenticationTag.Password).compareTo(userData.get(AuthenticationTag.PasswordAgain)) != 0) {
402 MessageBay.errorMessage("The provided passwords do not match, please fix this and try again.");
403 return;
404 }
405
406 // The emails provided must match
407 if (userData.get(AuthenticationTag.Email).compareTo(userData.get(AuthenticationTag.EmailAgain)) != 0) {
408 MessageBay.errorMessage("The provided emails do not match, please fix this and try again.");
409 return;
410 }
411
412 CreateResult result = Create.createAccount(userData);
413 if (result == CreateResult.SuccessCreateAccount) {
414 Authenticate.login(userData);
415 AuthenticatorBrowser.Authenticated = true;
416 } else {
417 MessageBay.errorMessage(result.toString());
418 }
419 } else {
420 MessageBay.errorMessage("Please fill out all the supplied text boxes.");
421 }
422 }
423 // End Create Account Actions
424
425 // Start Account Login Actions
426 /**
427 * Action used to start authentication as a specified user.
428 * Attempts to use content from text items on frame, will default to java properties if they cannot be found.
429 * Will fail if it cannot find content from text items on frame and all required java properties are not present.
430 * @throws Exception
431 */
432 public static void AuthLogin() {
433 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
434 Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username, AuthenticationTag.Password);
435 if (userdata.isPresent()) {
436 AuthenticationResult result = Authenticate.login(userdata.get());
437 if (result == AuthenticationResult.SuccessLogin) {
438 MessageBay.displayMessage(result.toString());
439 AuthenticatorBrowser.Authenticated = true;
440 } else {
441 MessageBay.errorMessage(result.toString());
442 }
443 } else {
444 MessageBay.errorMessage("Please fill out all the supplied text boxes.");
445 }
446 }
447
448 /**
449 * Action used by the user to log out of their account.
450 */
451 public static void AuthLogout() {
452 MessageBay.displayMessage(Authenticate.logout().toString());
453 }
454 // End Account Login Actions
455
456 // Start Change Access Actions
457 /**
458 * Action used to change the currently authenticated users password.
459 * Attempts to use content from text items on frame, will default to java properties if they cannot be found.
460 * Will fail if it cannot find content from text items on frame and all required java properties are not present.
461 * Will fail if no user is currently logged in.
462 * @throws IOException
463 * @throws CertificateException
464 * @throws FileNotFoundException
465 * @throws KeyStoreException
466 * @throws NoSuchAlgorithmException
467 * @throws SQLException
468 * @throws ClassNotFoundException
469 */
470 public static void AuthChangePassword() throws NoSuchAlgorithmException, KeyStoreException, FileNotFoundException, CertificateException, IOException, ClassNotFoundException, SQLException {
471 final Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
472
473 if (!AuthenticatorBrowser.Authenticated) {
474 MessageBay.errorMessage("You must be logged in to perform this action.");
475 } else {
476 final Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Password, AuthenticationTag.NewPassword, AuthenticationTag.NewPasswordAgain);
477 if (userdata.isPresent()) {
478 final Map<AuthenticationTag, String> userData = userdata.get();
479 if (userData.get(AuthenticationTag.NewPassword).compareTo(userData.get(AuthenticationTag.NewPasswordAgain)) != 0) {
480 MessageBay.errorMessage("The provided passwords do not match, please fix this and try again.");
481 } else {
482 userData.put(AuthenticationTag.Username, UserSettings.UserName.get());
483 Password.changePassword(userData);
484 }
485 } else {
486 MessageBay.errorMessage("Please fill out all the supplied text boxes.");
487 }
488 }
489 }
490 // End Change Access Actions
491
492 // Start Private Helper Functions.
493 /**
494 * Gets the public email address associated with the specified username.
495 * @param username
496 * @return
497 */
498 private static String getEmailFromUsername(String username) {
499 Path credentialsDirPath = Paths.get(FrameIO.PROFILE_PATH).resolve(username).resolve(username + "-credentials");
500 Path credentialsFilePath = credentialsDirPath.resolve("credentials.inf");
501 String fileName = null;
502 if (credentialsFilePath.toFile().exists()) {
503 try (Scanner in = new Scanner(credentialsFilePath)) {
504 fileName = in.nextLine();
505 } catch (IOException e) {
506 MessageBay.errorMessage("Unable to locate public email for specified user, are they registered on this computer?");
507 return null;
508 }
509 } else {
510 MessageBay.errorMessage("Unable to locate public email for specified user, are they registered on this computer?");
511 return null;
512 }
513
514 int number = Integer.parseInt(fileName.replace(".exp", ""));
515 Frame credentialsFrame = FrameIO.LoadFrame(username + number, FrameIO.PROFILE_PATH);
516 Collection<Text> textItems = credentialsFrame.getTextItems();
517 textItems.removeIf(text -> !text.getText().startsWith("Email: "));
518 if (textItems.isEmpty()) {
519 MessageBay.errorMessage("Unable to locate public email for specified user, are they registered on this computer?");
520 return null;
521 } else {
522 Text emailText = textItems.iterator().next();
523 String email = emailText.getText().replace("Email: ", "");
524 return email;
525 }
526 }
527 // End Private Helper Functions.
528
529 // Start Future Functionality
530 public static void AuthShareFrameset() throws IOException {
531 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
532
533 Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Frameset);
534 if (userdata.isPresent()) {
535 Map<AuthenticationTag, String> userData = userdata.get();
536 FrameIO.SuspendCache();
537 Frame toShare = FrameIO.LoadFrame(userData.get(AuthenticationTag.Frameset) + 1);
538 FrameIO.ResumeCache();
539
540 if (toShare == null) {
541 MessageBay.errorMessage("Insufficient information provided to complete this action.");
542 return;
543 }
544
545 shareFrameset(toShare);
546 }
547 }
548
549 /*
550 * Function to share a specified frameset.
551 * 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.
552 */
553 private static void shareFrameset(Frame toShare) throws IOException {
554 File destinationDir = new File(FrameIO.SHARED_FRAMESETS_PATH + File.separator + toShare.getFramesetName());
555 File sourceDir = new File(toShare.getFramesetPath());
556
557 if (destinationDir.exists()) {
558 MessageBay.errorMessage("A frameset by this name already exists.");
559 return;
560 }
561
562 destinationDir.mkdir();
563 List<Path> files = Files.walk(sourceDir.toPath()).collect(Collectors.toList());
564 Files.move(files.get(0), destinationDir.toPath(), StandardCopyOption.ATOMIC_MOVE);
565
566 MessageBay.displayMessage("The frameset " + toShare.getFramesetName() + " has been moved to " + destinationDir + ". Google Drive functionality can now be used to share it with colleagues.");
567 }
568
569 /*
570 * Function to submit a request to specified contacts to be the current users pw colleagues.
571 */
572 @SuppressWarnings("unused")
573 private static boolean submitTrustedUsersPasswordRecovery(Map<AuthenticationTag, String> userData) throws InvalidKeySpecException, NoSuchAlgorithmException, KeyStoreException, FileNotFoundException, CertificateException, ClassNotFoundException, IOException, SQLException {
574 String colleagueOne = userData.get(AuthenticationTag.TrustedUserOne);
575 String colleagueTwo = userData.get(AuthenticationTag.TrustedUserTwo);
576 PublicKey colleagueOneKey = AuthenticatorBrowser.getInstance().getPublicKey(colleagueOne);
577 PublicKey colleagueTwoKey = AuthenticatorBrowser.getInstance().getPublicKey(colleagueTwo);
578 if (colleagueOneKey == null) {
579 MessageBay.errorMessage("Unable to get public key for colleague: " + colleagueOne);
580 return false;
581 } else if (colleagueTwoKey == null) {
582 MessageBay.errorMessage("Unable to get public key for colleague: " + colleagueTwo);
583 return false;
584 } else {
585 String time = org.expeditee.stats.Formatter.getDateTime();
586 String sender = userData.get(AuthenticationTag.Username);
587 String topic = "You have received a request for cooperation from your colleague " + sender;
588 String message = "Should " + sender + " forget their password, they would like your help recoverying it.";
589 Map<String, String> arguments = new HashMap<String, String>();
590 arguments.put("I agree to assist " + sender + " if they loose access to their account.", "AuthConfirmPasswordColleagueRelationship " + sender);
591 arguments.put("I wish to excuse myself from this responsibility.", "AuthDenyPasswordColleagueRelationship " + sender);
592 MailEntry mail = new MailEntry(time, sender, colleagueOne, topic, message, arguments);
593 Mail.sendMail(mail, colleagueOne);
594 mail = new MailEntry(time, sender, colleagueTwo, topic, message, arguments);
595 Mail.sendMail(mail, colleagueTwo);
596 AuthenticatorBrowser.getInstance().markRequestedColleagues(UserSettings.UserName.get());
597 return true;
598 }
599 }
600 // End Future Functionality
601}
Note: See TracBrowser for help on using the repository browser.