mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-05 03:40:56 +01:00
add flag for anonymous mode availability to scm protocols and filter supported protocols accordingly
This commit is contained in:
@@ -34,6 +34,7 @@ import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryPermissions;
|
||||
import sonia.scm.repository.spi.RepositoryServiceProvider;
|
||||
import sonia.scm.repository.work.WorkdirProvider;
|
||||
import sonia.scm.security.Authentications;
|
||||
import sonia.scm.user.EMail;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -453,7 +454,8 @@ public final class RepositoryService implements Closeable {
|
||||
public Stream<ScmProtocol> getSupportedProtocols() {
|
||||
return protocolProviders.stream()
|
||||
.filter(protocolProvider -> protocolProvider.getType().equals(getRepository().getType()))
|
||||
.map(this::createProviderInstanceForRepository);
|
||||
.map(this::createProviderInstanceForRepository)
|
||||
.filter(protocol -> !Authentications.isAuthenticatedSubjectAnonymous() || protocol.isAnonymousEnabled());
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "java:S3740"})
|
||||
|
||||
@@ -40,4 +40,11 @@ public interface ScmProtocol {
|
||||
* The URL to access the repository providing this protocol.
|
||||
*/
|
||||
String getUrl();
|
||||
|
||||
/**
|
||||
* Whether the protocol can be used as an anonymous user.
|
||||
*/
|
||||
default boolean isAnonymousEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,11 +93,7 @@ public abstract class RepositoryToRepositoryDtoMapper extends BaseMapper<Reposit
|
||||
}
|
||||
try (RepositoryService repositoryService = serviceFactory.create(repository)) {
|
||||
if (RepositoryPermissions.pull(repository).isPermitted()) {
|
||||
Stream<ScmProtocol> supportedProtocols = repositoryService.getSupportedProtocols();
|
||||
if (Authentications.isAuthenticatedSubjectAnonymous()) {
|
||||
supportedProtocols = supportedProtocols.filter(p -> !p.getType().equals("ssh"));
|
||||
}
|
||||
List<Link> protocolLinks = supportedProtocols
|
||||
List<Link> protocolLinks = repositoryService.getSupportedProtocols()
|
||||
.map(this::createProtocolLink)
|
||||
.collect(toList());
|
||||
linksBuilder.array(protocolLinks);
|
||||
|
||||
Reference in New Issue
Block a user