ThaDafinser / Piwik-LdapConnection

Piwik plugin to connect to LDAP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Piwik LdapConnection Plugin

Description

Configurable piwik plugin to create an LDAP connection, which can be reused by other plugins. Is uses the ZF2 Ldap component: http://framework.zend.com/manual/2.3/en/index.html#zend-ldap

Currently used by https://github.com/ThaDafinser/LdapVisitorInfo

FAQ

Why is PIWIK 2.5 required?

Because the configuration (to be explicit accountFilterFormat) is destroyed in the previous version See the ticket here: matomo-org/matomo#5890

What does this plugin do?

It creates based on your configuration a connection to LDAP. Not more and not less :-)

How can i use this LDAP connection in another plugin?

This is an example to retrieve the connection. For documentation please see http://framework.zend.com/manual/2.3/en/index.html#zend-ldap

namespace Piwik\Plugins\YourPlugin;

use Piwik\Plugin;
use Piwik\Plugins\LdapConnection\API as APILdapConnection;
use Zend\Ldap\Ldap;

class YourPlugin extends Plugin
{
    private function doSomething()
    {
    	/* @var $ldap \Zend\Ldap\Ldap */
        $ldap = APILdapConnection::getInstance()->getConnection();
        $ldap->connect();
        
        $filter = sprintf('(&(objectclass=user)(samAccountName=%s))', $visitorUsername);
        $collection = $ldap->search($filter, null, Ldap::SEARCH_SCOPE_SUB, ['displayname']);
        
        if ($collection->count() >= 1) {
        	$result = $collection->getFirst();
        	//do something with the result...
        }
    }
}

About

Piwik plugin to connect to LDAP

License:MIT License


Languages

Language:PHP 94.3%Language:HTML 5.7%