English 中文(简体)
Authentication Module Issues with Apache 2 and Perl
原标题:

I am SharePoint Developer trying to get a Perl module to work with Subversion, but I think something is wrong with my syntax. I just need to get the username and password, pass it into the webservice, get a true/false and authenticate based on that information. Here is the code to the module in Perl:

package Apache2::AuthGetUser; #authenticates users based on bool value from a asmx webservice
use SOAP::Lite;
use Data::Dumper;
use strict;
use warnings;
use Apache2::Access();
use Apache2::RequestRec();
use Apache2::Const  :common ;

sub handler {
    my $r = shift;
    my $username = $r->user;
    my ($status, $password) = $r->get_basic_auth_pw;
    return $status unless $status == Apache2::Const::OK;

    my $endpoint = "http://localhost:2010/CIM.FBAAuthentication/12/template/layouts/wsFBAAuthentication.asmx"; #endpoint
    my $namespace = "http://tempuri.org/"; #namespace
    my $wsfunction = "AuthenticateUser"; #webservice function
    my $webservice = SOAP::Lite
        ->uri($namespace)
        ->on_action(sub { join  / , $namespace, $_[1] })
        ->proxy($endpoint);

    #my $method = SOAP::Data->name($wsfunction)
    my $method = SOAP::Data->name($wsfunction)
      ->attr({xmlns => $namespace});


    my @params = (SOAP::Data->name( UserName )->value($username)->type(  ), SOAP::Data->name( Password )->value($password)->type(  ));

    my $result = $webservice->call($method=>@params)->result;
    if($result ne "true"){
          $r->note_basic_auth_failure;
          #$r->log_reason($result);
          return AUTH_REQUIRED;
    }

    return Apache2::Const::OK;

}
1;

If anyone has any suggestions please let me know. I am receiving an error like such in the Apache Config files: Can t call method "value" on an undefined value at C:/usr/site/lib/Apache2/AuthGetUser.pm line 30. Thanks for everything. If I get this to work I will have a blog post upcoming.

问题回答

Try breaking down this line

 my @params = (SOAP::Data->name( UserName )->value($username)->type(  ), SOAP::Data->name( Password )->value($password)->type(  ));

For example does

 my $userParam = SOAP::Data->name( UserName )->value($username)->type( xsd:string );

work? How about:

 my $userParam = SOAP::Data->new(name =>  UserName , value => $username, type =>  xsd:string );

with

 my @params = ($userParam, $pwdParam);

where you define $pwdParam similarly.





相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签