Search in sources :

Example 1 with AccountTransfer

use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.

the class RemoteShareModel method toDataTransferObject.

@Override
public AccessPermission toDataTransferObject() {
    AccessPermission accessPermission = new AccessPermission();
    accessPermission.setArticle(AccessPermission.Article.REMOTE);
    // for remote access permissions, the article id is the actual permission
    accessPermission.setArticleId(this.permission.getId());
    accessPermission.setId(this.id);
    accessPermission.setType(this.permission.isCanWrite() ? AccessPermission.Type.WRITE_FOLDER : AccessPermission.Type.READ_FOLDER);
    AccountTransfer accountTransfer = new AccountTransfer();
    accountTransfer.setEmail(this.client.getEmail());
    accessPermission.setPartner(this.client.getRemotePartner().toDataTransferObject());
    accessPermission.setDisplay(accountTransfer.getEmail());
    return accessPermission;
}
Also used : AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 2 with AccountTransfer

use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.

the class PartnerResource method getRemoteUser.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/users/{email}")
public Response getRemoteUser(@PathParam("id") final long remoteId, @PathParam("email") final String email) {
    requireUserId();
    RemoteAccess remoteAccess = new RemoteAccess();
    AccountTransfer accountTransfer = remoteAccess.getRemoteUser(remoteId, email);
    return super.respond(accountTransfer);
}
Also used : RemoteAccess(org.jbei.ice.lib.access.RemoteAccess) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 3 with AccountTransfer

use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.

the class FolderPermissions method createRemotePermission.

/**
 * Creates an access folder permission for a remote user
 *
 * @param accessPermission access details
 * @return wrapper around the unique identifier for the remote permission created
 * @throws IllegalArgumentException if the partner record cannot be retrieved
 * @throws PermissionException      if user doesn't have write privileges on folder
 */
public AccessPermission createRemotePermission(AccessPermission accessPermission) {
    authorization.expectWrite(userId, folder);
    RegistryPartner partner = accessPermission.getPartner();
    RemotePartner remotePartner = remotePartnerDAO.get(partner.getId());
    if (remotePartner == null) {
        String errorMessage = "Could not find remote partner for remote permission";
        Logger.error(errorMessage);
        throw new IllegalArgumentException(errorMessage);
    }
    String remoteUserId = accessPermission.getUserId();
    String randomToken = tokenHash.generateRandomToken();
    // generate random token and also verify user Id
    accessPermission.setSecret(randomToken);
    AccountTransfer accountTransfer = new AccountTransfer();
    accountTransfer.setEmail(userId);
    accessPermission.setAccount(accountTransfer);
    accessPermission.setDisplay(folder.getName());
    accessPermission.setTypeId(folder.getId());
    // send to remote partner (throws illegal argument exception if user id doesn't exist on other side)
    if (!sendToken(accessPermission, remotePartner)) {
        Logger.error("Could not share folder remotely");
        // something happened with the send; likely user id is invalid
        return null;
    }
    // create local client record mapping to remote partner + user id
    // this narrows down the remote client allowed to access the article (folder)
    RemoteClientModel remoteClientModel = getOrCreateRemoteClient(remoteUserId, remotePartner);
    // store the access credentials locally by hashing the random token that was sent
    // when requesting the folder, the remote user will send the random token
    String secret = tokenHash.encrypt(folder.getId() + remotePartner.getUrl() + remoteUserId, randomToken);
    Permission remoteShare = new Permission();
    remoteShare.setClient(remoteClientModel);
    remoteShare.setSecret(secret);
    Account account = accountDAO.getByEmail(userId);
    remoteShare.setSharer(account);
    // add permissions
    remoteShare.setFolder(folder);
    remoteShare.setCanWrite(accessPermission.isCanWrite());
    remoteShare.setCanRead(accessPermission.isCanRead());
    remoteShare = this.permissionDAO.create(remoteShare);
    accessPermission.setId(remoteShare.getId());
    accessPermission.setArticleId(remoteShare.getId());
    accessPermission.setArticle(AccessPermission.Article.REMOTE);
    accessPermission.setPartner(remoteShare.getClient().getRemotePartner().toDataTransferObject());
    accessPermission.setDisplay(remoteShare.getClient().getEmail());
    return accessPermission;
}
Also used : RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 4 with AccountTransfer

