ldap

package
v0.0.0-...-e50112c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAccountNotExist

func IsAccountNotExist(err error) bool

func IsAuthFail

func IsAuthFail(err error) bool

func IsObjectNotExist

func IsObjectNotExist(err error) bool

func IsRequestFail

func IsRequestFail(err error) bool

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(cfg *Config) (*Client, error)

func (*Client) Check

func (this *Client) Check(dn ...string) error

func (*Client) Close

func (this *Client) Close()

func (*Client) FindSingleLevel

func (this *Client) FindSingleLevel(baseDN string, filter ...string) ([]*ldap.Entry, error)

func (*Client) FindSubtree

func (this *Client) FindSubtree(baseDN string, filter ...string) ([]*ldap.Entry, error)

func (*Client) Get

func (this *Client) Get(baseDN string, filter ...string) (*ldap.Entry, error)

func (*Client) GetSingleLevelOrganization

func (this *Client) GetSingleLevelOrganization(baseDN string) (map[string]*OrgUnit, map[string]*User, error)

func (*Client) GetSubTreeOrganization

func (this *Client) GetSubTreeOrganization(baseDN string) (map[string]*OrgUnit, map[string]*User, error)

func (*Client) UserAuth

func (this *Client) UserAuth(account, password string) (*User, error)

UserAuth 使用指定的账户、密码鉴权,并返回对应的人员信息

type Config

type Config struct {
	Host        string       `json:"host,omitempty"`
	Port        int          `json:"port,omitempty"`
	Username    string       `json:"username,omitempty"`
	Password    string       `json:"password,omitempty"`
	BaseDN      string       `json:"base_dn,omitempty"`
	Timeout     int          `json:"timeout,omitempty"` // 连接超时,单位:秒
	EnableTLS   bool         `json:"enable_tls,omitempty"`
	EntryParser IEntryParser `json:"-"`
}

type DefaultEntryParser

type DefaultEntryParser struct{}

func (DefaultEntryParser) EntrySearchFilter

func (e DefaultEntryParser) EntrySearchFilter() string

func (DefaultEntryParser) ToOrgUnit

func (e DefaultEntryParser) ToOrgUnit(entry *ldap.Entry, parentOrgUnit string) *OrgUnit

func (DefaultEntryParser) ToUser

func (e DefaultEntryParser) ToUser(entry *ldap.Entry, orgUnit string) *User

func (DefaultEntryParser) UUID

func (e DefaultEntryParser) UUID(entry *ldap.Entry) string

type ErrType

type ErrType int
const (
	ErrRequestFail ErrType = iota
	ErrAuthFail
	ErrObjectNotExist
	ErrAccountNotExist
)

func (ErrType) String

func (i ErrType) String() string

type Error

type Error struct {
	Type ErrType
	Err  error
}

func (*Error) Error

func (e *Error) Error() string

type IEntryParser

type IEntryParser interface {
	UUID(entry *ldap.Entry) string
	EntrySearchFilter() string
	ToUser(entry *ldap.Entry, orgUnit string) *User
	ToOrgUnit(entry *ldap.Entry, parentOrgUnit string) *OrgUnit
}

type OrgUnit

type OrgUnit struct {
	UID           string `json:"uid,omitempty"`             // 唯一标识
	DN            string `json:"dn,omitempty"`              // 组织单元DN
	ParentOrgUnit string `json:"parent_org_unit,omitempty"` // 父级组织单元的UID
	Name          string `json:"name,omitempty"`            // 组织单元名称
	Manager       string `json:"manager,omitempty"`         // 组织单元主管DN,由调用方自行转换成对应的人员UID
}

OrgUnit 组织单元

type User

type User struct {
	UID       string `json:"uid,omitempty"`       // 唯一标识
	DN        string `json:"dn,omitempty"`        // 人员DN
	OrgUnit   string `json:"org_unit,omitempty"`  // 所属组织单元的UID
	Account   string `json:"account,omitempty"`   // 账户
	Name      string `json:"name,omitempty"`      // 姓名
	Mobile    string `json:"mobile,omitempty"`    // 手机号码
	Telephone string `json:"telephone,omitempty"` // 电话号码
	Email     string `json:"email,omitempty"`     // 邮箱
}

User 组织人员

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL