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

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

Permissions for encrypting frames are now respected. (Group level permissions still need testing and maybe implementation)

The current implementation of Hetrogeneous Owner requires that the owner of the frame specify the available labels. Injecting the property "HetrogeneousEncryptionLabels: <label name>" into the frame name item adds the specified label to the list of labels that those with 'Hetrogeneous (Owner)' permission are able to use.

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