Search in sources :

Example 96 with Account

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

the class EntryDAOTest method testGetByPartNumber.

@Test
public void testGetByPartNumber() throws Exception {
    Account account = AccountCreator.createTestAccount("testGetByPartNumber", false);
    long id = TestEntryCreator.createTestPart(account.getEmail());
    Entry entry = entryDAO.get(id);
    Assert.assertNotNull(entry);
    Entry result = entryDAO.getByPartNumber(entry.getPartNumber());
    Assert.assertNotNull(result);
    Assert.assertEquals(entry.getPartNumber(), result.getPartNumber());
}
Also used : Account(org.jbei.ice.storage.model.Account) Entry(org.jbei.ice.storage.model.Entry) Test(org.junit.Test)

Example 97 with Account

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

the class EntryDAOTest method testGetByRecordId.

@Test
public void testGetByRecordId() throws Exception {
    Account account = AccountCreator.createTestAccount("testGetByRecordId", false);
    long id = TestEntryCreator.createTestPart(account.getEmail());
    Entry entry = entryDAO.get(id);
    Assert.assertNotNull(entry);
    Entry rEntry = entryDAO.getByRecordId(entry.getRecordId());
    Assert.assertNotNull(rEntry);
    Assert.assertEquals(entry.getRecordId(), rEntry.getRecordId());
}
Also used : Account(org.jbei.ice.storage.model.Account) Entry(org.jbei.ice.storage.model.Entry) Test(org.junit.Test)

Example 98 with Account

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

the class AccountController method getAccountBySessionKey.

/**
     * @param sessionKey
     * @return Account object matching a session key, or {@code null}
     */
public AccountTransfer getAccountBySessionKey(final String sessionKey) {
    final String userId = UserSessions.getUserIdBySession(sessionKey);
    if (userId == null) {
        Logger.warn("Could not retrieve user id for session " + sessionKey);
        return null;
    }
    Account account = dao.getByEmail(userId);
    if (account == null)
        return null;
    AccountTransfer transfer = account.toDataTransferObject();
    transfer.setSessionId(sessionKey);
    transfer.setAdmin(isAdministrator(userId));
    return transfer;
}
Also used : Account(org.jbei.ice.storage.model.Account)

Example 99 with Account

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

the class TokenVerification method verifyAPIKey.

public String verifyAPIKey(String token, String clientId, String userId) {
    // hash = (token, client + salt + client)
    Optional<ApiKey> optionalKey = DAOFactory.getApiKeyDAO().getByClientId(clientId);
    if (!optionalKey.isPresent())
        throw new PermissionException("Invalid client Id " + clientId);
    ApiKey key = optionalKey.get();
    String hash_token = tokenHash.encrypt(token, clientId + key.getSecret() + clientId);
    if (!hash_token.equalsIgnoreCase(key.getHashedToken()))
        throw new PermissionException("Invalid token");
    // if the api belongs to an admin, accept whatever user id they present
    AccountDAO accountDAO = DAOFactory.getAccountDAO();
    Account account = accountDAO.getByEmail(key.getOwnerEmail());
    if (userId == null)
        userId = account.getEmail();
    if (account.getType() == AccountType.ADMIN) {
        if (account.getEmail().equalsIgnoreCase(userId))
            return userId;
        if (accountDAO.getByEmail(userId) == null)
            throw new PermissionException("Invalid user id");
        return userId;
    }
    return key.getOwnerEmail();
}
Also used : Account(org.jbei.ice.storage.model.Account) ApiKey(org.jbei.ice.storage.model.ApiKey) AccountDAO(org.jbei.ice.storage.hibernate.dao.AccountDAO)

Example 100 with Account

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

the class UserIdAuthentication method authenticates.

@Override
public String authenticates(String userId, String password) throws AuthenticationException {
    AccountController retriever = new AccountController();
    Account account = retriever.getByEmail(userId);
    if (account == null)
        return null;
    return account.getEmail();
}
Also used : Account(org.jbei.ice.storage.model.Account) AccountController(org.jbei.ice.lib.account.AccountController)

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