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

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

When sharing contact details. If we can detect that the recipient is present on the same filesystem as the sender (due to the presence of a resources-recipient directory) then instead of providing directions, just copy the credentials-sender directory.

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