Login to the server, using the USER and PASS commands.
(String user, String password)
| 341 | * Login to the server, using the USER and PASS commands. |
| 342 | */ |
| 343 | synchronized String login(String user, String password) |
| 344 | throws IOException { |
| 345 | Response r; |
| 346 | // only pipeline password if connection is secure |
| 347 | boolean batch = pipelining && socket instanceof SSLSocket; |
| 348 | |
| 349 | try { |
| 350 | |
| 351 | if (noauthdebug && isTracing()) { |
| 352 | logger.fine("authentication command trace suppressed"); |
| 353 | suspendTracing(); |
| 354 | } |
| 355 | String dpw = null; |
| 356 | if (apopChallenge != null) |
| 357 | dpw = getDigest(password); |
| 358 | if (apopChallenge != null && dpw != null) { |
| 359 | r = simpleCommand("APOP " + user + " " + dpw); |
| 360 | } else if (batch) { |
| 361 | String cmd = "USER " + user; |
| 362 | batchCommandStart(cmd); |
| 363 | issueCommand(cmd); |
| 364 | cmd = "PASS " + password; |
| 365 | batchCommandContinue(cmd); |
| 366 | issueCommand(cmd); |
| 367 | r = readResponse(); |
| 368 | if (!r.ok) { |
| 369 | String err = r.data != null ? r.data : "USER command failed"; |
| 370 | readResponse(); // read and ignore PASS response |
| 371 | batchCommandEnd(); |
| 372 | return err; |
| 373 | } |
| 374 | r = readResponse(); |
| 375 | batchCommandEnd(); |
| 376 | } else { |
| 377 | r = simpleCommand("USER " + user); |
| 378 | if (!r.ok) |
| 379 | return r.data != null ? r.data : "USER command failed"; |
| 380 | r = simpleCommand("PASS " + password); |
| 381 | } |
| 382 | if (noauthdebug && isTracing()) |
| 383 | logger.log(Level.FINE, "authentication command {0}", |
| 384 | (r.ok ? "succeeded" : "failed")); |
| 385 | if (!r.ok) |
| 386 | return r.data != null ? r.data : "login failed"; |
| 387 | return null; |
| 388 | |
| 389 | } finally { |
| 390 | resumeTracing(); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * Gets the APOP message digest. |
no test coverage detected