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

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

Removed reliance of System.getProperty("user.name") by introducing some functions and a variable to Browser to be used instead. All previous occurrences of System.getProperty("user.name") now use these functions.

At the time, introduced new piping into various functions related to the creation and management of profile frames that distinguished between a profile name and a user name. This allows functions to be more specific about what is being used. For example, when modifying the users profile frames (in the profiles directory) that users profile name can be used instead of naming the variable 'username'. This distinction is important because while username's can end with numbers, profile names cannot and therefore get an 'A' on the end.

File size: 2.3 KB
Line 
1package org.expeditee.auth.tags;
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")), // Should use Browser.getExpediteeUserName()
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 EmailAgain ("txtEmailAgain", System.getProperty("user.email.again")),
18 TrustedUserOne ("txtTrustedUserOne", System.getProperty("user.colleague.one")),
19 TrustedUserTwo ("txtTrustedUserTwo", System.getProperty("user.colleague.two")),
20 Frameset ("txtFrameset", System.getProperty("user.toshare.frameset")),
21 IntergalacticNumber ("txtIntergalacticNumber", System.getProperty("user.intergalacticnumber")),
22 PasswordSliceOne ("txtPasswordPieceOne", System.getProperty("user.password.piece.one")),
23 PasswordSliceTwo ("txtPasswordPieceTwo", System.getProperty("user.password.piece.two"));
24
25 public String val;
26 public String def;
27
28 private AuthenticationTag(String tag, String def) {
29 this.val = tag;
30 this.def = def;
31 }
32
33 public static Optional<Map<AuthenticationTag, String>> fetchUserData(Collection<Text> from, boolean useDefaults, AuthenticationTag... tags) {
34 final Map<AuthenticationTag, String> fetchedData = new HashMap<AuthenticationTag, String>();
35
36 for (AuthenticationTag tag: tags) {
37 for (Text canditate: from) {
38 // use the canditate if it exists
39 if (canditate.hasData(tag.val)) {
40 if (tag.val.equals("txtUsername")) {
41 fetchedData.put(tag, canditate.getText().toLowerCase());
42 } else {
43 fetchedData.put(tag, canditate.getText());
44 }
45 break;
46 }
47 // otherwise try use the default
48 String property = tag.def;
49 if (property != null && !property.isEmpty()) {
50 fetchedData.put(tag, useDefaults ? property : null);
51 }
52 }
53 }
54
55 if (fetchedData.entrySet().size() == tags.length) {
56 return Optional.of(fetchedData);
57 } else {
58 return Optional.empty();
59 }
60 }
61}
Note: See TracBrowser for help on using the repository browser.