Documentation
¶
Overview ¶
Package manager connects to an LDAP directory, and keeps the connection, binding as the manager's user, and reconnecting when it's lost
Index ¶
- type Manager
- func (manager *Manager) AddGroupUsers(ctx context.Context, group string, users ...string) (_ *schema.Object, err error)
- func (manager *Manager) Bind(ctx context.Context, dn, password string) (_ *schema.Object, err error)
- func (manager *Manager) ChangePassword(ctx context.Context, dn string, req schema.ObjectPasswordRequest) (_ *schema.PasswordResponse, err error)
- func (manager *Manager) Connect(ctx context.Context) (err error)
- func (manager *Manager) Create(ctx context.Context, dn string, attrs schema.Attrs) (_ *schema.Object, err error)
- func (manager *Manager) CreateGroup(ctx context.Context, name string, attrs schema.Attrs) (_ *schema.Object, err error)
- func (manager *Manager) CreateUser(ctx context.Context, name string, attrs schema.Attrs, allocateGID bool) (_ *schema.Object, err error)
- func (manager *Manager) Delete(ctx context.Context, dn string) (_ *schema.Object, err error)
- func (manager *Manager) DeleteGroup(ctx context.Context, name string) (_ *schema.Object, err error)
- func (manager *Manager) DeleteUser(ctx context.Context, name string) (_ *schema.Object, err error)
- func (manager *Manager) Disconnect(ctx context.Context) (err error)
- func (manager *Manager) Get(ctx context.Context, dn string, attrs ...string) (_ *schema.Object, err error)
- func (manager *Manager) GetGroup(ctx context.Context, name string) (_ *schema.Object, err error)
- func (manager *Manager) GetUser(ctx context.Context, name string) (_ *schema.Object, err error)
- func (manager *Manager) Host() string
- func (manager *Manager) List(ctx context.Context, req schema.ObjectListRequest) (_ *schema.ObjectList, err error)
- func (manager *Manager) ListAttributeTypes(ctx context.Context, req schema.AttributeTypeListRequest) (_ *schema.AttributeTypeListResponse, err error)
- func (manager *Manager) ListGroups(ctx context.Context, req schema.GroupListRequest) (_ *schema.ObjectList, err error)
- func (manager *Manager) ListObjectClasses(ctx context.Context, req schema.ObjectClassListRequest) (_ *schema.ObjectClassListResponse, err error)
- func (manager *Manager) ListUsers(ctx context.Context, req schema.UserListRequest) (_ *schema.ObjectList, err error)
- func (manager *Manager) Port() uint
- func (manager *Manager) RemoveGroupUsers(ctx context.Context, group string, users ...string) (_ *schema.Object, err error)
- func (manager *Manager) Run(ctx context.Context, logger *slog.Logger) error
- func (manager *Manager) Status() schema.Status
- func (manager *Manager) Update(ctx context.Context, dn string, attrs schema.Attrs) (_ *schema.Object, err error)
- func (manager *Manager) UpdateGroup(ctx context.Context, name string, attrs schema.Attrs) (_ *schema.Object, err error)
- func (manager *Manager) UpdateUser(ctx context.Context, name string, attrs schema.Attrs) (_ *schema.Object, err error)
- func (manager *Manager) User() string
- func (manager *Manager) WhoAmI(ctx context.Context) (_ string, err error)
- type Opt
- func WithBaseDN(v string) Opt
- func WithBroadcaster(publisher Publisher) Opt
- func WithGroupDN(dn string, classes ...string) Opt
- func WithPassword(v string) Opt
- func WithSkipVerify() Opt
- func WithTracer(tracer trace.Tracer) Opt
- func WithUrl(v string) Opt
- func WithUser(v string) Opt
- func WithUserDN(dn string, classes ...string) Opt
- type Publisher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager keeps a connection to an LDAP directory
func New ¶
New returns a manager of the directory at the URL, ldap or ldaps, whose user and password are the URL's, unless they're options, under the base DN. It doesn't connect until Connect, or Run, is called.
func (*Manager) AddGroupUsers ¶
func (manager *Manager) AddGroupUsers(ctx context.Context, group string, users ...string) (_ *schema.Object, err error)
AddGroupUsers adds the users, by name, to the group, in one request, and returns it. Users who are members already are left as they are.
func (*Manager) Bind ¶
func (manager *Manager) Bind(ctx context.Context, dn, password string) (_ *schema.Object, err error)
Bind checks the password of the entry, whose DN is under the base DN, or relative to it, and returns the entry, or ErrNotAuthorized. It binds on a connection of its own, so the manager's stays bound as its user.
func (*Manager) ChangePassword ¶
func (manager *Manager) ChangePassword(ctx context.Context, dn string, req schema.ObjectPasswordRequest) (_ *schema.PasswordResponse, err error)
ChangePassword sets the password of the entry, whose DN is under the base DN, or relative to it, to the request's new password, or one which is generated, which is returned, when it's empty. With the old password, it binds as the entry, which changes its own password, so the old one is checked. Without it, the manager's user resets it.
An Active Directory user, whose objectClass is "user", has its unicodePwd set, which needs ldaps. Other directories have the password modify operation (RFC 3062).
func (*Manager) Connect ¶
Connect connects to the directory, and binds, or, when it's connected, checks the connection, which is closed when it's lost, so the next call connects again
func (*Manager) Create ¶
func (manager *Manager) Create(ctx context.Context, dn string, attrs schema.Attrs) (_ *schema.Object, err error)
Create adds the entry, whose DN is under the base DN, or relative to it, with the attributes, which need an objectClass, and returns it
func (*Manager) CreateGroup ¶
func (manager *Manager) CreateGroup(ctx context.Context, name string, attrs schema.Attrs) (_ *schema.Object, err error)
CreateGroup adds a group with the name, as its cn, and the attributes, and returns it. The groups' object classes are added, which, when they aren't set, are those the directory has, such as groupOfNames and posixGroup, or Active Directory's group. A posixGroup without a gidNumber has the next one. A group whose class needs a member has itself, as groupOfNames and groupOfUniqueNames do.
func (*Manager) CreateUser ¶
func (manager *Manager) CreateUser(ctx context.Context, name string, attrs schema.Attrs, allocateGID bool) (_ *schema.Object, err error)
CreateUser adds a user with the name, and the attributes, and returns it. The users' object classes are added, which, when they aren't set, are those the directory has, such as inetOrgPerson and posixAccount, or Active Directory's user. A posixAccount without a uidNumber has the next one, and, with allocateGID, the same gidNumber.
A password, in userPassword or unicodePwd, is set. An Active Directory user is created disabled, then has its password set, and is enabled, or is deleted when that fails. Without a password, it stays disabled.
func (*Manager) DeleteGroup ¶
DeleteGroup removes the group with the name, and returns it
func (*Manager) DeleteUser ¶
DeleteUser removes the user with the name, and returns it
func (*Manager) Disconnect ¶
Disconnect closes the connection to the directory, when it's connected
func (*Manager) Get ¶
func (manager *Manager) Get(ctx context.Context, dn string, attrs ...string) (_ *schema.Object, err error)
Get returns the entry, whose DN is under the base DN, or relative to it, with its attributes, or only those named, such as operational ones, which aren't returned otherwise, such as entryUUID
func (*Manager) List ¶
func (manager *Manager) List(ctx context.Context, req schema.ObjectListRequest) (_ *schema.ObjectList, err error)
List returns the entries under the base DN, or, with a prefix, in the subtree of its DN, relative to the base DN, or under it, or, with children, only those directly under it, which match the request's filter, or all of them, with its attributes, or all of them. Count is the number which match, and Body those from the offset, up to the limit, or schema.MaxListEntries.
func (*Manager) ListAttributeTypes ¶
func (manager *Manager) ListAttributeTypes(ctx context.Context, req schema.AttributeTypeListRequest) (_ *schema.AttributeTypeListResponse, err error)
ListAttributeTypes returns copies of the directory's attribute types, by name, which match the request. Count is the number which match, and Body those from the offset, up to the limit, or schema.MaxListEntries.
func (*Manager) ListGroups ¶
func (manager *Manager) ListGroups(ctx context.Context, req schema.GroupListRequest) (_ *schema.ObjectList, err error)
ListGroups returns the groups, which are the entries directly under the groups' DN, which match the request's filter, and, when it has a user, have it as a member
func (*Manager) ListObjectClasses ¶
func (manager *Manager) ListObjectClasses(ctx context.Context, req schema.ObjectClassListRequest) (_ *schema.ObjectClassListResponse, err error)
ListObjectClasses returns copies of the directory's object classes, by name, which match the request. Count is the number which match, and Body those from the offset, up to the limit, or schema.MaxListEntries. With For, they're only the classes users, or groups, are created with, and their superiors.
func (*Manager) ListUsers ¶
func (manager *Manager) ListUsers(ctx context.Context, req schema.UserListRequest) (_ *schema.ObjectList, err error)
ListUsers returns the users, which are the entries directly under the users' DN, which match the request's filter, and, when it has a group, are its members
func (*Manager) RemoveGroupUsers ¶
func (manager *Manager) RemoveGroupUsers(ctx context.Context, group string, users ...string) (_ *schema.Object, err error)
RemoveGroupUsers removes the users, by name, from the group, in one request, and returns it. Users who aren't members are left as they are.
func (*Manager) Run ¶
Run connects to the directory, and checks the connection, reconnecting when it's lost, with a growing delay, or at once when an operation loses it, until the context is cancelled, when it disconnects
func (*Manager) Status ¶ added in v0.0.15
Status returns the directory, and whether the manager is connected to it, without waiting for the requests it's making
func (*Manager) Update ¶
func (manager *Manager) Update(ctx context.Context, dn string, attrs schema.Attrs) (_ *schema.Object, err error)
Update replaces the entry's attributes which have values, and deletes those which have none, and returns it. Changing a value of the entry's RDN renames it first, keeping it under the same parent, then replaces the RDN's attribute with all its values, unless the rename has set them. When the changes fail, the rename is undone.
func (*Manager) UpdateGroup ¶
func (manager *Manager) UpdateGroup(ctx context.Context, name string, attrs schema.Attrs) (_ *schema.Object, err error)
UpdateGroup changes the group with the name, as Update does, and returns it. Changing its cn renames it.
func (*Manager) UpdateUser ¶
func (manager *Manager) UpdateUser(ctx context.Context, name string, attrs schema.Attrs) (_ *schema.Object, err error)
UpdateUser changes the user with the name, as Update does, and returns it. Changing its name renames it.
type Opt ¶
type Opt func(*opt) error
Opt represents a function that modifies the options
func WithBaseDN ¶
WithBaseDN sets the base DN, which the manager's DNs are under
func WithBroadcaster ¶ added in v0.0.15
WithTracer sets the OpenTelemetry tracer used for manager spans WithBroadcaster publishes the changes the manager makes, to objects, users and groups, and its connection coming up or going down, with schema.SchemaName as their schema
func WithGroupDN ¶
WithGroupDN sets the DN of the groups, and their object classes
func WithPassword ¶
WithPassword sets the password, rather than the URL's
func WithSkipVerify ¶
func WithSkipVerify() Opt
WithSkipVerify doesn't verify an ldaps server's certificate
func WithTracer ¶ added in v0.0.15
func WithUrl ¶
WithUrl sets the directory's URL, ldap or ldaps, which can have the user and password
func WithUser ¶
WithUser sets the user, rather than the URL's, which is a name under the base DN, or a DN
func WithUserDN ¶
WithUserDN sets the DN of the users, and their object classes