mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-17 02:11:38 +02:00
GUI -- Log the name of the logged-in user to the Javascript console, at beginning of index.html.
Change-Id: I973023edbb4aa1af3af816fc59895e8ab026192d
This commit is contained in:
parent
673c3e062f
commit
23f21e317e
@ -57,7 +57,7 @@ public class MainIndexResource extends AbstractInjectionResource {
|
||||
private static final String INJECT_JS_END = "<!-- {INJECTED-JAVASCRIPT-END} -->";
|
||||
|
||||
private static final byte[] SCRIPT_START = "\n<script>\n".getBytes();
|
||||
private static final byte[] SCRIPT_END = "\n</script>\n\n".getBytes();
|
||||
private static final byte[] SCRIPT_END = "</script>\n\n".getBytes();
|
||||
|
||||
@Context
|
||||
private SecurityContext ctx;
|
||||
@ -90,25 +90,31 @@ public class MainIndexResource extends AbstractInjectionResource {
|
||||
|
||||
StreamEnumeration streams =
|
||||
new StreamEnumeration(of(stream(index, 0, p0s),
|
||||
new ByteArrayInputStream(SCRIPT_START),
|
||||
stream(auth, 0, auth.length()),
|
||||
userPreferences(userName),
|
||||
new ByteArrayInputStream(SCRIPT_END),
|
||||
stream(index, p0e, p1s),
|
||||
includeJs(service),
|
||||
stream(index, p1e, p2s),
|
||||
includeCss(service),
|
||||
stream(index, p2e, p3s)));
|
||||
new ByteArrayInputStream(SCRIPT_START),
|
||||
stream(auth, 0, auth.length()),
|
||||
userPreferences(userName),
|
||||
userConsoleLog(userName),
|
||||
new ByteArrayInputStream(SCRIPT_END),
|
||||
stream(index, p0e, p1s),
|
||||
includeJs(service),
|
||||
stream(index, p1e, p2s),
|
||||
includeCss(service),
|
||||
stream(index, p2e, p3s)));
|
||||
|
||||
return Response.ok(new SequenceInputStream(streams)).build();
|
||||
}
|
||||
|
||||
private InputStream userConsoleLog(String userName) {
|
||||
String code = "console.log('Logging in as user >" + userName + "<');\n";
|
||||
return new ByteArrayInputStream(code.getBytes());
|
||||
}
|
||||
|
||||
// Produces an input stream including user preferences.
|
||||
private InputStream userPreferences(String userName) {
|
||||
UiPreferencesService service = get(UiPreferencesService.class);
|
||||
ObjectNode prefs = mapper().createObjectNode();
|
||||
service.getPreferences(userName).forEach(prefs::set);
|
||||
String string = "var userPrefs = " + prefs.toString() + ";";
|
||||
String string = "var userPrefs = " + prefs.toString() + ";\n";
|
||||
return new ByteArrayInputStream(string.getBytes());
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user