public void redirect() throws IllegalStateException {
   String referer = getReferer();
   try {
     ResourceMethod method = router.parse(referer, HttpMethod.GET, request);
     executeMethod(method, result.use(logic()).redirectTo(method.getResource().getType()));
   } catch (ResourceNotFoundException e) {
     result.use(page()).redirect(referer);
   } catch (MethodNotAllowedException e) {
     result.use(page()).redirect(referer);
   }
 }
  public void intercept(InterceptorStack stack, ResourceMethod method, Object resourceInstance) {
    if (usuarioSession.getUsuario() != null) {
      Permission methodPermission = method.getMethod().getAnnotation(Permission.class);
      Permission controllerPermission =
          method.getResource().getType().getAnnotation(Permission.class);
      if (this.hasAccess(methodPermission) && this.hasAccess(controllerPermission)) {
        stack.next(method, resourceInstance);
      } else {
        result.redirectTo(LoginController.class).acessoNegado();
      }

    } else {
      result.redirectTo(LoginController.class).login();
    }
  }
 @Override
 public boolean accepts(ResourceMethod method) {
   return !method.getResource().getType().isAnnotationPresent(Open.class)
       && !method.containsAnnotation(Open.class);
 }
 public boolean accepts(ResourceMethod method) {
   return !(method.getMethod().isAnnotationPresent(Public.class)
       || method.getResource().getType().isAnnotationPresent(Public.class));
   // return false;
 }