|
16 | 16 | // under the License. |
17 | 17 | package com.cloud.user.dao; |
18 | 18 |
|
19 | | -import java.sql.PreparedStatement; |
20 | | -import java.sql.ResultSet; |
21 | 19 | import java.util.Date; |
22 | 20 | import java.util.List; |
23 | 21 |
|
|
27 | 25 | import com.cloud.user.Account; |
28 | 26 | import com.cloud.user.Account.State; |
29 | 27 | import com.cloud.user.AccountVO; |
30 | | -import com.cloud.user.User; |
31 | | -import com.cloud.user.UserVO; |
32 | 28 | import com.cloud.utils.Pair; |
33 | | -import com.cloud.utils.crypt.DBEncryptionUtil; |
34 | 29 | import com.cloud.utils.db.Filter; |
35 | 30 | import com.cloud.utils.db.GenericDaoBase; |
36 | 31 | import com.cloud.utils.db.GenericSearchBuilder; |
37 | 32 | import com.cloud.utils.db.SearchBuilder; |
38 | 33 | import com.cloud.utils.db.SearchCriteria; |
39 | 34 | import com.cloud.utils.db.SearchCriteria.Func; |
40 | 35 | import com.cloud.utils.db.SearchCriteria.Op; |
41 | | -import com.cloud.utils.db.TransactionLegacy; |
42 | 36 |
|
43 | 37 | @Component |
44 | 38 | public class AccountDaoImpl extends GenericDaoBase<AccountVO, Long> implements AccountDao { |
45 | | - private static final String FIND_USER_ACCOUNT_BY_API_KEY = "SELECT u.id, u.uuid, u.username, u.account_id, u.secret_key, u.state, u.api_key_access, " |
46 | | - + "a.id, a.account_name, a.type, a.role_id, a.domain_id, a.state, a.api_key_access " + "FROM `cloud`.`user` u, `cloud`.`account` a " |
47 | | - + "WHERE u.account_id = a.id AND u.api_key = ? and u.removed IS NULL"; |
48 | 39 |
|
49 | 40 | protected final SearchBuilder<AccountVO> AllFieldsSearch; |
50 | 41 | protected final SearchBuilder<AccountVO> AccountTypeSearch; |
@@ -132,51 +123,6 @@ public List<AccountVO> findCleanupsForDisabledAccounts() { |
132 | 123 | return listBy(sc); |
133 | 124 | } |
134 | 125 |
|
135 | | - @Override |
136 | | - public Pair<User, Account> findUserAccountByApiKey(String apiKey) { |
137 | | - TransactionLegacy txn = TransactionLegacy.currentTxn(); |
138 | | - PreparedStatement pstmt = null; |
139 | | - Pair<User, Account> userAcctPair = null; |
140 | | - try { |
141 | | - pstmt = txn.prepareAutoCloseStatement(FIND_USER_ACCOUNT_BY_API_KEY); |
142 | | - pstmt.setString(1, apiKey); |
143 | | - ResultSet rs = pstmt.executeQuery(); |
144 | | - // TODO: make sure we don't have more than 1 result? ApiKey had better be unique |
145 | | - if (rs.next()) { |
146 | | - UserVO u = new UserVO(rs.getLong(1)); |
147 | | - u.setUuid(rs.getString(2)); |
148 | | - u.setUsername(rs.getString(3)); |
149 | | - u.setAccountId(rs.getLong(4)); |
150 | | - u.setSecretKey(DBEncryptionUtil.decrypt(rs.getString(5))); |
151 | | - u.setState(State.getValueOf(rs.getString(6))); |
152 | | - boolean apiKeyAccess = rs.getBoolean(7); |
153 | | - if (rs.wasNull()) { |
154 | | - u.setApiKeyAccess(null); |
155 | | - } else { |
156 | | - u.setApiKeyAccess(apiKeyAccess); |
157 | | - } |
158 | | - |
159 | | - AccountVO a = new AccountVO(rs.getLong(8)); |
160 | | - a.setAccountName(rs.getString(9)); |
161 | | - a.setType(Account.Type.getFromValue(rs.getInt(10))); |
162 | | - a.setRoleId(rs.getLong(11)); |
163 | | - a.setDomainId(rs.getLong(12)); |
164 | | - a.setState(State.getValueOf(rs.getString(13))); |
165 | | - apiKeyAccess = rs.getBoolean(14); |
166 | | - if (rs.wasNull()) { |
167 | | - a.setApiKeyAccess(null); |
168 | | - } else { |
169 | | - a.setApiKeyAccess(apiKeyAccess); |
170 | | - } |
171 | | - |
172 | | - userAcctPair = new Pair<>(u, a); |
173 | | - } |
174 | | - } catch (Exception e) { |
175 | | - logger.warn("Exception finding user/acct by api key: {}", apiKey, e); |
176 | | - } |
177 | | - return userAcctPair; |
178 | | - } |
179 | | - |
180 | 126 | @Override |
181 | 127 | public List<AccountVO> findAccountsLike(String accountName) { |
182 | 128 | return findAccountsLike(accountName, null).first(); |
|
0 commit comments