142 |
142 |
args_how => TAKE1,
|
143 |
143 |
errmsg => 'RedmineCacheCredsMax must be decimal number',
|
144 |
144 |
},
|
|
145 |
{
|
|
146 |
name => 'RedmineCacheCredsMaxAge',
|
|
147 |
req_override => OR_AUTHCFG,
|
|
148 |
args_how => TAKE1,
|
|
149 |
errmsg => 'RedmineCacheCredsMaxAge must be decimal number',
|
|
150 |
},
|
145 |
151 |
);
|
146 |
152 |
|
147 |
153 |
sub RedmineDSN {
|
... | ... | |
175 |
181 |
$self->{RedmineCacheCreds} = APR::Table::make($self->{RedmineCachePool}, $arg);
|
176 |
182 |
$self->{RedmineCacheCredsCount} = 0;
|
177 |
183 |
$self->{RedmineCacheCredsMax} = $arg;
|
|
184 |
$self->{RedmineCacheCredsMaxAge} ||= 300;
|
178 |
185 |
}
|
179 |
186 |
}
|
180 |
187 |
|
|
188 |
sub RedmineCacheCredsMaxAge { set_val('RedmineCacheCredsMaxAge', @_); }
|
|
189 |
|
181 |
190 |
sub trim {
|
182 |
191 |
my $string = shift;
|
183 |
192 |
$string =~ s/\s{2,}/ /g;
|
... | ... | |
348 |
357 |
my $access_mode = defined $read_only_methods{$r->method} ? "R" : "W";
|
349 |
358 |
|
350 |
359 |
my $cfg = Apache2::Module::get_config(__PACKAGE__, $r->server, $r->per_dir_config);
|
351 |
|
my $usrprojpass;
|
|
360 |
my $cache_key;
|
352 |
361 |
if ($cfg->{RedmineCacheCredsMax}) {
|
353 |
|
$usrprojpass = $cfg->{RedmineCacheCreds}->get($redmine_user.":".$project_id.":".$access_mode);
|
354 |
|
return 1 if (defined $usrprojpass and ($usrprojpass eq $pass_digest));
|
|
362 |
$cache_key = Digest::SHA1::sha1_hex($redmine_user, $pass_digest, $project_id, $access_mode);
|
|
363 |
my $expirationTime = $cfg->{RedmineCacheCreds}->get($cache_key);
|
|
364 |
if(defined $expirationTime) {
|
|
365 |
if($cfg->{RedmineCacheCredsMaxAge} && $r->request_time > $expirationTime) {
|
|
366 |
$cfg->{RedmineCacheCreds}->unset($cache_key);
|
|
367 |
$cfg->{RedmineCacheCredsCount}--;
|
|
368 |
} else {
|
|
369 |
return 1;
|
|
370 |
}
|
|
371 |
}
|
355 |
372 |
}
|
|
373 |
|
356 |
374 |
my $query = $cfg->{RedmineQuery};
|
357 |
375 |
my $sth = $dbh->prepare($query);
|
358 |
376 |
$sth->execute($redmine_user, $project_id);
|
... | ... | |
394 |
412 |
$dbh->disconnect();
|
395 |
413 |
undef $dbh;
|
396 |
414 |
|
397 |
|
if ($cfg->{RedmineCacheCredsMax} and $ret) {
|
398 |
|
if (defined $usrprojpass) {
|
399 |
|
$cfg->{RedmineCacheCreds}->set($redmine_user.":".$project_id.":".$access_mode, $pass_digest);
|
400 |
|
} else {
|
401 |
|
if ($cfg->{RedmineCacheCredsCount} < $cfg->{RedmineCacheCredsMax}) {
|
402 |
|
$cfg->{RedmineCacheCreds}->set($redmine_user.":".$project_id.":".$access_mode, $pass_digest);
|
403 |
|
$cfg->{RedmineCacheCredsCount}++;
|
404 |
|
} else {
|
405 |
|
$cfg->{RedmineCacheCreds}->clear();
|
406 |
|
$cfg->{RedmineCacheCredsCount} = 0;
|
407 |
|
}
|
|
415 |
if (defined $cache_key) {
|
|
416 |
if ($cfg->{RedmineCacheCredsCount} >= $cfg->{RedmineCacheCredsMax}) {
|
|
417 |
$cfg->{RedmineCacheCreds}->clear();
|
|
418 |
$cfg->{RedmineCacheCredsCount} = 0;
|
408 |
419 |
}
|
|
420 |
$cfg->{RedmineCacheCreds}->set($cache_key, $cfg->{RedmineCacheCredsMaxAge} ? $r->request_time + $cfg->{RedmineCacheCredsMaxAge} : 1);
|
|
421 |
$cfg->{RedmineCacheCredsCount}++;
|
409 |
422 |
}
|
410 |
423 |
|
411 |
424 |
$ret;
|