为什么我无法使用 Perl 的 AuthCAS 连接到我的 CAS 服务器?

发布于 2024-07-04 13:04:40 字数 1871 浏览 5 评论 0原文

我正在尝试使用现有的 CAS 服务器来验证 Perl CGI Web 脚本的登录,并使用 AuthCAS Perl 模块(v 1.3.1)。 我可以连接到 CAS 服务器来获取服务票证,但是当我尝试连接以验证票证时,我的脚本返回以下错误:IO::Socket::SSL 模块:

 500 Can't connect to [CAS Server]:443 (Bad hostname '[CAS Server]') 
 ([CAS Server] substituted for real server name)

症状/测试:

  1. 如果我将生成的身份验证 URL 输入到 Web 浏览器的地址栏中,它会按照预期返回XML 片段。 所以它不是一个坏的主机名。
  2. 如果我生成一个脚本而不使用 AuthCAS 模块,而是直接使用 IO::Socket::SSL 模块来查询 CAS 服务器以验证生成的服务票据,则 Perl 脚本将从命令行正常运行,但不能在浏览器中运行。
  3. 如果我将 AuthCAS 模块添加到第 2 项中的脚本中,该脚本将不再在命令行上运行,并且在浏览器中仍然无法运行。

这是产生错误的基本脚本:

#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use AuthCAS;
use CGI::Carp qw( fatalsToBrowser );

my $id = $ENV{QUERY_STRING};
my $q = new CGI;
my $target = "http://localhost/cgi-bin/testCAS.cgi";

my $cas = new AuthCAS(casUrl => 'https://cas_server/cas');

if ($id eq ""){
    my $login_url = $cas->getServerLoginURL($target);
    printf "Location: $login_url\n\n";
    exit 0;
} else {
    print $q->header();
    print "CAS TEST<br>\n";

    ## When coming back from the CAS server a ticket is provided in the QUERY_STRING
    print "QUERY_STRING = " . $id . "</br>\n";
    ## $ST should contain the received Service Ticket
    my $ST = $q->param('ticket');
    my $user = $cas->validateST($target, $ST);  #### This is what fails

    printf "Error: %s\n", &AuthCAS::get_errors() unless (defined $user);
}

关于冲突可能在哪里的任何想法?


该错误来自 Cebjyre 引用的片段正上方的行,即

$ssl_socket = new IO::Socket::SSL(%ssl_options);

套接字创建。 所有输入参数均正确。 我已经编辑了模块以放入调试语句并在调用之前打印出所有参数,它们都很好。 看来我必须更深入地研究 IO::Socket::SSL 模块。

I'm attempting to use an existing CAS server to authenticate login for a Perl CGI web script and am using the AuthCAS Perl module (v 1.3.1). I can connect to the CAS server to get the service ticket but when I try to connect to validate the ticket my script returns with the following error from the IO::Socket::SSL module:

 500 Can't connect to [CAS Server]:443 (Bad hostname '[CAS Server]') 
 ([CAS Server] substituted for real server name)

Symptoms/Tests:

  1. If I type the generated URL for the authentication into the web browser's location bar it returns just fine with the expected XML snippet. So it is not a bad host name.
  2. If I generate a script without using the AuthCAS module but using the IO::Socket::SSL module directly to query the CAS server for validation on the generated service ticket the Perl script will run fine from the command line but not in the browser.
  3. If I add the AuthCAS module into the script in item 2, the script no longer works on the command line and still doesn't work in the browser.

Here is the bare-bones script that produces the error:

#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use AuthCAS;
use CGI::Carp qw( fatalsToBrowser );

my $id = $ENV{QUERY_STRING};
my $q = new CGI;
my $target = "http://localhost/cgi-bin/testCAS.cgi";

my $cas = new AuthCAS(casUrl => 'https://cas_server/cas');

if ($id eq ""){
    my $login_url = $cas->getServerLoginURL($target);
    printf "Location: $login_url\n\n";
    exit 0;
} else {
    print $q->header();
    print "CAS TEST<br>\n";

    ## When coming back from the CAS server a ticket is provided in the QUERY_STRING
    print "QUERY_STRING = " . $id . "</br>\n";
    ## $ST should contain the received Service Ticket
    my $ST = $q->param('ticket');
    my $user = $cas->validateST($target, $ST);  #### This is what fails

    printf "Error: %s\n", &AuthCAS::get_errors() unless (defined $user);
}

Any ideas on where the conflict might be?


The error is coming from the line directly above the snippet Cebjyre quoted namely

$ssl_socket = new IO::Socket::SSL(%ssl_options);

namely the socket creation. All of the input parameters are correct. I had edited the module to put in debug statements and print out all the parameters just before that call and they are all fine. Looks like I'm going to have to dive deeper into the IO::Socket::SSL module.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清风疏影 2024-07-11 13:04:40

正如我发布此类问题时通常会发生的那样,我发现了问题。 事实证明 Crypt::SSLeay 模块未安装或至少未安装日期。 当然,错误消息没有给我任何线索。 更新它,所有问题都消失了,现在一切正常。

As usually happens when I post questions like this, I found the problem. It turns out the Crypt::SSLeay module was not installed or at least not up to date. Of course the error messages didn't give me any clues. Updating it and all the problems go away and things are working fine now.

浅浅 2024-07-11 13:04:40

好吧,从 模块源 看起来就像 IO::Socket 错误来自 get_https2,

[...]
unless ($ssl_socket) {
    $errors = sprintf "error %s unable to connect https://%s:%s/\n",&IO::Socket::SSL::errstr,$host,$port;
    return undef;
}
[...]

它由 callCAS 调用,而 callCAS 由 validateST 调用。

一种选择是暂时编辑模块文件以放入一些调试语句(如果可以的话),但如果我不得不猜测,我会说您提供的 casUrl 与 _parse_url 正则表达式不正确匹配 - 也许您有三个https 后面有斜杠吗?

Well, from the module source it looks like that IO::Socket error is coming from get_https2

[...]
unless ($ssl_socket) {
    $errors = sprintf "error %s unable to connect https://%s:%s/\n",&IO::Socket::SSL::errstr,$host,$port;
    return undef;
}
[...]

which is called by callCAS, which is called by validateST.

One option is to temporarily edit the module file to put some debug statements in if you can, but if I had to guess, I'd say the casUrl you are supplying isn't matching up to the _parse_url regex properly - maybe you have three slashes after the https?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文