Search in sources :

Example 6 with PermissionException

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;
    }
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) BulkUploads(org.jbei.ice.lib.bulkupload.BulkUploads) BulkUploadInfo(org.jbei.ice.lib.bulkupload.BulkUploadInfo) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) Folder(org.jbei.ice.storage.model.Folder)

Example 7 with PermissionException

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);
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException)

Example 8 with PermissionException

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();
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Account(org.jbei.ice.storage.model.Account)

Example 9 with PermissionException

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();
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) ApiKey(org.jbei.ice.storage.model.ApiKey)

Example 10 with PermissionException

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;
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Account(org.jbei.ice.storage.model.Account) ApiKey(org.jbei.ice.storage.model.ApiKey) Results(org.jbei.ice.lib.dto.common.Results) AccessKey(org.jbei.ice.lib.dto.access.AccessKey)

Aggregations

PermissionException (org.jbei.ice.lib.access.PermissionException)49 Account (org.jbei.ice.storage.model.Account)10 AccountController (org.jbei.ice.lib.account.AccountController)7 RemotePartner (org.jbei.ice.storage.model.RemotePartner)6 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)5 TokenHash (org.jbei.ice.lib.account.TokenHash)4 Results (org.jbei.ice.lib.dto.common.Results)4 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)4 Configuration (org.jbei.ice.storage.model.Configuration)4 Group (org.jbei.ice.storage.model.Group)4 ArrayList (java.util.ArrayList)3 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)3 DNAFeature (org.jbei.ice.lib.dto.DNAFeature)3 PartData (org.jbei.ice.lib.dto.entry.PartData)3 RegistryPartner (org.jbei.ice.lib.dto.web.RegistryPartner)3 HasEntry (org.jbei.ice.lib.entry.HasEntry)3 Annotations (org.jbei.ice.lib.entry.sequence.annotation.Annotations)3 ApiKey (org.jbei.ice.storage.model.ApiKey)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2