Rails的 - 让REMOTE_USER从阿帕奇返回用户名 [英] Rails - getting remote_user to return username from apache

查看:152
本文介绍了Rails的 - 让REMOTE_USER从阿帕奇返回用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我环顾四周,颇有几分没有找到关于这个专题的一些信息,但不能让它开始工作。我有我的公司里我的网络服务器安装的Apache / tomcat的。 previously在同一个Web服务器,当我在写的CGI应用程序我能够成功通过访问获得参观者的用户名在我的网站环境VAR REMOTE_USER。现在,我骑在轨道上,变量,request.env ['REMOTE_USER']返回任何内容。

I've looked around quite a bit and did find some information on the topic but couldn't get it to work. I have apache/tomcat installed on my webserver within my company. Previously on the same webserver when I was writing CGI applications I was successfully able to get the username of visitors on my site by access the environment var REMOTE_USER. Now that I'm riding on rails, the variable, request.env['REMOTE_USER'] returns nothing.

请注意,我没有运行杂种很多网上讨论的假设。另外,我不希望建立一个认证系统,我只是希望阅读(使用REMOTE_USER)谁访问我的网站的人员的用户名。

Please note that I am not running Mongrel which many of the online discussions assume. Also, i'm not looking to build an authentication system, I'm just looking to read in (using REMOTE_USER) the username of the people who access my site.

我知道,我需要调整我的.htaccess(位于我的公用文件夹)文件来自Apache这个信息转发到我的应用程序。通过查看网络上的例子,我没有改变它。

I'm aware that I would need to tweak my .htaccess (located in my public folder) file to forward this information from apache into my application. By looking at examples on the web, I did change it to..

RewriteCond %{REMOTE_USER} (.+)
RewriteRule ^.*$ - [E=RU:%1]
RequestHeader add X-Forwarded-User %{RU}e

..但是这并没有帮助。谢谢你。

..but this didn't help. Thanks.

推荐答案

如果您添加的X转发用户,你必须阅读request.headers ['X转发的用户'],而不是request.env ['REMOTE_USER ']。

If you add X-Forwarded-User, you have to read request.headers['X-Forwarded-User'] and not request.env['REMOTE_USER'].

将这个在下面的文件并使用,而不是request.env哈希http_remote_user。

Put this in the below file and use http_remote_user instead of the request.env hash.

# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
  def http_remote_user
    request.env['HTTP_REMOTE_USER'] || request.headers['X-Forwarded-User']
  end
  helper_method :http_remote_user
end

这篇关于Rails的 - 让REMOTE_USER从阿帕奇返回用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