Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/Controller/SAMLController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public function __construct($appName,
*/
private function autoprovisionIfPossible(array $auth) {
$uidMapping = $this->config->getAppValue('user_saml', 'general-uid_mapping');
$displayName = $auth['urn:oid:2.5.4.42'][0] . ' ' . $auth['urn:oid:1.2.40.0.10.2.1.1.261.20'][0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding those should be configurable values – right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point.
Two values like displayname.firstpart, displayname.secondpart to leave the admin a choice if first,last or last,first?


if(isset($auth[$uidMapping])) {
if(is_array($auth[$uidMapping])) {
$uid = $auth[$uidMapping][0];
Expand All @@ -101,7 +103,7 @@ private function autoprovisionIfPossible(array $auth) {
if(!$userExists && !$autoProvisioningAllowed) {
throw new NoUserFoundException();
} elseif(!$userExists && $autoProvisioningAllowed) {
$this->userBackend->createUserIfNotExists($uid);
$this->userBackend->createUserIfNotExists($uid,$displayName);
return;
}
}
Expand Down
22 changes: 17 additions & 5 deletions lib/userbackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ private function userExistsInDatabase($uid) {
*
* @param string $uid
*/
public function createUserIfNotExists($uid) {
public function createUserIfNotExists($uid,$displayname="") {
if(!$this->userExistsInDatabase($uid)) {
$values = [
'uid' => $uid,
'displayname' => $displayname,
];

/* @var $qb IQueryBuilder */
Expand All @@ -109,7 +110,7 @@ public function createUserIfNotExists($uid) {
* @since 4.5.0
*/
public function implementsActions($actions) {
return (bool)((\OC_User_Backend::CHECK_PASSWORD)
return (bool)((\OC_User_Backend::CHECK_PASSWORD|OC_USER_BACKEND_GET_DISPLAYNAME)
& $actions);
}

Expand Down Expand Up @@ -214,7 +215,19 @@ public function userExists($uid) {
* @since 4.5.0
*/
public function getDisplayName($uid) {
$qb = $this->db->getQueryBuilder();
$qb->select('displayname')
->from('user_saml_users')
->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid)))
->setMaxResults(1);
$result = $qb->execute();
$users = $result->fetchAll();

if ($users[0]['displayname']) {
return $users[0]['displayname'];
} else {
return false;
}
}

/**
Expand All @@ -230,9 +243,8 @@ public function getDisplayNames($search = '', $limit = null, $offset = null) {
$qb = $this->db->getQueryBuilder();
$qb->select('uid', 'displayname')
->from('user_saml_users')
->where(
$qb->expr()->iLike('uid', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($search) . '%'))
)
->where( $qb->expr()->iLike('uid', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($search) . '%')))
->orwhere ( $qb->expr()->iLike('displayname', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($search) . '%')))
->setMaxResults($limit);
if($offset !== null) {
$qb->setFirstResult($offset);
Expand Down