Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion engine/schema/src/main/java/com/cloud/user/UserVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public UserVO() {
}

public UserVO(long id) {
this();
this.id = id;
this.uuid = UUID.randomUUID().toString();
}

public UserVO(long accountId, String username, String password, String firstName, String lastName, String email, String timezone, String uuid, Source source) {
Expand Down
42 changes: 20 additions & 22 deletions engine/schema/src/main/java/com/cloud/user/dao/AccountDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

@Component
public class AccountDaoImpl extends GenericDaoBase<AccountVO, Long> implements AccountDao {
private static final String FIND_USER_ACCOUNT_BY_API_KEY = "SELECT u.id, u.username, u.account_id, u.secret_key, u.state, u.api_key_access, "
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, "
+ "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 "
+ "WHERE u.account_id = a.id AND u.api_key = ? and u.removed IS NULL";

Expand Down Expand Up @@ -138,41 +138,41 @@ public Pair<User, Account> findUserAccountByApiKey(String apiKey) {
PreparedStatement pstmt = null;
Pair<User, Account> userAcctPair = null;
try {
String sql = FIND_USER_ACCOUNT_BY_API_KEY;
pstmt = txn.prepareAutoCloseStatement(sql);
pstmt = txn.prepareAutoCloseStatement(FIND_USER_ACCOUNT_BY_API_KEY);
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.getValueOf(rs.getString(5)));
boolean apiKeyAccess = rs.getBoolean(6);
UserVO u = new UserVO(rs.getLong(1));
u.setUuid(rs.getString(2));
u.setUsername(rs.getString(3));
u.setAccountId(rs.getLong(4));
u.setSecretKey(DBEncryptionUtil.decrypt(rs.getString(5)));
u.setState(State.getValueOf(rs.getString(6)));
boolean apiKeyAccess = rs.getBoolean(7);
if (rs.wasNull()) {
u.setApiKeyAccess(null);
} else {
u.setApiKeyAccess(apiKeyAccess);
}

AccountVO a = new AccountVO(rs.getLong(7));
a.setAccountName(rs.getString(8));
a.setType(Account.Type.getFromValue(rs.getInt(9)));
a.setRoleId(rs.getLong(10));
a.setDomainId(rs.getLong(11));
a.setState(State.getValueOf(rs.getString(12)));
apiKeyAccess = rs.getBoolean(13);
AccountVO a = new AccountVO(rs.getLong(8));
a.setAccountName(rs.getString(9));
a.setType(Account.Type.getFromValue(rs.getInt(10)));
a.setRoleId(rs.getLong(11));
a.setDomainId(rs.getLong(12));
a.setState(State.getValueOf(rs.getString(13)));
apiKeyAccess = rs.getBoolean(14);
if (rs.wasNull()) {
a.setApiKeyAccess(null);
} else {
a.setApiKeyAccess(apiKeyAccess);
}

userAcctPair = new Pair<User, Account>(u, a);
userAcctPair = new Pair<>(u, a);
}
} catch (Exception e) {
logger.warn("Exception finding user/acct by api key: " + apiKey, e);
logger.warn("Exception finding user/acct by api key: {}", apiKey, e);
}
return userAcctPair;
}
Expand Down Expand Up @@ -341,11 +341,9 @@ public long getDomainIdForGivenAccountId(long id) {
domain_id = account_vo.getDomainId();
}
catch (Exception e) {
logger.warn("getDomainIdForGivenAccountId: Exception :" + e.getMessage());
}
finally {
return domain_id;
logger.warn("Can not get DomainId for the given AccountId; exception message : {}", e.getMessage());
}
return domain_id;
}

@Override
Expand Down
Loading