需求: 基于已有系统架构(LAMP)开发出windows集成认证,使得域内用户无需输入用户名和密码即可自动登录系统
原理: 内网用户使用NTLM 通过浏览器取得域用户信息,将信息发给domain controller 验证。 验证成功付给$_SERVER["REMOTE_USER"] 给网站模块用于验证。 外网用户,直接在网站中输入用户名密码,用之前网站的验证方式验证。
解决方案:
1. Apache 模块 AuthenNTLM (应该还有很多种,比如mod_authn_ntlm, mod_authn_kerb, mod_authn_sspi, mod_authn_winbind)
http://search.cpan.org/~speeves/Apache-AuthenNTLM-2.10
#针对整个网站都起作用 以根目录开始
<Location />
# Enable the Authentication module
PerlAuthenHandler Apache2::AuthenNTLM
# Do NTLM and basic authentication
AuthType ntlm,basic
# The name that should be displayed in the Auth box, if NTLM fails.
# This will not succeed on our setup where apache is not configured to authenticate on its own
AuthName XXXX(这个名字可以随便设置)
# Ask for a valid user.
require valid-user
# domain pdc bdc
# Domain : Your windows domain
# pdc : Primary Domain Controller
# bdc : Backup Domain controller.
#PerlAddVar ntdomain "OURDOMAIN domainpdc domainsdc"
PerlAddVar ntdomain "XXX XXX XXX" (默认的认证域名 主要的域名控制机 备用的域名控制机 没用备用的可以不写)
# What should be the default domain
PerlSetVar defaultdomain XXX (你的默认的认证域名)
# The user names are in the form "OURDOMAIN\user_name". Let us split it.
PerlSetVar splitdomainprefix 1
# Set the debug variables
PerlSetVar ntlmdebug 0
PerlSetVar ntlmauthoritative off
当然也可以将以上配置单独写入ntlm.conf文件里,此文件放在 /etc/apache2/conf.d文件夹里,我是这样做的
4. 修改 /etc/hosts 加入这么一条 : ip 主机名(pdc) ---- 用来ip地址和主机名的对应
修改 /etc/resolv.conf 加入这么两条: search domain(就是pdc.domain) nameserver ip(就是这台pdc的ip地址)
假如没有以上的修改。认证可能会报错,即:Bad/Missing NTLM/Basic Authorization Header for /
- 浏览器设置
IE浏览器设置工具--》Internet选项--》安全--》本地Intranet--》站点--》高级 加入网站 IP 这样就不会有密码请求框
Firefox 可以输入about:config 搜索ntlm 找到trust-ntlm-uris 同样输入网站 ip,这样也不会有密码请求框(多个域名或者IP用逗号分割)
- 外网密码请求框解决
使用apache2 的directive 中require deny allow order组合可以达到想要的效果。 详见黄字部分。