converted sync profiles to ldap to workflow

This commit is contained in:
JT Smith 2006-03-03 17:18:29 +00:00
parent f215d28b51
commit 8a86fea5f0
5 changed files with 88 additions and 154 deletions

View file

@ -133,7 +133,7 @@ sub addWorkflow {
"WebGUI::Workflow::Activity::ExpireGroupings", "WebGUI::Workflow::Activity::PurgeOldAssetRevisions",
"WebGUI::Workflow::Activity::ExpireSubscriptionCodes", "WebGUI::Workflow::Activity::PurgeOldTrash",
"WebGUI::Workflow::Activity::GetSyndicatedContent", "WebGUI::Workflow::Activity::ProcessRecurringPayments",
"WebGUI::Workflow::Activity::SummarizePassiveProfileLog"],
"WebGUI::Workflow::Activity::SyncProfilesToLdap", "WebGUI::Workflow::Activity::SummarizePassiveProfileLog"],
"WebGUI::User"=>["WebGUI::Workflow::Activity::CreateCronJob"],
"WebGUI::VersionTag"=>["WebGUI::Workflow::Activity::CommitVersionTag", "WebGUI::Workflow::Activity::RollbackVersionTag",
"WebGUI::Workflow::Activity::TrashVersionTag", "WebGUI::Workflow::Activity::CreateCronJob"]
@ -163,6 +163,8 @@ sub addWorkflow {
$activity->set("title", "Expire old subscription codes");
$activity = $workflow->addActivity("WebGUI::Workflow::Activity::SummarizePassiveProfileLog", "pbwfactivity0000000014");
$activity->set("title", "Summarize Passive Profiling Data");
$activity = $workflow->addActivity("WebGUI::Workflow::Activity::SyncProfilesToLdap", "pbwfactivity0000000015");
$activity->set("title", "Sync User Profiles With LDAP");
WebGUI::Workflow::Cron->create($session, {
title=>'Daily Maintenance',
enabled=>1,
@ -222,6 +224,7 @@ sub addWorkflow {
}, "pbcron0000000000000003");
$session->db->write("alter table assetVersionTag add column isLocked int not null default 0");
$session->db->write("alter table assetVersionTag add column lockedBy varchar(22) binary not null");
$session->config->delete("SyncProfilesToLDAP_hour");
$session->config->delete("fileCacheSizeLimit");
$session->config->delete("passiveProfileInterval");
$session->config->delete("CleanLoginHistory_ageToDelete");
@ -522,9 +525,8 @@ sub removeFiles {
unlink '../../lib/WebGUI/i18n/Asset_IndexedSearch.pm';
unlink '../../sbin/Hourly/IndexedSearch_buildIndex.pm';
rmtree('../../lib/WebGUI/Asset/Wobject/IndexedSearch');
# uncomment this after they've all been converted
#rmtree('../../sbin/Hourly');
#unlink('../../sbin/runHourly.pl');
rmtree('../../sbin/Hourly');
unlink('../../sbin/runHourly.pl');
}
#-------------------------------------------------

View file

@ -276,13 +276,6 @@
"u" : "u_companyUrl"
},
# What hour of the day (for example, 22 : 10 PM = 22:00:00)
# should WebGUI try to synchronize user profile information from
# the LDAP server. Note that this will only happen for users
# that have LDAP as their authentication.
"SyncProfilesToLDAP_hour" : 2,
# Define the subnets that WebGUI should expect Spectre communication
# to come from. All other subnets will be ignored. The subnet
# should be listed in CIDR notation.

View file

@ -1,23 +1,67 @@
package Hourly::SyncProfilesToLDAP;
package WebGUI::Workflow::Activity::SyncProfilesToLdap;
#------------------------------------------------------ -------------
# WebGUI is Copyright 2001-2006 Plain Black Corporation.
#------------------------------------------------------ -------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#------------------------------------------------------ -------------
# http://www.plainblack.com info@plainblack.com
#------------------------------------------------------ -------------
use Net::LDAP;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2006 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use WebGUI::DateTime;
use WebGUI::Session;
use WebGUI::SQL;
use base 'WebGUI::Workflow::Activity';
use Net::LDAP;
use WebGUI::Auth;
use WebGUI::User;
=head1 NAME
Package WebGUI::Workflow::Activity::SyncProfilesToLdap
=head1 DESCRIPTION
Synchoronizes the data in your LDAP directory with the WebGUI user's profile. This is a one way sync, so data comes from LDAP to WebGUI, not the other way around.
=head1 SYNOPSIS
See WebGUI::Workflow::Activity for details on how to use any activity.
=head1 METHODS
These methods are available from this class:
=cut
#-------------------------------------------------------------------
=head2 definition ( session, definition )
See WebGUI::Workflow::Activity::defintion() for details.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new($session, "AuthLDAP");
push(@{$definition}, {
name=>$i18n->get("sync profiles to ldap"),
properties=> { }
});
return $class->SUPER::definition($session,$definition);
}
my %ldapStatusCode = ( 0=>'success (0)', 1=>'Operations Error (1)', 2=>'Protocol Error (2)',
3=>'Time Limit Exceeded (3)', 4=>'Size Limit Exceeded (4)', 5=>'Compare False (5)',
6=>'Compare True (6)', 7=>'Auth Method Not Supported (7)', 8=>'Strong Auth Required (8)',
@ -51,15 +95,20 @@ sub _alias {
}
#-------------------------------------------------------------------
sub process {
my (@date, $userId, $u, $userData, $uri, $port, %args, $fieldName, $ldap, $search, $a, $b);
@date = WebGUI::DateTime::localtime(WebGUI::DateTime::time());
print $date[3];
if ($date[3] == $session{config}{SyncProfilesToLDAP_hour}) {
$a = WebGUI::SQL->read("select userId from users where authMethod='LDAP'");
=head2 execute ( )
See WebGUI::Workflow::Activity::execute() for details.
=cut
sub execute {
my $self = shift;
my ($userId, $u, $userData, $uri, $port, %args, $fieldName, $ldap, $search, $a, $b);
$a = $self->session->db->read("select userId from users where authMethod='LDAP'");
while (($userId) = $a->array) {
$u = WebGUI::User->new($userId);
my $auth = WebGUI::Auth->new("LDAP",$userId);
$u = WebGUI::User->new($self->session, $userId);
my $auth = WebGUI::Auth->new($self->session, "LDAP",$userId);
$userData = $auth->getParams;
$uri = URI->new($userData->{ldapUrl});
if ($uri->port < 1) {
@ -74,12 +123,12 @@ print $date[3];
if ($result->code == 0) {
$search = $ldap->search( base=>$userData->{connectDN}, filter=>"&(objectClass=*)" );
if($search->code) {
print "Couldn't search LDAP ".$uri->host." to find user ".$u->username." (".$userId.").\nError Message from LDAP: ".$ldapStatusCode{$search->code}."\n";
$self->session->errorHandler->warn("Couldn't search LDAP ".$uri->host." to find user ".$u->username." (".$userId.").\nError Message from LDAP: ".$ldapStatusCode{$search->code});
} elsif($search->count == 0) {
print "No results returned for user with dn ".$userData->{connectDN}."\n";
$self->session->errorHandler->warn("No results returned for user with dn ".$userData->{connectDN});
} else {
my $user = WebGUI::User->new($userId);
$b = WebGUI::SQL->read("select fieldName from userProfileField where profileCategoryId<>4");
my $user = WebGUI::User->new($self->session, $userId);
$b = $self->session->db->read("select fieldName from userProfileField where profileCategoryId<>4");
while (($fieldName) = $b->array) {
if ($search->entry(0)->get_value(_alias($fieldName)) ne "") {
$user->profileField($fieldName,$search->entry(0)->get_value(_alias($fieldName)));
@ -89,12 +138,11 @@ print $date[3];
}
$ldap->unbind;
} else {
print "Couldn't bind to LDAP host ".$uri->host."\nError Message from LDAP: ".$ldapStatusCode{$result->code}."\n";
$self->session->errorHandler->warn("Couldn't bind to LDAP host ".$uri->host."\nError Message from LDAP: ".$ldapStatusCode{$result->code});
}
}
}
$a->finish;
}
}
1;

View file

@ -1,6 +1,12 @@
package WebGUI::i18n::English::AuthLDAP;
our $I18N = {
'sync profiles to ldap' => {
message => q|Sync Profiles To LDAP|,
lastUpdated => 0,
context => q|the title for the sync profiles workflow activity|
},
'account template' => {
message => q|Account Template|,
lastUpdated => 1078852969

View file

@ -1,115 +0,0 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2006 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
our $webguiRoot;
BEGIN {
$webguiRoot = "..";
unshift (@INC, $webguiRoot."/lib");
}
use DBI;
use Getopt::Long;
use strict qw(subs vars);
use WebGUI::Session;
use WebGUI::Utility;
$|=1;
my $verbose;
my $help;
GetOptions(
'help'=>\$help,
'verbose'=>\$verbose
);
if ($help) {
print <<STOP;
Usage: perl $0
Options:
--help Displays this message.
--verbose Displays output describing the scheduler's
activities.
STOP
exit;
}
print "\nStarting.\n\n" if ($verbose);
my (@files, $cmd, $namespace, $file, $slash, $confdir, %plugins, $plugdir, $exclude);
$slash = ($^O =~ /^Win/i) ? "\\" : "/";
$confdir = $webguiRoot.$slash."etc".$slash;
$plugdir = $webguiRoot.$slash."sbin".$slash."Hourly".$slash;
print "Locating plug-ins:\n" if ($verbose);
if (opendir (PLUGDIR,$plugdir)) {
@files = readdir(PLUGDIR);
foreach $file (@files) {
if ($file =~ /(.*?)\.pm$/) {
$namespace = $1;
print "\tFound ".$namespace."\n" if ($verbose);
$cmd = "use Hourly::".$namespace;
eval($cmd);
$plugins{$namespace} = "Hourly::".$namespace."::process";
}
}
closedir(PLUGDIR);
} else {
print "Can't open $plugdir.\n";
exit;
}
if (opendir (CONFDIR,$confdir)) {
@files = readdir(CONFDIR);
foreach $file (@files) {
if ($file =~ /(.*?)\.conf$/ && $file ne "some_other_site.conf" && !($file =~ /log\.conf/ || $file =~ /(.*?)log\.conf$/)) {
print "\nProcessing ".$file.":\n" if ($verbose);
my $startTime = time();
WebGUI::Session::open($webguiRoot,$file);
if ($session{setting}{specialState} eq "upgrading") {
print "\nSkipping because this site is undergoing an upgrade.\n" if ($verbose);
WebGUI::Session::close();
next;
}
WebGUI::Session::refreshUserInfo(3,$session{dbh});
foreach $namespace (keys %plugins) {
my $taskTime = time();
print "\t".$namespace if ($verbose);
$exclude = $session{config}{excludeHourly};
$exclude =~ s/ //g;
unless (isIn($namespace, split(/,/,$exclude))) {
$cmd = $plugins{$namespace};
&$cmd($verbose);
}
print " (".(time()-$taskTime)." seconds)\n" if ($verbose);
}
WebGUI::Session::end($session{var}{sessionId});
WebGUI::Session::close();
print "\tTOTAL TIME: ".(time()-$startTime)." seconds\n" if ($verbose);
}
}
closedir(CONFDIR);
} else {
print "Can't open $confdir.\n";
exit;
}
print "\nFinished.\n" if ($verbose);