use of org.jbei.ice.storage.hibernate.dao.AccountDAO in project ice by JBEI.
the class EntryHistory method get.
public Results<History> get(int limit, int offset, boolean asc, String sort) {
entryAuthorization.expectWrite(userId, entry);
List<Audit> list = dao.getAuditsForEntry(entry, limit, offset, asc, sort);
Results<History> results = new Results<>();
AccountDAO accountDAO = DAOFactory.getAccountDAO();
for (Audit audit : list) {
History history = audit.toDataTransferObject();
if (history.getPartner() == null) {
Account account = accountDAO.getByEmail(history.getUserId());
if (account != null)
history.setAccount(account.toDataTransferObject());
}
results.getData().add(history);
}
long count = dao.getHistoryCount(this.entry);
results.setResultCount(count);
return results;
}
use of org.jbei.ice.storage.hibernate.dao.AccountDAO in project ice by JBEI.
the class AccountCreator method createTestAccount.
public static Account createTestAccount(String testName, boolean admin) throws Exception {
String email = testName + "@TESTER";
AccountDAO dao = DAOFactory.getAccountDAO();
Account account = dao.getByEmail(email);
if (account != null)
throw new Exception("duplicate account");
AccountTransfer accountTransfer = new AccountTransfer();
accountTransfer.setFirstName("TEST_FNAME");
accountTransfer.setLastName("TEST");
accountTransfer.setEmail(email);
accountTransfer = new AccountController().createNewAccount(accountTransfer, false);
Assert.assertNotNull(accountTransfer.getPassword());
account = dao.getByEmail(email);
Assert.assertNotNull(account);
if (admin) {
account.setType(AccountType.ADMIN);
dao.update(account);
}
return account;
}
use of org.jbei.ice.storage.hibernate.dao.AccountDAO 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();
}
use of org.jbei.ice.storage.hibernate.dao.AccountDAO in project ice by JBEI.
the class PreferencesController method getUserPreferences.
public UserPreferences getUserPreferences(String requester, long userId) {
AccountDAO accountDAO = DAOFactory.getAccountDAO();
Account account = accountDAO.getByEmail(requester);
Account requestedAccount = accountDAO.get(userId);
if (account == null || requestedAccount == null)
return null;
if (account.getType() != AccountType.ADMIN && !requester.equalsIgnoreCase(requestedAccount.getEmail()))
return null;
ArrayList<PreferenceKey> keys = new ArrayList<>();
keys.add(PreferenceKey.PRINCIPAL_INVESTIGATOR);
keys.add(PreferenceKey.FUNDING_SOURCE);
List<Preference> preferences = dao.getAccountPreferences(requestedAccount, keys);
if (preferences == null)
return null;
UserPreferences userPreferences = new UserPreferences();
userPreferences.setUserId(requestedAccount.getEmail());
for (Preference preference : preferences) {
userPreferences.getPreferences().add(preference.toDataTransferObject());
}
return userPreferences;
}
Aggregations