user undef

user undef

am 30.09.2009 16:16:54 von Bernhard Janetzki

--0016e6dbe5b5ce1be10474cc2e50
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hello together,
i'm trying basic authentication via

## apache2 config:

SetHandler perl-script
PerlAuthenHandler DataExchange::AuthHandler
#PerlResponseHandler ModPerl::Registry
Options +ExecCGI
PerlOptions +GlobalRequest

AuthType Basic
AuthName "The Gate"
Require valid-user



## Example script:

package DataExchange::AuthHandler;

use strict;
use warnings;

use Apache2::Access ();
use Apache2::RequestUtil ();

use Apache2::Const -compile =3D> qw(OK HTTP_UNAUTHORIZED);

sub handler {
my $r =3D shift;

warn $r->user();

my $password =3D $r->get_basic_auth_pw;

my $user =3D $r->user;
if ($r->user eq $password) {
print Apache2::Const::OK;
}

$r->note_basic_auth_failure;
return Apache2::Const::HTTP_UNAUTHORIZED;
}

1;

My password is filled up, but $r->user is undefined...
Any ideas?

Thanks!
Börni

p.s. mod_perl 2.0.4

--0016e6dbe5b5ce1be10474cc2e50
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hello together,
i'm trying basic authentication via

## apache=
2 config:
      =A0 <Location /auth>
    =
        =A0 SetHandler perl-script
      =A0=
       PerlAuthenHandler DataExchange::AuthHandler

            =A0 #PerlResponseHandler ModPerl::Regis=
try
            =A0 Options +ExecCGI
  =
          =A0 PerlOptions +GlobalRequest

  =
          =A0 AuthType Basic
      =A0=
       AuthName "The Gate"
      =A0=
       Require valid-user

      =A0 </Location>


## Example script:
r>package DataExchange::AuthHandler;

use strict;
use warnings; >
use Apache2::Access    =A0 ();
use Apache2::RequestUtil ();=


use Apache2::Const -compile =3D> qw(OK HTTP_UNAUTHORIZED);


sub handler {
  =A0 my $r =3D shift;
  =A0
  =A0 =
warn $r->user();
  =A0
     =A0 my $password =3D $r-&=
gt;get_basic_auth_pw;

  =A0 my $user =3D $r->user;  =A0 <=
br>  =A0 if ($r->user eq $password) {
  =A0   =A0 print A=
pache2::Const::OK;

  =A0 }

  =A0 $r->note_basic_auth_failure;
  =A0 r=
eturn Apache2::Const::HTTP_UNAUTHORIZED;
}

1;

My password =
is filled up, but $r->user is undefined...
Any ideas?

Thanks!<=
br>Börni


p.s. mod_perl 2.0.4


--0016e6dbe5b5ce1be10474cc2e50--

Re: user undef

am 30.09.2009 16:28:48 von Devin Teske

I believe what you want is:

# To set the variable so that CGI scripts can access $ENV{'REMOTE_USER'}
# which is normally populated by Basic-Auth (this is only if you want to
# take control over the variable... populating it yourself)
#
$r->subprocess_env(REMOTE_USER =3D> $user);

# To get the variable from the Apache request connection, you need to
# first populate %ENV
#
$r->subprocess_env;
my $user =3D $ENV{'REMOTE_USER'}

--
Devin

On Wed, 2009-09-30 at 16:16 +0200, Bernhard Janetzki wrote:
> Hello together,
> i'm trying basic authentication via
>=20
> ## apache2 config:
>
> SetHandler perl-script
> PerlAuthenHandler DataExchange::AuthHandler
> #PerlResponseHandler ModPerl::Registry
> Options +ExecCGI
> PerlOptions +GlobalRequest
>=20
> AuthType Basic
> AuthName "The Gate"
> Require valid-user
>

>=20
>=20
> ## Example script:
>=20
> package DataExchange::AuthHandler;
>=20
> use strict;
> use warnings;
>=20
> use Apache2::Access ();
> use Apache2::RequestUtil ();
>=20
> use Apache2::Const -compile =3D> qw(OK HTTP_UNAUTHORIZED);
>=20
> sub handler {
> my $r =3D shift;
> =20
> warn $r->user();
> =20
> my $password =3D $r->get_basic_auth_pw;
>=20
> my $user =3D $r->user; =20
> if ($r->user eq $password) {
> print Apache2::Const::OK;
> }
>=20
> $r->note_basic_auth_failure;
> return Apache2::Const::HTTP_UNAUTHORIZED;
> }
>=20
> 1;
>=20
> My password is filled up, but $r->user is undefined...
> Any ideas?
>=20
> Thanks!
> Börni
>=20
> p.s. mod_perl 2.0.4
--=20
Cheers,
Devin Teske

-> CONTACT INFORMATION <-
Field Engineer
Metavante Corporation
626-573-6040 Office
510-735-5650 Mobile
devin.teske@metavante.com

-> LEGAL DISCLAIMER <-
This message contains confidential and proprietary information
of the sender, and is intended only for the person(s) to whom it
is addressed. Any use, distribution, copying or disclosure by any
other person is strictly prohibited. If you have received this
message in error, please notify the e-mail sender immediately,
and delete the original message without making a copy.

-> END TRANSMISSION <-

Re: user undef

am 30.09.2009 16:44:14 von torsten.foertsch

On Wed 30 Sep 2009, Bernhard Janetzki wrote:
> Hello together,
> i'm trying basic authentication via
>
> ## apache2 config:
>
> SetHandler perl-script
> PerlAuthenHandler DataExchange::AuthHandler
> #PerlResponseHandler ModPerl::Registry
> Options +ExecCGI
> PerlOptions +GlobalRequest
>
> AuthType Basic
> AuthName "The Gate"
> Require valid-user
>

>
>
> ## Example script:
>
> package DataExchange::AuthHandler;
>
> use strict;
> use warnings;
>
> use Apache2::Access ();
> use Apache2::RequestUtil ();
>
> use Apache2::Const -compile => qw(OK HTTP_UNAUTHORIZED);
>
> sub handler {
> my $r = shift;
>
> warn $r->user();
>
> my $password = $r->get_basic_auth_pw;

have a look at
http://perl.apache.org/docs/2.0/api/Apache2/Access.html#C_ge t_basic_auth_pw_

get_basic_auth_pw returns a status and the password. Your code has to
check that status before proceeding.

see also
http://perl.apache.org/docs/2.0/user/handlers/http.html#Perl AuthenHandler

Torsten

--
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net