Search in sources :

Example 56 with Group

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

the class GroupDAOTest method testGetGroupsBy.

@Test
public void testGetGroupsBy() throws Exception {
    String uid = UUID.randomUUID().toString();
    Group group = createGroup(uid, GroupType.PUBLIC);
    group.setAutoJoin(true);
    dao.update(group);
    createGroup(UUID.randomUUID().toString(), GroupType.PUBLIC);
    createGroup(UUID.randomUUID().toString(), GroupType.PRIVATE);
    List<Group> groups = dao.getGroupsBy(GroupType.PUBLIC, true);
    Assert.assertEquals(1, groups.size());
    Assert.assertEquals(uid, groups.get(0).getUuid());
}
Also used : Group(org.jbei.ice.storage.model.Group) HibernateRepositoryTest(org.jbei.ice.storage.hibernate.HibernateRepositoryTest) Test(org.junit.Test)

Example 57 with Group

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

the class AccountController method authenticate.

/**
 * Authenticate a user in the database.
 * <p>
 * Using the {@link org.jbei.ice.lib.account.authentication.IAuthentication} specified in the
 * settings file, authenticate the user, and return the sessionData
 *
 * @param login
 * @param password
 * @param ip       IP Address of the user.
 * @return the account identifier (email) on a successful login, otherwise {@code null}
 */
protected Account authenticate(final String login, final String password, final String ip) {
    final IAuthentication authentication = new LocalAuthentication();
    String email;
    try {
        email = authentication.authenticates(login.trim(), password);
        if (email == null) {
            loginFailureCooldown();
            return null;
        }
    } catch (final AuthenticationException e2) {
        loginFailureCooldown();
        return null;
    }
    Account account = dao.getByEmail(email);
    if (account == null)
        return null;
    // add to public groups
    List<Group> groups = groupDAO.getGroupsBy(GroupType.PUBLIC, true);
    try {
        if (groups != null) {
            for (Group group : groups) {
                account.getGroups().add(group);
            }
            dao.update(account);
        }
    } catch (Exception e) {
        Logger.error(e);
    }
    account.setIp(ip);
    account.setLastLoginTime(Calendar.getInstance().getTime());
    account = save(account);
    UserSessions.createNewSessionForUser(account.getEmail());
    return account;
}
Also used : Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) AuthenticationException(org.jbei.ice.lib.account.authentication.AuthenticationException) LocalAuthentication(org.jbei.ice.lib.account.authentication.LocalAuthentication) IAuthentication(org.jbei.ice.lib.account.authentication.IAuthentication) AuthenticationException(org.jbei.ice.lib.account.authentication.AuthenticationException) PermissionException(org.jbei.ice.lib.access.PermissionException)

Example 58 with Group

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

the class FolderController method getPublicFolders.

/**
 * Retrieves folders that are shared shared publicly. Note that this is different from
 * featured folders that have a type of PUBLIC
 *
 * @return list of public folders on this site
 */
public ArrayList<FolderDetails> getPublicFolders() {
    Group publicGroup = groupController.createOrRetrievePublicGroup();
    List<Folder> folders = permissionDAO.getFolders(publicGroup);
    ArrayList<FolderDetails> list = new ArrayList<>();
    for (Folder folder : folders) {
        FolderDetails details = folder.toDataTransferObject();
        long folderSize = dao.getFolderSize(folder.getId(), null, true);
        details.setCount(folderSize);
        list.add(details);
    }
    Collections.sort(list);
    return list;
}
Also used : Group(org.jbei.ice.storage.model.Group) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) Folder(org.jbei.ice.storage.model.Folder)

Example 59 with Group

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

the class GroupController method createOrRetrievePublicGroup.

public Group createOrRetrievePublicGroup() {
    Group publicGroup = dao.getByUUID(PUBLIC_GROUP_UUID);
    if (publicGroup != null)
        return publicGroup;
    publicGroup = new Group();
    publicGroup.setLabel(PUBLIC_GROUP_NAME);
    publicGroup.setDescription(PUBLIC_GROUP_DESCRIPTION);
    publicGroup.setType(GroupType.SYSTEM);
    publicGroup.setUuid(PUBLIC_GROUP_UUID);
    return save(publicGroup);
}
Also used : Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup)

Example 60 with Group

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

the class Groups method update.

public boolean update(long groupId, UserGroup userGroup) {
    Group group = dao.get(groupId);
    if (group == null) {
        return false;
    }
    if (group.getType() == GroupType.PUBLIC && !accountController.isAdministrator(userId)) {
        String errMsg = "Non admin " + userId + " attempting to update public group";
        Logger.error(errMsg);
        throw new PermissionException(errMsg);
    }
    group.setLabel(userGroup.getLabel());
    group.setDescription(userGroup.getDescription());
    group.setAutoJoin(userGroup.isAutoJoin());
    group = dao.update(group);
    setGroupMembers(group, userGroup.getMembers(), userGroup.getRemoteMembers());
    return true;
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup)

Aggregations

Group (org.jbei.ice.storage.model.Group)62 Account (org.jbei.ice.storage.model.Account)26 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)16 DAOException (org.jbei.ice.storage.DAOException)15 GroupController (org.jbei.ice.lib.group.GroupController)12 ArrayList (java.util.ArrayList)10 HashSet (java.util.HashSet)9 PartData (org.jbei.ice.lib.dto.entry.PartData)9 PermissionException (org.jbei.ice.lib.access.PermissionException)7 HibernateRepositoryTest (org.jbei.ice.storage.hibernate.HibernateRepositoryTest)7 Entry (org.jbei.ice.storage.model.Entry)7 Test (org.junit.Test)7 HibernateException (org.hibernate.HibernateException)5 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)4 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)4 Folder (org.jbei.ice.storage.model.Folder)4 RemoteClientModel (org.jbei.ice.storage.model.RemoteClientModel)4 NativeQuery (org.hibernate.query.NativeQuery)3 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)3 Results (org.jbei.ice.lib.dto.common.Results)3