source: trunk/src/org/expeditee/auth/AuthenticationTag.java@ 1203

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

Initial commit of functionality concerning multiuser login, further to come.

Actions.java -> Actions that allow users to authenticate and secure their accounts.
AuthenticationTag.java -> Enum like structure for text fields associated with authentication.
Authenticator.java -> Startup functionality for when Expeditee is run in authentication mode.
EncryptedExpReader.java -> Reads exp files previously encrypted with EncryptedExpWriter (not currently used) and EncryptedProfileExpWriter
Mail.java -> Functions for transforming database stored messages into datastructures used to display those messages to the MailBay.

File size: 1.7 KB
Line 
1package org.expeditee.auth;
2
3import java.util.Collection;
4import java.util.HashMap;
5import java.util.Map;
6import java.util.Optional;
7
8import org.expeditee.items.Text;
9
10public enum AuthenticationTag {
11 Username ("txtUsername", System.getProperty("user.name")),
12 Password ("txtPassword", System.getProperty("user.password")),
13 PasswordAgain ("txtPasswordAgain", System.getProperty("user.password.again")),
14 NewPassword ("txtNewPassword", System.getProperty("user.new.password")),
15 NewPasswordAgain ("txtNewPasswordAgain", System.getProperty("user.new.password.again")),
16 Email ("txtEmail", System.getProperty("user.email")),
17 ColleagueOne ("txtColleagueOne", System.getProperty("user.colleague.one")),
18 ColleagueTwo ("txtColleagueTwo", System.getProperty("user.colleague.two"));
19
20 public String val;
21 public String def;
22
23 private AuthenticationTag(final String tag, final String def) {
24 this.val = tag;
25 this.def = def;
26 }
27
28 public static Optional<Map<AuthenticationTag, String>> fetchUserData(final Collection<Text> from, final AuthenticationTag... tags) {
29 final Map<AuthenticationTag, String> fetchedData = new HashMap<AuthenticationTag, String>();
30
31 for (final AuthenticationTag tag: tags) {
32 for (final Text canditate: from) {
33 // use the canditate if it exists
34 if (canditate.hasData(tag.val)) {
35 fetchedData.put(tag, canditate.getText());
36 break;
37 }
38 // otherwise try use the default
39 final String property = tag.def;
40 if (property != null && !property.isEmpty()) {
41 fetchedData.put(tag, property);
42 }
43 }
44 }
45
46 if (fetchedData.entrySet().size() == tags.length) {
47 return Optional.of(fetchedData);
48 } else {
49 return Optional.empty();
50 }
51 }
52}
Note: See TracBrowser for help on using the repository browser.