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

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