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());
}
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());
}
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;
}
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();
}
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();
}
Aggregations