Search in sources :

Example 1 with EntryAuthorization

use of org.jbei.ice.lib.entry.EntryAuthorization in project ice by JBEI.

the class PermissionsController method addPermission.

public Permission addPermission(String userId, AccessPermission access) {
    if (access.isEntry()) {
        Entry entry = DAOFactory.getEntryDAO().get(access.getTypeId());
        if (entry == null)
            throw new IllegalArgumentException("Cannot find entry " + access.getTypeId());
        EntryAuthorization authorization = new EntryAuthorization();
        authorization.expectWrite(userId, entry);
        return addPermission(access, entry, null, null);
    }
    if (access.isFolder()) {
        Folder folder = folderDAO.get(access.getTypeId());
        if (!hasWritePermission(userId, folder)) {
            Logger.error(userId + " not allowed to add " + access.toString());
            return null;
        }
        // propagate permissions
        if (folder.isPropagatePermissions()) {
            for (Entry folderContent : folder.getContents()) {
                addPermission(access, folderContent, null, null);
            }
        }
        return addPermission(access, null, folder, null);
    }
    // if bulk upload
    if (access.isUpload()) {
        BulkUpload upload = DAOFactory.getBulkUploadDAO().get(access.getTypeId());
        if (upload == null)
            throw new IllegalArgumentException("Cannot find upload " + access.getId());
        BulkUploadAuthorization uploadAuthorization = new BulkUploadAuthorization();
        uploadAuthorization.expectWrite(userId, upload);
        return addPermission(access, null, null, upload);
    }
    return null;
}
Also used : BulkUploadAuthorization(org.jbei.ice.lib.bulkupload.BulkUploadAuthorization) EntryAuthorization(org.jbei.ice.lib.entry.EntryAuthorization)

Example 2 with EntryAuthorization

use of org.jbei.ice.lib.entry.EntryAuthorization in project ice by JBEI.

the class FolderContents method addEntryPermission.

private void addEntryPermission(String userId, List<Permission> permissions, List<Entry> entries) {
    EntryAuthorization entryAuthorization = new EntryAuthorization();
    for (Permission folderPermission : permissions) {
        for (Entry entry : entries) {
            if (!entryAuthorization.canWrite(userId, entry))
                continue;
            // does the permissions already exists
            if (permissionDAO.hasPermission(entry, null, null, folderPermission.getAccount(), folderPermission.getGroup(), folderPermission.isCanRead(), folderPermission.isCanWrite())) {
                continue;
            }
            Permission permission = new Permission();
            permission.setEntry(entry);
            if (entry != null)
                entry.getPermissions().add(permission);
            permission.setGroup(folderPermission.getGroup());
            permission.setAccount(folderPermission.getAccount());
            permission.setCanRead(folderPermission.isCanRead());
            permission.setCanWrite(folderPermission.isCanWrite());
            permissionDAO.create(permission);
        }
    }
}
Also used : AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) EntryAuthorization(org.jbei.ice.lib.entry.EntryAuthorization)

Example 3 with EntryAuthorization

use of org.jbei.ice.lib.entry.EntryAuthorization in project ice by JBEI.

the class SBOLVisualDownloadServlet method getSBOLVisualType.

private void getSBOLVisualType(String userId, String entryId, HttpServletResponse response) {
    Entry entry = DAOFactory.getEntryDAO().getByRecordId(entryId);
    if (entry == null)
        return;
    Sequence sequence = DAOFactory.getSequenceDAO().getByEntry(entry);
    if (sequence == null) {
        return;
    }
    EntryAuthorization authorization = new EntryAuthorization();
    authorization.expectRead(userId, entry);
    // retrieve cached pigeon image or generate and cache
    String tmpDir = Utils.getConfigValue(ConfigurationKey.TEMPORARY_DIRECTORY);
    Path filePath = Paths.get(tmpDir, sequence.getFwdHash() + ".png");
    URI uri = PigeonSBOLv.generatePigeonVisual(sequence);
    if (uri != null) {
        try {
            IOUtils.copy(uri.toURL().openStream(), new FileOutputStream(filePath.toFile()));
        } catch (IOException e) {
            Logger.error(e);
            return;
        }
    }
    response.setContentType("image/png");
    if (!Files.exists(filePath) || !Files.isReadable(filePath))
        return;
    response.setContentLength((int) filePath.toFile().length());
    try {
        IOUtils.copy(new FileInputStream(filePath.toFile()), response.getOutputStream());
    } catch (IOException ioe) {
        Logger.error(ioe);
    }
}
Also used : Path(java.nio.file.Path) Entry(org.jbei.ice.storage.model.Entry) FileOutputStream(java.io.FileOutputStream) Sequence(org.jbei.ice.storage.model.Sequence) IOException(java.io.IOException) EntryAuthorization(org.jbei.ice.lib.entry.EntryAuthorization) URI(java.net.URI) FileInputStream(java.io.FileInputStream)

Example 4 with EntryAuthorization

use of org.jbei.ice.lib.entry.EntryAuthorization in project ice by JBEI.

the class PermissionsController method removePermission.

public void removePermission(String userId, AccessPermission access) {
    if (access.isEntry()) {
        Entry entry = DAOFactory.getEntryDAO().get(access.getTypeId());
        if (entry == null)
            return;
        EntryAuthorization authorization = new EntryAuthorization();
        authorization.expectWrite(userId, entry);
        // remove permission from entry
        removePermission(access, entry, null, null);
        return;
    }
    if (access.isFolder()) {
        Folder folder = folderDAO.get(access.getTypeId());
        FolderAuthorization folderAuthorization = new FolderAuthorization();
        folderAuthorization.expectWrite(userId, folder);
        // if folder is to be propagated, add removing permission from contained entries
        if (folder.isPropagatePermissions()) {
            for (Entry folderContent : folder.getContents()) {
                removePermission(access, folderContent, null, null);
            }
        }
        // remove permission from folder
        removePermission(access, null, folder, null);
        return;
    }
    if (access.isUpload()) {
        BulkUpload upload = DAOFactory.getBulkUploadDAO().get(access.getTypeId());
        if (upload == null)
            throw new IllegalArgumentException("Could not retrieve upload " + access.getTypeId());
        BulkUploadAuthorization uploadAuthorization = new BulkUploadAuthorization();
        uploadAuthorization.expectWrite(userId, upload);
        removePermission(access, null, null, upload);
    }
}
Also used : FolderAuthorization(org.jbei.ice.lib.dto.folder.FolderAuthorization) BulkUploadAuthorization(org.jbei.ice.lib.bulkupload.BulkUploadAuthorization) EntryAuthorization(org.jbei.ice.lib.entry.EntryAuthorization)

Aggregations

EntryAuthorization (org.jbei.ice.lib.entry.EntryAuthorization)4 BulkUploadAuthorization (org.jbei.ice.lib.bulkupload.BulkUploadAuthorization)2 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 URI (java.net.URI)1 Path (java.nio.file.Path)1 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)1 FolderAuthorization (org.jbei.ice.lib.dto.folder.FolderAuthorization)1 Entry (org.jbei.ice.storage.model.Entry)1 Sequence (org.jbei.ice.storage.model.Sequence)1