golang访问ad域实例
https://github.com/jtblin/go-ldap-client
该代码在20181229日测试通过,采用ldap方式链接ad域

package main

import (
    "log"

    "github.com/jtblin/go-ldap-client"
)

func main() {
    client := &ldap.LDAPClient{
        Base:         "dc=aiwaly,dc=com",
        Host:         "pekdc1-dcs.prod.aiwaly.com",
        Port:         389,
        UseSSL:       false,
        BindDN:       "cn=zeppelin.srv,ou=Business_Accounts,dc=aiwaly,dc=com",
        BindPassword: "xxxxxxx",
        UserFilter:   "(sAMAccountName=%s)",
        //GroupFilter:  "(memberUid=%s)",
        Attributes: []string{"sAMAccountName", "cn", "mail", "departmentName"},
    }
    // It is the responsibility of the caller to close the connection
    defer client.Close()

    ok, user, err := client.Authenticate("jacky2wang", "1qazeeWSX")
    if err != nil {
        log.Fatalf("Error authenticating user %s: %+v", "username", err)
    }
    if !ok {
        log.Fatalf("Authenticating failed for user %s", "username")
    }
    log.Printf("User: %+v", user)
    /*
        groups, err := client.GetGroupsOfUser("username")
        if err != nil {
            log.Fatalf("Error getting groups for user %s: %+v", "username", err)
        }
        log.Printf("Groups: %+v", groups)*/
}
文档更新时间: 2019-06-14 10:28   作者:月影鹏鹏