if (permission.atLeast(AccessPermission.PUSH) && !acceptPush(transport)) {
// downgrade the repo permission for this transport
// because it is not an acceptable PUSH transport
permission = AccessPermission.CLONE;
}
list.add(new RepositoryUrl(getRepositoryUrl(request, username, repository), permission));
}
}
// ssh daemon url
String sshDaemonUrl = servicesManager.getSshDaemonUrl(request, user, repository);
if (!StringUtils.isEmpty(sshDaemonUrl)) {
AccessPermission permission = user.getRepositoryPermission(repository).permission;
if (permission.exceeds(AccessPermission.NONE)) {
if (permission.atLeast(AccessPermission.PUSH) && !acceptPush(Transport.SSH)) {
// downgrade the repo permission for this transport
// because it is not an acceptable PUSH transport
permission = AccessPermission.CLONE;
}
list.add(new RepositoryUrl(sshDaemonUrl, permission));
}
}
// git daemon url
String gitDaemonUrl = servicesManager.getGitDaemonUrl(request, user, repository);
if (!StringUtils.isEmpty(gitDaemonUrl)) {
AccessPermission permission = servicesManager.getGitDaemonAccessPermission(user, repository);
if (permission.exceeds(AccessPermission.NONE)) {
if (permission.atLeast(AccessPermission.PUSH) && !acceptPush(Transport.GIT)) {
// downgrade the repo permission for this transport
// because it is not an acceptable PUSH transport
permission = AccessPermission.CLONE;
}
list.add(new RepositoryUrl(gitDaemonUrl, permission));
}
}
// add all other urls
// {0} = repository
// {1} = username
for (String url : settings.getStrings(Keys.web.otherUrls)) {
if (url.contains("{1}")) {
// external url requires username, only add url IF we have one
if (!StringUtils.isEmpty(username)) {
list.add(new RepositoryUrl(MessageFormat.format(url, repository.name, username), null));
}
} else {
// external url does not require username
list.add(new RepositoryUrl(MessageFormat.format(url, repository.name), null));
}
}
// sort transports by highest permission and then by transport security
Collections.sort(list, new Comparator<RepositoryUrl>() {
@Override
public int compare(RepositoryUrl o1, RepositoryUrl o2) {
if (!o1.isExternal() && o2.isExternal()) {
// prefer Gitblit over external
return -1;
} else if (o1.isExternal() && !o2.isExternal()) {
// prefer Gitblit over external
return 1;
} else if (o1.isExternal() && o2.isExternal()) {
// sort by Transport ordinal
return o1.transport.compareTo(o2.transport);
} else if (o1.permission.exceeds(o2.permission)) {
// prefer highest permission
return -1;
} else if (o2.permission.exceeds(o1.permission)) {
// prefer highest permission
return 1;
}
// prefer more secure transports
return o1.transport.compareTo(o2.transport);
}
});
// consider the user's transport preference
RepositoryUrl preferredUrl = null;
Transport preferredTransport = user.getPreferences().getTransport();
if (preferredTransport != null) {
Iterator<RepositoryUrl> itr = list.iterator();
while (itr.hasNext()) {
RepositoryUrl url = itr.next();
if (url.transport.equals(preferredTransport)) {
itr.remove();
preferredUrl = url;
break;
}