Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- * Copyright 2016 NueveBit, todos los derechos reservados.
- */
- package com.nuevebit.acec.binder.ws.rest.util;
- import com.nuevebit.acec.binder.core.auth.Rol;
- import com.nuevebit.acec.binder.core.auth.Usuario;
- import com.nuevebit.acec.binder.core.auth.UsuarioRepository;
- import com.nuevebit.acec.binder.core.util.CRUDService;
- import com.nuevebit.persistence.Identificable;
- import com.nuevebit.persistence.repository.SearchableRepository;
- import javax.inject.Inject;
- import org.restlet.data.Status;
- import org.restlet.resource.Post;
- import org.restlet.resource.ResourceException;
- /**
- *
- * @author emerino
- */
- public abstract class EntitiesResource<T extends Identificable<?>, S>
- extends SearchableResource<T, S> {
- @Inject
- private UsuarioRepository usuarioRepository;
- @Override
- protected SearchableRepository<T, ?, S> getRepository()throws ResourceException{
- Usuario usuario = getUsuarioAutenticado();
- if (usuario != null) {
- if (!Rol.SUPER_ADMIN.equals(usuario.getRol())) {
- throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED);
- }
- }
- return getCRUDService();
- }
- protected abstract CRUDService<T, ?, S> getCRUDService();
- @Post("json")
- public T create(T obj) throws Exception {
- return getCRUDService().store(obj);
- }
- /**
- * Obtener el Usuario autenticado.
- *
- * @return
- */
- protected Usuario getUsuarioAutenticado() {
- return usuarioRepository
- .findByAlias(getChallengeResponse().getIdentifier());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement