當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Conn.Bind方法代碼示例

本文整理匯總了Golang中github.com/go-ldap/ldap.Conn.Bind方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.Bind方法的具體用法?Golang Conn.Bind怎麽用?Golang Conn.Bind使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/go-ldap/ldap.Conn的用法示例。


在下文中一共展示了Conn.Bind方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: getBindDN

func getBindDN(cfg *ConfigEntry, c *ldap.Conn, username string) (string, error) {
	bindDN := ""
	if cfg.DiscoverDN || (cfg.BindDN != "" && cfg.BindPassword != "") {
		if err := c.Bind(cfg.BindDN, cfg.BindPassword); err != nil {
			return bindDN, fmt.Errorf("LDAP bind (service) failed: %v", err)
		}
		result, err := c.Search(&ldap.SearchRequest{
			BaseDN: cfg.UserDN,
			Scope:  2, // subtree
			Filter: fmt.Sprintf("(%s=%s)", cfg.UserAttr, ldap.EscapeFilter(username)),
		})
		if err != nil {
			return bindDN, fmt.Errorf("LDAP search for binddn failed: %v", err)
		}
		if len(result.Entries) != 1 {
			return bindDN, fmt.Errorf("LDAP search for binddn 0 or not unique")
		}
		bindDN = result.Entries[0].DN
	} else {
		if cfg.UPNDomain != "" {
			bindDN = fmt.Sprintf("%[email protected]%s", EscapeLDAPValue(username), cfg.UPNDomain)
		} else {
			bindDN = fmt.Sprintf("%s=%s,%s", cfg.UserAttr, EscapeLDAPValue(username), cfg.UserDN)
		}
	}

	return bindDN, nil
}
開發者ID:faradayio,項目名稱:vault-1,代碼行數:28,代碼來源:backend.go

示例2: Bind

// Bind binds to a given LDAP connection if a bind DN and password were given.
// Bind returns whether a bind occurred and whether an error occurred
func (l *LDAPClientConfig) Bind(connection *ldap.Conn) (bound bool, err error) {
	if len(l.BindDN) > 0 {
		if err := connection.Bind(l.BindDN, l.BindPassword); err != nil {
			return false, err
		} else {
			return true, nil
		}
	}

	return false, nil
}
開發者ID:urashidmalik,項目名稱:origin,代碼行數:13,代碼來源:client.go

示例3: bindReadOnlyUser

func (la *LDAPAuth) bindReadOnlyUser(l *ldap.Conn) error {
	if la.config.BindDN != "" {
		password, err := ioutil.ReadFile(la.config.BindPasswordFile)
		if err != nil {
			return err
		}
		glog.V(2).Infof("Bind read-only user %s", string(password))
		err = l.Bind(la.config.BindDN, string(password))
		if err != nil {
			return err
		}
	}
	return nil
}
開發者ID:frank12268,項目名稱:docker_auth,代碼行數:14,代碼來源:ldap_auth.go

示例4: bindReadOnlyUser

func (la *LDAPAuth) bindReadOnlyUser(l *ldap.Conn) error {
	if la.config.BindDN != "" {
		password, err := ioutil.ReadFile(la.config.BindPasswordFile)
		if err != nil {
			return err
		}
		password_str := strings.TrimSpace(string(password))
		glog.V(2).Infof("Bind read-only user (DN = %s)", la.config.BindDN)
		err = l.Bind(la.config.BindDN, password_str)
		if err != nil {
			return err
		}
	}
	return nil
}
開發者ID:nautsio,項目名稱:docker_auth,代碼行數:15,代碼來源:ldap_auth.go

示例5: indexHandler


