//UserMemberOf returns the group list of a given user.
UserMemberOf returns the group list of a given user.
// UserMemberOf returns the group list of a given user .
func (lc *HelperLDAP) UserMemberOf(username string) ([]string, liberr.Error) {
	var (
		err liberr.Error
		src *ldap.SearchResult
		grp []string
	)
	if username, err = lc.getUserName(username); err != nil {
		return nil, err
	}
	grp = make([]string, 0)
	src, err = lc.runSearch(fmt.Sprintf(lc.config.FilterUser, userFieldUid, username), []string{"memberOf"})
	if err != nil {
		return grp, err
	}
	for _, entry := range src.Entries {
		for _, mmb := range entry.GetAttributeValues("memberOf") {
			lc.getLogEntry(liblog.DebugLevel, "ldap find user group list building").FieldAdd("ldap.user", username).FieldAdd("ldap.raw.groups", mmb).Log()
			mmo := lc.ParseEntries(mmb)
			grp = append(grp, mmo["cn"]...)
		}
	}
	lc.getLogEntry(liblog.DebugLevel, "ldap user group list success").FieldAdd("ldap.user", username).FieldAdd("ldap.grouplist", grp).Log()
	return grp, nil
}
func ( lc * HelperLDAP ) UserMemberOf ( username string ) ( [ ] string , liberr . Error ) { var ( err liberr . Error src * ldap . SearchResult grp [ ] string ) if username , err = lc . getUserName ( username ) ; err != nil { return nil , err } grp = make ( [ ] string , 0 ) src , err = lc . runSearch ( fmt . Sprintf ( lc . config . FilterUser , userFieldUid , username ) , [ ] string { " " } ) if err != nil { return grp , err } for _ , entry := range src . Entries { for _ , mmb := range entry . GetAttributeValues ( " " ) { lc . getLogEntry ( liblog . DebugLevel , " " ) . FieldAdd ( " " , username ) . FieldAdd ( " " , mmb ) . Log ( ) mmo := lc . ParseEntries ( mmb ) grp = append ( grp , mmo [ " " ] ... ) } } lc . getLogEntry ( liblog . DebugLevel , " " ) . FieldAdd ( " " , username ) . FieldAdd ( " " , grp ) . Log ( ) return grp , nil }
UserMemberOf returns the group list of a given user.
UserMemberOf returns the group list of a given user .