use of org.onosproject.ui.UiSessionToken in project onos by opennetworkinglab.
the class MainIndexResource method getMainIndex.
@GET
@Produces(MediaType.TEXT_HTML)
@Path("/index.html")
public Response getMainIndex() throws IOException {
ClassLoader classLoader = getClass().getClassLoader();
UiExtensionService service;
UiTokenService tokens;
try {
service = get(UiExtensionService.class);
tokens = get(UiTokenService.class);
} catch (ServiceNotFoundException e) {
return Response.ok(classLoader.getResourceAsStream(NOT_READY)).build();
}
InputStream indexTemplate = classLoader.getResourceAsStream(INDEX);
String index = new String(toByteArray(indexTemplate));
int p0s = split(index, 0, INJECT_USER_START) - INJECT_USER_START.length();
int p0e = split(index, p0s, INJECT_USER_END);
int p1s = split(index, p0e, INJECT_JS_START) - INJECT_JS_START.length();
int p1e = split(index, p1s, INJECT_JS_END);
int p2s = split(index, p1e, INJECT_CSS_START) - INJECT_CSS_START.length();
int p2e = split(index, p2s, INJECT_CSS_END);
int p3s = split(index, p2e, null);
// FIXME: use global opaque auth token to allow secure failover
// for now, just use the user principal name...
String userName = ctx.getUserPrincipal().getName();
// get a session token to use for UI-web-socket authentication
UiSessionToken token = tokens.issueToken(userName);
String auth = "var onosUser='" + userName + "',\n" + " onosAuth='" + token + "';\n";
StreamEnumeration streams = new StreamEnumeration(of(stream(index, 0, p0s), 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();
}
use of org.onosproject.ui.UiSessionToken in project onos by opennetworkinglab.
the class MainIndexResource method getMainIndex.
@GET
@Produces(MediaType.TEXT_HTML)
@Path("/index.html")
public Response getMainIndex() throws IOException {
ClassLoader classLoader = getClass().getClassLoader();
UiExtensionService service;
UiTokenService tokens;
try {
service = get(UiExtensionService.class);
tokens = get(UiTokenService.class);
} catch (ServiceNotFoundException e) {
return Response.ok(classLoader.getResourceAsStream(NOT_READY)).build();
}
InputStream indexTemplate = classLoader.getResourceAsStream(INDEX);
String index = new String(toByteArray(indexTemplate));
int p0s = split(index, 0, INJECT_USER_START) - INJECT_USER_START.length();
int p0e = split(index, p0s, INJECT_USER_END);
int p3s = split(index, p0e, null);
// FIXME: use global opaque auth token to allow secure failover
// for now, just use the user principal name...
String userName = ctx.getUserPrincipal().getName();
// get a session token to use for UI-web-socket authentication
UiSessionToken token = tokens.issueToken(userName);
String auth = "var onosUser='" + userName + "',\n" + " onosAuth='" + token + "';\n";
StreamEnumeration streams = new StreamEnumeration(of(stream(index, 0, p0s), new ByteArrayInputStream(SCRIPT_START), stream(auth, 0, auth.length()), userPreferences(userName), userConsoleLog(userName), new ByteArrayInputStream(SCRIPT_END), stream(index, p0e, p3s)));
return Response.ok(new SequenceInputStream(streams)).build();
}
use of org.onosproject.ui.UiSessionToken in project onos by opennetworkinglab.
the class UiWebSocket method authenticate.
private void authenticate(String type, ObjectNode message) {
if (!AUTHENTICATION.equals(type)) {
log.warn("WebSocket not authenticated: {}", message);
sendMessage(ERROR, notAuthorized(null));
close();
return;
}
String tokstr = message.path(PAYLOAD).path(TOKEN).asText(UNKNOWN);
UiSessionToken token = new UiSessionToken(tokstr);
if (tokenService().isTokenValid(token)) {
sessionToken = token;
log.info("Session token authenticated");
log.debug("WebSocket authenticated: {}", message);
} else {
log.warn("Invalid Authentication Token: {}", message);
sendMessage(ERROR, notAuthorized(token));
}
}
use of org.onosproject.ui.UiSessionToken in project onos by opennetworkinglab.
the class UiExtensionManager method issueToken.
// =====================================================================
// UiTokenService
@Override
public UiSessionToken issueToken(String username) {
UiSessionToken token = new UiSessionToken(tokenGen.nextSessionId());
tokens.put(token, username);
log.debug("UiSessionToken issued: {}", token);
return token;
}
Aggregations