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

Kevin Falcone falcone at bestpractical.com
Thu Mar 24 16:48:22 EDT 2011


On Thu, Mar 24, 2011 at 06:46:19PM +0100, sercuto wrote:
> I have change the script. I running the script and local users or
> LDAP users, but don't  create user.

Did you check if you already have a user with a blank EmailAddress
like I suggested?

select count(*) from Users where EmailAddress = '';
your logs say you're not pulling email back from LDAP

Maybe you should explain what you're trying to do.  It is possible
that there are better ways to accomplish your goal.
If all you want to do is require that new users exist in LDAP, then
make sure that AutoCreateNonExternalUsers is set to 0.

-kevin

> This is my new script:
> 
> #!/usr/bin/perl
> use lib ("/usr/local/rt-3.8.2_pruebas/lib/");
> 
> use RT::Interface::CLI qw(CleanEnv);
> use RT;
> use RT::Util;
> 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 = 'pruebas';
> my $mail = 'pruebas at dominio.com';
> 
> 
> $session{'CurrentUser'} = RT::CurrentUser->new();
> my $load_method = RT->Config->Get('WebExternalGecos') ?
> 'LoadByGecos' : 'Load';
> $session{'CurrentUser'} = RT::CurrentUser->new();
> $session{'CurrentUser'}->$load_method($user);
>  my $UserObj = RT::User->new(RT::CurrentUser->new('RT_System'));
>             my ($val, $msg) = $UserObj->Create(
>                                                %{ref($RT::AutoCreate)
> ? $RT::AutoCreate : {}},
>                                                Name   => $user,
>                                                Gecos  => $user,
>                                                );
> 
> $session{'CurrentUser'}->Load($user) if $UserObj->Id;
> $RT::Logger->error( "No puedo crear el usuario $user: $msg" );
> 
> 
> -------------------------------------------------------------------------------------------
> 
> This is my ouput log file:
> 
> [Thu Mar 24 17:40:34 2011] [debug]:
> RT::Authen::ExternalAuth::CanonicalizeUserInfo called by RT::User
> /usr/local/rt-3.8.2_pruebas/lib//RT/User_Vendor.pm 20 with:
> Disabled: 0, EmailAddress: , Gecos: pruebas, Name: pruebas,
> Privileged: 0
> (/usr/local/rt-3.8.2_pruebas/lib//RT/Authen/ExternalAuth.pm:450)
> [Thu Mar 24 17:40:34 2011] [debug]: Attempting to get user info
> using this external service:
> (/usr/local/rt-3.8.2_pruebas/lib//RT/Authen/ExternalAuth.pm:458)
> [Thu Mar 24 17:40:34 2011] [info]:
> RT::Authen::ExternalAuth::CanonicalizeUserInfo returning Disabled:
> 0, EmailAddress: , Gecos: pruebas, Name: pruebas, Privileged: 0
> (/usr/local/rt-3.8.2_pruebas/lib//RT/Authen/ExternalAuth.pm:536)
> [Thu Mar 24 17:40:34 2011] [error]: No puedo crear el usuario
> pruebas: Could not set user info (./crea_user2.pl:39)
> ...................................................................................................................................
> 
> thanks.
> 
> El 24/03/2011 18:33, Kevin Falcone escribió:
> >On Thu, Mar 24, 2011 at 05:22:05PM +0100, sercuto wrote:
> >>Mi log file is this:
> >I don't see most of your log messages showing up there, especially the
> >part that tells you if this is an external or internal user.  Are they
> >getting cut out?
> >
> >You're also not returning an email address for the user, which makes
> >me think you might already have a user in the system with a blank
> >email address and RT won't allow you to make two like that.
> >
> >-kevin
> >
> >>[Thu Mar 24 16:20:36 2011] [debug]:
> >>RT::Authen::ExternalAuth::CanonicalizeUserInfo called by RT::User
> >>/usr/local/rt-3.8.2_pruebas/lib//RT/User_Vendor.pm 20 with:
> >>Disabled: 0, EmailAddress: , Gecos: pruebas, Name: pruebas,
> >>Privileged: 0
> >>(/usr/local/rt-3.8.2_pruebas/lib//RT/Authen/ExternalAuth.pm:450)
> >>[Thu Mar 24 16:20:36 2011] [debug]: Attempting to get user info
> >>using this external service:
> >>(/usr/local/rt-3.8.2_pruebas/lib//RT/Authen/ExternalAuth.pm:458)
> >>[Thu Mar 24 16:20:36 2011] [info]:
> >>RT::Authen::ExternalAuth::CanonicalizeUserInfo returning Disabled:
> >>0, EmailAddress: , Gecos: pruebas, Name: pruebas, Privileged: 0
> >>(/usr/local/rt-3.8.2_pruebas/lib//RT/Authen/ExternalAuth.pm:536)
> >>[Thu Mar 24 16:20:36 2011] [error]: No puedo crear el usuario
> >>pruebas: Could not set user info (./scripts/crea_user2.pl:39)
> >>
> >>Thanks.
> >>
> >>El 24/03/2011 16:58, Kevin Falcone escribió:
> >>>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/e6e08149/attachment.sig>


More information about the rt-users mailing list