Exemplo n.º 1
0
// getValue returns the first non-empty value the entry has for the given attributes
func getAttributeValue(entry *ldap.Entry, attributes []string) string {
	for _, k := range attributes {
		// Ignore empty attributes
		if len(k) == 0 {
			continue
		}
		// Special-case DN, since it's not an attribute
		if strings.ToLower(k) == "dn" {
			return entry.DN
		}
		// Otherwise get an attribute and return it if present
		if v := entry.GetAttributeValue(k); len(v) > 0 {
			return v
		}
	}
	return ""
}
Exemplo n.º 2
0
func entryToUser(entry *ldap.Entry) (u *models.Staff) {
	// log.Printf("entry: %v", entry)
	u = new(models.Staff)
	u.Uid = entry.GetAttributeValue("uid")
	u.Surname = entry.GetAttributeValue("sn")
	u.GivenName = entry.GetAttributeValue("givenName")
	u.CommonName = entry.GetAttributeValue("cn")
	u.Email = entry.GetAttributeValue("mail")
	u.Nickname = entry.GetAttributeValue("displayName")
	u.Mobile = entry.GetAttributeValue("mobile")
	u.EmployeeNumber = entry.GetAttributeValue("employeeNumber")
	u.EmployeeType = entry.GetAttributeValue("employeeType")
	u.Description = entry.GetAttributeValue("description")
	return
}