// if the username is not null, set up authentication
if (username != null && username.length() > 0 &&
password != null && password.length() > 0)
{
ServerSessionManager ssm = LoginManager.getSessionManager(serverUrl.toString());
ServerDetails details = ssm.getDetails();
AuthenticationInfo info = details.getAuthInfo().clone();
// if the type is EITHER, we choose to login with authentication,
// since guest logins won't be allowed without authentication
if (info.getType() == AuthenticationInfo.Type.EITHER) {
info.setType(AuthenticationInfo.Type.WEB_SERVICE);