realm = repository.getLocation().getUserInfo() + "@" + realm;
}
int reconnect = 1;
while(true) {
SVNSSHAuthentication authentication = (SVNSSHAuthentication) authManager.getFirstAuthentication(ISVNAuthenticationManager.SSH, realm, repository.getLocation());
SSHConnectionInfo connection = null;
// lock SVNSSHSession to make sure connection opening and session creation is atomic.
SVNSSHSession.lock(Thread.currentThread());
try {
while (authentication != null) {
try {
connection = SVNSSHSession.getConnection(repository.getLocation(), authentication, authManager.getConnectTimeout(repository), myIsUseConnectionPing);
if (connection == null) {
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.RA_SVN_CONNECTION_CLOSED, "Cannot connect to ''{0}''", repository.getLocation().setPath("", false));
SVNErrorManager.error(err, SVNLogType.NETWORK);
}
authManager.acknowledgeAuthentication(true, ISVNAuthenticationManager.SSH, realm, null, authentication);
break;
} catch (SVNAuthenticationException e) {
SVNDebugLog.getDefaultLog().logFine(SVNLogType.NETWORK, e);
authManager.acknowledgeAuthentication(false, ISVNAuthenticationManager.SSH, realm, e.getErrorMessage(), authentication);
authentication = (SVNSSHAuthentication) authManager.getNextAuthentication(ISVNAuthenticationManager.SSH, realm, repository.getLocation());
connection = null;
}
}
if (authentication == null) {
SVNErrorManager.cancel("authentication cancelled", SVNLogType.NETWORK);
} else if (connection == null) {
SVNErrorManager.error(SVNErrorMessage.create(SVNErrorCode.RA_SVN_CONNECTION_CLOSED, "Can not establish connection to ''{0}''", realm), SVNLogType.NETWORK);
}
try {
mySession = connection.openSession();
SVNAuthentication author = authManager.getFirstAuthentication(ISVNAuthenticationManager.USERNAME, realm, repository.getLocation());
if (author == null) {
SVNErrorManager.cancel("authentication cancelled", SVNLogType.NETWORK);
}
String userName = author.getUserName();
if (userName == null || "".equals(userName.trim())) {
userName = authentication.getUserName();
}
if (author.getUserName() == null || author.getUserName().equals(authentication.getUserName()) ||
"".equals(author.getUserName())) {
repository.setExternalUserName("");
} else {
repository.setExternalUserName(author.getUserName());
}