[rt-users] script create user in RT system with validation LDAP

Kevin Falcone falcone at bestpractical.com
Thu Mar 24 11:58:06 EDT 2011


On Thu, Mar 24, 2011 at 03:20:12PM +0100, Sergio Cubero wrote:
> I want create user with perl script, but don't working.
> Can you help me?

How doesn't it work? 
Please describe the failure and provide the logs.

-kevin

> #!/usr/bin/perl
> use lib ("/usr/local/rt-3.8.2/lib/");
> use RT::Interface::CLI qw(CleanEnv);
> use RT;
> RT::LoadConfig();
> RT::Init();
> use RT::Ticket;
> use RT::CurrentUser;
> use RT::CustomField;
> use RT::Action::Generic;
> use RT::Transaction;
> use MIME::Entity;
> package RT::Action::MyAction;
> use base qw(RT::Action::Generic);
> use RT::Authen::ExternalAuth::LDAP;
> use RT::Authen::ExternalAuth::DBI;
> 
> my $user = 'username';
> my $mail = 'username at domain.com';
> RT->Config->Get('WebExternalAuto');
> 
> $session->{'CurrentUser'} = RT::CurrentUser->new();
> $session->{'CurrentUser'}->Load($user);
> 
> my $UserObj = RT::User->new($RT::SystemUser);
> print $UserObj."\n";
> my ($val, $msg) = $UserObj->SetName($user);
> 
> my ($val, $msg) =
> 
> $UserObj->Create(
>                  %{ref($RT::AutoCreate) ? $RT::AutoCreate : {}},
>                  Name   => $user,
>                  Gecos  => $user,
>                  _RecordTransaction => 1,
>                  EmailAddress => $mail,
>                  RealName     => 'User USer',
>                  Comments => 'user LDAP',
>                  WorkPhone => 'phone,
>                  Address1 => 'streetAddress',
>                  City => 'l',
>                  State => 'st',
>                  Zip => 'postalCode',
>                  Country => 'co'
>                  );
> $RT::Logger->info("Autocreated authenticated user " . $UserObj->Name .
>                                    " (" . $UserObj->Id . ")\n");
> 
> $session{'CurrentUser'}->Load($user) if $UserObj->Id;
> $RT::Logger->error( "No puedo crear el usuario $user: $msg" );
> 
> if(RT::Authen::ExternalAuth::UserExists($user)){ print "EXISTS";}
> else {print "NO EXISTS";}
> 
> 
> 
> $RT::Logger->info(  "Autocreated external user",
>                                 $UserObj->Name,
>                                 "(",
>                                 $UserObj->Id,
>                                 ")");
> 
>             $RT::Logger->debug("Loading new user (",
>                                 $username,
>                                 ") into current session");
>             $session->{'CurrentUser'}->Load($username);
> 
> 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20110324/5d873519/attachment.sig>


More information about the rt-users mailing list