Index: src/main/java/quickfix/Session.java =================================================================== --- src/main/java/quickfix/Session.java (revision 627) +++ src/main/java/quickfix/Session.java (working copy) @@ -25,28 +25,7 @@ import java.util.Map; import java.util.WeakHashMap; -import quickfix.field.BeginSeqNo; -import quickfix.field.BeginString; -import quickfix.field.BusinessRejectReason; -import quickfix.field.EncryptMethod; -import quickfix.field.EndSeqNo; -import quickfix.field.GapFillFlag; -import quickfix.field.HeartBtInt; -import quickfix.field.MsgSeqNum; -import quickfix.field.MsgType; -import quickfix.field.NewSeqNo; -import quickfix.field.OrigSendingTime; -import quickfix.field.PossDupFlag; -import quickfix.field.RefMsgType; -import quickfix.field.RefSeqNum; -import quickfix.field.RefTagID; -import quickfix.field.ResetSeqNumFlag; -import quickfix.field.SenderCompID; -import quickfix.field.SendingTime; -import quickfix.field.SessionRejectReason; -import quickfix.field.TargetCompID; -import quickfix.field.TestReqID; -import quickfix.field.Text; +import quickfix.field.*; /** * The Session is the primary FIX abstraction for message communication. It @@ -193,6 +172,11 @@ */ public static final String SETTING_PERSIST_MESSAGES = "PersistMessages"; + public static final String SETTING_LOGON_USERNAME = "Username"; + public static final String SETTING_LOGON_PASSWORD = "Password"; + + + // @GuardedBy(sessions) private static final Map sessions = new WeakHashMap(); @@ -229,12 +213,15 @@ private final boolean persistMessages; private final boolean checkCompID; + private final String username; + private final String password; + Session(Application application, MessageStoreFactory messageStoreFactory, SessionID sessionID, DataDictionary dataDictionary, SessionSchedule sessionSchedule, LogFactory logFactory, MessageFactory messageFactory, int heartbeatInterval) { this(application, messageStoreFactory, sessionID, dataDictionary, sessionSchedule, logFactory, messageFactory, heartbeatInterval, true, 120, true, false, false, - false, false, false, true, false, true, false); + false, false, false, true, false, true, false, null, null); } Session(Application application, MessageStoreFactory messageStoreFactory, SessionID sessionID, @@ -243,7 +230,8 @@ int maxLatency, boolean millisecondsInTimeStamp, boolean resetOnLogon, boolean resetOnLogout, boolean resetOnDisconnect, boolean resetWhenInitiatingLogon, boolean refreshMessageStoreAtLogon, boolean checkCompID, - boolean redundantResentRequestsAllowed, boolean persistMessages, boolean refreshOnLogon) { + boolean redundantResentRequestsAllowed, boolean persistMessages, boolean refreshOnLogon, + String username, String password) { this.application = application; this.sessionID = sessionID; this.sessionSchedule = sessionSchedule; @@ -259,6 +247,8 @@ this.checkCompID = checkCompID; this.redundantResentRequestsAllowed = redundantResentRequestsAllowed; this.persistMessages = persistMessages; + this.username = username; + this.password = password; synchronized (this) { if (logFactory != null) { @@ -1310,12 +1300,26 @@ if (isResetNeeded()) { logon.setBoolean(ResetSeqNumFlag.FIELD, true); } + + addAuthenticationToLogon(logon); + state.setLastReceivedTime(SystemTime.currentTimeMillis()); state.clearTestRequestCounter(); state.setLogonSent(true); return sendRaw(logon, 0); } + private void addAuthenticationToLogon(Message logon) { + if(dataDictionary==null || dataDictionary.isMsgField(MsgType.LOGON, Username.FIELD)) { + if(username!=null) { + logon.setField(Username.FIELD, username); + } + if(password!=null) { + logon.setField(Password.FIELD, password); + } + } + } + /** * Logs out from session and closes the network connection. * @@ -1529,6 +1533,7 @@ } logon.setInt(HeartBtInt.FIELD, otherLogon.getInt(HeartBtInt.FIELD)); initializeHeader(logon.getHeader()); + addAuthenticationToLogon(logon); sendRaw(logon, 0); state.setLogonSent(true); } Index: src/main/java/quickfix/DefaultSessionFactory.java =================================================================== --- src/main/java/quickfix/DefaultSessionFactory.java (revision 627) +++ src/main/java/quickfix/DefaultSessionFactory.java (working copy) @@ -149,11 +149,15 @@ int logonTimeout = getSetting(settings, sessionID, Session.SETTING_LOGON_TIMEOUT, 10); int logoutTimeout = getSetting(settings, sessionID, Session.SETTING_LOGON_TIMEOUT, 2); + String username = getSetting(settings, sessionID, Session.SETTING_LOGON_USERNAME, null); + String password = getSetting(settings, sessionID, Session.SETTING_LOGON_PASSWORD, null); + Session session = new Session(application, messageStoreFactory, sessionID, dataDictionary, new SessionSchedule(settings, sessionID), logFactory, messageFactory, heartbeatInterval, checkLatency, maxLatency, millisInTimestamp, resetOnLogon, resetOnLogout, resetOnDisconnect, resetOnLogon, refreshAtLogon, - checkCompID, redundantResentRequestAllowed, persistMessages, refreshAtLogon); + checkCompID, redundantResentRequestAllowed, persistMessages, refreshAtLogon, + username, password); session.setLogonTimeout(logonTimeout); session.setLogoutTimeout(logoutTimeout); @@ -186,4 +190,10 @@ : defaultValue; } + private String getSetting(SessionSettings settings, SessionID sessionID, String key, + String defaultValue) throws ConfigError, FieldConvertError { + return settings.isSetting(sessionID, key) + ? settings.getString(sessionID, key) + : defaultValue; + } }