Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dokuwiki
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BRIC
dokuwiki
Commits
70a89417
Commit
70a89417
authored
9 years ago
by
Andreas Gohr
Browse files
Options
Downloads
Patches
Plain Diff
added user group selection
parent
f64dbc90
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/plugins/authpdo/_test/sqlite.test.php
+8
-0
8 additions, 0 deletions
lib/plugins/authpdo/_test/sqlite.test.php
lib/plugins/authpdo/auth.php
+68
-15
68 additions, 15 deletions
lib/plugins/authpdo/auth.php
lib/plugins/authpdo/conf/default.php
+11
-3
11 additions, 3 deletions
lib/plugins/authpdo/conf/default.php
with
87 additions
and
18 deletions
lib/plugins/authpdo/_test/sqlite.test.php
+
8
−
0
View file @
70a89417
...
...
@@ -24,6 +24,8 @@ class sqlite_plugin_authpdo_test extends DokuWikiTest {
$conf
[
'plugin'
][
'authpdo'
][
'select-user'
]
=
'SELECT id as uid, login as user, name, pass as clear, mail FROM user WHERE login = :user'
;
$conf
[
'plugin'
][
'authpdo'
][
'select-user-groups'
]
=
'SELECT * FROM member AS m, "group" AS g WHERE m.gid = g.id AND m.uid = :uid'
;
}
public
function
tearDown
()
{
...
...
@@ -45,5 +47,11 @@ class sqlite_plugin_authpdo_test extends DokuWikiTest {
$this
->
assertFalse
(
$auth
->
checkPass
(
'admin'
,
'password'
));
$this
->
assertFalse
(
$auth
->
checkPass
(
'user'
,
md5
(
'password'
)));
// access user data
$info
=
$auth
->
getUserData
(
'admin'
);
$this
->
assertEquals
(
'admin'
,
$info
[
'user'
]);
$this
->
assertEquals
(
'The Admin'
,
$info
[
'name'
]);
$this
->
assertEquals
(
'admin@example.com'
,
$info
[
'mail'
]);
$this
->
assertEquals
(
array
(
'admin'
,
'user'
),
$info
[
'grps'
]);
}
}
This diff is collapsed.
Click to expand it.
lib/plugins/authpdo/auth.php
+
68
−
15
View file @
70a89417
...
...
@@ -38,7 +38,8 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin {
$this
->
getConf
(
'user'
),
$this
->
getConf
(
'pass'
),
array
(
PDO
::
ATTR_DEFAULT_FETCH_MODE
=>
PDO
::
FETCH_ASSOC
PDO
::
ATTR_DEFAULT_FETCH_MODE
=>
PDO
::
FETCH_ASSOC
,
// always fetch as array
PDO
::
ATTR_EMULATE_PREPARES
=>
true
,
// emulating prepares allows us to reuse param names
)
);
}
catch
(
PDOException
$e
)
{
...
...
@@ -107,8 +108,11 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin {
$data
=
$this
->
_selectUser
(
$user
);
if
(
$data
==
false
)
return
false
;
if
(
$requireGroups
)
{
if
(
isset
(
$data
[
'hash'
]))
unset
(
$data
[
'hash'
]);
if
(
isset
(
$data
[
'clean'
]))
unset
(
$data
[
'clean'
]);
if
(
$requireGroups
)
{
$data
[
'grps'
]
=
$this
->
_selectUserGroups
(
$data
);
}
return
$data
;
...
...
@@ -304,20 +308,10 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin {
protected
function
_selectUser
(
$user
)
{
$sql
=
$this
->
getConf
(
'select-user'
);
try
{
$sth
=
$this
->
pdo
->
prepare
(
$sql
);
$sth
->
execute
(
array
(
':user'
=>
$user
));
$result
=
$sth
->
fetchAll
();
$sth
->
closeCursor
();
$sth
=
null
;
}
catch
(
PDOException
$e
)
{
$this
->
_debug
(
$e
);
$result
=
array
();
}
$found
=
count
(
$result
);
if
(
$found
==
0
)
return
false
;
$result
=
$this
->
query
(
$sql
,
array
(
':user'
=>
$user
));
if
(
!
$result
)
return
false
;
if
(
$f
oun
d
>
1
)
{
if
(
c
oun
t
(
$result
)
>
1
)
{
$this
->
_debug
(
'Found more than one matching user'
,
-
1
,
__LINE__
);
return
false
;
}
...
...
@@ -346,6 +340,65 @@ class auth_plugin_authpdo extends DokuWiki_Auth_Plugin {
return
$data
;
}
/**
* Select all groups of a user
*
* @param array $userdata The userdata as returned by _selectUser()
* @return array
*/
protected
function
_selectUserGroups
(
$userdata
)
{
global
$conf
;
$sql
=
$this
->
getConf
(
'select-user-groups'
);
$result
=
$this
->
query
(
$sql
,
$userdata
);
$groups
=
array
(
$conf
[
'defaultgroup'
]);
// always add default config
if
(
$result
)
foreach
(
$result
as
$row
)
{
if
(
!
isset
(
$row
[
'group'
]))
continue
;
$groups
[]
=
$row
[
'group'
];
}
$groups
=
array_unique
(
$groups
);
sort
(
$groups
);
return
$groups
;
}
/**
* Executes a query
*
* @param string $sql The SQL statement to execute
* @param array $arguments Named parameters to be used in the statement
* @return array|bool The result as associative array
*/
protected
function
query
(
$sql
,
$arguments
)
{
// prepare parameters - we only use those that exist in the SQL
$params
=
array
();
foreach
(
$arguments
as
$key
=>
$value
)
{
if
(
is_array
(
$value
))
continue
;
if
(
is_object
(
$value
))
continue
;
if
(
$key
[
0
]
!=
':'
)
$key
=
":
$key
"
;
// prefix with colon if needed
if
(
strpos
(
$sql
,
$key
)
!==
false
)
$params
[
$key
]
=
$value
;
}
// execute
try
{
$sth
=
$this
->
pdo
->
prepare
(
$sql
);
$sth
->
execute
(
$params
);
$result
=
$sth
->
fetchAll
();
if
((
int
)
$sth
->
errorCode
())
{
$this
->
_debug
(
join
(
' '
,
$sth
->
errorInfo
()),
-
1
,
__LINE__
);
$result
=
false
;
}
$sth
->
closeCursor
();
$sth
=
null
;
}
catch
(
PDOException
$e
)
{
$this
->
_debug
(
$e
);
$result
=
false
;
}
return
$result
;
}
/**
* Wrapper around msg() but outputs only when debug is enabled
*
...
...
This diff is collapsed.
Click to expand it.
lib/plugins/authpdo/conf/default.php
+
11
−
3
View file @
70a89417
...
...
@@ -13,9 +13,17 @@ $conf['user'] = '';
$conf
[
'pass'
]
=
''
;
/**
* statement to select a single user identified by its login name
given as :user
* statement to select a single user identified by its login name
*
*
return; user, name, mail, (clear|hash), [uid]
*
other fields are returned but not used
*
input: :user
*
return: user, name, mail, (clear|hash), [uid], [*]
*/
$conf
[
'select-user'
]
=
''
;
/**
* Select all the group names a user is member of
*
* input: :user, [:uid], [*]
* return: group
*/
$conf
[
'select-user-group'
]
=
''
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment