第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Golang 與 LDAP 通信

Golang 與 LDAP 通信

Go
眼眸繁星 2021-12-07 10:36:17
我正在嘗試使用 golang 將用戶連接到 ldap 并對其進(jìn)行身份驗證。我將go-ldap-client與以下示例代碼一起使用:package mainimport (    "log"    "github.com/jtblin/go-ldap-client")func main() {    client := &ldap.LDAPClient{        Base:         "dc=example,dc=com",        Host:         "ldap.example.com",        Port:         389,        UseSSL:       false,        BindDN:       "uid=readonlysuer,ou=People,dc=example,dc=com",        BindPassword: "readonlypassword",        UserFilter:   "(uid=%s)",        GroupFilter: "(memberUid=%s)",        Attributes:   []string{"givenName", "sn", "mail", "uid"},    }    # It is the responsibility of the caller to close the connection    defer client.Close()    ok, user, err := client.Authenticate("username", "password")    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) }安裝了對 gopkg.in/ldap.v2 的依賴。該問題是,我收到以下錯誤:2016/01/15 17:34:55 Error authenticating user username: LDAP Result Code 2 "Protocol Error": ldap: cannot StartTLS (unsupported extended operation)exit status 1有關(guān)此錯誤的任何提示?
查看完整描述

3 回答

?
LEATH

TA貢獻(xiàn)1936條經(jīng)驗 獲得超7個贊

好的,讓我們嘗試使用github.com/go-ldap/ldap. 首先,您需要創(chuàng)建一個*ldap.Conn. 如果您的 LDAP 服務(wù)器支持,我建議使用 TLS:


// TLS, for testing purposes disable certificate verification, check https://golang.org/pkg/crypto/tls/#Config for further information.

tlsConfig := &tls.Config{InsecureSkipVerify: true}

l, err := ldap.DialTLS("tcp", "ldap.example.com:636", tlsConfig)


// No TLS, not recommended

l, err := ldap.Dial("tcp", "ldap.example.com:389")

現(xiàn)在您應(yīng)該有一個到 LDAP 服務(wù)器的活動連接。使用此連接,您必須執(zhí)行綁定:


err := l.Bind("user@test.com", "password")

if err != nil {

    // error in ldap bind

    log.Println(err)

}

// successful bind


查看完整回答
反對 回復(fù) 2021-12-07
?
慕少森

TA貢獻(xiàn)2019條經(jīng)驗 獲得超9個贊

問題是默認(rèn)情況下,上述 LDAP 客戶端中未設(shè)置“SkipTLS”標(biāo)志。您需要將參數(shù)顯式設(shè)置為 false:


client := &ldap.LDAPClient{

        Base:         "dc=example,dc=com",

        Host:         "ldap.example.com",

        Port:         389,

        UseSSL:       false,

        BindDN:       "uid=readonlysuer,ou=People,dc=example,dc=com",

        BindPassword: "readonlypassword",

        UserFilter:   "(uid=%s)",

        GroupFilter:  "(memberUid=%s)",

        SkipTLS:      true,

        Attributes:   []string{"givenName", "sn", "mail", "uid"},

    }

我將 SkipTLS 設(shè)置為 true 并且它起作用了。希望這可以幫助!


查看完整回答
反對 回復(fù) 2021-12-07
?
溫溫醬

TA貢獻(xiàn)1752條經(jīng)驗 獲得超4個贊

使用go-guardian LDAP 策略的另一種可能的解決方案


基于在線 LDAP 測試服務(wù)器的工作示例


package main


import (

    "fmt"

    "github.com/shaj13/go-guardian/auth/strategies/ldap"

    "net/http"

)


func main() {

    cfg := ldap.Config{

        BaseDN:       "dc=example,dc=com",

        BindDN:       "cn=read-only-admin,dc=example,dc=com",

        Port:         "389",

        Host:         "ldap.forumsys.com",

        BindPassword: "password",

        Filter:       "(uid=%s)",

    }


    r, _ := http.NewRequest("GET", "/", nil)

    r.SetBasicAuth("tesla", "password")


    user, err := ldap.New(&cfg).Authenticate(r.Context(), r)

    fmt.Println(user, err)

}


查看完整回答
反對 回復(fù) 2021-12-07
  • 3 回答
  • 0 關(guān)注
  • 399 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號