Search in sources :

Example 16 with PermissionException

use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.

the class AnnotationResource method rebuildAnnotations.

@PUT
@Path("/indexes")
public Response rebuildAnnotations() {
    String userId = requireUserId();
    Annotations annotations = new Annotations(userId);
    try {
        annotations.rebuild();
    } catch (PermissionException pe) {
        Logger.error(pe);
        throw new WebApplicationException(Response.Status.FORBIDDEN);
    }
    return super.respond(true);
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Annotations(org.jbei.ice.lib.entry.sequence.annotation.Annotations)

Example 17 with PermissionException

use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.

the class AnnotationResource method curate.

/**
 * Curate available annotations to include or exclude them from auto-annotation feature
 *
 * @param list list of annotations each with specified curate
 */
@PUT
@Produces(MediaType.APPLICATION_JSON)
public Response curate(List<DNAFeature> list) {
    String userId = requireUserId();
    Annotations annotations = new Annotations(userId);
    try {
        final Type fooType = new TypeToken<ArrayList<DNAFeature>>() {
        }.getType();
        final Gson gson = new GsonBuilder().create();
        final ArrayList<DNAFeature> features = gson.fromJson(gson.toJsonTree(list), fooType);
        annotations.curate(features);
        return super.respond(true);
    } catch (PermissionException e) {
        Logger.error(e);
        throw new WebApplicationException(Response.Status.FORBIDDEN);
    }
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) MediaType(javax.ws.rs.core.MediaType) Type(java.lang.reflect.Type) Annotations(org.jbei.ice.lib.entry.sequence.annotation.Annotations) GsonBuilder(com.google.gson.GsonBuilder) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) DNAFeature(org.jbei.ice.lib.dto.DNAFeature)

Example 18 with PermissionException

use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.

the class ApiKeyResource method getApiKeys.

/**
 * retrieves list of api keys created by user
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getApiKeys(@DefaultValue("0") @QueryParam("offset") int offset, @DefaultValue("15") @QueryParam("limit") int limit, @DefaultValue("true") @QueryParam("asc") boolean asc, @DefaultValue("creationTime") @QueryParam("sort") String sort, @DefaultValue("false") @QueryParam("getAll") boolean getAll) {
    String userId = requireUserId();
    UserApiKeys apiKeys = new UserApiKeys(userId);
    try {
        return super.respond(apiKeys.getKeys(limit, offset, sort, asc, getAll));
    } catch (PermissionException pe) {
        throw new WebApplicationException(Response.Status.FORBIDDEN);
    }
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) UserApiKeys(org.jbei.ice.lib.account.UserApiKeys)

Example 19 with PermissionException

use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.

the class GroupController method deleteGroup.

public boolean deleteGroup(String userIdStr, long groupId) {
    Account account = DAOFactory.getAccountDAO().getByEmail(userIdStr);
    Group group = dao.get(groupId);
    if (group == null)
        return false;
    if (group.getType() == GroupType.PUBLIC && account.getType() != AccountType.ADMIN) {
        String errMsg = "Non admin " + account.getEmail() + " attempting to delete public group";
        Logger.error(errMsg);
        throw new PermissionException(errMsg);
    }
    if (group.getMembers() != null) {
        for (Account member : group.getMembers()) {
            accountController.removeMemberFromGroup(group.getId(), member.getEmail());
        }
    }
    DAOFactory.getPermissionDAO().clearPermissions(group);
    dao.delete(group);
    return true;
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup)

Example 20 with PermissionException

use of org.jbei.ice.lib.access.PermissionException in project ice by JBEI.

the class Groups method addGroup.

/**
 * Adds group to the list of groups for current user
 *
 * @param userGroup information about group to be added, including members (local and remote)
 * @return added group
 */
public UserGroup addGroup(UserGroup userGroup) {
    if (userGroup.getType() == null)
        userGroup.setType(GroupType.PRIVATE);
    if (userGroup.getType() == GroupType.PUBLIC && !accountController.isAdministrator(userId)) {
        String errMsg = "Non admin '" + userId + "' attempting to create public group";
        Logger.error(errMsg);
        throw new PermissionException(errMsg);
    }
    Account account = accountDAO.getByEmail(userId);
    Group group = new Group();
    group.setUuid(Utils.generateUUID());
    group.setLabel(userGroup.getLabel());
    group.setDescription(userGroup.getDescription() == null ? "" : userGroup.getDescription());
    group.setType(userGroup.getType());
    group.setOwner(account);
    group.setAutoJoin(userGroup.isAutoJoin());
    group.setCreationTime(new Date());
    group = dao.create(group);
    // add local members
    if (userGroup.getMembers() != null && !userGroup.getMembers().isEmpty()) {
        for (AccountTransfer accountTransfer : userGroup.getMembers()) {
            Account memberAccount = accountDAO.getByEmail(accountTransfer.getEmail());
            if (memberAccount == null)
                continue;
            group.getMembers().add(memberAccount);
            memberAccount.getGroups().add(group);
            accountDAO.update(memberAccount);
        }
    }
    // add remote members
    for (RemoteUser remoteUser : userGroup.getRemoteMembers()) {
        RegistryPartner partner = remoteUser.getPartner();
        if (partner == null)
            continue;
        RemotePartner remotePartner = remotePartnerDAO.get(partner.getId());
        if (remotePartner == null)
            continue;
        AccountTransfer accountTransfer = remoteUser.getUser();
        if (accountTransfer == null || StringUtils.isEmpty(accountTransfer.getEmail()))
            continue;
        String email = accountTransfer.getEmail();
        RemoteClientModel remoteClientModel = remoteClientModelDAO.getModel(email, remotePartner);
        if (remoteClientModel == null) {
            remoteClientModel = new RemoteClientModel();
            remoteClientModel.setEmail(email);
            remoteClientModel.setRemotePartner(remotePartner);
            remoteClientModel = remoteClientModelDAO.create(remoteClientModel);
        }
        remoteClientModel.getGroups().add(group);
        remoteClientModelDAO.update(remoteClientModel);
    }
    return group.toDataTransferObject();
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup) RemoteUser(org.jbei.ice.lib.dto.web.RemoteUser) RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner) RemotePartner(org.jbei.ice.storage.model.RemotePartner) RemoteClientModel(org.jbei.ice.storage.model.RemoteClientModel) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

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