Search in sources :

Example 6 with TemplateCall

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();
}
Also used : LogSubscriber(com.peterphi.servicemanager.service.logging.hub.LogSubscriber) TemplateCall(com.peterphi.std.guice.web.rest.templating.TemplateCall)

Example 7 with TemplateCall

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)));
    }
}
Also used : OAuth2TokenResponse(com.peterphi.usermanager.rest.iface.oauth2server.types.OAuth2TokenResponse) Response(javax.ws.rs.core.Response) OAuthServiceEntity(com.peterphi.usermanager.db.entity.OAuthServiceEntity) SessionNonceStore(com.peterphi.usermanager.guice.nonce.SessionNonceStore) TemplateCall(com.peterphi.std.guice.web.rest.templating.TemplateCall) AuthConstraint(com.peterphi.std.guice.common.auth.annotations.AuthConstraint) Retry(com.peterphi.std.guice.common.retry.annotation.Retry)

Example 8 with TemplateCall

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();
    }
}
Also used : TemplateCall(com.peterphi.std.guice.web.rest.templating.TemplateCall) AuthConstraint(com.peterphi.std.guice.common.auth.annotations.AuthConstraint)

Example 9 with TemplateCall

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();
}
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 10 with TemplateCall

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();
}
Also used : AuthenticationFailureException(com.peterphi.usermanager.guice.authentication.AuthenticationFailureException) AuthConstraint(com.peterphi.std.guice.common.auth.annotations.AuthConstraint) UserEntity(com.peterphi.usermanager.db.entity.UserEntity) TemplateCall(com.peterphi.std.guice.web.rest.templating.TemplateCall) 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