use of com.peterphi.std.guice.web.rest.templating.TemplateCall in project stdlib by petergeneric.
the class GuiceRestDaemonsServiceImpl method getStackTrace.
@Override
public String getStackTrace(final String name) {
final Optional<GuiceDaemon> result = registry.getAll().stream().filter(d -> StringUtils.equals(name, d.getName())).findFirst();
if (result.isPresent()) {
final GuiceDaemon daemon = result.get();
final StackTraceElement[] stack;
if (daemon.isThreadRunning() && daemon.getThread() != null) {
Thread thread = daemon.getThread();
stack = thread.getStackTrace();
} else {
stack = null;
}
final TemplateCall template = templater.template(PREFIX + "daemon_stacktrace.html");
template.set("stack", stack);
template.set("name", daemon.getName());
template.set("registry", registry);
template.set("daemonDescriber", (Function<GuiceDaemon, String>) this::getDescription);
return template.process();
} else {
throw new IllegalArgumentException("No daemon with name: " + name);
}
}
use of com.peterphi.std.guice.web.rest.templating.TemplateCall in project stdlib by petergeneric.
the class GuiceRestDaemonsServiceImpl method getIndex.
@Override
public String getIndex(String message) {
final TemplateCall template = templater.template(PREFIX + "daemon_list.html");
template.set("message", message);
template.set("registry", registry);
template.set("daemonDescriber", (Function<GuiceDaemon, String>) this::getDescription);
return template.process();
}
use of com.peterphi.std.guice.web.rest.templating.TemplateCall in project stdlib by petergeneric.
the class JwtCreationRestServiceImpl method getResult.
@Override
public String getResult(String token, final String secret, final String payload, final String op) {
final TemplateCall template = templater.template(PREFIX + "jwt_generated.html");
final Long expireTime;
if (token == null) {
try {
JwtClaims claims = JwtClaims.parse(payload);
if (claims.getExpirationTime() != null)
expireTime = claims.getExpirationTime().getValueInMillis();
else
expireTime = null;
token = createJWT(secret, payload);
} catch (InvalidJwtException | MalformedClaimException | JoseException e) {
throw new RuntimeException(e);
}
} else {
// User has provided a JWT. We should simply parse it and extract the expiry time (for the cookie)
try {
JwtConsumer jwtConsumer = new JwtConsumerBuilder().setSkipAllValidators().setDisableRequireSignature().setSkipSignatureVerification().build();
final JwtClaims claims = jwtConsumer.processToClaims(token);
if (claims.getExpirationTime() != null)
expireTime = claims.getExpirationTime().getValueInMillis();
else
expireTime = null;
} catch (InvalidJwtException | MalformedClaimException e) {
throw new RuntimeException(e);
}
}
final boolean save = StringUtils.equalsIgnoreCase("save", op);
// Optionally save as a cookie
if (save) {
Cookie cookie = new Cookie(cookieName, token);
// Set the cookie path based on the webapp endpoint path
cookie.setPath(webappEndpoint.getPath());
// If the webapp has an https endpoint (or if we were accessed by HTTPS) then set the cookie as a secure cookie
cookie.setSecure(HttpCallContext.get().getRequest().isSecure() || StringUtils.equalsIgnoreCase("https", webappEndpoint.getScheme()));
// Expire the cookie 1 minute before the token expires
if (expireTime != null)
cookie.setMaxAge(expireTime.intValue() - 60);
// Kill the current session (just in case it's associated with a job manager login)
final HttpSession session = HttpCallContext.get().getRequest().getSession(false);
if (session != null) {
session.invalidate();
}
// Now add the JWT cookie
HttpCallContext.get().getResponse().addCookie(cookie);
}
template.set("saved", save);
template.set("token", token);
return template.process();
}
use of com.peterphi.std.guice.web.rest.templating.TemplateCall in project stdlib by petergeneric.
the class RestConfigListImpl method index.
@Override
public String index() throws Exception {
final TemplateCall template = templater.template(PREFIX + "config_list.html");
template.set("showProperties", showProperties);
template.set("showBoundValues", showBoundValues);
template.set("allowReconfigure", allowReconfigure);
template.set("config", this.serviceConfig);
template.set("configRegistry", configRegistry);
return template.process();
}
use of com.peterphi.std.guice.web.rest.templating.TemplateCall in project stdlib by petergeneric.
the class RestServiceListImpl method index.
@Override
public String index(final HttpHeaders headers, final UriInfo uriInfo) throws Exception {
final TemplateCall template = templater.template(PREFIX + "service_list.html");
template.set("services", services);
template.set("schemaGenerator", schemaGenerator);
return template.process();
}
Aggregations