source: trunk/src/org/expeditee/auth/account/Authenticate.java@ 1434

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

Implementation of ProfileManager. Refactor + additional content for how new profiles are created. The refactoring split out the creation of the default profile from user profiles. Refactoring revealed a long term bug that was causing user profiles to generate with incorrect information. The additional content fixed this bug by introducing the ${USER.NAME} variable, so that the default profile frameset can specify resource locations located in the users resource directory.

org.expeditee.auth.AuthenticatorBrowser
org.expeditee.auth.account.Create
org.expeditee.gui.Browser
org.expeditee.gui.management.ProfileManager
org.expeditee.setting.DirectoryListSetting
org.expeditee.setting.ListSetting
org.expeditee.settings.UserSettings

Implementation of ResourceManager as a core location to get resources from the file system. Also the additional variable ${CURRENT_FRAMESET} to represent the current frameset, so that images can be stored in the directory of the current frameset. This increases portability of framesets.

org.expeditee.gui.FrameIO
org.expeditee.gui.management.ResourceManager
org.expeditee.gui.management.ResourceUtil
Audio:

#NB: Audio used to only operate on a single directory. This has been updated to work in a same way as images. That is: when you ask for a specific resouce, it looks to the user settings to find a sequence of directories to look at in order until it manages to find the desired resource.


There is still need however for a single(ish) source of truth for the .banks and .mastermix file. Therefore these files are now always located in resource-<username>\audio.
org.apollo.agents.MelodySearch
org.apollo.audio.structure.AudioStructureModel
org.apollo.audio.util.MultiTrackPlaybackController
org.apollo.audio.util.SoundDesk
org.apollo.gui.FrameLayoutDaemon
org.apollo.io.AudioPathManager
org.apollo.util.AudioPurger
org.apollo.widgets.FramePlayer
org.apollo.widgets.SampledTrack

Images:

org.expeditee.items.ItemUtils

Frames:

org.expeditee.gui.FrameIO

Fixed a error in the FramePlayer class caused by an incorrect use of toArray().

org.apollo.widgets.FramePlayer


Added several short cut keys to allow for the Play/Pause (Ctrl + P), mute (Ctrl + M) and volume up/down (Ctrl + +/-) when hovering over SampledTrack widgets.

org.apollo.widgets.SampledTrack


Changed the way that Authenticate.login parses the new users profile to be more consistance with other similar places in code.

org.expeditee.auth.account.Authenticate


Encapsulated _body, _surrogateItemsBody and _primaryItemsBody in Frame class. Also changed getBody function to take a boolean flag as to if it should respect the current surrogate mode. If it should then it makes sure that labels have not changed since last time getBody was called.

org.expeditee.gui.Frame

