Search in sources :

Example 21 with TemplateCall

use of com.peterphi.std.guice.web.rest.templating.TemplateCall in project stdlib by petergeneric.

the class TemplateExceptionRenderer method render.

@Override
public Response render(final RestFailure failure) {
    if (!enabled)
        // Don't run if we're not enabled
        return null;
    if (failure == null)
        // Don't run if the failure is null
        return null;
    if (HttpCallContext.peek() == null)
        // Don't run unless we have an HttpCallContext
        return null;
    else if (!shouldRenderHtmlForRequest(HttpCallContext.get().getRequest()))
        // Don't run unless we should be rendering HTML for this request
        return null;
    final TemplateCall call = templater.template("exception");
    call.set("failure", failure);
    // Make sure there's a login (even if anonymous) associated with the current HTTP Session
    // N.B. this is a bit of an ugly layering, we could duplicate the logic here but that also seems ugly
    loginProvider.ensureLoginOnSession(HttpCallContext.get().getRequest().getSession());
    return call.process(Response.status(failure.httpCode).type(MediaType.TEXT_HTML_TYPE));
}
Also used : TemplateCall(com.peterphi.std.guice.web.rest.templating.TemplateCall)

Example 22 with TemplateCall

use of com.peterphi.std.guice.web.rest.templating.TemplateCall in project stdlib by petergeneric.

the class ConfigUIServiceImpl method getConfigPage.

@Override
public String getConfigPage(final String path) {
    final ConfigPropertyData config = repo.get(REF, path);
    final List<String> paths = repo.getPaths(REF);
    final List<ConfigPropertyValue> inheritedProperties;
    final List<ConfigPropertyValue> definedProperties;
    {
        // Sort alphabetically for the UI
        config.properties.sort(Comparator.comparing(ConfigPropertyValue::getName));
        inheritedProperties = computeInheritedProperties(config);
        definedProperties = computeDefinedProperties(config);
    }
    final TemplateCall call = templater.template("config-edit");
    call.set("nonce", nonceStore.getValue(NONCE_USE));
    call.set("repo", repo);
    call.set("config", config);
    call.set("inheritedProperties", inheritedProperties);
    call.set("definedProperties", definedProperties);
    call.set("path", config.path);
    call.set("paths", paths);
    call.set("children", getChildren(config.path, paths));
    call.set("parent", getParent(config.path));
    return call.process();
}
Also used : ConfigPropertyData(com.peterphi.std.guice.config.rest.types.ConfigPropertyData) ConfigPropertyValue(com.peterphi.std.guice.config.rest.types.ConfigPropertyValue) TemplateCall(com.peterphi.std.guice.web.rest.templating.TemplateCall)

Example 23 with TemplateCall

use of com.peterphi.std.guice.web.rest.templating.TemplateCall in project stdlib by petergeneric.

the class ConfigUIServiceImpl method getIndex.

@Override
public String getIndex() {
    final TemplateCall call = templater.template("index");
    call.set("paths", repo.getPaths(REF));
    call.set("commits", repo.getRecentCommits(10));
    return call.process();
}
Also used : TemplateCall(com.peterphi.std.guice.web.rest.templating.TemplateCall)

Example 24 with TemplateCall

use of com.peterphi.std.guice.web.rest.templating.TemplateCall in project stdlib by petergeneric.

the class RoleUIServiceImpl method get.

@Override
@Transactional(readOnly = true)
public String get(final String id) {
    TemplateCall call = templater.template("role");
    final RoleEntity entity = dao.getById(id);
    if (entity == null)
        throw new IllegalArgumentException("No such Role: " + id);
    call.set("entity", entity);
    call.set("allUsers", userDao.getAll());
    call.set("users", userDao.findByUriQuery(new WebQuery().eq("roles.id", id)).getList());
    call.set("nonce", nonceStore.getValue(NONCE_USE));
    return call.process();
}
Also used : RoleEntity(com.peterphi.usermanager.db.entity.RoleEntity) WebQuery(com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery) TemplateCall(com.peterphi.std.guice.web.rest.templating.TemplateCall) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 25 with TemplateCall

use of com.peterphi.std.guice.web.rest.templating.TemplateCall in project stdlib by petergeneric.

the class RegisterUIServiceImpl method getRegister.

@AuthConstraint(id = "register_service", skip = true, comment = "register page handles own constraints")
@Transactional(readOnly = true)
@Override
public String getRegister() {
    if (!allowAnonymousRegistration && !login.isAdmin())
        throw new AuthenticationFailureException("Anonymous registration is not enabled. Please log in to create other users");
    TemplateCall call = templater.template("register");
    call.set("nonce", nonceStore.allocate());
    if (login.isAdmin())
        // Admin user, role picker will be available
        call.set("roles", roleDao.getAll());
    else
        // Anonymous registration, no role select
        call.set("roles", Collections.emptyList());
    return call.process();
}
Also used : AuthenticationFailureException(com.peterphi.usermanager.guice.authentication.AuthenticationFailureException) TemplateCall(com.peterphi.std.guice.web.rest.templating.TemplateCall) AuthConstraint(com.peterphi.std.guice.common.auth.annotations.AuthConstraint) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Aggregations

TemplateCall (com.peterphi.std.guice.web.rest.templating.TemplateCall)28 Transactional (com.peterphi.std.guice.database.annotation.Transactional)9 AuthConstraint (com.peterphi.std.guice.common.auth.annotations.AuthConstraint)6 WebQuery (com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery)4 OAuthServiceEntity (com.peterphi.usermanager.db.entity.OAuthServiceEntity)3 RoleEntity (com.peterphi.usermanager.db.entity.RoleEntity)2 UserEntity (com.peterphi.usermanager.db.entity.UserEntity)2 AuthenticationFailureException (com.peterphi.usermanager.guice.authentication.AuthenticationFailureException)2 Function (java.util.function.Function)2 Response (javax.ws.rs.core.Response)2 Counting (com.codahale.metrics.Counting)1 Metered (com.codahale.metrics.Metered)1 Sampling (com.codahale.metrics.Sampling)1 Inject (com.google.inject.Inject)1 Named (com.google.inject.name.Named)1 Rules (com.peterphi.rules.types.Rules)1 ResourceTemplateEntity (com.peterphi.servicemanager.service.db.entity.ResourceTemplateEntity)1 LogSubscriber (com.peterphi.servicemanager.service.logging.hub.LogSubscriber)1 Doc (com.peterphi.std.annotation.Doc)1 GuiceProperties (com.peterphi.std.guice.apploader.GuiceProperties)1