[rt-users] Problems when calling RT::Init more than once?

Jan Algermissen jalgermissen at topicmapping.com
Mon Jun 21 04:59:48 EDT 2004


Hi,

I am using RT's database for general site authentication. For this I wrote
a small Perl Apache handler that I hook to Apache's authentication phase.

The authentication handler verifies the supplied credentials against RT's database,
to control access.

I am experiencing problems with the MySQL connection and I wonder if these are
related to the fact that I now call RT::Init more than once during a complete
request cycle (in the Auth phase via my handler and in the main phase via
RT::Mason::handler
defined in webmux.pl).

Bottom line: does it do any harm to call RT::Init more than once inside a single process?

[Since RT::Init is called inside the handler subroutine in webmux.pl it is called once
per request anyway, so I actually do not see any problems....?]

If anyone can help me out, many thanks in advance.

Jan

P.S. Here is the authentication handler's code just in case someone is interested in
     doing a similar thing:


package MyRTAuth;
 
use strict;
use Apache::Constants qw(:common);
 
use lib ("/opt/rt3/local/lib", "/opt/rt3/lib");
use RT;
 
RT::Init();   # does this need to go inside the handler routine?
 
sub handler
{
        my $r = shift;
        my ($res,$sent_pw) = $r->get_basic_auth_pw;
        return $res if $res != OK;
 
        my $user = $r->connection->user;
 
        my $SystemUser = new RT::CurrentUser();
        $SystemUser->LoadByName('RT_System');
 
        my $rt_user = RT::User->new($SystemUser);
        my $rv = $rt_user->Load($user);

	# does the user exist?
        if($rv eq "Couldn't find row")
        {
                return AUTH_REQUIRED;
        }

	# correct password supplied?
        if(! $rt_user->IsPassword($sent_pw) )
        {
                return AUTH_REQUIRED;
        }

        return OK;
 
}

1;
__END__

httpd.conf:

<Location />
 AuthName "Site Access"
 AuthType Basic
 PerlRequire conf/startup.pl
 PerlAuthenHandler MyRTAuth
 require valid-user
</Location>



rt-users at lists.bestpractical.com
-- 
Jan Algermissen                           http://www.topicmapping.com
Consultant & Programmer	                  http://www.gooseworks.org



More information about the rt-users mailing list