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

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

Added ability to send one off secure messages.

File size: 28.3 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.Iterator;
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.Mail.MailEntry;
42import org.expeditee.auth.account.Authenticate;
43import org.expeditee.auth.account.Authenticate.AuthenticationResult;
44import org.expeditee.auth.account.Create;
45import org.expeditee.auth.account.Create.CreateResult;
46import org.expeditee.auth.account.Password;
47import org.expeditee.auth.gui.MailBay;
48import org.expeditee.auth.tags.AuthenticationTag;
49import org.expeditee.core.Colour;
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.passwordrecovery.Colleagues;
59import org.expeditee.settings.identity.secrets.KeyList;
60import org.expeditee.stats.Formatter;
61import org.ngikm.cryptography.CryptographyConstants;
62
63public class Actions implements CryptographyConstants {
64
65 //Debug Functions
66 public static void SendTestMessage(String colleagueName) throws InvalidKeySpecException, NoSuchAlgorithmException, FileNotFoundException, KeyStoreException, CertificateException, ClassNotFoundException, IOException, SQLException {
67 String time = org.expeditee.stats.Formatter.getDateTime();
68 String sender = UserSettings.UserName.get();
69 String topic = "Test Message";
70 String message = "This is a test message.";
71 Map<String, String> options = new HashMap<String, String>();
72 options.put("Neat", "Beep");
73 MailEntry mail = new MailEntry(time, sender, colleagueName, topic, message, options);
74 Mail.sendMail(mail, colleagueName);
75 MessageBay.displayMessage("Test message sent.");
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 public static void SendTestOneOffMessage(String colleagueName) {
90 String time = Formatter.getDateTime();
91 String sender = UserSettings.UserName.get();
92 String topic = "Test Message";
93 String message = "This is a test message.";
94 Map<String, String> options = new HashMap<String, String>();
95 options.put("Neat", "Beep");
96 MailEntry mail = new MailEntry(time, sender, colleagueName, topic, message, options);
97 Random rand = new SecureRandom();
98 byte[] key = new byte[16];
99 rand.nextBytes(key);
100 System.out.println(Base64.getEncoder().encodeToString(key));
101 Mail.sendOneOffMail(mail, colleagueName, key);
102 }
103 public static void AuthOneOffSecureMessage(Text cursor, Text actionItem) {
104 byte[] keyBytes = Base64.getDecoder().decode(cursor.getText());
105 SecretKey key = new SecretKeySpec(keyBytes, SymmetricAlgorithm);
106 List<String> data = actionItem.getData();
107 String topic = new String(org.expeditee.auth.sharing.Actions.DecryptSymmetric(Base64.getDecoder().decode(data.get(3)), key));
108 String message = new String(org.expeditee.auth.sharing.Actions.DecryptSymmetric(Base64.getDecoder().decode(data.get(4)), key));
109 Map<String, String> options = new HashMap<String, String>();
110 for (int i = 5; i < data.size(); i+=2) {
111 String k = new String(org.expeditee.auth.sharing.Actions.DecryptSymmetric(Base64.getDecoder().decode(data.get(i)), key));
112 String v = new String(org.expeditee.auth.sharing.Actions.DecryptSymmetric(Base64.getDecoder().decode(data.get(i + 1)), key));
113 options.put(k, v);
114 }
115 MailBay.addMessage(data.get(0), topic, message, options);
116 StandardGestureActions.Refresh();
117 }
118 public static void SetPWColleagues(String colleagueOne, String colleagueTwo) {
119 Colleagues.Colleague_One.set(colleagueOne);
120 Colleagues.Colleague_Two.set(colleagueTwo);
121 Colleagues.Colleague_One_Email.set("[email protected]");
122 Colleagues.Colleague_Two_Email.set("[email protected]");
123 }
124
125 private static String userbackup = "authadmin";
126 public static void ToggleAuth() {
127 String backup = UserSettings.UserName.get();
128 UserSettings.UserName.set(userbackup);
129 userbackup = backup;
130 }
131
132 /**
133 * Display Expeditee Mail
134 * @throws IOException
135 * @throws SQLException
136 * @throws ClassNotFoundException
137 * @throws CertificateException
138 * @throws NoSuchAlgorithmException
139 * @throws FileNotFoundException
140 * @throws KeyStoreException
141 * @throws ParseException
142 * @throws InvalidKeySpecException
143 * @throws BadPaddingException
144 * @throws IllegalBlockSizeException
145 * @throws NoSuchPaddingException
146 * @throws InvalidKeyException
147 */
148 public static void ToggleBay() throws KeyStoreException, FileNotFoundException, NoSuchAlgorithmException, CertificateException, ClassNotFoundException, SQLException, IOException, ParseException, InvalidKeySpecException, InvalidKeyException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException {
149 if (!AuthenticatorBrowser.isAuthenticated()) return;
150 if (!DisplayController.isMailMode()) {
151 MailBay.ensureLink();
152 Mail.clear();
153 String keyEncoded = KeyList.PrivateKey.get().getData().get(0);
154 byte[] keyBytes = Base64.getDecoder().decode(keyEncoded);
155 PrivateKey key = KeyFactory.getInstance(AsymmetricAlgorithm).generatePrivate(new PKCS8EncodedKeySpec(keyBytes));
156 Mail.checkMail(key);
157 }
158 DisplayController.ToggleMailMode();
159 }
160
161 /**
162 * Action used to navigate the authorised user back to their desktop.
163 */
164 public static void AuthGoToDesktop() {
165 DisplayController.setCurrentFrame(FrameIO.LoadFrame(UserSettings.HomeFrame.get()), true);
166 }
167
168 /**
169 * Action used to created a new user account.
170 * Attempts to use content from text items on frame, will default to java properties if they cannot be found.
171 * Will fail if it cannot find content from text items on frame and all required java properties are not present.
172 * @throws SQLException
173 * @throws IOException
174 * @throws ExistingFramesetException
175 * @throws InvalidFramesetNameException
176 * @throws ClassNotFoundException
177 * @throws FileNotFoundException
178 * @throws CertificateException
179 * @throws NoSuchAlgorithmException
180 * @throws KeyStoreException
181 * @throws BadPaddingException
182 * @throws IllegalBlockSizeException
183 * @throws NoSuchPaddingException
184 * @throws InvalidKeySpecException
185 * @throws InvalidKeyException
186 * @throws ParseException
187 * @throws Exception
188 */
189 public static void AuthCreateAccount() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, ClassNotFoundException, InvalidFramesetNameException, ExistingFramesetException, IOException, SQLException, InvalidKeyException, InvalidKeySpecException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, ParseException {
190 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
191 Optional<Map<AuthenticationTag, String>> userdata =
192 AuthenticationTag.fetchUserData(textItems, false,
193 AuthenticationTag.Username,
194 AuthenticationTag.Password,
195 AuthenticationTag.PasswordAgain,
196 AuthenticationTag.Email,
197 AuthenticationTag.EmailAgain);
198
199 if (userdata.isPresent()) {
200 Map<AuthenticationTag, String> userData = userdata.get();
201
202 // A profile already existing with 'username' means an account cannot be created with that username.
203 if (FrameIO.getProfilesList().contains(userData.get(AuthenticationTag.Username))) {
204 MessageBay.errorMessage("A Expeditee profile with this username already exists, please choose another.");
205 return;
206 }
207
208 // The chosen username must be a valid frameset name.
209 if (!FrameIO.isValidFramesetName(userData.get(AuthenticationTag.Username))) {
210 MessageBay.errorMessage("The provided username must begin and end with a letter and contain only letters and numbers inbetween, please choose another.");
211 return;
212 }
213
214 // The passwords provided must match
215 if (userData.get(AuthenticationTag.Password).compareTo(userData.get(AuthenticationTag.PasswordAgain)) != 0) {
216 MessageBay.errorMessage("The provided passwords do not match, please fix this and try again.");
217 return;
218 }
219
220 // The emails provided must match
221 if (userData.get(AuthenticationTag.Email).compareTo(userData.get(AuthenticationTag.EmailAgain)) != 0) {
222 MessageBay.errorMessage("The provided emails do not match, please fix this and try again.");
223 return;
224 }
225
226 CreateResult result = Create.createAccount(userData);
227 if (result == CreateResult.SuccessCreateAccount) {
228 Authenticate.login(userData);
229 AuthenticatorBrowser.Authenticated = true;
230 } else {
231 MessageBay.errorMessage(result.toString());
232 }
233 } else {
234 MessageBay.errorMessage("Please fill out all the supplied text boxes.");
235 }
236 }
237
238 /**
239 * Action used to start authentication as a specified user.
240 * Attempts to use content from text items on frame, will default to java properties if they cannot be found.
241 * Will fail if it cannot find content from text items on frame and all required java properties are not present.
242 * @throws Exception
243 */
244 public static void AuthLogin() {
245 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
246 Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username, AuthenticationTag.Password);
247 if (userdata.isPresent()) {
248 AuthenticationResult result = Authenticate.login(userdata.get());
249 if (result == AuthenticationResult.SuccessLogin) {
250 MessageBay.displayMessage(result.toString());
251 AuthenticatorBrowser.Authenticated = true;
252 } else {
253 MessageBay.errorMessage(result.toString());
254 }
255 } else {
256 MessageBay.errorMessage("Please fill out all the supplied text boxes.");
257 }
258 }
259
260 public static void AuthLogout() {
261 MessageBay.displayMessage(Authenticate.logout().toString());
262 }
263
264 /**
265 * Action used to change the currently authenticated users password.
266 * Attempts to use content from text items on frame, will default to java properties if they cannot be found.
267 * Will fail if it cannot find content from text items on frame and all required java properties are not present.
268 * Will fail if no user is currently logged in.
269 * @throws IOException
270 * @throws CertificateException
271 * @throws FileNotFoundException
272 * @throws KeyStoreException
273 * @throws NoSuchAlgorithmException
274 * @throws SQLException
275 * @throws ClassNotFoundException
276 */
277 public static void AuthChangePassword() throws NoSuchAlgorithmException, KeyStoreException, FileNotFoundException, CertificateException, IOException, ClassNotFoundException, SQLException {
278 final Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
279
280 if (!AuthenticatorBrowser.Authenticated) {
281 MessageBay.errorMessage("You must be logged in to perform this action.");
282 } else {
283 final Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Password, AuthenticationTag.NewPassword, AuthenticationTag.NewPasswordAgain);
284 if (userdata.isPresent()) {
285 final Map<AuthenticationTag, String> userData = userdata.get();
286 if (userData.get(AuthenticationTag.NewPassword).compareTo(userData.get(AuthenticationTag.NewPasswordAgain)) != 0) {
287 MessageBay.errorMessage("The provided passwords do not match, please fix this and try again.");
288 } else {
289 userData.put(AuthenticationTag.Username, UserSettings.UserName.get());
290 Password.changePassword(userData);
291 }
292 } else {
293 MessageBay.errorMessage("Please fill out all the supplied text boxes.");
294 }
295 }
296 }
297
298 public static void AuthGotoAccountManagement() {
299 if (AuthenticatorBrowser.Authenticated) {
300 DisplayController.setCurrentFrame(FrameIO.LoadFrame("multiuser1"), false);
301 } else {
302 DisplayController.setCurrentFrame(FrameIO.LoadFrame("authentication1"), false);
303 }
304 }
305
306 public static void AuthDistributeIntergalacticNumber() {
307 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
308 Optional<Map<AuthenticationTag, String>> userdata =
309 AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username);
310 if (userdata.isPresent()) {
311 Map<AuthenticationTag, String> userData = userdata.get();
312 String username = userData.get(AuthenticationTag.Username);
313 String email = getEmailFromUsername(username);
314 userData.put(AuthenticationTag.Email, email);
315 Password.generateAndDeliverIntergalacticNumber(userData);
316 MessageBay.displayMessage("A identity number has been sent to the email "
317 + "associated with your account. Enter it below to proceed.");
318 }
319 }
320
321 public static void AuthSubmitIntergalacticNumber() {
322 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
323 Optional<Map<AuthenticationTag, String>> userdata =
324 AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username,
325 AuthenticationTag.IntergalacticNumber);
326 if (userdata.isPresent()) {
327 Map<AuthenticationTag, String> tags = userdata.get();
328 String username = tags.get(AuthenticationTag.Username);
329 String intergalacticNumber = tags.get(AuthenticationTag.IntergalacticNumber);
330 boolean match = false;
331 try {
332 match = AuthenticatorBrowser.getInstance().confirmIntergalaticNumber(username, intergalacticNumber);
333 } catch (NoSuchAlgorithmException | KeyStoreException | CertificateException | ClassNotFoundException
334 | IOException | SQLException e) {
335 e.printStackTrace();
336 return;
337 }
338 if (!match) {
339 MessageBay.errorMessage("The provided identity number does not match the one stored on file.");
340 return;
341 }
342 String[] colleagues = getPasswordColleaguesFromUsername(username);
343 Password.confirmIntergalacticNumberAndAlertColleagues(userdata.get(), colleagues);
344 }
345 }
346
347 private static String getEmailFromUsername(String username) {
348 Path credentialsDirPath = Paths.get(FrameIO.PROFILE_PATH).resolve(username).resolve(username + "-credentials");
349 Path credentialsFilePath = credentialsDirPath.resolve("credentials.inf");
350 String fileName = null;
351 if (credentialsFilePath.toFile().exists()) {
352 try (Scanner in = new Scanner(credentialsFilePath)) {
353 fileName = in.nextLine();
354 } catch (IOException e) {
355 MessageBay.errorMessage("Unable to locate public email for specified user, are they registered on this computer?");
356 return null;
357 }
358 } else {
359 MessageBay.errorMessage("Unable to locate public email for specified user, are they registered on this computer?");
360 return null;
361 }
362
363 int number = Integer.parseInt(fileName.replace(".exp", ""));
364 Frame credentialsFrame = FrameIO.LoadFrame(username + number, FrameIO.PROFILE_PATH);
365 Collection<Text> textItems = credentialsFrame.getTextItems();
366 textItems.removeIf(text -> !text.getText().startsWith("Email: "));
367 if (textItems.isEmpty()) {
368 MessageBay.errorMessage("Unable to locate public email for specified user, are they registered on this computer?");
369 return null;
370 } else {
371 Text emailText = textItems.iterator().next();
372 String email = emailText.getText().replace("Email: ", "");
373 return email;
374 }
375 }
376
377 private static String[] getPasswordColleaguesFromUsername(String username) {
378 Path credentialsDirPath = Paths.get(FrameIO.PROFILE_PATH).resolve(username).resolve(username + "-credentials");
379 Path credentialsFilePath = credentialsDirPath.resolve("pwcolleagues.inf");
380 String fileName = null;
381 if (credentialsFilePath.toFile().exists()) {
382 try (Scanner in = new Scanner(credentialsFilePath)) {
383 fileName = in.nextLine();
384 } catch (IOException e) {
385 MessageBay.errorMessage("Unable to password colleague frame for specified user, are they registered on this computer?");
386 return null;
387 }
388 } else {
389 MessageBay.errorMessage("Unable to password colleague frame for specified user, are they registered on this computer?");
390 return null;
391 }
392
393 int number = Integer.parseInt(fileName.replace(".exp", ""));
394 Frame pwColleagueFrame = FrameIO.LoadFrame(username + number, FrameIO.PROFILE_PATH);
395 Collection<Text> textItems = pwColleagueFrame.getTextItems();
396 textItems.removeIf(text -> !text.getText().startsWith("Colleague"));
397
398 String[] ret = new String[4];
399 Iterator<Text> it = textItems.iterator();
400 while(it.hasNext()) {
401 String content = it.next().getText().toLowerCase().trim();
402 if (content.contains("colleague_one:")) {
403 ret[0] = content.replace("colleague_one:", "").trim();
404 } else if (content.contains("colleague_two:")) {
405 ret[1] = content.replace("colleague_two:", "").trim();
406 } else if (content.contains("colleague_one_email:")) {
407 ret[2] = content.replace("colleague_one_email:", "").trim();
408 } else if (content.contains("colleague_two_email:")) {
409 ret[3] = content.replace("colleague_two_email:", "").trim();
410 }
411 }
412 return ret;
413 }
414
415 public static void AuthShareFrameset() throws IOException {
416 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
417
418 Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Frameset);
419 if (userdata.isPresent()) {
420 Map<AuthenticationTag, String> userData = userdata.get();
421 FrameIO.SuspendCache();
422 Frame toShare = FrameIO.LoadFrame(userData.get(AuthenticationTag.Frameset) + 1);
423 FrameIO.ResumeCache();
424
425 if (toShare == null) {
426 MessageBay.errorMessage("Insufficient information provided to complete this action.");
427 return;
428 }
429
430 shareFrameset(toShare);
431 }
432 }
433
434 /**
435 * Navigation action for progressing the process of recruiting colleagues to assist in password recovery.
436 * Hides certain content that AuthSubmitPWCollegues goes onto show if it does not fail.
437 */
438 public static void AuthGotoColleagueSubmissionFrame() {
439 Frame destination = FrameIO.LoadFrame("authentication7");
440 DisplayController.setCurrentFrame(destination, true);
441 Collection<Item> toHide = getByData(destination, "ShowOnProgress");
442 for (Item i: toHide) {
443 i.setVisible(false);
444 }
445 }
446
447 /**
448 * Action used to start the process of formalising the password recovery process.
449 * @throws SQLException
450 * @throws IOException
451 * @throws ClassNotFoundException
452 * @throws CertificateException
453 * @throws NoSuchAlgorithmException
454 * @throws FileNotFoundException
455 * @throws KeyStoreException
456 * @throws InvalidKeySpecException
457 */
458 public static void AuthSubmitPWColleagues() throws InvalidKeySpecException, NoSuchAlgorithmException, KeyStoreException, FileNotFoundException, CertificateException, ClassNotFoundException, IOException, SQLException {
459 Frame currentFrame = DisplayController.getCurrentFrame();
460 Collection<Text> textItems = currentFrame.getTextItems();
461
462 if (!AuthenticatorBrowser.Authenticated) {
463 MessageBay.errorMessage("You must be logged in to perform this action.");
464 return;
465 }
466
467 Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.ColleagueOne, AuthenticationTag.ColleagueTwo);
468 if (userdata.isPresent()) {
469 Map<AuthenticationTag, String> userData = userdata.get();
470 String colleagueOne = userData.get(AuthenticationTag.ColleagueOne);
471 Path colleagueOnePath = Paths.get(FrameIO.CONTACTS_PATH).resolve(colleagueOne + "-credentials");
472 String colleagueTwo = userData.get(AuthenticationTag.ColleagueTwo);
473 Path colleagueTwoPath = Paths.get(FrameIO.CONTACTS_PATH).resolve(colleagueTwo + "-credentials");
474 if (!colleagueOnePath.toFile().exists()) {
475 MessageBay.errorMessage("Your nominated colleague: " + colleagueOne + " must exist in your contacts.");
476 } else if (!colleagueTwoPath.toFile().exists()) {
477 MessageBay.errorMessage("Your nominated colleague: " + colleagueTwo + " must exist in your contacts.");
478 } else {
479 userData.put(AuthenticationTag.Username, UserSettings.UserName.get());
480 boolean success = submitPWColleagues(userData);
481 if (success) {
482 Collection<Item> toShow = getByData(currentFrame, "ShowOnProgress");
483 for (Item i: toShow) {
484 i.setVisible(true);
485 }
486 currentFrame.change();
487 MessageBay.displayMessage("-------Messages sent-------");
488 }
489 FrameIO.SaveFrame(currentFrame);
490 DisplayController.requestRefresh(false);
491 }
492 }
493 }
494
495// public static void AuthSetupPasswordRecovery() throws KeyStoreException, FileNotFoundException, NoSuchAlgorithmException, CertificateException, ClassNotFoundException, IOException, SQLException, UnrecoverableEntryException {
496// if (!UserSettings.Authenticated.get()) {
497// MessageBay.errorMessage("You must be logged in to perform this action.");
498// } else if (!Authenticator.getInstance().hasRegisteredEmail(UserSettings.UserName.get())) {
499// Frame registerEmailFrame = FrameIO.LoadFrame("authentication4");
500// DisplayController.setCurrentFrame(registerEmailFrame, true);
501// } else if (!Authenticator.getInstance().hasRequestedColleagues(UserSettings.UserName.get()) && Authenticator.getInstance().getColleagues(UserSettings.UserName.get()) == null) {
502// Frame submitColleaguesFrame = FrameIO.LoadFrame("authentication5");
503// DisplayController.setCurrentFrame(submitColleaguesFrame, true);
504// } else if (Authenticator.getInstance().hasRequestedColleagues(UserSettings.UserName.get()) && Authenticator.getInstance().getColleagues(UserSettings.UserName.get()) == null) {
505// MessageBay.displayMessage("You have already nominated two colleagues to assist you in the process of password recovery and are awaiting their response."
506// + " You will be alerted on Expeditee startup when they have both responded.");
507// } else if (Authenticator.getInstance().getColleagues(UserSettings.UserName.get()) != null) {
508// MessageBay.displayMessage("You have completed the Password Recovery Setup process, there is nothing more to do here.");
509// }
510// }
511
512 public static void AuthConfirmPasswordColleagueRelationship(String colleagueName) {
513
514 }
515
516 public static void AuthDenyPasswordColleagueRelationship(String colleagueName) throws InvalidKeySpecException, NoSuchAlgorithmException,
517 KeyStoreException, FileNotFoundException, CertificateException, ClassNotFoundException, IOException, SQLException {
518 denyPasswordColleagueRelationship(colleagueName);
519 }
520
521 public static void AuthClearPWColleaguesNominated() {
522
523 }
524
525 /*
526 * Function to share a specified frameset.
527 * 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.
528 */
529 private static void shareFrameset(Frame toShare) throws IOException {
530 File destinationDir = new File(FrameIO.SHARED_FRAMESETS_PATH + File.separator + toShare.getFramesetName());
531 File sourceDir = new File(toShare.getFramesetPath());
532
533 if (destinationDir.exists()) {
534 MessageBay.errorMessage("A frameset by this name already exists.");
535 return;
536 }
537
538 destinationDir.mkdir();
539 List<Path> files = Files.walk(sourceDir.toPath()).collect(Collectors.toList());
540 Files.move(files.get(0), destinationDir.toPath(), StandardCopyOption.ATOMIC_MOVE);
541
542 MessageBay.displayMessage("The frameset " + toShare.getFramesetName() + " has been moved to " + destinationDir + ". Google Drive functionality can now be used to share it with colleagues.");
543 }
544
545 private static void denyPasswordColleagueRelationship(String colleagueName) throws InvalidKeySpecException, NoSuchAlgorithmException, KeyStoreException, FileNotFoundException, CertificateException, ClassNotFoundException, IOException, SQLException {
546 String time = org.expeditee.stats.Formatter.getDateTime();
547 String sender = UserSettings.UserName.get();
548 String message = "You have received a reply from " + sender + " reguarding your request for assistance.";
549 String message2 = "Unfortunately " + sender + " has indicated that they are unable to help you with your potential password recovery.";
550 Map<String, String> options = new HashMap<String, String>();
551 options.put("Clear Preview Colleague Nominations", "AuthClearPWColleaguesNominated");
552 MailEntry mail = new MailEntry(time, sender, colleagueName, message, message2, options);
553 Mail.sendMail(mail, colleagueName);
554 }
555
556 private static boolean submitPWColleagues(Map<AuthenticationTag, String> userData) throws InvalidKeySpecException, NoSuchAlgorithmException, KeyStoreException, FileNotFoundException, CertificateException, ClassNotFoundException, IOException, SQLException {
557 String colleagueOne = userData.get(AuthenticationTag.ColleagueOne);
558 String colleagueTwo = userData.get(AuthenticationTag.ColleagueTwo);
559 PublicKey colleagueOneKey = AuthenticatorBrowser.getInstance().getPublicKey(colleagueOne);
560 PublicKey colleagueTwoKey = AuthenticatorBrowser.getInstance().getPublicKey(colleagueTwo);
561 if (colleagueOneKey == null) {
562 MessageBay.errorMessage("Unable to get public key for colleague: " + colleagueOne);
563 return false;
564 } else if (colleagueTwoKey == null) {
565 MessageBay.errorMessage("Unable to get public key for colleague: " + colleagueTwo);
566 return false;
567 } else {
568 String time = org.expeditee.stats.Formatter.getDateTime();
569 String sender = userData.get(AuthenticationTag.Username);
570 String topic = "You have received a request for cooperation from your colleague " + sender;
571 String message = "Should " + sender + " forget their password, they would like your help recoverying it.";
572 Map<String, String> arguments = new HashMap<String, String>();
573 arguments.put("I agree to assist " + sender + " if they loose access to their account.", "AuthConfirmPasswordColleagueRelationship " + sender);
574 arguments.put("I wish to excuse myself from this responsibility.", "AuthDenyPasswordColleagueRelationship " + sender);
575 MailEntry mail = new MailEntry(time, sender, colleagueOne, topic, message, arguments);
576 Mail.sendMail(mail, colleagueOne);
577 mail = new MailEntry(time, sender, colleagueTwo, topic, message, arguments);
578 Mail.sendMail(mail, colleagueTwo);
579 AuthenticatorBrowser.getInstance().markRequestedColleagues(UserSettings.UserName.get());
580 return true;
581 }
582 }
583
584 public static void TickBox(final Text item) {
585 if (item.getBackgroundColor() != Colour.RED) {
586 item.setBackgroundColor(Colour.RED);
587 } else {
588 item.setBackgroundColor(Colour.GREEN);
589 }
590 }
591
592 /*
593 * Gets all items on a specified frame that contain the specified data.
594 */
595 public static Collection<Item> getByData(final Frame frame, final String data) {
596 final Collection<Item> allItems = frame.getAllItems();
597 allItems.removeIf(i -> i.getData() == null || !i.hasData(data));
598 return allItems;
599 }
600
601 public static Collection<Item> getByContent(final Frame frame, final String content) {
602 final Collection<Item> allItems = frame.getAllItems();
603 allItems.removeIf(i -> i.getText().compareTo(content) != 0);
604 return allItems;
605 }
606}
Note: See TracBrowser for help on using the repository browser.