From 35f601e7698cdbec2c4744addbe496865bf7e37c Mon Sep 17 00:00:00 2001 From: Liwiusz Ociepa Date: Tue, 6 May 2008 15:14:58 +0000 Subject: [PATCH] Cache Credentials added (login:proj -> "sha1_hex(pass)) git-svn-id: http://redmine.rubyforge.org/svn/branches/swistak@1419 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- extra/svn/Redmine.pm | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/extra/svn/Redmine.pm b/extra/svn/Redmine.pm index 618c39db5..4ae20df51 100644 --- a/extra/svn/Redmine.pm +++ b/extra/svn/Redmine.pm @@ -61,6 +61,8 @@ Authen::Simple::LDAP (and IO::Socket::SSL if LDAPS is used): ## Optional where clause (fulltext search would be slow and ## database dependant). # RedmineDbWhereClause "and members.role_id IN (1,2)" + ## Optional credentials cache size + # RedmineCacheCredsMax 50 To be able to browse repository inside redmine, you must add something @@ -108,6 +110,8 @@ use Apache2::ServerRec qw(); use Apache2::RequestRec qw(); use Apache2::RequestUtil qw(); use Apache2::Const qw(:common :override :cmd_how); +use APR::Pool (); +use APR::Table (); # use Apache2::Directive qw(); @@ -133,6 +137,11 @@ my @directives = ( req_override => OR_AUTHCFG, args_how => TAKE1, }, + { + name => 'RedmineCacheCredsMax', + req_override => OR_AUTHCFG, + args_how => TAKE1, + }, ); sub RedmineDSN { set_val('RedmineDSN', @_); } @@ -152,6 +161,16 @@ sub RedmineDbWhereClause { $self->{RedmineQuery} = trim($query.($arg ? $arg : "").";"); } +sub RedmineCacheCredsMax { + my ($self, $parms, $arg) = @_; + if ($arg) { + $self->{RedmineCachePool} = APR::Pool->new; + $self->{RedmineCacheCreds} = APR::Table::make($self->{RedmineCachePool}, $arg); + $self->{RedmineCacheCredsCount} = 0; + $self->{RedmineCacheCredsMax} = $arg; + } +} + sub trim { my $string = shift; $string =~ s/\s{2,}/ /g; @@ -243,6 +262,11 @@ sub is_member { my $pass_digest = Digest::SHA1::sha1_hex($redmine_pass); my $cfg = Apache2::Module::get_config(__PACKAGE__, $r->server, $r->per_dir_config); + my $usrprojpass; + if ($cfg->{RedmineCacheCredsMax}) { + $usrprojpass = $cfg->{RedmineCacheCreds}->get($redmine_user.":".$project_id); + return 1 if (defined $usrprojpass and ($usrprojpass eq $pass_digest)); + } my $query = $cfg->{RedmineQuery}; my $sth = $dbh->prepare($query); $sth->execute($redmine_user, $project_id); @@ -276,6 +300,20 @@ sub is_member { $sth->finish(); $dbh->disconnect(); + if ($cfg->{RedmineCacheCredsMax} and $ret) { + if (defined $usrprojpass) { + $cfg->{RedmineCacheCreds}->set($redmine_user.":".$project_id, $pass_digest); + } else { + if ($cfg->{RedmineCacheCredsCount} < $cfg->{RedmineCacheCredsMax}) { + $cfg->{RedmineCacheCreds}->set($redmine_user.":".$project_id, $pass_digest); + $cfg->{RedmineCacheCredsCount}++; + } else { + $cfg->{RedmineCacheCreds}->clear(); + $cfg->{RedmineCacheCredsCount} = 0; + } + } + } + $ret; } -- 2.39.5