use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.
the class FolderController method delete.
/**
* Deletes either a user folder or bulk upload (which is represented as a folder to the user)
*
* @param userId unique identifier for user requesting delete action
* @param folderId unique identifier for folder to be deleted
* @param type type of folder to be deleted (either "UPLOAD" or "PRIVATE")
* @return delete folder details
*/
public FolderDetails delete(String userId, long folderId, FolderType type) {
switch(type) {
case UPLOAD:
BulkUploads controller = new BulkUploads();
BulkUploadInfo info = controller.deleteDraftById(userId, folderId);
if (info == null) {
Logger.error("Could not locate bulk upload id " + folderId + " for deletion");
return null;
}
FolderDetails details = new FolderDetails();
details.setId(info.getId());
return details;
case PRIVATE:
case TRANSFERRED:
case SHARED:
Folder folder = dao.get(folderId);
if (folder == null)
return null;
if (!accountController.isAdministrator(userId) && !folder.getOwnerEmail().equalsIgnoreCase(userId)) {
String errorMsg = userId + ": insufficient permissions to delete folder " + folderId;
Logger.warn(errorMsg);
throw new PermissionException(errorMsg);
}
details = folder.toDataTransferObject();
long folderSize = dao.getFolderSize(folderId, null, true);
details.setCount(folderSize);
permissionDAO.clearPermissions(folder);
dao.delete(folder);
return details;
default:
Logger.error("Cannot delete folder of type " + type);
return null;
}
}
use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.
the class Annotations method rebuild.
/**
* Rebuild the annotations blast database
*
* @throws PermissionException if the specified user does not have administrator privileges
*/
public void rebuild() {
if (!isAdministrator())
throw new PermissionException("Administrative privileges required to rebuild blast features");
AutoAnnotationBlastDbBuildTask autoAnnotationBlastDbBuildTask = new AutoAnnotationBlastDbBuildTask(true);
IceExecutorService.getInstance().runTask(autoAnnotationBlastDbBuildTask);
}
use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.
the class AccountController method updatePassword.
/**
* Updates the specified user account's password
*
* @param userId email of user making change. If it is not the same as the email associated with the
* <code>id</code>, then this account must have administrator privileges
* @param id unique (db) identifier for user whose password is to be changed.
* @param transfer wrapper around new password
* @return updated account object
* @throws PermissionException if the account associated with <code>userId</code> and <code>id</code> are not
* the same but the <code>userId</code> does not have administrative privileges
*/
public AccountTransfer updatePassword(String userId, long id, AccountTransfer transfer) throws PermissionException {
Account account = dao.get(id);
if (account == null) {
throw new IllegalArgumentException("Could not retrieve account by id " + id);
}
if (!isAdministrator(userId) && !account.getEmail().equalsIgnoreCase(userId)) {
throw new PermissionException("User " + userId + " does not have permission to change " + transfer.getEmail() + "'s password");
}
account.setPassword(AccountUtils.encryptNewUserPassword(transfer.getPassword(), account.getSalt()));
return dao.update(account).toDataTransferObject();
}
use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.
the class UserApiKeys method update.
public AccessKey update(long id, AccessKey apiKey) {
ApiKey key = apiKeyDAO.get(id);
if (key == null)
return null;
if (!apiKey.getSecret().equals(key.getSecret()))
throw new PermissionException("Mismatched api secret. Cannot update");
// must be admin or owner to update
if (!this.userId.equalsIgnoreCase(key.getOwnerEmail()))
if (!new AccountController().isAdministrator(userId))
throw new PermissionException("Invalid privileges to update access key");
key.setAllowDelegate(apiKey.isAllowDelegate());
key.setReadOnly(apiKey.isReadOnly());
return apiKeyDAO.update(key).toDataTransferObject();
}
use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.
the class UserApiKeys method getKeys.
/**
* Retrieves either list of available keys for current user or all keys.
* If requesting all keys then user must be an administrator
*
* @param limit maximum number of keys to retrieve
* @param offset paging parameter start
* @param sortField field to sort on
* @param asc whether the retrieve order is in ascending order
* @param getAvailable whether to retrieve all available keys or restrict by current user
* @return wrapper around list of retrieved keys including number available
* @throws PermissionException if <code>getAvailable</code> is true but user making the request does not have
* administrative privileges
*/
public Results<AccessKey> getKeys(int limit, int offset, String sortField, boolean asc, boolean getAvailable) {
Results<AccessKey> accessKeyResults = new Results<>();
List<ApiKey> results;
AccountController accountController = new AccountController();
boolean isAdmin = accountController.isAdministrator(this.userId);
if (getAvailable) {
if (!isAdmin)
throw new PermissionException("Cannot retrieve all api keys without admin privileges");
results = apiKeyDAO.getAllApiKeys(sortField, limit, offset, asc);
} else {
results = apiKeyDAO.getApiKeysForUser(userId, sortField, limit, offset, asc);
}
for (ApiKey key : results) {
AccessKey accessKey = key.toDataTransferObject();
Account account = accountController.getByEmail(key.getOwnerEmail());
accessKey.setAccount(account.toDataTransferObject());
accessKeyResults.getData().add(accessKey);
}
// get count
String user = getAvailable ? null : this.userId;
long count = apiKeyDAO.getApiKeysCount(user);
accessKeyResults.setResultCount(count);
return accessKeyResults;
}
Aggregations