Search in sources :

Example 6 with OAuthServiceEntity

use of com.peterphi.usermanager.db.entity.OAuthServiceEntity in project stdlib by petergeneric.

the class ServiceUIServiceImpl method get.

@Override
@Transactional(readOnly = true)
public String get(final String id) {
    final OAuthServiceEntity entity = dao.getById(id);
    if (entity == null)
        throw new IllegalArgumentException("No such service with client_id: " + id);
    final TemplateCall call = templater.template("service");
    call.set("nonce", nonceStore.getValue(NONCE_USE));
    call.set("entity", entity);
    call.set("localEndpoint", localEndpoint);
    return call.process();
}
Also used : OAuthServiceEntity(com.peterphi.usermanager.db.entity.OAuthServiceEntity) TemplateCall(com.peterphi.std.guice.web.rest.templating.TemplateCall) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Example 7 with OAuthServiceEntity

use of com.peterphi.usermanager.db.entity.OAuthServiceEntity in project stdlib by petergeneric.

the class ServiceUIServiceImpl method setEndpoints.

@Override
@Transactional
public Response setEndpoints(final String nonce, final String id, final String endpoints) {
    nonceStore.validate(NONCE_USE, nonce);
    final OAuthServiceEntity entity = dao.getById(id);
    if (entity == null)
        throw new IllegalArgumentException("No such service with client_id: " + id);
    else if (!entity.isEnabled())
        throw new IllegalArgumentException("Cannot set endpoints on disabled service: " + id);
    else if (entity.getOwner().getId() != userProvider.get().getId() && !userProvider.get().isAdmin())
        throw new IllegalArgumentException("Only the owner or an admin can change endpoints of a service!");
    entity.setEndpoints(endpoints);
    dao.update(entity);
    return Response.seeOther(URI.create("/service/" + id)).build();
}
Also used : OAuthServiceEntity(com.peterphi.usermanager.db.entity.OAuthServiceEntity) Transactional(com.peterphi.std.guice.database.annotation.Transactional)

Aggregations

OAuthServiceEntity (com.peterphi.usermanager.db.entity.OAuthServiceEntity)7 Transactional (com.peterphi.std.guice.database.annotation.Transactional)5 TemplateCall (com.peterphi.std.guice.web.rest.templating.TemplateCall)3 AuthConstraint (com.peterphi.std.guice.common.auth.annotations.AuthConstraint)2 Retry (com.peterphi.std.guice.common.retry.annotation.Retry)1 WebQuery (com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery)1 OAuthSessionContextEntity (com.peterphi.usermanager.db.entity.OAuthSessionContextEntity)1 UserEntity (com.peterphi.usermanager.db.entity.UserEntity)1 SessionNonceStore (com.peterphi.usermanager.guice.nonce.SessionNonceStore)1 OAuth2TokenResponse (com.peterphi.usermanager.rest.iface.oauth2server.types.OAuth2TokenResponse)1 Response (javax.ws.rs.core.Response)1