-
Notifications
You must be signed in to change notification settings - Fork 5
/
Monitor.java
152 lines (139 loc) · 7.91 KB
/
Monitor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package org.genericsystem.reactor.gscomponents3;
import org.genericsystem.reactor.modelproperties.PasswordDefaults;
import org.genericsystem.reactor.modelproperties.UserRoleDefaults;
import org.genericsystem.reactor.htmltag.HtmlButton;
import org.genericsystem.reactor.htmltag.HtmlInputText;
import org.genericsystem.reactor.htmltag.HtmlLabel;
import org.genericsystem.reactor.htmltag.HtmlSpan;
import java.util.Arrays;
import javafx.beans.binding.Bindings;
import org.genericsystem.common.Generic;
import org.genericsystem.reactor.EncryptionUtils;
import org.genericsystem.reactor.annotations.Attribute;
import org.genericsystem.reactor.annotations.BindAction;
import org.genericsystem.reactor.annotations.BindText;
import org.genericsystem.reactor.annotations.Children;
import org.genericsystem.reactor.annotations.Mode;
import org.genericsystem.reactor.annotations.SelectModel;
import org.genericsystem.reactor.annotations.SetText;
import org.genericsystem.reactor.annotations.Style;
import org.genericsystem.reactor.annotations.Style.FlexDirectionStyle;
import org.genericsystem.reactor.gscomponents.FlexDirection;
import org.genericsystem.reactor.gscomponents.GSDiv;
import org.genericsystem.reactor.gscomponents3.Monitor.MonitorLogin.LoggedUserDiv;
import org.genericsystem.reactor.gscomponents3.Monitor.MonitorLogin.LoggedUserDiv.DisconnectButton;
import org.genericsystem.reactor.gscomponents3.Monitor.MonitorLogin.LoggedUserDiv.ModeSwitchButtons;
import org.genericsystem.reactor.gscomponents3.Monitor.MonitorLogin.LoginDiv;
import org.genericsystem.reactor.gscomponents3.Monitor.MonitorLogin.LoginDiv.ValidateButton;
import org.genericsystem.reactor.model.ContextAction;
import org.genericsystem.reactor.model.ContextAction.CANCEL;
import org.genericsystem.reactor.model.ContextAction.FLUSH;
import org.genericsystem.reactor.model.ContextAction.GC;
import org.genericsystem.reactor.model.ContextAction.MOUNT;
import org.genericsystem.reactor.model.ContextAction.SHIFTTS;
import org.genericsystem.reactor.model.ContextAction.UNMOUNT;
import org.genericsystem.reactor.model.TagSelector;
import org.genericsystem.reactor.model.ObservableModelSelector;
import org.genericsystem.reactor.model.TextBinding;
import org.genericsystem.security.model.User;
import org.genericsystem.security.model.User.Password;
import org.genericsystem.security.model.User.Salt;
@Children({ HtmlButton.class, HtmlLabel.class, HtmlButton.class })
@SetText(path = HtmlButton.class, pos = 0, value = "Save")
@BindAction(path = HtmlButton.class, pos = 0, value = FLUSH.class)
@SetText(path = HtmlButton.class, pos = 1, value = "Cancel")
@BindAction(path = HtmlButton.class, pos = 1, value = CANCEL.class)
@BindText(path = HtmlLabel.class, pos = 0, value = TextBinding.LAST_UPDATE.class)
@FlexDirectionStyle(FlexDirection.ROW)
@Style(name = "justify-content", value = "space-around")
@Style(name = "padding", value = "10px")
public class Monitor extends GSDiv {
@Children({ HtmlButton.class, HtmlButton.class, HtmlButton.class, HtmlLabel.class, HtmlButton.class, HtmlButton.class, HtmlLabel.class /* , HtmlButton.class */})
@SetText(path = HtmlButton.class, pos = 2, value = "Mount")
@BindAction(path = HtmlButton.class, pos = 2, value = MOUNT.class)
@SetText(path = HtmlButton.class, pos = 3, value = "Unmount")
@BindAction(path = HtmlButton.class, pos = 3, value = UNMOUNT.class)
@SetText(path = HtmlButton.class, pos = 4, value = "ShiftTs")
@BindAction(path = HtmlButton.class, pos = 4, value = SHIFTTS.class)
@SetText(path = HtmlButton.class, pos = 5, value = "Collect")
@BindAction(path = HtmlButton.class, pos = 5, value = GC.class)
@BindText(path = HtmlLabel.class, pos = 1, value = TextBinding.CACHE_LEVEL.class)
public static class MonitorExtended extends Monitor {
}
@Children({ HtmlButton.class, HtmlButton.class, HtmlLabel.class, LoginDiv.class, LoggedUserDiv.class })
public static class MonitorLogin extends Monitor implements UserRoleDefaults {
@SelectModel(ObservableModelSelector.LOGGED_USER.class)
@Children({ ModeSwitchButtons.class, HtmlLabel.class, DisconnectButton.class })
@FlexDirectionStyle(FlexDirection.ROW)
public static class LoggedUserDiv extends GSDiv implements UserRoleDefaults {
@Override
public void init() {
find(HtmlLabel.class)
.bindText(
context -> Bindings.createStringBinding(() -> getLoggedUserProperty(context).getValue() != null ? "Current user: " + (String) getLoggedUserProperty(context).getValue().getValue() : "No user logged.",
getLoggedUserProperty(context)));
}
@Children({ HtmlButton.class, HtmlButton.class, HtmlButton.class, HtmlButton.class, HtmlButton.class })
@SetText(path = HtmlButton.class, pos = 0, value = "Admin mode")
@SetText(path = HtmlButton.class, pos = 1, value = "User mode")
@SetText(path = HtmlButton.class, pos = 2, value = "button2")
@SetText(path = HtmlButton.class, pos = 3, value = "button3")
@SetText(path = HtmlButton.class, pos = 4, value = "button4")
@SelectModel(ObservableModelSelector.LOGGED_USER_ADMIN.class)
@Mode(path = HtmlButton.class, pos = 0, value = TagSelector.NORMAL_MODE_ONLY.class)
@Mode(path = HtmlButton.class, pos = 1, value = TagSelector.ADMIN_MODE_ONLY.class)
@BindAction(path = HtmlButton.class, pos = 0, value = ContextAction.SET_ADMIN_MODE.class)
@BindAction(path = HtmlButton.class, pos = 1, value = ContextAction.SET_NORMAL_MODE.class)
@Mode(path = HtmlButton.class, pos = 3, value = TagSelector.ADMIN_MODE_ONLY.class)
public static class ModeSwitchButtons extends GSDiv {
}
@SetText("Disconnect")
public static class DisconnectButton extends HtmlButton implements UserRoleDefaults {
@Override
public void init() {
bindAction(context -> getLoggedUserProperty(context).setValue(null));
}
}
}
@SelectModel(ObservableModelSelector.NO_LOGGED_USER.class)
@Children({ HtmlLabel.class, HtmlInputText.class, HtmlLabel.class, HtmlInputText.class, ValidateButton.class, HtmlSpan.class, HtmlSpan.class })
@FlexDirectionStyle(FlexDirection.ROW)
@SetText(path = HtmlLabel.class, pos = 0, value = "Login: ")
@SetText(path = HtmlLabel.class, pos = 1, value = "Password: ")
@SetText(path = HtmlSpan.class, pos = 0, value = "Invalid username.")
@SetText(path = HtmlSpan.class, pos = 1, value = "Invalid password.")
@Style(path = HtmlSpan.class, name = "display", value = "none")
@Attribute(path = HtmlInputText.class, pos = 1, name = "type", value = "password")
public static class LoginDiv extends GSDiv implements UserRoleDefaults {
@SetText("OK")
public static class ValidateButton extends HtmlButton implements PasswordDefaults, UserRoleDefaults {
@Override
public void init() {
createSaltProperty();
bindAction(context -> {
HtmlInputText loginInput = getParent().find(HtmlInputText.class);
HtmlInputText passwordInput = getParent().find(HtmlInputText.class, 1);
HtmlSpan invalidLogin = getParent().find(HtmlSpan.class);
HtmlSpan invalidPassword = getParent().find(HtmlSpan.class, 1);
Generic user = context.find(User.class).getInstance(loginInput.getDomNodeAttributes(context).get("value"));
if (user != null) {
Generic hashGeneric = context.find(Password.class).getInstance(user);
byte[] salt = (byte[]) context.find(Salt.class).getInstance(hashGeneric).getValue();
if (Arrays.equals((byte[]) hashGeneric.getValue(), EncryptionUtils.getEncryptedPassword(passwordInput.getDomNodeAttributes(context).get("value"), salt))) {
loginInput.getDomNodeAttributes(context).put("value", "");
passwordInput.getDomNodeAttributes(context).put("value", "");
invalidLogin.addStyle(context, "display", "none");
invalidPassword.addStyle(context, "display", "none");
getLoggedUserProperty(context).setValue(user);
} else {
invalidLogin.addStyle(context, "display", "none");
invalidPassword.addStyle(context, "display", "inline");
}
} else
invalidLogin.addStyle(context, "display", "inline");
});
}
}
}
}
}