Skip to main content
 首页 » 编程设计

python之Web2py + MS SQL Server 2008 R2 + LDAP 身份验证 HelloWorld 应用程序

2025年05月04日35落叶

一段时间以来,我一直在出色的 *nix 环境中使用 Web2py,并在我的个人项目中使用开源 RDMS(MySQL、Postgre、SQLLite 等)。

对于我完全在 .Net 环境中工作的工作场所,我需要制作一个快速的 Web 应用程序(员工主数据维护),该应用程序在具有身份验证和用户角色的本地 Intranet 上运行。

我计划在 web2py 上开发应用程序并将其部署在默认的 Rocket 服务器上,但被 DAL 困住了。我已经尝试过 pyodbc、mssql、mssql2 适配器以及人们在 google Group 和其他论坛上完成的所有工作。

我的生产和部署环境详细信息是:

操作系统:MS Windows Server 2008
数据库:MS SQL Server 2008 R2(通过 LAN 托管,使用 Windows 身份验证而非 SQL 身份验证)
python :2.7
WebServer:最好是 IIS 7.0,但我可以在 Rocket 上工作。

是否有涵盖以下主题的“HelloWorld”应用程序教程:

  1. 在 Web2py 中使用用户角色的 Windows 域身份验证
  2. Web2py-to-MSSQLServer2008R2 DAL
  3. Web2py-IIS7.0部署

如果有人可以帮助我,我可以在完成后将其发布为 web2py 设备。

请您参考如下方法:

这是一个部分答案,它只处理使用 Active Directory 的身份验证(我假设它与域身份验证相同或相似)。我不是 Windows 专家,但有本地 Windows 管理员帮助我。这是我在 web2py 中为此应用程序放入 db.py 文件的代码。

if localauth: 
    # I set localauth to 1 when using the app on my home lan, else 0 
    # I am a consultant and not always connected to the client VPN 
    # FYI, I do have a db of same type and name with same user/pw at home 
    # in this case use the basic login that comes as default with web2py 
    pass 
else: 
    from gluon.contrib.login_methods.ldap_auth import ldap_auth 
    auth.settings.login_methods = [ldap_auth(mode='ad', 
                                             server='<server ip address>', 
                                             base_dn='<base_dn>')] 
    # the above line forces active directory to be the ONLY authentication method 
# my base_dn looked like this: 'OU=<ou>,DC=<subdomain>,DC=<domain>,DC=<tld e.g. com, net, edu, etc.>' 
# an active directory knowledgeable person can help you here 

周杰伦