//.........這裏部分代碼省略.........
	}

	if strings.ToLower(dn) != strings.ToLower(rconf.LDAP_URL[ldap_count][3]) {
		if ldapSearchMode == 1 && xSearchPplMode == 0 {
			dn_back_tmp = strings.Split(dn, ",")
			for ckl1 = 1; ckl1 < len(dn_back_tmp); ckl1++ {
				if ckl1 == 1 {
					dn_back = dn_back_tmp[ckl1]
				} else {
					dn_back += fmt.Sprintf(",%s", dn_back_tmp[ckl1])
				}
			}
		}
	}

	//	log.Printf("%s ... Initialize LDAP connector...", remIPClient)

	if initLDAPConnector() == "error" {
		return
	}

	l, err = ldap.Dial("tcp", rconf.LDAP_URL[ldap_count][0])
	if err != nil {
		fmt.Fprintf(w, err.Error())
		log.Printf("LDAP::Initialize() error: %v\n", err)
		return
	}

	//		l.Debug = true
	defer l.Close()

	log.Printf("%s =!= Connected to server %d of %d: %s", remIPClient, ldap_count+1, len(rconf.LDAP_URL), rconf.LDAP_URL[ldap_count][0])

	err = l.Bind(rconf.LDAP_URL[ldap_count][1], rconf.LDAP_URL[ldap_count][2])
	if err != nil {
		fmt.Fprintf(w, err.Error())
		log.Printf("LDAP::Bind() error: %v\n", err)
		return
	}

	t, err := template.ParseFiles("templates/header.html")
	if err != nil {
		fmt.Fprintf(w, err.Error())
		log.Println(err.Error())
		return
	}

	t.ExecuteTemplate(w, "header", template.FuncMap{"Pagetitle": rconf.WLB_HTML_Title, "FRColor": xFRColor, "BGColor": xBGColor})

	t, err = template.ParseFiles("templates/search.html")
	if err != nil {
		fmt.Fprintf(w, err.Error())
		log.Println(err.Error())
		return
	}

	t.ExecuteTemplate(w, "search", template.FuncMap{"GoHome": go_home_button, "PrevDN": dn_back, "DN": dn, "xSearch": xSearch, "xMessage": xMessage, "LineColor": "#EEEEEE", "LUserName": LUserName, "LoginShow": "Yes", "RedirectDN": r.RequestURI})

	t, err = template.ParseFiles("templates/index.html")
	if err != nil {
		fmt.Fprintf(w, err.Error())
		log.Println(err.Error())
		return
	}

	if xSearchPplMode == 0 {
開發者ID:BestianRU,項目名稱:SABookServices,代碼行數:67,代碼來源:WebLDAPBook.go

示例6: davDNHandler


//.........這裏部分代碼省略.........
		queryx = fmt.Sprintf("insert into aaa_dav_ntu (userid,updtime) select %d,%v where not exists (select userid from aaa_dav_ntu where userid=%d); update aaa_dav_ntu set updtime=%v where userid=%d;", xId, time.Now().Unix(), xId, time.Now().Unix(), xId)
		//fmt.Printf("%s\n", queryx)
		_, err = dbpg.Query(queryx)
		if err != nil {
			log.Printf("%s\n", queryx)
			log.Printf("PG::Query() Update NTU table: %v\n", err)
			return
		}

		log.Printf("%s --> Set DavDN List for %s", remIPClient, uFullname)

		time.Sleep(time.Second)
		fmt.Fprintf(w, "<script type=\"text/javascript\">window.close();</script>")

	} else {

		log.Printf("%s <-- Get DavDN List for %s", remIPClient, uFullname)

		if initLDAPConnector() == "error" {
			return
		}

		l, err = ldap.Dial("tcp", rconf.LDAP_URL[ldap_count][0])
		if err != nil {
			fmt.Fprintf(w, err.Error())
			log.Printf("LDAP::Initialize() error: %v\n", err)
			return
		}

		//		l.Debug = true
		defer l.Close()

		log.Printf("%s =!= Connected to server %d of %d: %s", remIPClient, ldap_count+1, len(rconf.LDAP_URL), rconf.LDAP_URL[ldap_count][0])

		err = l.Bind(rconf.LDAP_URL[ldap_count][1], rconf.LDAP_URL[ldap_count][2])
		if err != nil {
			fmt.Fprintf(w, err.Error())
			log.Printf("LDAP::Bind() error: %v\n", err)
			return
		}

		t, err := template.ParseFiles("templates/header.html")
		if err != nil {
			fmt.Fprintf(w, err.Error())
			log.Println(err.Error())
			return
		}
		t.ExecuteTemplate(w, "header", template.FuncMap{"Pagetitle": rconf.WLB_HTML_Title, "FRColor": xFRColor, "BGColor": xBGColor, "TREEOn": "Yes"})

		t, err = template.ParseFiles("templates/tree-00.html")
		if err != nil {
			fmt.Fprintf(w, err.Error())
			log.Println(err.Error())
			return
		}
		t.ExecuteTemplate(w, "tree-00", template.FuncMap{"UID": uid})

		queryx = fmt.Sprintf("select distinct uid from ldap_entries where lower(dn)=lower('%s') limit 1;", rconf.LDAP_URL[ldap_count][3])
		rows, err := dbpg.Query(queryx)
		if err != nil {
			log.Printf("%s\n", queryx)
			log.Printf("PG::Query() Get UID for DN: %v\n", err)
			return
		}
		rows.Next()
		uidDN := ""
		rows.Scan(&uidDN)

		queryx = fmt.Sprintf("select z.uid from aaa_dns as x, aaa_logins as y, ldap_entries as z where x.userid=y.id and x.dn=z.dn and y.uid='%s';", uid)
		//fmt.Printf("%s\n", queryx)
		rows, err = dbpg.Query(queryx)
		if err != nil {
			log.Printf("%s\n", queryx)
			log.Printf("PG::Query() Get UID for DN: %v\n", err)
			return
		}

		dnList := make([]string, 0)

		x := ""
		for rows.Next() {
			rows.Scan(&x)
			dnList = append(dnList, x)
			//fmt.Printf("%s\n", x)
		}

		//fmt.Printf("%v\n", dnList)

		getLDAPdnList(l, uidDN, 0, rconf.WLB_DavDNTreeDepLev, w, r, dnList)

		t, err = template.ParseFiles("templates/tree-10.html")
		if err != nil {
			fmt.Fprintf(w, err.Error())
			log.Println(err.Error())
			return
		}
		t.ExecuteTemplate(w, "tree-10", nil)

	}
}
開發者ID:BestianRU,項目名稱:SABookServices,代碼行數:101,代碼來源:WebLDAPBook.go


注:本文中的github.com/go-ldap/ldap.Conn.Bind方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。