(c flags.FlagContext)
| 212 | } |
| 213 | |
| 214 | func (cmd Login) authenticate(c flags.FlagContext) error { |
| 215 | if cmd.config.UAAGrantType() == "client_credentials" { |
| 216 | return errors.New(T("Service account currently logged in. Use 'cf logout' to log out service account and try again.")) |
| 217 | } |
| 218 | |
| 219 | usernameFlagValue := c.String("u") |
| 220 | passwordFlagValue := c.String("p") |
| 221 | |
| 222 | prompts, err := cmd.authenticator.GetLoginPromptsAndSaveUAAServerURL() |
| 223 | if err != nil { |
| 224 | return err |
| 225 | } |
| 226 | passwordKeys := []string{} |
| 227 | credentials := make(map[string]string) |
| 228 | |
| 229 | if value, ok := prompts["username"]; ok { |
| 230 | if prompts["username"].Type == coreconfig.AuthPromptTypeText && usernameFlagValue != "" { |
| 231 | credentials["username"] = usernameFlagValue |
| 232 | } else { |
| 233 | credentials["username"] = cmd.ui.Ask(T(value.DisplayName)) |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | for key, prompt := range prompts { |
| 238 | if prompt.Type == coreconfig.AuthPromptTypePassword { |
| 239 | if key == "passcode" || key == "password" { |
| 240 | continue |
| 241 | } |
| 242 | |
| 243 | passwordKeys = append(passwordKeys, key) |
| 244 | } else if key == "username" { |
| 245 | continue |
| 246 | } else { |
| 247 | credentials[key] = cmd.ui.Ask(T(prompt.DisplayName)) |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | for i := 0; i < maxLoginTries; i++ { |
| 252 | |
| 253 | // ensure that password gets prompted before other codes (eg. mfa code) |
| 254 | if passPrompt, ok := prompts["password"]; ok { |
| 255 | if passwordFlagValue != "" { |
| 256 | credentials["password"] = passwordFlagValue |
| 257 | passwordFlagValue = "" |
| 258 | } else { |
| 259 | credentials["password"] = cmd.ui.AskForPassword(T(passPrompt.DisplayName)) |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | for _, key := range passwordKeys { |
| 264 | credentials[key] = cmd.ui.AskForPassword(T(prompts[key].DisplayName)) |
| 265 | } |
| 266 | |
| 267 | credentialsCopy := make(map[string]string, len(credentials)) |
| 268 | for k, v := range credentials { |
| 269 | credentialsCopy[k] = v |
| 270 | } |
| 271 |
no test coverage detected