1 | package org.expeditee.auth;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.io.FileNotFoundException;
|
---|
5 | import java.io.IOException;
|
---|
6 | import java.nio.file.Files;
|
---|
7 | import java.nio.file.Path;
|
---|
8 | import java.nio.file.Paths;
|
---|
9 | import java.nio.file.StandardCopyOption;
|
---|
10 | import java.security.InvalidKeyException;
|
---|
11 | import java.security.KeyFactory;
|
---|
12 | import java.security.KeyStoreException;
|
---|
13 | import java.security.NoSuchAlgorithmException;
|
---|
14 | import java.security.PrivateKey;
|
---|
15 | import java.security.PublicKey;
|
---|
16 | import java.security.cert.CertificateException;
|
---|
17 | import java.security.spec.InvalidKeySpecException;
|
---|
18 | import java.security.spec.PKCS8EncodedKeySpec;
|
---|
19 | import java.sql.SQLException;
|
---|
20 | import java.text.ParseException;
|
---|
21 | import java.util.Base64;
|
---|
22 | import java.util.Collection;
|
---|
23 | import java.util.HashMap;
|
---|
24 | import java.util.List;
|
---|
25 | import java.util.Map;
|
---|
26 | import java.util.Optional;
|
---|
27 | import java.util.Scanner;
|
---|
28 | import java.util.stream.Collectors;
|
---|
29 |
|
---|
30 | import javax.crypto.BadPaddingException;
|
---|
31 | import javax.crypto.IllegalBlockSizeException;
|
---|
32 | import javax.crypto.NoSuchPaddingException;
|
---|
33 |
|
---|
34 | import org.expeditee.agents.ExistingFramesetException;
|
---|
35 | import org.expeditee.agents.InvalidFramesetNameException;
|
---|
36 | import org.expeditee.auth.Mail.MailEntry;
|
---|
37 | import org.expeditee.auth.account.Authenticate;
|
---|
38 | import org.expeditee.auth.account.Authenticate.AuthenticationResult;
|
---|
39 | import org.expeditee.auth.account.Create;
|
---|
40 | import org.expeditee.auth.account.Password;
|
---|
41 | import org.expeditee.auth.gui.MailBay;
|
---|
42 | import org.expeditee.auth.tags.AuthenticationTag;
|
---|
43 | import org.expeditee.core.Colour;
|
---|
44 | import org.expeditee.gui.DisplayController;
|
---|
45 | import org.expeditee.gui.Frame;
|
---|
46 | import org.expeditee.gui.FrameIO;
|
---|
47 | import org.expeditee.gui.MessageBay;
|
---|
48 | import org.expeditee.items.Item;
|
---|
49 | import org.expeditee.items.Text;
|
---|
50 | import org.expeditee.settings.UserSettings;
|
---|
51 | import org.expeditee.settings.identity.secrets.KeyList;
|
---|
52 | import org.expeditee.stats.Formatter;
|
---|
53 | import org.ngikm.cryptography.CryptographyConstants;
|
---|
54 |
|
---|
55 | public class Actions implements CryptographyConstants {
|
---|
56 |
|
---|
57 | //Debug Functions
|
---|
58 | public static void SendTestMessage(String colleagueName) throws InvalidKeySpecException, NoSuchAlgorithmException, FileNotFoundException, KeyStoreException, CertificateException, ClassNotFoundException, IOException, SQLException {
|
---|
59 | String time = org.expeditee.stats.Formatter.getDateTime();
|
---|
60 | String sender = UserSettings.UserName.get();
|
---|
61 | String topic = "Test Message";
|
---|
62 | String message = "This is a test message.";
|
---|
63 | Map<String, String> options = new HashMap<String, String>();
|
---|
64 | options.put("Neat", "Beep");
|
---|
65 | MailEntry mail = new MailEntry(time, sender, colleagueName, topic, message, options);
|
---|
66 | Mail.sendMail(mail, colleagueName);
|
---|
67 | MessageBay.displayMessage("Test message sent.");
|
---|
68 | }
|
---|
69 | public static void SendTestMessageHemi(String param) {
|
---|
70 | String time = Formatter.getDateTime();
|
---|
71 | String sender = UserSettings.UserName.get();
|
---|
72 | String recipient = param.split(" ")[0];
|
---|
73 | String message = param.split(" ")[1];
|
---|
74 | Map<String, String> options = new HashMap<String, String>();
|
---|
75 | options.put("Accept", "beep");
|
---|
76 | options.put("Reject", "beep");
|
---|
77 | MailEntry mail = new MailEntry(time, sender, recipient, "Have a key", message, options);
|
---|
78 | Mail.sendMail(mail, recipient);
|
---|
79 | MessageBay.displayMessage("Test message sent.");
|
---|
80 | }
|
---|
81 |
|
---|
82 | private static String userbackup = "authadmin";
|
---|
83 | public static void ToggleAuth() {
|
---|
84 | String backup = UserSettings.UserName.get();
|
---|
85 | UserSettings.UserName.set(userbackup);
|
---|
86 | userbackup = backup;
|
---|
87 | }
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Display Expeditee Mail
|
---|
91 | * @throws IOException
|
---|
92 | * @throws SQLException
|
---|
93 | * @throws ClassNotFoundException
|
---|
94 | * @throws CertificateException
|
---|
95 | * @throws NoSuchAlgorithmException
|
---|
96 | * @throws FileNotFoundException
|
---|
97 | * @throws KeyStoreException
|
---|
98 | * @throws ParseException
|
---|
99 | * @throws InvalidKeySpecException
|
---|
100 | * @throws BadPaddingException
|
---|
101 | * @throws IllegalBlockSizeException
|
---|
102 | * @throws NoSuchPaddingException
|
---|
103 | * @throws InvalidKeyException
|
---|
104 | */
|
---|
105 | public static void ToggleBay() throws KeyStoreException, FileNotFoundException, NoSuchAlgorithmException, CertificateException, ClassNotFoundException, SQLException, IOException, ParseException, InvalidKeySpecException, InvalidKeyException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException {
|
---|
106 | if (!AuthenticatorBrowser.isAuthenticated()) return;
|
---|
107 | if (!DisplayController.isMailMode()) {
|
---|
108 | MailBay.ensureLink();
|
---|
109 | Mail.clear();
|
---|
110 | String keyEncoded = KeyList.PrivateKey.get().getData().get(0);
|
---|
111 | byte[] keyBytes = Base64.getDecoder().decode(keyEncoded);
|
---|
112 | PrivateKey key = KeyFactory.getInstance(AsymmetricAlgorithm).generatePrivate(new PKCS8EncodedKeySpec(keyBytes));
|
---|
113 | Mail.checkMail(key);
|
---|
114 | }
|
---|
115 | DisplayController.ToggleMailMode();
|
---|
116 | }
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * Action used to navigate the authorised user back to their desktop.
|
---|
120 | */
|
---|
121 | public static void AuthGoToDesktop() {
|
---|
122 | DisplayController.setCurrentFrame(FrameIO.LoadFrame(UserSettings.HomeFrame.get()), true);
|
---|
123 | }
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * Action used to created a new user account.
|
---|
127 | * Attempts to use content from text items on frame, will default to java properties if they cannot be found.
|
---|
128 | * Will fail if it cannot find content from text items on frame and all required java properties are not present.
|
---|
129 | * @throws SQLException
|
---|
130 | * @throws IOException
|
---|
131 | * @throws ExistingFramesetException
|
---|
132 | * @throws InvalidFramesetNameException
|
---|
133 | * @throws ClassNotFoundException
|
---|
134 | * @throws FileNotFoundException
|
---|
135 | * @throws CertificateException
|
---|
136 | * @throws NoSuchAlgorithmException
|
---|
137 | * @throws KeyStoreException
|
---|
138 | * @throws BadPaddingException
|
---|
139 | * @throws IllegalBlockSizeException
|
---|
140 | * @throws NoSuchPaddingException
|
---|
141 | * @throws InvalidKeySpecException
|
---|
142 | * @throws InvalidKeyException
|
---|
143 | * @throws ParseException
|
---|
144 | * @throws Exception
|
---|
145 | */
|
---|
146 | public static void AuthCreateAccount() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, ClassNotFoundException, InvalidFramesetNameException, ExistingFramesetException, IOException, SQLException, InvalidKeyException, InvalidKeySpecException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, ParseException {
|
---|
147 | Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
|
---|
148 | Optional<Map<AuthenticationTag, String>> userdata =
|
---|
149 | AuthenticationTag.fetchUserData(textItems, false,
|
---|
150 | AuthenticationTag.Username,
|
---|
151 | AuthenticationTag.Password,
|
---|
152 | AuthenticationTag.PasswordAgain,
|
---|
153 | AuthenticationTag.Email,
|
---|
154 | AuthenticationTag.EmailAgain);
|
---|
155 |
|
---|
156 | if (userdata.isPresent()) {
|
---|
157 | Map<AuthenticationTag, String> userData = userdata.get();
|
---|
158 |
|
---|
159 | // A profile already existing with 'username' means an account cannot be created with that username.
|
---|
160 | if (FrameIO.getProfilesList().contains(userData.get(AuthenticationTag.Username))) {
|
---|
161 | MessageBay.errorMessage("A Expeditee profile with this username already exists, please choose another.");
|
---|
162 | return;
|
---|
163 | }
|
---|
164 |
|
---|
165 | // The chosen username must be a valid frameset name.
|
---|
166 | if (!FrameIO.isValidFramesetName(userData.get(AuthenticationTag.Username))) {
|
---|
167 | MessageBay.errorMessage("The provided username must begin and end with a letter and contain only letters and numbers inbetween, please choose another.");
|
---|
168 | return;
|
---|
169 | }
|
---|
170 |
|
---|
171 | // The passwords provided must match
|
---|
172 | if (userData.get(AuthenticationTag.Password).compareTo(userData.get(AuthenticationTag.PasswordAgain)) != 0) {
|
---|
173 | MessageBay.errorMessage("The provided passwords do not match, please fix this and try again.");
|
---|
174 | return;
|
---|
175 | }
|
---|
176 |
|
---|
177 | // The emails provided must match
|
---|
178 | if (userData.get(AuthenticationTag.Email).compareTo(userData.get(AuthenticationTag.EmailAgain)) != 0) {
|
---|
179 | MessageBay.errorMessage("The provided emails do not match, please fix this and try again.");
|
---|
180 | return;
|
---|
181 | }
|
---|
182 |
|
---|
183 | Create.createAccount(userData);
|
---|
184 | Authenticate.login(userData);
|
---|
185 | AuthenticatorBrowser.Authenticated = true;
|
---|
186 | } else {
|
---|
187 | MessageBay.errorMessage("Please fill out all the supplied text boxes.");
|
---|
188 | }
|
---|
189 | }
|
---|
190 |
|
---|
191 | /**
|
---|
192 | * Action used to start authentication as a specified user.
|
---|
193 | * Attempts to use content from text items on frame, will default to java properties if they cannot be found.
|
---|
194 | * Will fail if it cannot find content from text items on frame and all required java properties are not present.
|
---|
195 | * @throws Exception
|
---|
196 | */
|
---|
197 | public static void AuthLogin() {
|
---|
198 | final Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
|
---|
199 | final Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username, AuthenticationTag.Password);
|
---|
200 | if (userdata.isPresent()) {
|
---|
201 | AuthenticationResult result = Authenticate.login(userdata.get());
|
---|
202 | if (result == AuthenticationResult.SuccessLogin) {
|
---|
203 | MessageBay.displayMessage(result.toString());
|
---|
204 | } else {
|
---|
205 | MessageBay.errorMessage(result.toString());
|
---|
206 | }
|
---|
207 | //login(userdata.get());
|
---|
208 | AuthenticatorBrowser.Authenticated = true;
|
---|
209 | } else {
|
---|
210 | MessageBay.errorMessage("Please fill out all the supplied text boxes.");
|
---|
211 | }
|
---|
212 | }
|
---|
213 |
|
---|
214 | public static void AuthLogout() {
|
---|
215 | MessageBay.displayMessage(Authenticate.logout().toString());
|
---|
216 | }
|
---|
217 |
|
---|
218 | /**
|
---|
219 | * Action used to change the currently authenticated users password.
|
---|
220 | * Attempts to use content from text items on frame, will default to java properties if they cannot be found.
|
---|
221 | * Will fail if it cannot find content from text items on frame and all required java properties are not present.
|
---|
222 | * Will fail if no user is currently logged in.
|
---|
223 | * @throws IOException
|
---|
224 | * @throws CertificateException
|
---|
225 | * @throws FileNotFoundException
|
---|
226 | * @throws KeyStoreException
|
---|
227 | * @throws NoSuchAlgorithmException
|
---|
228 | * @throws SQLException
|
---|
229 | * @throws ClassNotFoundException
|
---|
230 | */
|
---|
231 | public static void AuthChangePassword() throws NoSuchAlgorithmException, KeyStoreException, FileNotFoundException, CertificateException, IOException, ClassNotFoundException, SQLException {
|
---|
232 | final Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
|
---|
233 |
|
---|
234 | if (!AuthenticatorBrowser.Authenticated) {
|
---|
235 | MessageBay.errorMessage("You must be logged in to perform this action.");
|
---|
236 | } else {
|
---|
237 | final Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Password, AuthenticationTag.NewPassword, AuthenticationTag.NewPasswordAgain);
|
---|
238 | if (userdata.isPresent()) {
|
---|
239 | final Map<AuthenticationTag, String> userData = userdata.get();
|
---|
240 | if (userData.get(AuthenticationTag.NewPassword).compareTo(userData.get(AuthenticationTag.NewPasswordAgain)) != 0) {
|
---|
241 | MessageBay.errorMessage("The provided passwords do not match, please fix this and try again.");
|
---|
242 | } else {
|
---|
243 | userData.put(AuthenticationTag.Username, UserSettings.UserName.get());
|
---|
244 | Password.changePassword(userData);
|
---|
245 | }
|
---|
246 | } else {
|
---|
247 | MessageBay.errorMessage("Please fill out all the supplied text boxes.");
|
---|
248 | }
|
---|
249 | }
|
---|
250 | }
|
---|
251 |
|
---|
252 | public static void AuthGotoAccountManagement() {
|
---|
253 | if (AuthenticatorBrowser.Authenticated) {
|
---|
254 | DisplayController.setCurrentFrame(FrameIO.LoadFrame("multiuser1"), false);
|
---|
255 | } else {
|
---|
256 | DisplayController.setCurrentFrame(FrameIO.LoadFrame("authentication1"), false);
|
---|
257 | }
|
---|
258 | }
|
---|
259 |
|
---|
260 | public static void AuthResetPasswordPt1() {
|
---|
261 | Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
|
---|
262 | Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username);
|
---|
263 | if (userdata.isPresent()) {
|
---|
264 | Map<AuthenticationTag, String> userData = userdata.get();
|
---|
265 | String username = userData.get(AuthenticationTag.Username);
|
---|
266 | String email = getEmailFromUsername(username);
|
---|
267 | userData.put(AuthenticationTag.Email, email);
|
---|
268 | Password.generateAndDeliverIntergalacticNumber(userData);
|
---|
269 | MessageBay.displayMessage("A Intergalactic number has been sent to the email associated with your account. Enter it below to proceed.");
|
---|
270 | }
|
---|
271 | }
|
---|
272 |
|
---|
273 | public static void AuthResetPasswordPt2() {
|
---|
274 | Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
|
---|
275 | Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username,
|
---|
276 | AuthenticationTag.IntergalacticNumber, AuthenticationTag.NewPassword, AuthenticationTag.NewPasswordAgain);
|
---|
277 | if (userdata.isPresent()) {
|
---|
278 | Map<AuthenticationTag, String> userData = userdata.get();
|
---|
279 | String username = userData.get(AuthenticationTag.Username);
|
---|
280 | String email = getEmailFromUsername(username);
|
---|
281 | userData.put(AuthenticationTag.Email, email);
|
---|
282 | Password.confirmIntergalacticNumberAndGenerateSubstituteAccount(userData);
|
---|
283 | }
|
---|
284 | }
|
---|
285 |
|
---|
286 | private static String getEmailFromUsername(String username) {
|
---|
287 | Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
|
---|
288 | Path credentialsDirPath = Paths.get(FrameIO.PROFILE_PATH).resolve(username).resolve(username + "-credentials");
|
---|
289 | Path credentialsFilePath = credentialsDirPath.resolve("credentials.inf");
|
---|
290 | String fileName = null;
|
---|
291 | if (credentialsFilePath.toFile().exists()) {
|
---|
292 | try (Scanner in = new Scanner(credentialsFilePath)) {
|
---|
293 | fileName = in.nextLine();
|
---|
294 | } catch (IOException e) {
|
---|
295 | MessageBay.errorMessage("Unable to locate public email for specified user, are they registered on this computer?");
|
---|
296 | return null;
|
---|
297 | }
|
---|
298 | } else {
|
---|
299 | MessageBay.errorMessage("Unable to locate public email for specified user, are they registered on this computer?");
|
---|
300 | return null;
|
---|
301 | }
|
---|
302 |
|
---|
303 | int number = Integer.parseInt(fileName.replace(".exp", ""));
|
---|
304 | Frame credentialsFrame = FrameIO.LoadFrame(username + number, FrameIO.PROFILE_PATH);
|
---|
305 | textItems = credentialsFrame.getTextItems();
|
---|
306 | textItems.removeIf(text -> !text.getText().startsWith("Email: "));
|
---|
307 | if (textItems.isEmpty()) {
|
---|
308 | MessageBay.errorMessage("Unable to locate public email for specified user, are they registered on this computer?");
|
---|
309 | return null;
|
---|
310 | } else {
|
---|
311 | Text emailText = textItems.iterator().next();
|
---|
312 | String email = emailText.getText().replace("Email: ", "");
|
---|
313 | return email;
|
---|
314 | }
|
---|
315 | }
|
---|
316 |
|
---|
317 | public static void AuthShareFrameset() throws IOException {
|
---|
318 | Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
|
---|
319 |
|
---|
320 | Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Frameset);
|
---|
321 | if (userdata.isPresent()) {
|
---|
322 | Map<AuthenticationTag, String> userData = userdata.get();
|
---|
323 | FrameIO.SuspendCache();
|
---|
324 | Frame toShare = FrameIO.LoadFrame(userData.get(AuthenticationTag.Frameset) + 1);
|
---|
325 | FrameIO.ResumeCache();
|
---|
326 |
|
---|
327 | if (toShare == null) {
|
---|
328 | MessageBay.errorMessage("Insufficient information provided to complete this action.");
|
---|
329 | return;
|
---|
330 | }
|
---|
331 |
|
---|
332 | shareFrameset(toShare);
|
---|
333 | }
|
---|
334 | }
|
---|
335 |
|
---|
336 | /**
|
---|
337 | * Navigation action for progressing the process of recruiting colleagues to assist in password recovery.
|
---|
338 | * Hides certain content that AuthSubmitPWCollegues goes onto show if it does not fail.
|
---|
339 | */
|
---|
340 | public static void AuthGotoColleagueSubmissionFrame() {
|
---|
341 | Frame destination = FrameIO.LoadFrame("authentication7");
|
---|
342 | DisplayController.setCurrentFrame(destination, true);
|
---|
343 | Collection<Item> toHide = getByData(destination, "ShowOnProgress");
|
---|
344 | for (Item i: toHide) {
|
---|
345 | i.setVisible(false);
|
---|
346 | }
|
---|
347 | }
|
---|
348 |
|
---|
349 | /**
|
---|
350 | * Action used to start the process of formalising the password recovery process.
|
---|
351 | * @throws SQLException
|
---|
352 | * @throws IOException
|
---|
353 | * @throws ClassNotFoundException
|
---|
354 | * @throws CertificateException
|
---|
355 | * @throws NoSuchAlgorithmException
|
---|
356 | * @throws FileNotFoundException
|
---|
357 | * @throws KeyStoreException
|
---|
358 | * @throws InvalidKeySpecException
|
---|
359 | */
|
---|
360 | public static void AuthSubmitPWColleagues() throws InvalidKeySpecException, NoSuchAlgorithmException, KeyStoreException, FileNotFoundException, CertificateException, ClassNotFoundException, IOException, SQLException {
|
---|
361 | Frame currentFrame = DisplayController.getCurrentFrame();
|
---|
362 | Collection<Text> textItems = currentFrame.getTextItems();
|
---|
363 |
|
---|
364 | if (!AuthenticatorBrowser.Authenticated) {
|
---|
365 | MessageBay.errorMessage("You must be logged in to perform this action.");
|
---|
366 | return;
|
---|
367 | }
|
---|
368 |
|
---|
369 | Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.ColleagueOne, AuthenticationTag.ColleagueTwo);
|
---|
370 | if (userdata.isPresent()) {
|
---|
371 | Map<AuthenticationTag, String> userData = userdata.get();
|
---|
372 | String colleagueOne = userData.get(AuthenticationTag.ColleagueOne);
|
---|
373 | Path colleagueOnePath = Paths.get(FrameIO.CONTACTS_PATH).resolve(colleagueOne + "-credentials");
|
---|
374 | String colleagueTwo = userData.get(AuthenticationTag.ColleagueTwo);
|
---|
375 | Path colleagueTwoPath = Paths.get(FrameIO.CONTACTS_PATH).resolve(colleagueTwo + "-credentials");
|
---|
376 | if (!colleagueOnePath.toFile().exists()) {
|
---|
377 | MessageBay.errorMessage("Your nominated colleague: " + colleagueOne + " must exist in your contacts.");
|
---|
378 | } else if (!colleagueTwoPath.toFile().exists()) {
|
---|
379 | MessageBay.errorMessage("Your nominated colleague: " + colleagueTwo + " must exist in your contacts.");
|
---|
380 | } else {
|
---|
381 | userData.put(AuthenticationTag.Username, UserSettings.UserName.get());
|
---|
382 | boolean success = submitPWColleagues(userData);
|
---|
383 | if (success) {
|
---|
384 | Collection<Item> toShow = getByData(currentFrame, "ShowOnProgress");
|
---|
385 | for (Item i: toShow) {
|
---|
386 | i.setVisible(true);
|
---|
387 | }
|
---|
388 | currentFrame.change();
|
---|
389 | MessageBay.displayMessage("-------Messages sent-------");
|
---|
390 | }
|
---|
391 | FrameIO.SaveFrame(currentFrame);
|
---|
392 | DisplayController.requestRefresh(false);
|
---|
393 | }
|
---|
394 | }
|
---|
395 | }
|
---|
396 |
|
---|
397 | // public static void AuthSetupPasswordRecovery() throws KeyStoreException, FileNotFoundException, NoSuchAlgorithmException, CertificateException, ClassNotFoundException, IOException, SQLException, UnrecoverableEntryException {
|
---|
398 | // if (!UserSettings.Authenticated.get()) {
|
---|
399 | // MessageBay.errorMessage("You must be logged in to perform this action.");
|
---|
400 | // } else if (!Authenticator.getInstance().hasRegisteredEmail(UserSettings.UserName.get())) {
|
---|
401 | // Frame registerEmailFrame = FrameIO.LoadFrame("authentication4");
|
---|
402 | // DisplayController.setCurrentFrame(registerEmailFrame, true);
|
---|
403 | // } else if (!Authenticator.getInstance().hasRequestedColleagues(UserSettings.UserName.get()) && Authenticator.getInstance().getColleagues(UserSettings.UserName.get()) == null) {
|
---|
404 | // Frame submitColleaguesFrame = FrameIO.LoadFrame("authentication5");
|
---|
405 | // DisplayController.setCurrentFrame(submitColleaguesFrame, true);
|
---|
406 | // } else if (Authenticator.getInstance().hasRequestedColleagues(UserSettings.UserName.get()) && Authenticator.getInstance().getColleagues(UserSettings.UserName.get()) == null) {
|
---|
407 | // MessageBay.displayMessage("You have already nominated two colleagues to assist you in the process of password recovery and are awaiting their response."
|
---|
408 | // + " You will be alerted on Expeditee startup when they have both responded.");
|
---|
409 | // } else if (Authenticator.getInstance().getColleagues(UserSettings.UserName.get()) != null) {
|
---|
410 | // MessageBay.displayMessage("You have completed the Password Recovery Setup process, there is nothing more to do here.");
|
---|
411 | // }
|
---|
412 | // }
|
---|
413 |
|
---|
414 | public static void AuthConfirmPasswordColleagueRelationship(String colleagueName) {
|
---|
415 |
|
---|
416 | }
|
---|
417 |
|
---|
418 | public static void AuthDenyPasswordColleagueRelationship(String colleagueName) throws InvalidKeySpecException, NoSuchAlgorithmException,
|
---|
419 | KeyStoreException, FileNotFoundException, CertificateException, ClassNotFoundException, IOException, SQLException {
|
---|
420 | denyPasswordColleagueRelationship(colleagueName);
|
---|
421 | }
|
---|
422 |
|
---|
423 | public static void AuthClearPWColleaguesNominated() {
|
---|
424 |
|
---|
425 | }
|
---|
426 |
|
---|
427 | /*
|
---|
428 | * Function to share a specified frameset.
|
---|
429 | * 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.
|
---|
430 | */
|
---|
431 | private static void shareFrameset(Frame toShare) throws IOException {
|
---|
432 | File destinationDir = new File(FrameIO.SHARED_FRAMESETS_PATH + File.separator + toShare.getFramesetName());
|
---|
433 | File sourceDir = new File(toShare.getFramesetPath());
|
---|
434 |
|
---|
435 | if (destinationDir.exists()) {
|
---|
436 | MessageBay.errorMessage("A frameset by this name already exists.");
|
---|
437 | return;
|
---|
438 | }
|
---|
439 |
|
---|
440 | destinationDir.mkdir();
|
---|
441 | List<Path> files = Files.walk(sourceDir.toPath()).collect(Collectors.toList());
|
---|
442 | Files.move(files.get(0), destinationDir.toPath(), StandardCopyOption.ATOMIC_MOVE);
|
---|
443 |
|
---|
444 | MessageBay.displayMessage("The frameset " + toShare.getFramesetName() + " has been moved to " + destinationDir + ". Google Drive functionality can now be used to share it with colleagues.");
|
---|
445 | }
|
---|
446 |
|
---|
447 | private static void denyPasswordColleagueRelationship(String colleagueName) throws InvalidKeySpecException, NoSuchAlgorithmException, KeyStoreException, FileNotFoundException, CertificateException, ClassNotFoundException, IOException, SQLException {
|
---|
448 | String time = org.expeditee.stats.Formatter.getDateTime();
|
---|
449 | String sender = UserSettings.UserName.get();
|
---|
450 | String message = "You have received a reply from " + sender + " reguarding your request for assistance.";
|
---|
451 | String message2 = "Unfortunately " + sender + " has indicated that they are unable to help you with your potential password recovery.";
|
---|
452 | Map<String, String> options = new HashMap<String, String>();
|
---|
453 | options.put("Clear Preview Colleague Nominations", "AuthClearPWColleaguesNominated");
|
---|
454 | MailEntry mail = new MailEntry(time, sender, colleagueName, message, message2, options);
|
---|
455 | Mail.sendMail(mail, colleagueName);
|
---|
456 | }
|
---|
457 |
|
---|
458 | private static boolean submitPWColleagues(Map<AuthenticationTag, String> userData) throws InvalidKeySpecException, NoSuchAlgorithmException, KeyStoreException, FileNotFoundException, CertificateException, ClassNotFoundException, IOException, SQLException {
|
---|
459 | String colleagueOne = userData.get(AuthenticationTag.ColleagueOne);
|
---|
460 | String colleagueTwo = userData.get(AuthenticationTag.ColleagueTwo);
|
---|
461 | PublicKey colleagueOneKey = AuthenticatorBrowser.getInstance().getPublicKey(colleagueOne);
|
---|
462 | PublicKey colleagueTwoKey = AuthenticatorBrowser.getInstance().getPublicKey(colleagueTwo);
|
---|
463 | if (colleagueOneKey == null) {
|
---|
464 | MessageBay.errorMessage("Unable to get public key for colleague: " + colleagueOne);
|
---|
465 | return false;
|
---|
466 | } else if (colleagueTwoKey == null) {
|
---|
467 | MessageBay.errorMessage("Unable to get public key for colleague: " + colleagueTwo);
|
---|
468 | return false;
|
---|
469 | } else {
|
---|
470 | String time = org.expeditee.stats.Formatter.getDateTime();
|
---|
471 | String sender = userData.get(AuthenticationTag.Username);
|
---|
472 | String topic = "You have received a request for cooperation from your colleague " + sender;
|
---|
473 | String message = "Should " + sender + " forget their password, they would like your help recoverying it.";
|
---|
474 | Map<String, String> arguments = new HashMap<String, String>();
|
---|
475 | arguments.put("I agree to assist " + sender + " if they loose access to their account.", "AuthConfirmPasswordColleagueRelationship " + sender);
|
---|
476 | arguments.put("I wish to excuse myself from this responsibility.", "AuthDenyPasswordColleagueRelationship " + sender);
|
---|
477 | MailEntry mail = new MailEntry(time, sender, colleagueOne, topic, message, arguments);
|
---|
478 | Mail.sendMail(mail, colleagueOne);
|
---|
479 | mail = new MailEntry(time, sender, colleagueTwo, topic, message, arguments);
|
---|
480 | Mail.sendMail(mail, colleagueTwo);
|
---|
481 | AuthenticatorBrowser.getInstance().markRequestedColleagues(UserSettings.UserName.get());
|
---|
482 | return true;
|
---|
483 | }
|
---|
484 | }
|
---|
485 |
|
---|
486 | public static void TickBox(final Text item) {
|
---|
487 | if (item.getBackgroundColor() != Colour.RED) {
|
---|
488 | item.setBackgroundColor(Colour.RED);
|
---|
489 | } else {
|
---|
490 | item.setBackgroundColor(Colour.GREEN);
|
---|
491 | }
|
---|
492 | }
|
---|
493 |
|
---|
494 | /*
|
---|
495 | * Gets all items on a specified frame that contain the specified data.
|
---|
496 | */
|
---|
497 | public static Collection<Item> getByData(final Frame frame, final String data) {
|
---|
498 | final Collection<Item> allItems = frame.getAllItems();
|
---|
499 | allItems.removeIf(i -> i.getData() == null || !i.hasData(data));
|
---|
500 | return allItems;
|
---|
501 | }
|
---|
502 |
|
---|
503 | public static Collection<Item> getByContent(final Frame frame, final String content) {
|
---|
504 | final Collection<Item> allItems = frame.getAllItems();
|
---|
505 | allItems.removeIf(i -> i.getText().compareTo(content) != 0);
|
---|
506 | return allItems;
|
---|
507 | }
|
---|
508 | }
|
---|