use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.

the class Messages method send.

/**
 * Sends message contained in the MessageInfo to the specified recipients. It some of the
 * recipients do not exist, the routine does its best to deliver as many as possible
 *
 * @param info details of message including recipient(s)
 * @return false if the message fails to be sent to all the intended recipients
 */
public boolean send(MessageInfo info) {
    if (info == null || info.getAccounts().isEmpty() && info.getUserGroups().isEmpty())
        return false;
    boolean success = true;
    Message message = new Message();
    message.setDateSent(new Date());
    message.setFromEmail(this.userId);
    message.setMessage(info.getMessage());
    message.setTitle(info.getTitle());
    if (info.getAccounts() != null) {
        for (AccountTransfer accountTransfer : info.getAccounts()) {
            Account account = accountDAO.getByEmail(accountTransfer.getEmail());
            if (account == null) {
                success = false;
                continue;
            }
            message.getDestinationAccounts().add(account);
        }
    }
    if (info.getUserGroups() != null) {
        for (UserGroup userGroup : info.getUserGroups()) {
            Group group = DAOFactory.getGroupDAO().get(userGroup.getId());
            if (group == null) {
                Logger.warn("Could not retrieve group with id " + userGroup.getId() + " to send message");
                success = false;
                continue;
            }
            message.getDestinationGroups().add(group);
        }
    }
    if (!success)
        return false;
    if (message.getDestinationAccounts().isEmpty() && message.getDestinationGroups().isEmpty())
        return false;
    return dao.create(message) != null;
}
Also used : Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup) Message(org.jbei.ice.storage.model.Message) Date(java.util.Date) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer) UserGroup(org.jbei.ice.lib.dto.group.UserGroup)

Example 5 with AccountTransfer

use of org.jbei.ice.lib.account.AccountTransfer in project ice by JBEI.

the class Messages method get.

public Results<MessageInfo> get(int start, int limit) {
    Account account = accountDAO.getByEmail(this.userId);
    List<Group> groups = DAOFactory.getGroupDAO().retrieveMemberGroups(account);
    List<Message> messages = new ArrayList<>(dao.retrieveMessages(account, groups, start, limit));
    Results<MessageInfo> results = new Results<>();
    for (Message message : messages) {
        Account from = accountDAO.getByEmail(message.getFromEmail());
        if (from == null)
            continue;
        MessageInfo info = new MessageInfo();
        info.setId(message.getId());
        // get from details
        AccountTransfer accountTransfer = new AccountTransfer();
        accountTransfer.setEmail(from.getEmail());
        accountTransfer.setFirstName(account.getFirstName());
        accountTransfer.setLastName(account.getLastName());
        info.setFrom(accountTransfer);
        info.setTitle(message.getTitle());
        info.setRead(message.isRead());
        info.setSent(message.getDateSent().getTime());
        results.getData().add(info);
    }
    int totalSize = dao.retrieveMessageCount(account, groups);
    results.setResultCount(totalSize);
    return results;
}
Also used : Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup) Message(org.jbei.ice.storage.model.Message) Results(org.jbei.ice.lib.dto.common.Results) ArrayList(java.util.ArrayList) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer) MessageInfo(org.jbei.ice.lib.dto.message.MessageInfo)

Aggregations

AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)31 Account (org.jbei.ice.storage.model.Account)10 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)6 RemotePartner (org.jbei.ice.storage.model.RemotePartner)6 RemoteUser (org.jbei.ice.lib.dto.web.RemoteUser)5 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)4 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)4 Group (org.jbei.ice.storage.model.Group)4 PermissionException (org.jbei.ice.lib.access.PermissionException)3 Results (org.jbei.ice.lib.dto.common.Results)3 RegistryPartner (org.jbei.ice.lib.dto.web.RegistryPartner)3 Folder (org.jbei.ice.storage.model.Folder)3 Test (org.junit.Test)3 TraceSequenceAnalysis (org.jbei.ice.lib.dto.entry.TraceSequenceAnalysis)2 Message (org.jbei.ice.storage.model.Message)2 RemoteClientModel (org.jbei.ice.storage.model.RemoteClientModel)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 RemoteAccess (org.jbei.ice.lib.access.RemoteAccess)1 AccountController (org.jbei.ice.lib.account.AccountController)1