Commit b63a52f4 authored by Mickaël Guessant's avatar Mickaël Guessant

Log all connections and logon success / failure

git-svn-id: https://svn.code.sf.net/p/davmail/code/trunk@2463 3d1905a2-6b24-0410-a738-b14d5a86fcbd
parent b205fadd
......@@ -21,6 +21,7 @@ package davmail;
import davmail.exception.DavMailException;
import davmail.exchange.ExchangeSession;
import davmail.ui.tray.DavGatewayTray;
import org.apache.log4j.Logger;
import java.io.*;
import java.net.Socket;
......@@ -143,6 +144,7 @@ public class AbstractConnection extends Thread {
public AbstractConnection(String name, Socket clientSocket, String encoding) {
super(name + '-' + clientSocket.getPort());
this.client = clientSocket;
logConnection("CONNECT", "");
try {
in = new LineReaderInputStream(client.getInputStream(), encoding);
os = new BufferedOutputStream(client.getOutputStream());
......@@ -152,6 +154,10 @@ public class AbstractConnection extends Thread {
}
}
public void logConnection(String action, String userName) {
Logger.getLogger("davmail.connection").info(action+" - "+client.getInetAddress().getHostAddress()+":"+client.getPort()+" " + userName);
}
/**
* Send message to client followed by CRLF.
*
......
......@@ -166,8 +166,10 @@ public class CaldavConnection extends AbstractConnection {
// need to check session on each request, credentials may have changed or session expired
try {
session = ExchangeSessionFactory.getInstance(userName, password);
logConnection("LOGON", userName);
handleRequest(command, path, headers, content);
} catch (DavMailAuthenticationException e) {
logConnection("FAILED", userName);
if (Settings.getBooleanProperty("davmail.enableKerberos")) {
// authentication failed in Kerberos mode => not available
throw new HttpServerErrorException("Kerberos authentication failed");
......@@ -756,6 +758,9 @@ public class CaldavConnection extends AbstractConnection {
}
}
if (!eventName.equals(item.getName())) {
DavGatewayTray.warn(new BundleMessage("LOG_MESSAGE", "wrong item name requested "+eventName+" received "+item.getName()));
}
appendItemResponse(response, request, item);
}
} catch (SocketException e) {
......
......@@ -110,9 +110,11 @@ public class ImapConnection extends AbstractConnection {
splitUserName();
try {
session = ExchangeSessionFactory.getInstance(userName, password);
logConnection("LOGON", userName);
sendClient(commandId + " OK Authenticated");
state = State.AUTHENTICATED;
} catch (Exception e) {
logConnection("FAILED", userName);
DavGatewayTray.error(e);
if (Settings.getBooleanProperty("davmail.enableKerberos")) {
sendClient(commandId + " NO LOGIN Kerberos authentication failed");
......@@ -135,9 +137,11 @@ public class ImapConnection extends AbstractConnection {
state = State.PASSWORD;
password = IOUtil.decodeBase64AsString(readClient());
session = ExchangeSessionFactory.getInstance(userName, password);
logConnection("LOGON", userName);
sendClient(commandId + " OK Authenticated");
state = State.AUTHENTICATED;
} catch (Exception e) {
logConnection("FAILED", userName);
DavGatewayTray.error(e);
sendClient(commandId + " NO LOGIN failed");
state = State.INITIAL;
......
......@@ -565,8 +565,10 @@ public class LdapConnection extends AbstractConnection {
DavGatewayTray.debug(new BundleMessage("LOG_LDAP_REQ_BIND_USER", currentMessageId, userName));
try {
session = ExchangeSessionFactory.getInstance(userName, password);
logConnection("LOGON", userName);
DavGatewayTray.debug(new BundleMessage("LOG_LDAP_REQ_BIND_SUCCESS"));
} catch (IOException e) {
logConnection("FAILED", userName);
serverResponse = EMPTY_BYTE_ARRAY;
status = LDAP_INVALID_CREDENTIALS;
DavGatewayTray.debug(new BundleMessage("LOG_LDAP_REQ_BIND_INVALID_CREDENTIALS"));
......@@ -605,9 +607,11 @@ public class LdapConnection extends AbstractConnection {
DavGatewayTray.debug(new BundleMessage("LOG_LDAP_REQ_BIND_USER", currentMessageId, userName));
try {
session = ExchangeSessionFactory.getInstance(userName, password);
logConnection("LOGON", userName);
DavGatewayTray.debug(new BundleMessage("LOG_LDAP_REQ_BIND_SUCCESS"));
sendClient(currentMessageId, LDAP_REP_BIND, LDAP_SUCCESS, "");
} catch (IOException e) {
logConnection("FAILED", userName);
DavGatewayTray.debug(new BundleMessage("LOG_LDAP_REQ_BIND_INVALID_CREDENTIALS"));
sendClient(currentMessageId, LDAP_REP_BIND, LDAP_INVALID_CREDENTIALS, "");
}
......
......@@ -138,9 +138,11 @@ public class PopConnection extends AbstractConnection {
password = line.substring("PASS".length() + 1);
try {
session = ExchangeSessionFactory.getInstance(userName, password);
logConnection("LOGON", userName);
sendOK("PASS");
state = State.AUTHENTICATED;
} catch (SocketException e) {
logConnection("FAILED", userName);
// can not send error to client after a socket exception
LOGGER.warn(BundleMessage.formatLog("LOG_CLIENT_CLOSED_CONNECTION"));
} catch (Exception e) {
......
......@@ -223,9 +223,11 @@ public class SmtpConnection extends AbstractConnection {
protected void authenticate() throws IOException {
try {
session = ExchangeSessionFactory.getInstance(userName, password);
logConnection("LOGON", userName);
sendClient("235 OK Authenticated");
state = State.AUTHENTICATED;
} catch (Exception e) {
logConnection("FAILED", userName);
DavGatewayTray.error(e);
String message = e.getMessage();
if (message == null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment