//UserInfoByField used to retrieve the information of a given username but use a given field to make the search.
UserInfoByField used to retrieve the information of a given username but use a given field to make the search.
// UserInfoByField used to retrieve the information of a given username but use a given field to make the search .
func (lc *HelperLDAP) UserInfoByField(username string, fieldOfUnicValue string) (map[string]string, liberr.Error) {
	var (
		err     liberr.Error
		src     *ldap.SearchResult
		userRes map[string]string
	)
	if username, err = lc.getUserName(username); err != nil {
		return nil, err
	}
	userRes = make(map[string]string)
	attributes := append(lc.Attributes, "cn")
	src, err = lc.runSearch(fmt.Sprintf(lc.config.FilterUser, fieldOfUnicValue, username), attributes)
	if err != nil {
		return userRes, err
	}
	if len(src.Entries) != 1 {
		if len(src.Entries) > 1 {
			return userRes, ErrorLDAPUserNotUniq.Error(nil)
		} else {
			return userRes, ErrorLDAPUserNotFound.Error(nil)
		}
	}
	for _, attr := range attributes {
		userRes[attr] = src.Entries[0].GetAttributeValue(attr)
	}
	if _, ok := userRes["DN"]; !ok {
		userRes["DN"] = src.Entries[0].DN
	}
	lc.getLogEntry(liblog.DebugLevel, "ldap user find success").FieldAdd("ldap.user", username).FieldAdd("ldap.map", userRes).Log()
	return userRes, nil
}
func ( lc * HelperLDAP ) UserInfoByField ( username string , fieldOfUnicValue string ) ( map [ string ] string , liberr . Error ) { var ( err liberr . Error src * ldap . SearchResult userRes map [ string ] string ) if username , err = lc . getUserName ( username ) ; err != nil { return nil , err } userRes = make ( map [ string ] string ) attributes := append ( lc . Attributes , " " ) src , err = lc . runSearch ( fmt . Sprintf ( lc . config . FilterUser , fieldOfUnicValue , username ) , attributes ) if err != nil { return userRes , err } if len ( src . Entries ) != 1 { if len ( src . Entries ) > 1 { return userRes , ErrorLDAPUserNotUniq . Error ( nil ) } else { return userRes , ErrorLDAPUserNotFound . Error ( nil ) } } for _ , attr := range attributes { userRes [ attr ] = src . Entries [ 0 ] . GetAttributeValue ( attr ) } if _ , ok := userRes [ " " ] ; ! ok { userRes [ " " ] = src . Entries [ 0 ] . DN } lc . getLogEntry ( liblog . DebugLevel , " " ) . FieldAdd ( " " , username ) . FieldAdd ( " " , userRes ) . Log ( ) return userRes , nil }
UserInfoByField used to retrieve the information of a given username but use a given field to make the search.
UserInfoByField used to retrieve the information of a given username but use a given field to make the search .