首页 \ 问答 \ RAILS Faye - 令牌认证(RAILS Faye - token authentication)

RAILS Faye - 令牌认证(RAILS Faye - token authentication)

我构建了与各种平台客户端交互的Rails API。 在服务器端,实现了faye服务器,例如:

Faye::RackAdapter.new(:mount => '/faye', :timeout => 25)

在服务器端,我想通过令牌添加autentication。 我使用faye扩展:

class ServerAuth
  def incoming(message, callback)
    # Let non-subscribe messages throughs
    unless message['channel'] == '/meta/subscribe'
      return callback.call(message)
    end
    # Get subscribed channel and auth token
    msg_token = message['ext'] && message['ext']['authToken']
    # Add an error if the tokens don't match
    if msg_token != '12345'
      message['error'] = 'Invalid subscription auth token'
    end
    # Call the server back now we're done
    callback.call(message)
  end
end

实际上它不像我那样工作。 当客户端传递正确的令牌时,一切似乎都可以,但是当他传递无效令牌时,即使他从服务器收到错误消息,他仍然能够推送消息。 我应该如何阻止客户端不会收到它们的消息(显然在服务器端)。


I build Rails API that interacts with various platform clients. On the server side there is implemented faye server something like:

Faye::RackAdapter.new(:mount => '/faye', :timeout => 25)

On the server side I would like to add autentication via token. I use faye extension:

class ServerAuth
  def incoming(message, callback)
    # Let non-subscribe messages throughs
    unless message['channel'] == '/meta/subscribe'
      return callback.call(message)
    end
    # Get subscribed channel and auth token
    msg_token = message['ext'] && message['ext']['authToken']
    # Add an error if the tokens don't match
    if msg_token != '12345'
      message['error'] = 'Invalid subscription auth token'
    end
    # Call the server back now we're done
    callback.call(message)
  end
end

Actually It doesn't work as I except. When client passes correct token everything seems be all right but when he passes invalid token then he still is able to push messages even that he gets back error message from server. How should I block such messages that clients won't recive them (on the server side obviously).


原文:https://stackoverflow.com/questions/32745883
更新时间:2022-10-15 20:10

最满意答案

声明你的循环的变量otsido:

<%!
    public String autoPONo()throws SQLException{
               String POno = null;
                rs=pst.executeQuery();

                if(rs.next()){
                   String po= rs.getString("max(PONo)");
                   int intNo = Integer.parseInt(po);
                   intNo+=1;

                   POno = Integer.toString(intNo);  
                }

           return POno; 
        }
    }
%>

Declare the variable otsido of your loop:

<%!
    public String autoPONo()throws SQLException{
               String POno = null;
                rs=pst.executeQuery();

                if(rs.next()){
                   String po= rs.getString("max(PONo)");
                   int intNo = Integer.parseInt(po);
                   intNo+=1;

                   POno = Integer.toString(intNo);  
                }

           return POno; 
        }
    }
%>

相关问答

更多
  • 没有必要这样做,你可以直接调用URLEncoder.encode(String) 。 就像是 htmlString.append(" " + foo + " "); There isn't any need to do so, you can call URLEnc ...
  • 在主体内部使用设置值的问题在于它始终是一个字符串(将主体内容评估为字符串)。 如果使用value属性,则结果是评估值的类型: 但只有当你有“暴露”的东西进行评估时,才有可能实现上述目标。 我假设标签是Spring Security的taglibs的一部分 ? 如果是这种情况,你使用它的方式是导致字符串强制(而不是 )。 标记可以将属性值写入输出流(作为字 ...
  • 最后它奏效了。 这是因为路径问题。 我必须完整的道路。 C:\\xampp\\tomcat\\webapps\\Location_API\\WEB-INF\\classes\\location\\test.xml 它像魅力一样工作。 谢谢大家的宝贵时间。 :) finally it worked. It was because of the path problem. I had to give the full path. C:\\xampp\\tomcat\\webapps\\Location_API ...
  • 由于您使用逻辑迭代来加载列表框中的项目,因此您将遇到问题选项1.使用jquery或javascript on load设置使用jstl访问表单数据的列表框的值,这将在请求范围中可用2.或者使用逻辑迭代器代替迭代列表使用html:options http://www.coderanch.com/t/57329/Struts/populate-html-select-options-struts Since you are using logic iterate to load the items in the ...
  • 我通过执行以下操作解决了这个问题: 为结果构建包装器 public class Row { String value; public String getValue() { return value; } public void setValue(String value) { this.value = value; } public String toString() { return valu ...
  • 您将文本框的值设置为floorValue,而不是newValue。 I was using onKeyUp in the jsp which was causing the trouble. instead i changed it to onBlur as it was providing the same effect as per my requirement. And thank you 'nnnnnn' for your suggestion. Its working now.
  • 声明你的循环的变量otsido: <%! public String autoPONo()throws SQLException{ String POno = null; rs=pst.executeQuery(); if(rs.next()){ String po= rs.getString("max(PONo)"); int ...
  • SQL参数仅允许在具有感知“值”的位置。 被拒绝代替桌子或柱子。 "SELECT * FROM patients WHERE ? like ? ORDER BY id" -- bad, field 'substitution' is not alowed "SELECT * FROM ? WHERE id like ? ORDER BY id" -- bad, column is not alowed "SELECT * FROM patients WHERE Name like ? ORDE ...
  • 不,
    未随请求一起提交。 而是创建一个hidden该信息的hidden输入元素。 或者可能是submit元素 这些表单中的任何一个都将作为url编码参数发送。 如果您解释目标,可能会有更好的解决方案。 考虑寻找实现目标的不同模式。 No, a
  • 在控制器函数中使用ModelMap map而不是Model模型,然后在该映射中添加属性。 还要检查jsp顶部的页面目录。 该标签中是否有任何属性,如isELIgnored='true' ,然后将其删除,然后尝试使用此属性。 我认为它应该可以解决你的问题。 干杯。 Instead of Model model in your controller function use ModelMap map and then add your attribute in that map. Also check in y ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)