2023-03-15 11:40:40 -04:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
|
|
|
|
package ldap
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/boundary/globals"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/auth"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/db"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/errors"
|
2023-11-15 19:55:46 -05:00
|
|
|
"github.com/hashicorp/boundary/internal/types/resource"
|
2023-03-15 11:40:40 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
2023-11-15 19:55:46 -05:00
|
|
|
globals.RegisterPrefixToResourceInfo(globals.LdapAuthMethodPrefix, resource.AuthMethod, auth.Domain, Subtype)
|
|
|
|
|
globals.RegisterPrefixToResourceInfo(globals.LdapAccountPrefix, resource.Account, auth.Domain, Subtype)
|
|
|
|
|
globals.RegisterPrefixToResourceInfo(globals.LdapManagedGroupPrefix, resource.ManagedGroup, auth.Domain, Subtype)
|
2023-03-15 11:40:40 -04:00
|
|
|
}
|
|
|
|
|
|
2023-11-02 16:03:47 -04:00
|
|
|
const (
|
2023-11-15 19:55:46 -05:00
|
|
|
Subtype = globals.Subtype("ldap")
|
2023-11-02 16:03:47 -04:00
|
|
|
)
|
|
|
|
|
|
2023-03-15 11:40:40 -04:00
|
|
|
func newAuthMethodId(ctx context.Context) (string, error) {
|
|
|
|
|
const op = "ldap.newAuthMethodId"
|
2023-06-06 17:09:08 -04:00
|
|
|
id, err := db.NewPublicId(ctx, globals.LdapAuthMethodPrefix)
|
2023-03-15 11:40:40 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return "", errors.Wrap(ctx, err, op)
|
|
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func newAccountId(ctx context.Context, authMethodId, loginName string) (string, error) {
|
|
|
|
|
const op = "ldap.newAccountId"
|
|
|
|
|
// there's a unique index on: auth method id + login name
|
2023-06-06 17:09:08 -04:00
|
|
|
id, err := db.NewPublicId(ctx, globals.LdapAccountPrefix, db.WithPrngValues([]string{authMethodId, loginName}))
|
2023-03-15 11:40:40 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return "", errors.Wrap(ctx, err, op)
|
|
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func newManagedGroupId(ctx context.Context) (string, error) {
|
|
|
|
|
const op = "ldap.newManagedGroupId"
|
2023-06-06 17:09:08 -04:00
|
|
|
id, err := db.NewPublicId(ctx, globals.LdapManagedGroupPrefix)
|
2023-03-15 11:40:40 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return "", errors.Wrap(ctx, err, op)
|
|
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|