You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Kiran k <k_...@rediffmail.com> on 2001/04/10 12:31:56 UTC
Authhandler
Hi ,
I am having problems with the stacked handlers , i have enclosed the code below ,
the error i get is undefined value ($r) in sub authenticate
package SetRealm1;
use Apache;
use Apache::Constants qw(:common);
use DBI;
use diagnostics;
sub handler {
my $r = shift;
$r->push_handlers(PerlAuthenHandler => \authenticate());
## uri's are
return OK unless is_protected($r);
my $realm = get_realm($r);
my $authheader = 'Basic realm="'.$realm.'"';
$r->header_out("WWW-Authenticate" ,$authheader);
## Return 401 to browser and prompt for login
$r->status(AUTH_REQUIRED);
$r->send_http_header("text/html");
return AUTH_REQUIRED;
}
sub get_realm {
my $r = shift;
return " Test".int(rand(1000000)) if ($r->uri =~ /\/test/);
}
sub is_protected {
my $r = shift;
my @protected = ('\/test','\/icons');
for (@protected) { return 1 if ($r->uri =~ /$_/); }
return 0;
}
sub authenticate {
my $r = shift;
return OK unless $r->is_initial_req;
my ($res,$password) = $r->get_basic_auth_pw;
$r->log_reason("res is $res pword is $password ");
return $res if $res != OK;
my $username = $r->connection->user;
unless ($username && $pass)
{
$r->note_basic_auth_failure;
$r->log_reason("Did not provide username");
return AUTH_REQUIRED;
}
### check against database
return OK;
}
1;
thanks in advance
Kiran
_____________________________________________________
Chat with your friends as soon as they come online. Get Rediff Bol at
http://bol.rediff.com
Re: Authhandler
Posted by Mike Cameron <mc...@mirusweb.com>.
Kiran k wrote:
> Hi ,
> I am having problems with the stacked handlers , i have enclosed the code below ,
>
> the error i get is undefined value ($r) in sub authenticate
>
> package SetRealm1;
>
> use Apache;
> use Apache::Constants qw(:common);
> use DBI;
> use diagnostics;
> sub handler {
> my $r = shift;
>
> $r->push_handlers(PerlAuthenHandler => \authenticate());
the push_handlers method does not pass the Apache request object as its first argument.
>
> ## uri's are
> return OK unless is_protected($r);
> my $realm = get_realm($r);
> my $authheader = 'Basic realm="'.$realm.'"';
> $r->header_out("WWW-Authenticate" ,$authheader);
>
> ## Return 401 to browser and prompt for login
> $r->status(AUTH_REQUIRED);
> $r->send_http_header("text/html");
>
> return AUTH_REQUIRED;
> }
>
> sub get_realm {
> my $r = shift;
> return " Test".int(rand(1000000)) if ($r->uri =~ /\/test/);
> }
>
> sub is_protected {
> my $r = shift;
> my @protected = ('\/test','\/icons');
>
> for (@protected) { return 1 if ($r->uri =~ /$_/); }
> return 0;
> }
>
> sub authenticate {
> my $r = shift;
>
Add this....
$r||=Apache->request;
>
> return OK unless $r->is_initial_req;
>
> my ($res,$password) = $r->get_basic_auth_pw;
> $r->log_reason("res is $res pword is $password ");
> return $res if $res != OK;
>
> my $username = $r->connection->user;
> unless ($username && $pass)
> {
> $r->note_basic_auth_failure;
> $r->log_reason("Did not provide username");
> return AUTH_REQUIRED;
> }
> ### check against database
>
> return OK;
>
> }
>
> 1;
>
> thanks in advance
>
> Kiran
>
> _____________________________________________________
> Chat with your friends as soon as they come online. Get Rediff Bol at
> http://bol.rediff.com
Re: Authhandler
Posted by Robin Berjon <ro...@knowscape.com>.
At 10:31 10/04/2001 +0000, Kiran k wrote:
> I am having problems with the stacked handlers , i have enclosed the code
>below ,
>
>the error i get is undefined value ($r) in sub authenticate
>
> $r->push_handlers(PerlAuthenHandler => \authenticate());
You're missing a & in there :) It's calling authenticate (without any
argument) and try setting the AuthenHandler to a ref of whatever it would
return if it didn't die.
$r->push_handlers(PerlAuthenHandler => \&authenticate);
_______________________________________________________________________
Robin Berjon <ro...@knowscape.com> -- CTO
k n o w s c a p e : // venture knowledge agency www.knowscape.com
--
Learn from your parents mistakes - use birth control.
_______________________________________________________________________
Re: Authhandler
Posted by Paul <yd...@yahoo.com>.
--- Kiran k <k_...@rediffmail.com> wrote:
> . . .
> the error i get is undefined value ($r) in sub authenticate
> . . .
> r->push_handlers(PerlAuthenHandler =>> \authenticate());
r->push_handlers has no lexical symbol, and authenticate has no lexical
and no argument. Try this:
$r->push_handlers(PerlAuthenHandler =>> \&authenticate($r));
^ ^ ^^
Also,
> . . .
> sub authenticate {
> my $r = shift;
Try adding a back-up check:
my $r = shift || Apache->request;
That shouldn't be necessary, but it should also never be used; if it
does get used, it's covering your assets from some other error
somewhere else. =o)
Paul
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/