[rt-users] script create user in RT system with validation LDAP
Sergio Cubero
sercuto at alumni.uv.es
Thu Mar 24 10:20:12 EDT 2011
Hi all!
I want create user with perl script, but don't working.
Can you help me?
#!/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);
More information about the rt-users
mailing list