CGI应用程序身份验证使用多个驱

pra*_*rat 5 authentication perl cgi driver

我一直试图通过2个驱动程序验证我的CGI应用程序,一个使用存储在数据库中的用户名/密码,另一个使用ldap活动目录.

以下是代码

$self->authen->config( 
DRIVER => [ 'DBI',
  DBH         => $self->dbh,
  TABLE       => 'user',
  CONSTRAINTS => {
    'user.username'     => '__CREDENTIAL_1__',
    'MD5:user.password' => '__CREDENTIAL_2__'
  },
],

DRIVER => [ 'Authen::Simple::LDAP',
     host   => 'ldapad.company.com',
     basedn => 'OU=XXX,OU=XX,DC=XXX,DC=XXX', 
binddn => 'CN=usename,OU=Users,OU=XXX,OU=AD,DC=XXX,DC=xxx',
bindpw => 'secret',
filter => '(cn=%s)',   
],


CREDENTIALS    => [ 'authen_username', 'authen_password' ],
STORE                => 'Session',
LOGOUT_RUNMODE       => 'logout',
LOGIN_RUNMODE        => 'login',
POST_LOGIN_RUNMODE   => 'okay',
RENDER_LOGIN         => \&my_login_form,
);
Run Code Online (Sandbox Code Playgroud)

如何使应用程序检查其他驱动程序未通过身份验证.现在,正如预期的那样,它的底部列出的驱动程序是有效的,它们都可以,具体取决于最后分配的驱动程序.

Cos*_*imo 2

我假设你正在使用CGI::Application::Plugin::Authentication. 我认为您的代码中存在一个小问题,这证明了只有最后一个可以工作的事实。

你的代码是这样的:

$self->authen->config(
  驾驶员 => [ 'DBI', ... ],
  驱动程序 => [ 'Authen::Simple::LDAP', ... ],
  凭证 => [ 'authen_username', 'authen_password' ],
  存储 => '会话',
  # ...
);

$self->authen->config()需要哈希。例如,看一下C::A::P::Authentication 发行版中的示例

作为哈希,这意味着最后一个DRIVER条目将覆盖之前的条目。我相信修复方法非常简单:

$self->authen->config(
  驾驶员 => [
       ['DBI',...],
       ['Authen::Simple::LDAP', ... ],
  ],
  凭证 => [ 'authen_username', 'authen_password' ],
  存储 => '会话',
  # ...
);

您可以在模块文档中找到这样的示例:

http://search.cpan.org/~silasmonk/CGI-Application-Plugin-Authentication/lib/CGI/Application/Plugin/Authentication.pm#config