File size: 7.6 KB
Line 
1package org.expeditee.auth.account;
2
3import java.io.IOException;
4import java.security.InvalidKeyException;
5import java.security.KeyFactory;
6import java.security.KeyStoreException;
7import java.security.NoSuchAlgorithmException;
8import java.security.PrivateKey;
9import java.security.cert.CertificateException;
10import java.security.spec.InvalidKeySpecException;
11import java.security.spec.PKCS8EncodedKeySpec;
12import java.sql.SQLException;
13import java.text.ParseException;
14import java.util.ArrayList;
15import java.util.Base64;
16import java.util.Collection;
17import java.util.List;
18import java.util.Map;
19
20import javax.crypto.BadPaddingException;
21import javax.crypto.IllegalBlockSizeException;
22import javax.crypto.NoSuchPaddingException;
23import javax.crypto.SecretKey;
24
25import org.expeditee.auth.Actions;
26import org.expeditee.auth.AuthenticatorBrowser;
27import org.expeditee.auth.mail.gui.MailBay;
28import org.expeditee.auth.tags.AuthenticationTag;
29import org.expeditee.encryption.CryptographyConstants;
30import org.expeditee.gui.Browser;
31import org.expeditee.gui.DisplayController;
32import org.expeditee.gui.Frame;
33import org.expeditee.gui.FrameIO;
34import org.expeditee.gui.FrameUtils;
35import org.expeditee.gui.MessageBay;
36import org.expeditee.items.Item;
37import org.expeditee.items.Text;
38import org.expeditee.settings.Settings;
39import org.expeditee.settings.UserSettings;
40import org.expeditee.settings.identity.secrets.KeyList;
41
42public class Authenticate implements CryptographyConstants {
43
44 /**
45 * Given a username and password, potentially login.
46 * @param userdata
47 * @return AuthenticationResult.SuccessLogin if login works, AuthenticationResult.ErrorLoginNobody or AuthenticationResult.ErrorLoginUsernamePasswordCombo otherwise.
48 */
49 public static AuthenticationResult login(Map<AuthenticationTag, String> userdata) {
50 String username = userdata.get(AuthenticationTag.Username);
51 String password = userdata.get(AuthenticationTag.Password);
52
53 if (username.equals(AuthenticatorBrowser.USER_NOBODY)) {
54 return AuthenticationResult.ErrorLoginNobody;
55 }
56
57 SecretKey personalKey = null;
58 try {
59 personalKey = AuthenticatorBrowser.getInstance().getSecretKey(username, password);
60 } catch (Exception e) {
61 return AuthenticationResult.ErrorLoginUsernamePasswordCombo;
62 }
63
64 if (personalKey == null) {
65 return AuthenticationResult.ErrorLoginUsernamePasswordCombo;
66 }
67
68 UserSettings.UserName.set(username);
69 if (!username.equals(AuthenticatorBrowser.ADMINACCOUNT)) {
70 // Set the personal key to bootstrap the encrypted frame loading.
71 Text personalKeyText = KeyList.PersonalKey.generateText();
72 personalKeyText.setData(Base64.getEncoder().encodeToString(personalKey.getEncoded()));
73 KeyList.PersonalKey.setSetting(personalKeyText);
74
75 // Load in and cache the profile frame using the personal key fetched from keystore.
76 FrameIO.ClearCache();
77 Frame oneFrame = FrameIO.LoadProfile(username);
78 for (int i = 1; i <= FrameIO.getLastNumber(oneFrame.getFramesetName()); i++) {
79 Frame f = FrameIO.LoadFrame(oneFrame.getFramesetName() + i);
80 if (f != null) {
81 List<String> data = f.getData();
82 if(data != null && data.contains("MultiuserCredentials")) {
83 AuthenticatorBrowser.CREDENTIALS_FRAME = f.getNumber();
84 } else if (data != null && data.contains("PasswordColleagues")) {
85 AuthenticatorBrowser.PASSWORD_RECOVERY_FRAME = f.getNumber();
86 } else if (data != null && data.contains("SecretsFrame")) {
87 AuthenticatorBrowser.SECRETS_FRAME = f.getNumber();
88 }
89 }
90 }
91
92 // Update were we get our frames.
93 UserSettings.setupDefaultFolders();
94 MessageBay.clear();
95 MessageBay.updateFramesetLocation();
96 MailBay.disconnect();
97
98 // Parse the users profile to refresh settings.
99 //Text settingsLink = new Text("settings");
100 //settingsLink.setLink(oneFrame.getFramesetName() + "2");
101 //Settings.parseSettings(settingsLink);
102 FrameUtils.ParseProfile(oneFrame);
103
104 // At this point we at least login, but maybe with problems.
105 AuthenticationResult res = AuthenticationResult.SuccessLogin;
106
107 // Check mail and update last read files.
108 MailBay.clear();
109 try {
110 Text keyItem = KeyList.PrivateKey.get();
111 if (keyItem.getData() != null) {
112 // Check mail.
113 String keyEncoded = keyItem.getData().get(0);
114 byte[] keyBytes = Base64.getDecoder().decode(keyEncoded);
115 PrivateKey key = KeyFactory.getInstance(AsymmetricAlgorithm).generatePrivate(new PKCS8EncodedKeySpec(keyBytes));
116 org.expeditee.auth.mail.Mail.checkMail(key);
117 } else {
118 res.additionalInfo.add("No private key present: your communication with other Expeditee users will be limited until this is resolved.");
119 }
120 } catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | ClassNotFoundException
121 | SQLException | ParseException | IOException | InvalidKeyException | NoSuchPaddingException |
122 IllegalBlockSizeException | BadPaddingException e) {
123 res.additionalInfo.add("An error occured while attempting to load in mail sent to you by other Expeditee users. See the exception for more information.");
124 e.printStackTrace();
125 } catch (InvalidKeySpecException e) {
126 res.additionalInfo.add("Stored data cannot be used to create a private key. See exception for more information.");
127 e.printStackTrace();
128 }
129
130 Collection<Item> usernameFields = Actions.getByData(FrameIO.LoadFrame("multiuser1"), "txtUsername");
131 usernameFields.forEach(usernameField -> usernameField.setText(username));
132
133 Frame requestedFrame = FrameIO.LoadFrame(Browser.getStartFrame());
134 Frame homeFrame = FrameIO.LoadFrame("home1");
135 Frame choice = requestedFrame != null ? requestedFrame : homeFrame != null ? homeFrame : oneFrame;
136 DisplayController.setCurrentFrame(choice, true);
137 }
138
139 return AuthenticationResult.SuccessLogin;
140 }
141
142 /**
143 * Logs out the current authenticated user.
144 * @return AuthenticationResult.SuccessLogout to signal the logout has occured.
145 */
146 public static AuthenticationResult logout() {
147 // Set user to nobody.
148 UserSettings.UserName.set(AuthenticatorBrowser.USER_NOBODY);
149
150 // Update were we get our frames.
151 UserSettings.setupDefaultFolders();
152 MessageBay.updateFramesetLocation();
153 MailBay.disconnect();
154
155 // Reset all of the settings.
156 Settings.resetAllSettings();
157
158 // Display login frame
159 Frame auth1 = FrameIO.LoadFrame("authentication1");
160 DisplayController.setCurrentFrame(auth1, true);
161
162 return AuthenticationResult.SuccessLogout;
163 }
164
165 public enum AuthenticationResult {
166
167 SuccessLogin, SuccessLogout, ErrorLoginNobody, ErrorLoginUsernamePasswordCombo;
168
169 private List<String> additionalInfo = new ArrayList<String>();
170
171 public String toString() {
172 switch (this) {
173 case SuccessLogin:
174 StringBuilder sb = new StringBuilder();
175 sb.append("Logged in as: " + UserSettings.UserName.get());
176 if (additionalInfo.isEmpty()) {
177 return sb.toString();
178 } else {
179 String nl = System.getProperty("line.separator");
180 sb.append("However: " + nl);
181 for (String info: additionalInfo) {
182 sb.append(info + nl);
183 }
184 return sb.toString();
185 }
186 case SuccessLogout:
187 return "You are now logged out of Expeditee.";
188 case ErrorLoginNobody:
189 return "You cannot log into Expeditee as the user \'nobody\'";
190 case ErrorLoginUsernamePasswordCombo:
191 return "The username + password combination was incorrect.";
192 }
193
194 String message = "Was the list of possible enum results updated without nessasary changes to the toString() function?";
195 throw new IllegalArgumentException(message);
196 }
197 }
198}
Note: See TracBrowser for help on using the repository browser.