cyllenea/multiple-ldap 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cyllenea/multiple-ldap

Composer 安装命令:

composer require cyllenea/multiple-ldap

包简介

Multiple LDAP Authenticator

README 文档

README

Tato jednoduchá knihovna slouží pro autoarizaci na více LDAP/AD serverech.

Pokud přihlášení na jednom serveru nebylo úspěšné, pokusí se přihlásit na druhém serveru.

Běžné použití je v globální aplikaci ve firemním prostředí, kde existuje několik různých lokalit s vlastním AD serverem.

Registrace knihovny

extensions:
    ldap: cyllenea\multiple-ldap\LDAPExtension

Nastavení atributů, které mají být získány z Active Directory záznamu

ldap:
    attributes:
        - employeeNumber    # Employee ID
        - employeeID        # Cost center
        - mail              # Email address
        - cn                # Common name
        - sn                # Surname
        - givenName         # First name

Nastavení ověřovacích serverů

ldap:
    controllers:
        wnc:
            host: wnc.local
            port: 389
            domain: "%s@wnc.local"
            dn: "OU=COMPANY,DC=wnc,DC=local"

        wv:
            host: wvdc01.wv.local
            port: 389
            domain: "%s@wv.local"
            dn: "OU=COMPANY,DC=wv,DC=local"

Registrace vlastní autorizační služby

services:
    authenticator:
        class: cyllenea\multiple-ldap\Authenticator
        setup:
            - setIdentityGenerator([@userManagemenent, 'createIdentity'])

Ukázka implementace vlastní autorizační služby

<?php declare(strict_types = 1);

namespace App\Model\Security\Authenticator;

use cyllenea\ldap\Exception\LDAPErrorException;
use cyllenea\ldap\LDAP;
use Nette;

final class UserAuthenticator implements Nette\Security\IAuthenticator
{

    private LDAP $ldap;

    public function __construct(LDAP $ldap)
    {
        $this->ldap = $ldap;
    }

    public function authenticate(array $credentials): Nette\Security\IIdentity
    {
        [$username, $password] = $credentials;

        $user = null;

        $attributes = [];

        try {

            // Login to LDAP
            $this->ldap->login($username, $password);

            // Search user
            $obtainedAttributes = $this->ldap->search($username);

            // Get attributes
            $attributes = Nette\Utils\ArrayHash::from($this->ldap->parseAttributes($obtainedAttributes));

        } catch (LDAPErrorException | \Exception $e) {

            throw new Nette\Security\AuthenticationException('Authentication failed. Please check your username/password.');

        } finally {

            // Disconnect
            $this->ldap->disconnect();

        }

        return new Nette\Security\Identity($username, [], $attributes);
    }

}

Přihlášení

try {
    $this->user->login("USERNAME", "PASSWORD");
    return true;
} catch (AuthenticationException $e) {
    // Něco se pokazilo, pop.ř. - dump($e->getMessage());
}

统计信息

  • 总下载量: 2.66k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固