Passed
Push — master ( 1c7137...b5ef5e )
by Pieter van der
03:26 queued 14s
created

Tiqr_UserSecretStorage_Ldap::setUserSecret()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 2
1
<?php
2
/**
3
 * This file is part of the tiqr project.
4
 * 
5
 * The tiqr project aims to provide an open implementation for 
6
 * authentication using mobile devices. It was initiated by 
7
 * SURFnet and developed by Egeniq.
8
 *
9
 * More information: http://www.tiqr.org
10
 *
11
 * @author Ivo Jansch <[email protected]>
12
 * 
13
 * @package tiqr
14
 *
15
 * @license New BSD License - See LICENSE file for details.
16
 *
17
 * @copyright (C) 2010-2012 SURFnet BV
18
 */
19
20
require_once 'Zend/Ldap.php';
21
require_once 'Zend/Ldap/Attribute.php';
22
require_once 'Zend/Ldap/Dn.php';
23
24
require_once 'Tiqr/UserStorage/Ldap.php';
25
26
/**
27
 * LDAP Tiqr storage driver.
28
 */
29
class Tiqr_UserSecretStorage_Ldap extends Tiqr_UserStorage_Ldap implements Tiqr_UserSecretStorage_Interface
30
{
31
    /**
32
     * Construct a user class
33
     *
34
     * @param array $config The configuration that a specific user class may use.
35
     */
36
    public function __construct($config)
37
    {
38
        $this->_userClass = isset($config['userClass']) ? $config['userClass'] : "tiqrPerson";
39
        $this->_dnPattern = isset($config['dnPattern']) ? $config['dnPattern'] : "%s";
40
        $this->_idAttr = isset($config['idAttr']) ? $config['idAttr'] : 'dn';
41
        $this->_secretAttr = isset($config['secretAttr']) ? $config['secretAttr'] : 'tiqrSecret';
42
43
        $ldapOptions = array(
44
            "host" => $config['host'],
45
            "username" => $config['username'],
46
            "password" => $config['password'],
47
            "bindRequiresDn" => $config['bindRequiresDn'],
48
            "accountDomainName" => $config['accountDomainName'],
49
            "baseDn" => $config['baseDn'],
50
        );
51
52
        $this->_ldap = new Zend_Ldap($ldapOptions);
53
    }
54
55
    /**
56
     * Get the user's secret
57
     *
58
     * @param String $userId
59
     *
60
     * @return String The user's secret
61
     */
62
    public function getUserSecret($userId)
63
    {
64
        if ($user = $this->_loadUser($userId)) {
65
            return $this->_getLDAPAttribute($user, $this->_secretAttr);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->_getLDAPAt...er, $this->_secretAttr) also could return the type array which is incompatible with the documented return type string.
Loading history...
66
        }
67
        return NULL;
68
    }
69
70
    /**
71
     * Store a secret for a user
72
     *
73
     * @param String $userId
74
     * @param String $secret
75
     */
76
    public function setUserSecret($userId, $secret)
77
    {
78
        $user = $this->_loadUser($userId);
79
        $this->_setLDAPAttribute($user, $this->_secretAttr, $secret);
0 ignored issues
show
Bug introduced by
$user of type false is incompatible with the type array expected by parameter $entry of Tiqr_UserStorage_Ldap::_setLDAPAttribute(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

79
        $this->_setLDAPAttribute(/** @scrutinizer ignore-type */ $user, $this->_secretAttr, $secret);
Loading history...
80
        $this->_saveUser($userId, $user);
81
    }
82
}
83