// GetUserIDViaCache gets the user from cache
498846
func (auth *AuthProxy) GetUserIDViaCache() (int64, error) {
	var (
		cacheKey    = auth.getKey()
		userID, err = auth.store.Get(cacheKey)
	)

	if err != nil {
		return 0, err
	}

	return userID.(int64), nil
}
897234
func (ic *ImageCache) GetCache(parentID string, cfg *containertypes.Config) (string, error) {
	imgID, err := ic.localImageCache.GetCache(parentID, cfg)
	if err != nil {
		return "", err
	}
	if imgID != "" {
		for _, s := range ic.sources {
			if ic.isParent(s.ID(), image.ID(imgID)) {
				return imgID, nil
			}
		}
	}

	var parent *image.Image
	lenHistory := 0
	if parentID != "" {
		parent, err = ic.store.Get(image.ID(parentID))
		if err != nil {
			return "", errors.Wrapf(err, "unable to find image %v", parentID)
		}
		lenHistory = len(parent.History)
	}

	for _, target := range ic.sources {
		if !isValidParent(target, parent) || !isValidConfig(cfg, target.History[lenHistory]) {
			continue
		}

		if len(target.History)-1 == lenHistory { // last
			if parent != nil {
				if err := ic.store.SetParent(target.ID(), parent.ID()); err != nil {
					return "", errors.Wrapf(err, "failed to set parent for %v to %v", target.ID(), parent.ID())
				}
			}
			return target.ID().String(), nil
		}

		imgID, err := ic.restoreCachedImage(parent, target, cfg)
		if err != nil {
			return "", errors.Wrapf(err, "failed to restore cached image from %q to %v", parentID, target.ID())
		}

		ic.sources = []*image.Image{target} // avoid jumping to different target, tuned for safety atm
		return imgID.String(), nil
	}

	return "", nil
}
136649
func (obj *Global) GetAuthenticatedUser(ctx context.Context) (string, error) {
	result := &struct {
		Return string	`json:"qReturn"`
	} {}
	err := obj.rpc(ctx, "GetAuthenticatedUser", result)
	return result.Return, err 
}
1142306
func (c *ACLCaches) GetIdentity(id string) *IdentityCacheEntry {
	if c == nil || c.identities == nil {
		return nil
	}

	if raw, ok := c.identities.Get(id); ok {
		return raw.(*IdentityCacheEntry)
	}

	return nil
}
912218
func (a *AuthServer) GetUsers() (users []services.User, err error) {
	return a.GetCache().GetUsers()
}
112786
func (app *App) UserCache() string {
	return UserCacheDir(app.Name, app.Author, app.Version, app.Opinion)
}
541740
func getUserKey(attr admission.Attributes) string {
	userInfo := attr.GetUserInfo()
	if userInfo == nil {
		return ""
	}
	return userInfo.GetName()
}
989304
func (s *service) RetrieveUserInfoByUserId(userId uint) (resDTO rest.ResponseDTOUserInfo, error *servicehelper.Error) {
	entity, err := s.repo.FindByID(userId)
	if err != nil {
		return rest.ResponseDTOUserInfo{}, &servicehelper.Error{Detail: errors.New("no result found"), Code: servicehelper.NotFound}
	}
	return rest.ResponseDTOUserInfo{
		UserId: entity.ID,
		Email:  entity.Email,
	}, nil
}
1044023
func (self *OpenIdProvider) GetAuthenticatedUser(w http.ResponseWriter, r *http.Request) (User, Token, error) {

	// Parse the url parameters
	params := r.URL.Query()

	// Check to see if the user successfully authenticated
	if params.Get("openid.mode") == "cancel" {
		return nil, nil, ErrAuthDeclined
	}

	// Get the user details from the URL parameters
	lastName := params.Get("openid.ext1.value.lastname")
	firstName := params.Get("openid.ext1.value.firstname")
	fullName := fmt.Sprintf("%s %s", firstName, lastName)
	email := params.Get("openid.ext1.value.email")

	// Return the User data
	// TODO for now we are re-using the Google User
	user := user{id: email, email: email, name: fullName, provider: self.endpoint }
	return &user, nil, nil
}
494999
func GetUsername() *string {
	// user.Current only fails on some internal cache error: not sure what
	// corrective action is appropriate... on failure return NULL.
	if u, err := user.Current(); err == nil {
		return &u.Username
	}
	return nil
}
193601
func GetCAByUniqueID(c context.Context, id int64) (string, error) {
	cached, err := mappingCache.Fetch(c, func(interface{}) (interface{}, time.Duration, error) {
		val, err := LoadCAUniqueIDToCNMap(c)
		return val, time.Minute, err
	})
	if err != nil {
		return "", err
	}
	mapping := cached.(map[int64]string)
	return mapping[id], nil
}
358580
func (sys *IAMSys) GetUserPolicy(accessKey string) (policyName string, err error) {
	objectAPI := newObjectLayerFn()
	if objectAPI == nil {
		return "", errServerNotInitialized
	}

	sys.RLock()
	defer sys.RUnlock()

	if _, ok := sys.iamUsersMap[accessKey]; !ok {
		return "", errNoSuchUser
	}

	if _, ok := sys.iamPolicyMap[accessKey]; !ok {
		return "", errNoSuchUser
	}

	return sys.iamPolicyMap[accessKey], nil
}
238501
func (c *UserCardCache) Get(uid keybase1.UID, useSession bool) (*keybase1.UserCard, error) {
	v, err := c.cache.Get(c.key(uid, useSession))
	if err != nil {
		if err == ramcache.ErrNotFound {
			return nil, nil
		}
		return nil, err
	}
	card, ok := v.(keybase1.UserCard)
	if !ok {
		return nil, fmt.Errorf("invalid type in cache: %T", v)
	}
	return &card, nil
}
296593
func (s *serverConfig) GetCacheConfig() CacheConfig {
	if globalIsDiskCacheEnabled {
		return CacheConfig{
			Drives:  globalCacheDrives,
			Exclude: globalCacheExcludes,
			Expiry:  globalCacheExpiry,
			MaxUse:  globalCacheMaxUse,
		}
	}
	if s == nil {
		return CacheConfig{}
	}
	return s.Cache
}
460405
func GetIdentityCache() IdentityCache {
	cache := IdentityCache{}

	if IdentityAllocator != nil {

		IdentityAllocator.ForeachCache(func(id idpool.ID, val allocator.AllocatorKey) {
			if val != nil {
				if gi, ok := val.(globalIdentity); ok {
					cache[identity.NumericIdentity(id)] = gi.LabelArray
				} else {
					log.Warningf("Ignoring unknown identity type '%s': %+v",
						reflect.TypeOf(val), val)
				}
			}
		})
	}

	for key, identity := range identity.ReservedIdentityCache {
		cache[key] = identity.Labels.LabelArray()
	}

	if localIdentities != nil {
		for _, identity := range localIdentities.GetIdentities() {
			cache[identity.ID] = identity.Labels.LabelArray()
		}
	}

	return cache
}
349522
func GetUserByLoginOrEmail(c *m.ReqContext) Response {
	query := m.GetUserByLoginQuery{LoginOrEmail: c.Query("loginOrEmail")}
	if err := bus.Dispatch(&query); err != nil {
		if err == m.ErrUserNotFound {
			return Error(404, m.ErrUserNotFound.Error(), nil)
		}
		return Error(500, "Failed to get user", err)
	}
	user := query.Result
	result := m.UserProfileDTO{
		Id:             user.Id,
		Name:           user.Name,
		Email:          user.Email,
		Login:          user.Login,
		Theme:          user.Theme,
		IsGrafanaAdmin: user.IsAdmin,
		OrgId:          user.OrgId,
	}
	return JSON(200, &result)
}
760421
func (api UsersAPI) GetUserInformation(w http.ResponseWriter, r *http.Request) {
	username := mux.Vars(r)["username"]
	userMgr := user.NewManager(r)

	userobj, err := userMgr.GetByName(username)
	if err != nil {
		http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
		return
	}

	requestingClient, validClient := context.Get(r, "client_id").(string)
	if !validClient {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	availableScopes, _ := context.Get(r, "availablescopes").(string)
	isAdmin := oauth2.CheckScopes([]string{"user:admin"}, oauth2.SplitScopeString(availableScopes))

	authorization, err := userMgr.GetAuthorization(username, requestingClient)
	if handleServerError(w, "getting authorization", err) {
		return
	}

	//Create an administrator authorization
	// TODO: rework for non admin scope in client credentials
	// if authorization is nil we are already assured that this is client credentials due to the middleware
	authorizedScopes := oauth2.SplitScopeString(availableScopes)
	if authorization == nil {
		authorization = &user.Authorization{
			// TODO: check bool values
			Name:                    false,
			Github:                  false,
			Facebook:                false,
			Addresses:               []user.AuthorizationMap{},
			BankAccounts:            []user.AuthorizationMap{},
			DigitalWallet:           []user.DigitalWalletAuthorization{},
			EmailAddresses:          []user.AuthorizationMap{},
			ValidatedEmailAddresses: []user.AuthorizationMap{},
			Phonenumbers:            []user.AuthorizationMap{},
			ValidatedPhonenumbers:   []user.AuthorizationMap{},
			PublicKeys:              []user.AuthorizationMap{},
			Avatars:                 []user.AuthorizationMap{},
			Organizations:           []string{},
		}
		_, all := filterAuthorizedInfo(authorizedScopes, "user:name")
		if isAdmin || all {
			authorization.Name = true
		}
		_, all = filterAuthorizedInfo(authorizedScopes, "user:github")
		if isAdmin || all {
			authorization.Github = true
		}
		_, all = filterAuthorizedInfo(authorizedScopes, "user:facebook")
		if isAdmin || all {
			authorization.Facebook = true
		}
		for _, address := range userobj.Addresses {
			labels, all := filterAuthorizedInfo(authorizedScopes, "user:address")
			if all || isAdmin {
				authorization.Addresses = append(authorization.Addresses, user.AuthorizationMap{RequestedLabel: address.Label, RealLabel: address.Label})
				continue
			}
			for _, label := range labels {
				if label == address.Label {
					authorization.Addresses = append(authorization.Addresses, user.AuthorizationMap{RequestedLabel: address.Label, RealLabel: address.Label})
				}
			}
		}
		for _, a := range userobj.BankAccounts {
			labels, all := filterAuthorizedInfo(authorizedScopes, "user:bankaccount")
			if all || isAdmin {
				authorization.BankAccounts = append(authorization.BankAccounts, user.AuthorizationMap{RequestedLabel: a.Label, RealLabel: a.Label})
				continue
			}
			for _, label := range labels {
				if label == a.Label {
					authorization.BankAccounts = append(authorization.BankAccounts, user.AuthorizationMap{RequestedLabel: a.Label, RealLabel: a.Label})
				}
			}
		}
		for _, a := range userobj.DigitalWallet {
			labels, all := filterAuthorizedInfo(authorizedScopes, "user:digitalwalletaddress")
			if all || isAdmin {
				authorization.DigitalWallet = append(authorization.DigitalWallet, user.DigitalWalletAuthorization{Currency: a.CurrencySymbol, AuthorizationMap: user.AuthorizationMap{RequestedLabel: a.Label, RealLabel: a.Label}})
				continue
			}
			for _, label := range labels {
				if label == a.Label {
					authorization.DigitalWallet = append(authorization.DigitalWallet, user.DigitalWalletAuthorization{Currency: a.CurrencySymbol, AuthorizationMap: user.AuthorizationMap{RequestedLabel: a.Label, RealLabel: a.Label}})
				}
			}
		}
		for _, a := range userobj.EmailAddresses {
			labels, all := filterAuthorizedInfo(authorizedScopes, "user:email")
			if all || isAdmin {
				authorization.EmailAddresses = append(authorization.EmailAddresses, user.AuthorizationMap{RequestedLabel: a.Label, RealLabel: a.Label})
				continue
			}
			for _, label := range labels {
				if label == a.Label {
					authorization.EmailAddresses = append(authorization.EmailAddresses, user.AuthorizationMap{RequestedLabel: a.Label, RealLabel: a.Label})
				}
			}
		}
		for _, a := range userobj.EmailAddresses {
			labels, all := filterAuthorizedInfo(authorizedScopes, "user:validated:email")
			if all || isAdmin {
				authorization.ValidatedEmailAddresses = append(authorization.ValidatedEmailAddresses, user.AuthorizationMap{RequestedLabel: a.Label, RealLabel: a.Label})
				continue
			}
			for _, label := range labels {
				if label == a.Label {
					authorization.ValidatedEmailAddresses = append(authorization.ValidatedEmailAddresses, user.AuthorizationMap{RequestedLabel: a.Label, RealLabel: a.Label})
				}
			}
		}
		for _, a := range userobj.Phonenumbers {
			labels, all := filterAuthorizedInfo(authorizedScopes, "user:phone")
			if all || isAdmin {
				authorization.Phonenumbers = append(authorization.Phonenumbers, user.AuthorizationMap{RequestedLabel: a.Label, RealLabel: a.Label})
				continue
			}
			for _, label := range labels {
				if label == a.Label {
					authorization.Phonenumbers = append(authorization.Phonenumbers, user.AuthorizationMap{RequestedLabel: a.Label, RealLabel: a.Label})
				}
			}
		}
		for _, a := range userobj.Phonenumbers {
			labels, all := filterAuthorizedInfo(authorizedScopes, "user:validated:phone")
			if all || isAdmin {
				authorization.ValidatedPhonenumbers = append(authorization.ValidatedPhonenumbers, user.AuthorizationMap{RequestedLabel: a.Label, RealLabel: a.Label})
				continue
			}
			for _, label := range labels {
				if label == a.Label {
					authorization.ValidatedPhonenumbers = append(authorization.ValidatedPhonenumbers, user.AuthorizationMap{RequestedLabel: a.Label, RealLabel: a.Label})
				}
			}
		}
		for _, a := range userobj.PublicKeys {
			labels, all := filterAuthorizedInfo(authorizedScopes, "user:publickey")
			if all || isAdmin {
				authorization.PublicKeys = append(authorization.PublicKeys, user.AuthorizationMap{RequestedLabel: a.Label, RealLabel: a.Label})
				continue
			}
			for _, label := range labels {
				if label == a.Label {
					authorization.PublicKeys = append(authorization.PublicKeys, user.AuthorizationMap{RequestedLabel: a.Label, RealLabel: a.Label})
				}
			}
		}
		for _, a := range userobj.Avatars {
			labels, all := filterAuthorizedInfo(authorizedScopes, "user:avatar")
			if all || isAdmin {
				authorization.Avatars = append(authorization.Avatars, user.AuthorizationMap{RequestedLabel: a.Label, RealLabel: a.Label})
				continue
			}
			for _, label := range labels {
				if label == a.Label {
					authorization.Avatars = append(authorization.Avatars, user.AuthorizationMap{RequestedLabel: a.Label, RealLabel: a.Label})
				}
			}
		}
		labels, _ := filterAuthorizedInfo(authorizedScopes, "user:memberof")
		if len(labels) > 0 || isAdmin {
			userOrgs, err := organizationDb.NewManager(r).AllByUserChain(username)
			if handleServerError(w, "Getting user organizations", err) {
				return
			}
			for _, a := range userOrgs {
				if isAdmin {
					authorization.Organizations = append(authorization.Organizations, a)
					continue
				}
				for _, l := range labels {
					if l == a {
						authorization.Organizations = append(authorization.Organizations, a)
					}
				}
			}
		}

	}
	if authorization == nil {
		http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
		return
	}

	respBody := &Userview{
		Username:                userobj.Username,
		Github:                  user.GithubAccount{},
		Facebook:                user.FacebookAccount{},
		Addresses:               []user.Address{},
		EmailAddresses:          []user.EmailAddress{},
		ValidatedEmailAddresses: []user.EmailAddress{},
		Phonenumbers:            []user.Phonenumber{},
		ValidatedPhonenumbers:   []user.Phonenumber{},
		BankAccounts:            []user.BankAccount{},
		DigitalWallet:           []user.DigitalAssetAddress{},
		OwnerOf: user.OwnerOf{
			EmailAddresses: []string{},
		},
		PublicKeys:    []user.PublicKey{},
		Avatars:       []user.Avatar{},
		Organizations: []string{},
	}

	if authorization.Name {
		respBody.Firstname = userobj.Firstname
		respBody.Lastname = userobj.Lastname
	}

	if authorization.Github {
		respBody.Github = userobj.Github
	}

	if authorization.Facebook {
		respBody.Facebook = userobj.Facebook
	}

	if authorization.Addresses != nil {
		for _, addressmap := range authorization.Addresses {
			address, err := userobj.GetAddressByLabel(addressmap.RealLabel)
			if err == nil {
				newaddress := user.Address{
					Label:      addressmap.RequestedLabel,
					City:       address.City,
					Country:    address.Country,
					Nr:         address.Nr,
					Other:      address.Other,
					Postalcode: address.Postalcode,
					Street:     address.Street,
				}
				respBody.Addresses = append(respBody.Addresses, newaddress)
			} else {
				log.Debug(err)
			}
		}
	}

	if authorization.EmailAddresses != nil {
		for _, emailmap := range authorization.EmailAddresses {
			email, err := userobj.GetEmailAddressByLabel(emailmap.RealLabel)
			if err == nil {
				newemail := user.EmailAddress{
					Label:        emailmap.RequestedLabel,
					EmailAddress: email.EmailAddress,
				}
				respBody.EmailAddresses = append(respBody.EmailAddresses, newemail)
			} else {
				log.Debug(err)
			}
		}
	}

	if authorization.Phonenumbers != nil {
		for _, phonemap := range authorization.Phonenumbers {
			phonenumber, err := userobj.GetPhonenumberByLabel(phonemap.RealLabel)
			if err == nil {
				newnumber := user.Phonenumber{
					Label:       phonemap.RequestedLabel,
					Phonenumber: phonenumber.Phonenumber,
				}
				respBody.Phonenumbers = append(respBody.Phonenumbers, newnumber)
			} else {
				log.Debug(err)
			}
		}
	}

	if authorization.BankAccounts != nil {
		for _, bankmap := range authorization.BankAccounts {
			bank, err := userobj.GetBankAccountByLabel(bankmap.RealLabel)
			if err == nil {
				newbank := user.BankAccount{
					Label:   bankmap.RequestedLabel,
					Bic:     bank.Bic,
					Country: bank.Country,
					Iban:    bank.Iban,
				}
				respBody.BankAccounts = append(respBody.BankAccounts, newbank)
			} else {
				log.Debug(err)
			}
		}
	}

	if authorization.DigitalWallet != nil {
		for _, addressMap := range authorization.DigitalWallet {
			walletAddress, err := userobj.GetDigitalAssetAddressByLabel(addressMap.RealLabel)
			if err == nil {
				walletAddress.Label = addressMap.RequestedLabel
				respBody.DigitalWallet = append(respBody.DigitalWallet, walletAddress)
			} else {
				log.Debug(err)
			}
		}
	}

	if authorization.PublicKeys != nil {
		for _, publicKeyMap := range authorization.PublicKeys {
			publicKey, err := userobj.GetPublicKeyByLabel(publicKeyMap.RealLabel)
			if err == nil {
				publicKey.Label = publicKeyMap.RequestedLabel
				respBody.PublicKeys = append(respBody.PublicKeys, publicKey)
			} else {
				log.Debug(err)
			}
		}
	}

	if authorization.Avatars != nil {
		for _, avatarMap := range authorization.Avatars {
			avatar, err := userobj.GetAvatarByLabel(avatarMap.RealLabel)
			if err == nil {
				avatar.Label = avatarMap.RequestedLabel
				respBody.Avatars = append(respBody.Avatars, avatar)
			} else {
				log.Debug(err)
			}
		}
	}

	if authorization.Organizations != nil {
		respBody.Organizations = authorization.Organizations
	}

	valMgr := validationdb.NewManager(r)
	if authorization.ValidatedEmailAddresses != nil {
		for _, validatedEmailMap := range authorization.ValidatedEmailAddresses {
			email, err := userobj.GetEmailAddressByLabel(validatedEmailMap.RealLabel)
			if err == nil {
				validated, err := valMgr.IsEmailAddressValidated(authorization.Username, email.EmailAddress)
				if err != nil {
					log.Error("Failed to verify if email address is validated for this user: ", err)
					continue
				}
				if !validated {
					continue
				}
				email.Label = validatedEmailMap.RequestedLabel
				respBody.ValidatedEmailAddresses = append(respBody.ValidatedEmailAddresses, email)
			} else {
				log.Debug(err)
			}
		}

		if authorization.ValidatedPhonenumbers != nil {
			for _, validatedPhoneMap := range authorization.ValidatedPhonenumbers {
				phone, err := userobj.GetPhonenumberByLabel(validatedPhoneMap.RealLabel)
				if err == nil {
					validated, err := valMgr.IsPhonenumberValidated(authorization.Username, phone.Phonenumber)
					if err != nil {
						log.Error("Failed to verify if phone number is validated for this user: ", err)
						continue
					}
					if !validated {
						continue
					}
					phone.Label = validatedPhoneMap.RequestedLabel
					respBody.ValidatedPhonenumbers = append(respBody.ValidatedPhonenumbers, phone)
				} else {
					log.Debug(err)
				}
			}
		}
	}

	if authorization.OwnerOf.EmailAddresses != nil {
		respBody.OwnerOf.EmailAddresses = authorization.OwnerOf.EmailAddresses
	}

	w.Header().Set("Content-Type", "application/json")
	json.NewEncoder(w).Encode(respBody)
}