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;
}
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);
}
}
}
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);
}
}
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);
}
}
Aggregations