| 51 |
51 |
PerlAuthenHandler Apache::Authn::Redmine::authen_handler
|
| 52 |
52 |
|
| 53 |
53 |
## for mysql
|
| 54 |
|
RedmineDSN "DBI:mysql:database=databasename;host=my.db.server"
|
|
54 |
PerlSetVar RedmineDSN "DBI:mysql:database=databasename;host=my.db.server"
|
| 55 |
55 |
## for postgres
|
| 56 |
|
# RedmineDSN "DBI:Pg:dbname=databasename;host=my.db.server"
|
|
56 |
# PerlSetVar RedmineDSN "DBI:Pg:dbname=databasename;host=my.db.server"
|
| 57 |
57 |
|
| 58 |
|
RedmineDbUser "redmine"
|
| 59 |
|
RedmineDbPass "password"
|
|
58 |
PerlSetVar RedmineDbUser "redmine"
|
|
59 |
PerlSetVar RedmineDbPass "password"
|
| 60 |
60 |
## Optional where clause (fulltext search would be slow and
|
| 61 |
61 |
## database dependant).
|
| 62 |
|
# RedmineDbWhereClause "and members.role_id IN (1,2)"
|
|
62 |
# PerlSetVar RedmineDbWhereClause "and members.role_id IN (1,2)"
|
| 63 |
63 |
## Optional credentials cache size
|
| 64 |
|
# RedmineCacheCredsMax 50
|
|
64 |
# PerlSetVar RedmineCacheCredsMax 50
|
| 65 |
65 |
</Location>
|
| 66 |
66 |
|
| 67 |
67 |
To be able to browse repository inside redmine, you must add something
|
| ... | ... | |
| 113 |
113 |
use APR::Table ();
|
| 114 |
114 |
|
| 115 |
115 |
# use Apache2::Directive qw();
|
|
116 |
my %read_only_methods = map { $_ => 1 } qw/GET PROPFIND REPORT OPTIONS/;
|
| 116 |
117 |
|
| 117 |
|
my @directives = (
|
| 118 |
|
{
|
| 119 |
|
name => 'RedmineDSN',
|
| 120 |
|
req_override => OR_AUTHCFG,
|
| 121 |
|
args_how => TAKE1,
|
| 122 |
|
errmsg => 'Dsn in format used by Perl DBI. eg: "DBI:Pg:dbname=databasename;host=my.db.server"',
|
| 123 |
|
},
|
| 124 |
|
{
|
| 125 |
|
name => 'RedmineDbUser',
|
| 126 |
|
req_override => OR_AUTHCFG,
|
| 127 |
|
args_how => TAKE1,
|
| 128 |
|
},
|
| 129 |
|
{
|
| 130 |
|
name => 'RedmineDbPass',
|
| 131 |
|
req_override => OR_AUTHCFG,
|
| 132 |
|
args_how => TAKE1,
|
| 133 |
|
},
|
| 134 |
|
{
|
| 135 |
|
name => 'RedmineDbWhereClause',
|
| 136 |
|
req_override => OR_AUTHCFG,
|
| 137 |
|
args_how => TAKE1,
|
| 138 |
|
},
|
| 139 |
|
{
|
| 140 |
|
name => 'RedmineCacheCredsMax',
|
| 141 |
|
req_override => OR_AUTHCFG,
|
| 142 |
|
args_how => TAKE1,
|
| 143 |
|
errmsg => 'RedmineCacheCredsMax must be decimal number',
|
| 144 |
|
},
|
| 145 |
|
);
|
|
118 |
my $cfg;
|
| 146 |
119 |
|
| 147 |
|
sub RedmineDSN {
|
| 148 |
|
my ($self, $parms, $arg) = @_;
|
| 149 |
|
$self->{RedmineDSN} = $arg;
|
| 150 |
|
my $query = "SELECT
|
| 151 |
|
hashed_password, salt, auth_source_id, permissions
|
|
120 |
sub initialize {
|
|
121 |
my $r = shift;
|
|
122 |
my $ret = 1;
|
|
123 |
|
|
124 |
$cfg->{RedmineDSN} = $r->dir_config('RedmineDSN');
|
|
125 |
$cfg->{RedmineDbUser} = $r->dir_config('RedmineDbUser');
|
|
126 |
$cfg->{RedmineDbPass} = $r->dir_config('RedmineDbPass');
|
|
127 |
|
|
128 |
unless ($cfg->{RedmineDSN}) {
|
|
129 |
$r->log_reason("No DSN has been configured. Maybe PerlSetVar is missing at the beginning of the line");
|
|
130 |
$ret = 0;
|
|
131 |
}
|
|
132 |
|
|
133 |
unless ($cfg->{RedmineDbUser}) {
|
|
134 |
$r->log_reason("No DSN user has been configured. Maybe PerlSetVar is missing at the beginning of the line");
|
|
135 |
$ret = 0;
|
|
136 |
}
|
|
137 |
|
|
138 |
unless ($cfg->{RedmineDbPass}) {
|
|
139 |
$r->log_reason("No DSN user password has been configured. Maybe PerlSetVar is missing at the beginning of the line");
|
|
140 |
$ret = 0;
|
|
141 |
}
|
|
142 |
|
|
143 |
if ($r->dir_config('RedmineCacheCredsMax')) {
|
|
144 |
$cfg->{RedmineCachePool} = APR::Pool->new;
|
|
145 |
$cfg->{RedmineCacheCreds} = APR::Table::make($cfg->{RedmineCachePool}, $r->dir_config('RedmineCacheCredsMax'));
|
|
146 |
$cfg->{RedmineCacheCredsCount} = 0;
|
|
147 |
$cfg->{RedmineCacheCredsMax} = $r->dir_config('RedmineCacheCredsMax');
|
|
148 |
}
|
|
149 |
|
|
150 |
my $query = trim("SELECT
|
|
151 |
hashed_password, auth_source_id, permissions
|
| 152 |
152 |
FROM members, projects, users, roles, member_roles
|
| 153 |
153 |
WHERE
|
| 154 |
154 |
projects.id=members.project_id
|
| ... | ... | |
| 157 |
157 |
AND roles.id=member_roles.role_id
|
| 158 |
158 |
AND users.status=1
|
| 159 |
159 |
AND login=?
|
| 160 |
|
AND identifier=? ";
|
| 161 |
|
$self->{RedmineQuery} = trim($query);
|
| 162 |
|
}
|
|
160 |
AND identifier=? ");
|
| 163 |
161 |
|
| 164 |
|
sub RedmineDbUser { set_val('RedmineDbUser', @_); }
|
| 165 |
|
sub RedmineDbPass { set_val('RedmineDbPass', @_); }
|
| 166 |
|
sub RedmineDbWhereClause {
|
| 167 |
|
my ($self, $parms, $arg) = @_;
|
| 168 |
|
$self->{RedmineQuery} = trim($self->{RedmineQuery}.($arg ? $arg : "")." ");
|
| 169 |
|
}
|
|
162 |
$cfg->{RedmineQuery} = trim($query.($r->dir_config('RedmineDbWhereClause') ? $r->dir_config('RedmineDbWhereClause') : "")." ");
|
| 170 |
163 |
|
| 171 |
|
sub RedmineCacheCredsMax {
|
| 172 |
|
my ($self, $parms, $arg) = @_;
|
| 173 |
|
if ($arg) {
|
| 174 |
|
$self->{RedmineCachePool} = APR::Pool->new;
|
| 175 |
|
$self->{RedmineCacheCreds} = APR::Table::make($self->{RedmineCachePool}, $arg);
|
| 176 |
|
$self->{RedmineCacheCredsCount} = 0;
|
| 177 |
|
$self->{RedmineCacheCredsMax} = $arg;
|
| 178 |
|
}
|
|
164 |
return $ret;
|
| 179 |
165 |
}
|
| 180 |
166 |
|
|
167 |
|
| 181 |
168 |
sub trim {
|
| 182 |
169 |
my $string = shift;
|
| 183 |
170 |
$string =~ s/\s{2,}/ /g;
|
| 184 |
171 |
return $string;
|
| 185 |
172 |
}
|
| 186 |
173 |
|
| 187 |
|
sub set_val {
|
| 188 |
|
my ($key, $self, $parms, $arg) = @_;
|
| 189 |
|
$self->{$key} = $arg;
|
| 190 |
|
}
|
| 191 |
174 |
|
| 192 |
|
Apache2::Module::add(__PACKAGE__, \@directives);
|
| 193 |
|
|
| 194 |
|
|
| 195 |
|
my %read_only_methods = map { $_ => 1 } qw/GET PROPFIND REPORT OPTIONS/;
|
| 196 |
|
|
| 197 |
175 |
sub access_handler {
|
| 198 |
176 |
my $r = shift;
|
| 199 |
177 |
|
|
178 |
unless (initialize($r)) {
|
|
179 |
$r->log_reason("Please check redmine connfiguration");
|
|
180 |
return FORBIDDEN;
|
|
181 |
}
|
|
182 |
|
| 200 |
183 |
unless ($r->some_auth_required) {
|
| 201 |
184 |
$r->log_reason("No authentication has been configured");
|
| 202 |
185 |
return FORBIDDEN;
|
| ... | ... | |
| 216 |
199 |
sub authen_handler {
|
| 217 |
200 |
my $r = shift;
|
| 218 |
201 |
|
|
202 |
unless (initialize($r)) {
|
|
203 |
$r->log_reason("Please check redmine connfiguration");
|
|
204 |
return AUTH_REQUIRED;
|
|
205 |
}
|
|
206 |
|
| 219 |
207 |
my ($res, $redmine_pass) = $r->get_basic_auth_pw();
|
| 220 |
208 |
return $res unless $res == OK;
|
| 221 |
209 |
|
| ... | ... | |
| 305 |
293 |
|
| 306 |
294 |
my $pass_digest = Digest::SHA1::sha1_hex($redmine_pass);
|
| 307 |
295 |
|
| 308 |
|
my $cfg = Apache2::Module::get_config(__PACKAGE__, $r->server, $r->per_dir_config);
|
| 309 |
296 |
my $usrprojpass;
|
| 310 |
297 |
if ($cfg->{RedmineCacheCredsMax}) {
|
| 311 |
298 |
$usrprojpass = $cfg->{RedmineCacheCreds}->get($redmine_user.":".$project_id);
|
| ... | ... | |
| 378 |
365 |
}
|
| 379 |
366 |
|
| 380 |
367 |
sub connect_database {
|
| 381 |
|
my $r = shift;
|
| 382 |
|
|
| 383 |
|
my $cfg = Apache2::Module::get_config(__PACKAGE__, $r->server, $r->per_dir_config);
|
| 384 |
368 |
return DBI->connect($cfg->{RedmineDSN}, $cfg->{RedmineDbUser}, $cfg->{RedmineDbPass});
|
| 385 |
369 |
}
|
| 386 |
370 |
|