Search in sources :

Example 26 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class LblLdapAuthentication method checkCreateAccount.

/**
     * Intended to be called when the credentials successfully authenticate with ldap.
     * Ensures an account exists with the login specified in the parameter which also belongs to the
     * LBL/JBEI group.
     * <p/>
     * Since LBL's LDAP mechanism handles authentication, no password information is
     * managed
     *
     * @param loginId unique login identifier
     */
private Account checkCreateAccount(String loginId) throws AuthenticationException {
    AccountController retriever = new AccountController();
    Account account = retriever.getByEmail(loginId);
    if (account == null) {
        account = new Account();
        Date currentTime = Calendar.getInstance().getTime();
        account.setCreationTime(currentTime);
        account.setEmail(getEmail().toLowerCase());
        account.setFirstName(getGivenName());
        account.setLastName(getSirName());
        account.setDescription(getDescription());
        account.setPassword("");
        account.setInitials("");
        account.setIp("");
        account.setInstitution("Lawrence Berkeley Laboratory");
        account.setModificationTime(currentTime);
        account = DAOFactory.getAccountDAO().create(account);
    }
    return account;
}
Also used : Account(org.jbei.ice.storage.model.Account) Date(java.util.Date) AccountController(org.jbei.ice.lib.account.AccountController)

Example 27 with Account

use of org.jbei.ice.storage.model.Account 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)

Example 28 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class LblLdapAuthentication method authenticates.

@Override
public String authenticates(String loginId, String password) throws AuthenticationException {
    if (loginId == null || password == null || loginId.isEmpty() || password.isEmpty()) {
        throw new AuthenticationException("Username and Password are mandatory!");
    }
    loginId = loginId.toLowerCase().trim();
    String authenticatedEmail;
    if (isWikiUser(loginId)) {
        try {
            authenticatedEmail = authenticateWithLDAP(loginId, password);
            if (authenticatedEmail == null) {
                return null;
            }
        } catch (AuthenticationException ae) {
            return null;
        }
        Account account = checkCreateAccount(authenticatedEmail);
        if (account == null)
            return null;
        return account.getEmail();
    } else {
        LocalAuthentication localBackend = new LocalAuthentication();
        return localBackend.authenticates(loginId, password);
    }
}
Also used : Account(org.jbei.ice.storage.model.Account)

Example 29 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class FolderController method getSharedUserFolders.

/**
     * Retrieves folders that have been shared with specified user as an individual or as part of a group.
     *
     * @param userId User whose shared folders are being retrieved
     * @return list of folders meeting the shared criteria
     */
public ArrayList<FolderDetails> getSharedUserFolders(String userId) {
    Account account = getAccount(userId);
    ArrayList<FolderDetails> folderDetails = new ArrayList<>();
    Set<Group> groups = account.getGroups();
    groups.remove(groupController.createOrRetrievePublicGroup());
    List<Folder> sharedFolders = DAOFactory.getPermissionDAO().retrieveFolderPermissions(account, groups);
    if (sharedFolders == null)
        return null;
    for (Folder folder : sharedFolders) {
        FolderDetails details = folder.toDataTransferObject();
        details.setType(folder.getType());
        long folderSize = dao.getFolderSize(folder.getId(), null, true);
        details.setCount(folderSize);
        if (folder.getCreationTime() != null)
            details.setCreationTime(folder.getCreationTime().getTime());
        folderDetails.add(details);
    }
    return folderDetails;
}
Also used : Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) Folder(org.jbei.ice.storage.model.Folder)

Example 30 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class FolderController method getUserFolders.

public ArrayList<FolderDetails> getUserFolders(String userId) {
    Account account = getAccount(userId);
    List<Folder> folders = dao.getFoldersByOwner(account);
    ArrayList<FolderDetails> folderDetails = new ArrayList<>();
    for (Folder folder : folders) {
        if (!folder.getOwnerEmail().equalsIgnoreCase(userId))
            continue;
        FolderDetails details = new FolderDetails(folder.getId(), folder.getName());
        long folderSize = dao.getFolderSize(folder.getId(), null, true);
        details.setCount(folderSize);
        details.setType(folder.getType());
        if (folder.getCreationTime() != null)
            details.setCreationTime(folder.getCreationTime().getTime());
        details.setCanEdit(true);
        folderDetails.add(details);
    }
    return folderDetails;
}
Also used : Account(org.jbei.ice.storage.model.Account) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) Folder(org.jbei.ice.storage.model.Folder)

Aggregations

Account (org.jbei.ice.storage.model.Account)153 Test (org.junit.Test)71 Group (org.jbei.ice.storage.model.Group)24 Entry (org.jbei.ice.storage.model.Entry)21 Strain (org.jbei.ice.storage.model.Strain)20 PartData (org.jbei.ice.lib.dto.entry.PartData)18 Folder (org.jbei.ice.storage.model.Folder)18 ArrayList (java.util.ArrayList)16 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)16 PermissionException (org.jbei.ice.lib.access.PermissionException)11 EntryCreator (org.jbei.ice.lib.entry.EntryCreator)10 Plasmid (org.jbei.ice.storage.model.Plasmid)10 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)8 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)8 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)8 DAOException (org.jbei.ice.storage.DAOException)8 RemotePartner (org.jbei.ice.storage.model.RemotePartner)8 HibernateException (org.hibernate.HibernateException)7 HashSet (java.util.HashSet)6 Part (org.jbei.ice.storage.model.Part)6