@Override public Pair<User, Account> findUserAccountByApiKey(String apiKey) { Transaction txn = Transaction.currentTxn(); PreparedStatement pstmt = null; Pair<User, Account> userAcctPair = null; try { String sql = FIND_USER_ACCOUNT_BY_API_KEY; pstmt = txn.prepareAutoCloseStatement(sql); pstmt.setString(1, apiKey); ResultSet rs = pstmt.executeQuery(); // TODO: make sure we don't have more than 1 result? ApiKey had better be unique if (rs.next()) { User u = new UserVO(rs.getLong(1)); u.setUsername(rs.getString(2)); u.setAccountId(rs.getLong(3)); u.setSecretKey(DBEncryptionUtil.decrypt(rs.getString(4))); u.setState(State.valueOf(rs.getString(5))); AccountVO a = new AccountVO(rs.getLong(6)); a.setAccountName(rs.getString(7)); a.setType(rs.getShort(8)); a.setDomainId(rs.getLong(9)); a.setState(State.valueOf(rs.getString(10))); userAcctPair = new Pair<User, Account>(u, a); } } catch (Exception e) { s_logger.warn("Exception finding user/acct by api key: " + apiKey, e); } return userAcctPair; }
@Before public void setUp() { ComponentContext.initComponentsLifeCycle(); acct.setType(Account.ACCOUNT_TYPE_NORMAL); acct.setAccountName("user1"); acct.setDomainId(domainId); acct.setId(accountId); UserVO user = new UserVO( 1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString()); CallContext.register(user, acct); }