ISVNAuthenticationManager authManager = repos.getAuthenticationManager();
if (authManager != null && authManager.isAuthenticationForced() && mechs.contains("ANONYMOUS") && mechs.contains("CRAM-MD5")) {
mechs.remove("ANONYMOUS");
}
SVNURL location = repos.getLocation();
SVNPasswordAuthentication auth = null;
if (repos.getExternalUserName() != null && mechs.contains("EXTERNAL")) {
getConnection().write("(w(s))", new Object[]{"EXTERNAL", ""});
failureReason = readAuthResponse();
} else if (mechs.contains("ANONYMOUS")) {
getConnection().write("(w(s))", new Object[]{"ANONYMOUS", ""});
failureReason = readAuthResponse();
} else if (mechs.contains("CRAM-MD5")) {
while (true) {
CramMD5 authenticator = new CramMD5();
if (location != null) {
realm = "<" + location.getProtocol() + "://"
+ location.getHost() + ":"
+ location.getPort() + "> " + realm;
}
try {
if (auth == null && authManager != null) {
auth = (SVNPasswordAuthentication) authManager.getFirstAuthentication(ISVNAuthenticationManager.PASSWORD, realm, location);
} else if (authManager != null) {
authManager.acknowledgeAuthentication(false, ISVNAuthenticationManager.PASSWORD, realm, failureReason, auth);
auth = (SVNPasswordAuthentication) authManager.getNextAuthentication(ISVNAuthenticationManager.PASSWORD, realm, location);
}
} catch (SVNException e) {
if (e.getErrorMessage().getErrorCode() == SVNErrorCode.CANCELLED) {
throw e;
} else if (getLastError() != null) {
SVNErrorManager.error(getLastError(), SVNLogType.NETWORK);
}
throw e;
}
if (auth == null) {
failureReason = SVNErrorMessage.create(SVNErrorCode.CANCELLED, "Authentication cancelled");
setLastError(failureReason);
break;
}
if (auth.getUserName() == null || auth.getPassword() == null) {
failureReason = SVNErrorMessage.create(SVNErrorCode.RA_NOT_AUTHORIZED, "Can''t get password. Authentication is required for ''{0}''", realm);
break;
}
getConnection().write("(w())", new Object[]{"CRAM-MD5"});
while (true) {