-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
custom_search_filters.go
46 lines (38 loc) · 991 Bytes
/
custom_search_filters.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
package examples
import (
"fmt"
"github.com/dlampsi/adc"
)
func mainCustomSearchFilters() {
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",
// Custom filter for all users search requests
Users: &adc.UsersConfigs{
FilterById: "(&(objectClass=person)(cn=%v))",
},
// Custom filter for all groups search requests
Groups: &adc.GroupsConfigs{
FilterById: "(&(objectClass=group)(cn=%v))",
},
}
cl := adc.New(cfg)
if err := cl.Connect(); err != nil {
panic(err)
}
// Do stuff...
// Custom search filter per search
// Note that provided `Filter` argument int `GetUserArgs` overwrites `Id` and `Dn` arguments usage.
user, err := cl.GetUser(adc.GetUserArgs{Filter: "(&(objectClass=person)(sAMAccountName=someID))"})
if err != nil {
panic(err)
}
if user == nil {
panic("User not found")
}
fmt.Println(user)
}