基于Apache表单的LDAP身份验证

u0sqgete  于 6个月前  发布在  Apache
关注(0)|答案(1)|浏览(67)

我有Apache 2.4(httpd)在红帽9.0。我有基本的身份验证工作与LDAP。它给出了弹出框,要求用户名和密码。所以现在我想改变,以便我可以提出一个自定义的形式。
这就是我目前所拥有的。

<Directory /var/www/html/private>
    AuthType Basic
    AuthName "Login"
    AuthBasicAuthoritative off
    AuthBasicProvider ldap
    AuthLDAPURL "ldap://DC:389/OU=Users,dc=x,dc=com?sAMAccountName?sub?(objectClass=*)"
    Require valid-user
    AuthLDAPBindDN username
    AuthLDAPBindPassword pAsSwOrD
</Directory>

字符串
试图跟随
https://blog.sensecodons.com/2023/01/use-custom-login-page-when-using-apache.htm l
这是我试图添加的

<Directory "/do-login.html">
    SetHandler form-login-handler
    AuthFormLoginRequiredLocation "login.html"
    AuthFormLoginSuccessLocation "/admin/index.html"
    AuthFormProvider ldap
    AuthUserFile  /dev/null
    AuthType form
    AuthName "Admin"
    Session On
    SessionCookieName session path=/
</Directory>


我在第一个指令中将AuthType更改为'Form'
我有一个表格:

<form method="POST" action="/do-login.html">
  Username: <input type="text" name="httpd_username" value="" />
  Password: <input type="password" name="httpd_password" value="" />
  <input type="submit" name="login" value="Login" />
</form>


这对我不起作用,它一直把我送回login.html。
do-login.html应该是什么样子的?

pxiryf3j

pxiryf3j1#

我有2个指令,我必须把所有的ldap的东西添加到第二个,包括网址,名称和密码

<Directory /var/www/html/private>
    AuthType Form
    AuthName "Login"
    AuthFormProvider ldap
    AuthFormLoginRequiredLocation "/login.shtml"
    AuthLDAPURL "ldap://DC:389/OU=Users,dc=x,dc=com?sAMAccountName?sub?(objectClass=*)"
    Require valid-user
    AuthLDAPBindDN username
    AuthLDAPBindPassword pAsSwOrD
    Session On
    SessionCookieName session path=/
</Directory>

字符串
然后利用地理位置

<location "/do-login.html">
    SetHandler form-login-handler
    AuthFormLoginRequiredLocation "badlogin.shtml"
    AuthFormLoginSuccessLocation "/private/index.html"
    AuthFormProvider ldap
    AuthLDAPURL "ldap://DC:389/OU=Users,dc=x,dc=com?sAMAccountName?sub?(objectClass=*)"
    Require valid-user
    AuthLDAPBindDN username
    AuthLDAPBindPassword pAsSwOrD
    AuthType form
    AuthName "Login"
    Session On
    SessionCookieName session path=/
</location>


这对我来说很好用。我用HTML和CSS Package 了登录表单。我用这里找到的一些代码创建了一个很好的登录表单:

https://w3codepen.com/html-css-login-form-page/


如果凭证不正确,它将加载badlogin.shtml,这是同一个表单,但以红色字体添加了“Bad username or password”。
顺便说一下,do-login.html只是一个空白页面。你甚至不需要拥有这个页面。我只是把它作为一个空白的html文件。
使用非表单的ldap登录,用户只是得到了一个弹出框,他们以错误的格式输入了他们的凭据。使用表单,我能够自定义外观,使其看起来更用户友好,并给予所需凭据格式的说明。
希望这对某人有帮助。
2023年10月30日更新:

https://stackoverflow.com/questions/43287063/redirect-to-previous-page-after-login-from-authformloginlocation-apache2-config/44718693#44718693


我正准备发布这个问题,
我的网站有一个公共和私人部分。有链接到私人部分在一个菜单中。当一个私人链接被选中,你会被定向到登录页面。登录页面将您定向到AuthFormLoginLocation,而不是从该菜单中选择的私人页面。这可能吗?类似于:AuthFormLoginLocation =“page selected”
就像上面的那样,我就做到了这一点。所以我觉得我基于表单的Apache登录现在已经完成了。

相关问题