-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
custom_attributes.go
54 lines (43 loc) · 969 Bytes
/
custom_attributes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package examples
import (
"fmt"
"github.com/dlampsi/adc"
)
func mainCustomAttributes() {
cfg := &adc.Config{
URL: "ldaps://my.ad.site:636",
Bind: &adc.BindAccount{
DN: "CN=admin,DC=company,DC=com",
Password: "***",
},
SearchBase: "OU=default,DC=company,DC=com",
}
cl := adc.New(cfg)
if err := cl.Connect(); err != nil {
panic(err)
}
// Append custom user attributes to all searches and get it.
cl.Config.AppendUsersAttributes("manager")
user, err := cl.GetUser(adc.GetUserArgs{
Id: "exampleUserId",
})
if err != nil {
panic(err)
}
if user == nil {
panic("User not found")
}
fmt.Println(user.GetStringAttribute("manager"))
// Append custom user attributes per-search.
user2, err := cl.GetUser(adc.GetUserArgs{
Id: "exampleUserId",
Attributes: []string{"manager"},
})
if err != nil {
panic(err)
}
if user2 == nil {
panic("User not found")
}
fmt.Println(user2.GetStringAttribute("manager"))
}