use of com.peterphi.std.guice.web.rest.templating.TemplateCall in project stdlib by petergeneric.
the class ServiceManagerUIServiceImpl method getTail.
@Override
public String getTail() {
final TemplateCall call = templater.template("tail");
// Create a new subscription to the log stream
// Also take this opportunity to remove purged subscriptions from the map
final String subscriptionId = user.getUsername() + "_" + SimpleId.alphanumeric(10);
synchronized (subscribers) {
log.info("Created log tail subscription " + subscriptionId);
subscribers.put(subscriptionId, loggingService.subscribe(new LogSubscriber(subscriptionId)));
// Remove purged subscribers
final Iterator<Map.Entry<String, LogSubscriber>> it = subscribers.entrySet().iterator();
while (it.hasNext()) {
if (it.next().getValue().isPurged())
it.remove();
}
}
call.set("nonce", nonceStore.getValue());
call.set("subscriptionId", subscriptionId);
return call.process();
}
use of com.peterphi.std.guice.web.rest.templating.TemplateCall in project stdlib by petergeneric.
the class UserManagerOAuthServiceImpl method getAuth.
@Override
@AuthConstraint(id = "oauth2server_auth", role = "authenticated", comment = "Must be logged in to the User Manager to initiate a service login")
@Retry
public Response getAuth(final String responseType, final String clientId, final String redirectUri, final String state, final String scope) {
// Has the current user approved this client+scope before? If so just redirect straight back
// Otherwise, bring up the authorisation UI
final Response response = createSessionAndRedirect(responseType, clientId, redirectUri, state, scope, autoGrantInteractiveAccessToAllServices);
if (response != null) {
return response;
} else {
final OAuthServiceEntity client = serviceDao.getByClientIdAndEndpoint(clientId, redirectUri);
if (client == null)
throw new IllegalArgumentException("Unknown client_id=" + clientId + " or invalid redirect uri for this service: " + redirectUri);
final TemplateCall call = templater.template("connect_to_service");
SessionNonceStore nonceStore = nonceStoreProvider.get();
// Provide additional client information
call.set("client", client);
call.set("nonce", nonceStore.allocate());
// Scopes as a list
if (StringUtils.isBlank(scope))
call.set("scopes", Collections.emptyList());
else
call.set("scopes", Arrays.asList(StringUtils.trimToEmpty(scope).split(" ")));
// Copy the request info
call.set("clientId", client.getId());
call.set("responseType", responseType);
call.set("redirectUri", redirectUri);
call.set("scope", scope);
call.set("state", state);
return call.process(Response.ok().type(MediaType.APPLICATION_XML).cacheControl(CacheControl.valueOf(NO_CACHE)));
}
}
use of com.peterphi.std.guice.web.rest.templating.TemplateCall in project stdlib by petergeneric.
the class LoginUIServiceImpl method getLogin.
@Override
@AuthConstraint(skip = true, comment = "login page")
public String getLogin(String returnTo, String errorText) {
if (login.isLoggedIn()) {
throw new IllegalArgumentException("You are already logged in!");
} else {
TemplateCall call = templater.template("login");
call.set("allowAnonymousRegistration", allowAnonymousRegistration);
call.set("returnTo", returnTo);
call.set("errorText", errorText);
return call.process();
}
}
use of com.peterphi.std.guice.web.rest.templating.TemplateCall in project stdlib by petergeneric.
the class RoleUIServiceImpl method getRoles.
@Override
@Transactional(readOnly = true)
public String getRoles(UriInfo query) {
ConstrainedResultSet<RoleEntity> resultset = dao.findByUriQuery(new WebQuery().orderAsc("id").decode(query));
TemplateCall call = templater.template("roles");
call.set("resultset", resultset);
call.set("roles", resultset.getList());
call.set("nonce", nonceStore.getValue(NONCE_USE));
return call.process();
}
use of com.peterphi.std.guice.web.rest.templating.TemplateCall in project stdlib by petergeneric.
the class UserUIServiceImpl method getUserEdit.
@Override
@Transactional(readOnly = true)
public String getUserEdit(final int userId) {
final int localUser = login.getId();
if (localUser != userId && !login.isAdmin())
throw new AuthenticationFailureException("Only a User Admin can edit the profile of another user!");
TemplateCall call = templater.template("user_edit");
final UserEntity user = accountDao.getById(userId);
call.set("entity", user);
call.set("user", user);
call.set("timezones", Arrays.asList(TimeZone.getAvailableIDs()));
call.set("dateformats", Arrays.asList("YYYY-MM-dd HH:mm:ss zzz", "YYYY-MM-dd HH:mm:ss", "YYYY-MM-dd HH:mm"));
call.set("entityRoleIds", getRoles(user));
call.set("roles", roleDao.getAll());
call.set("nonce", nonceStore.getValue(NONCE_USE));
return call.process();
}
Aggregations