[英]How do I set REMOTE_USER in a HTTP header?
I've got an issue with my Apache settings.我的 Apache 设置有问题。
I installed a web application that partly accepts external authentication:我安装了一个部分接受外部身份验证的 Web 应用程序:
Here is the issue : I can authenticate successfully (most of the time) but my HTTP header is set to null.这是问题:我可以成功进行身份验证(大部分时间),但我的 HTTP 标头设置为空。
Some additional details :一些额外的细节:
With the following Apache config file I have the authentication form when I try to access my application but the REMOTE_USER header is set to null.使用以下 Apache 配置文件,当我尝试访问我的应用程序时,我有身份验证表单,但 REMOTE_USER 标头设置为空。
Listen 2208 <VirtualHost *:2208> RewriteEngine on DocumentRoot "/path/to/static" <Directory "/path/to/static"> Options +Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny Allow from all AuthType Basic AuthName "Authentifiez vous" PerlAuthenHandler Apache2::AuthenNIS PerlAuthzHandler Apache2::AuthzNIS PerlSetVar AllowAlternateAuth no require valid-user </Directory> RewriteEngine on RewriteRule . - [E=RU:%{LA-U:REMOTE_USER}] RequestHeader set REMOTE_USER %{RU}e RewriteRule ^/apps$ /apps/ [R] RewriteRule ^/static/style/(.*) /path/to/static/june_2007_style/blue/$1 [L] RewriteRule ^/static/scripts/(.*) /path/to/static/scripts/packed/$1 [L] RewriteRule ^/static/(.*) /path/to/static/$1 [L] RewriteRule ^/favicon.ico /path/to/static/favicon.ico [L] RewriteRule ^/robots.txt /path/to/static/robots.txt [L] RewriteRule ^(.*) http://localhost:2209$1 [P] </VirtualHost>
If I set RequestHeader set REMOTE_USER "username" the application opens on the corresponding user session.如果我设置 RequestHeader set REMOTE_USER "username" 应用程序打开相应的用户会话。
To see the value of REMOTE_USER I use the Firebug Firefox module to display the values of the http header + my application has a script that displays the value of variables passed to it.要查看 REMOTE_USER 的值,我使用 Firebug Firefox 模块来显示 http 标头的值 + 我的应用程序有一个脚本来显示传递给它的变量的值。
I tested an almost identical Apache configuration on an index.php page that displays the values of server variables in a http request.我在 index.php 页面上测试了几乎相同的 Apache 配置,该页面显示 http 请求中服务器变量的值。 The difference lies in the RewriteRules.
不同之处在于 RewriteRules。
<?PHP
foreach($_SERVER as $key_name => $key_value) {
print $key_name . " = " . $key_value . "<br>";
}
?>
In this case, I get a REMOTE_USER et HTTP_REMOTE_USER with a username value.在这种情况下,我得到一个带有用户名值的 REMOTE_USER 和 HTTP_REMOTE_USER。
I don't understand where my problem lies.我不明白我的问题出在哪里。
Apache 2.2.31 RedHat 6.5 Apache 2.2.31 红帽 6.5
Thanks in advance !提前致谢 !
do NOT use the following, because you will get into trouble with execution phases if the REMOTE_USER is set with a module like mod_authn_ntlm (ntlm with local computer, see https://support.microsoft.com/en-us/kb/896861 ).请勿使用以下内容,因为如果 REMOTE_USER 设置为 mod_authn_ntlm 等模块(本地计算机的 ntlm,请参阅https://support.microsoft.com/en-us/kb/896861 ),您将在执行阶段遇到问题.
RewriteCond %{LA-U:REMOTE_USER} (.+)
RewriteRule . - [E=RU:%1]
RequestHeader set X-Remote-User %{RU}e
instead use the following methods:而是使用以下方法:
RequestHeader set X-Remote-User expr=%{REMOTE_USER}
there is also a solution with mod_ssl还有一个使用 mod_ssl 的解决方案
RequestHeader set X-Remote-User %{REMOTE_USER}s
In Apache 2.2 server we gave below configuration.在 Apache 2.2 服务器中,我们给出了以下配置。 We have C# ASP.NET Core 2.1 application and in our HTTP Request header we get user name like below
我们有 C# ASP.NET Core 2.1 应用程序,在我们的 HTTP 请求标头中,我们得到如下用户名
<LocationMatch ^/mylocation>
AuthName "NTLM Authentication"
NTLMAuth on
NTLMAuthHelper "/usr/bin/ntlm_auth --helper-protocol=squid-2.5-ntlmssp"
NTLMBasicAuthoritative on
NTLMBasicRealm xxx_yy
AuthType NTLM
require valid-user
RewriteCond %{LA-U:REMOTE_USER} (.+)
RewriteRule . - [E=RU:%1]
RequestHeader set X-Remote-User %{RU}e
</LocationMatch>
In our C# ASP.NET Core 2.1 application application we get below in HTTP Request Header在我们的 C# ASP.NET Core 2.1 应用程序中,我们在 HTTP 请求标头中得到以下内容
Key: X-Remote-User, Value=xxx_yy\abcdefg
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.