Skip to content

Commit

Permalink
Fix permission check for static resources form NFS storages
Browse files Browse the repository at this point in the history
  • Loading branch information
mzueva committed Aug 2, 2023
1 parent 60f8941 commit f79fd0c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,26 @@ public AbstractDataStorage loadDataStorageByPathOrId(final String pathOrId) {
messageHelper.getMessage(MessageConstants.ERROR_DATASTORAGE_NOT_FOUND, pathOrId)));
}

public Optional<AbstractDataStorage> findDataStorage(final String pathOrId) {
return CommonUtils.first(
() -> loadById(pathOrId),
() -> loadByNameOrPath(pathOrId),
() -> loadByPrefixes(pathOrId),
() -> loadByRoot(pathOrId));
}

private Optional<AbstractDataStorage> loadById(final String id) {
if (NumberUtils.isDigits(id)) {
return Optional.ofNullable(dataStorageDao.loadDataStorage(Long.parseLong(id)));
}
return Optional.empty();
}

private Optional<AbstractDataStorage> loadByRoot(final String path) {
final String root = path.split(ProviderUtils.DELIMITER)[0];
return Optional.ofNullable(dataStorageDao.loadDataStorageByNameOrPath(root, root));
}

private Optional<AbstractDataStorage> loadByNameOrPath(final String path) {
return Optional.ofNullable(dataStorageDao.loadDataStorageByNameOrPath(path, path));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ public boolean storagePermissionByName(final String identifier,
public boolean storagePermissionByPath(final String path,
final String permissionName) {
try {
final AbstractSecuredEntity storage = storagePathLoader.loadDataStorageByPathOrId(path);
return grantPermissionManager.storagePermission(storage, permissionName);
final Optional<AbstractDataStorage> storage = storagePathLoader.findDataStorage(path);
return storage.map(s -> grantPermissionManager.storagePermission(s, permissionName)).orElse(false);
} catch (IllegalArgumentException e) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import com.epam.pipeline.manager.google.CredentialsManager;
import com.epam.pipeline.manager.issue.IssueManager;
import com.epam.pipeline.manager.log.LogManager;
import com.epam.pipeline.manager.log.storage.StorageRequestManager;
import com.epam.pipeline.manager.metadata.CategoricalAttributeManager;
import com.epam.pipeline.manager.metadata.MetadataDownloadManager;
import com.epam.pipeline.manager.metadata.MetadataEntityManager;
Expand Down Expand Up @@ -586,6 +587,9 @@ protected FolderTemplateManager folderTemplateManager() {
@MockBean
protected UserNotificationRepository userNotificationRepository;

@MockBean
protected StorageRequestManager storageRequestManager;

@Bean
public GrantPermissionManager grantPermissionManager() {
GrantPermissionManager grantPermissionManager = new GrantPermissionManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.epam.pipeline.acl.datastorage.lifecycle.DataStorageLifecycleApiService;
import com.epam.pipeline.acl.datastorage.lustre.LustreFSApiService;
import com.epam.pipeline.acl.log.LogApiService;
import com.epam.pipeline.acl.log.storage.StorageRequestApiService;
import com.epam.pipeline.acl.notification.UserNotificationApiService;
import com.epam.pipeline.acl.ontology.OntologyApiService;
import com.epam.pipeline.acl.pipeline.PipelineApiService;
Expand Down Expand Up @@ -278,4 +279,7 @@ public class ControllerTestBeans {

@MockBean
protected GitlabIssueApiService gitlabIssueApiService;

@MockBean
protected StorageRequestApiService storageRequestApiService;
}

0 comments on commit f79fd0c

Please sign in to comment.