Skip to content

Commit 1300fc8

Browse files
author
Alena Prokharchyk
committed
AccountManager/Service: reduced visibility for methods that are called only from AccountManagerImpl itself
1 parent 973fc84 commit 1300fc8

6 files changed

Lines changed: 32 additions & 222 deletions

File tree

api/src/com/cloud/user/AccountService.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,15 @@
1616
// under the License.
1717
package com.cloud.user;
1818

19-
import java.util.List;
2019
import java.util.Map;
2120

2221
import org.apache.cloudstack.acl.ControlledEntity;
2322
import org.apache.cloudstack.acl.RoleType;
2423
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
25-
import org.apache.cloudstack.api.command.admin.account.UpdateAccountCmd;
26-
import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
27-
import org.apache.cloudstack.api.command.admin.user.RegisterCmd;
28-
import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
29-
3024
import org.apache.cloudstack.api.command.admin.user.RegisterCmd;
3125

3226
import com.cloud.domain.Domain;
3327
import com.cloud.exception.PermissionDeniedException;
34-
import com.cloud.utils.Pair;
3528

3629
public interface AccountService {
3730

@@ -83,13 +76,11 @@ UserAccount createUserAccount(String userName, String password, String firstName
8376

8477
Account finalizeOwner(Account caller, String accountName, Long domainId, Long projectId);
8578

86-
Pair<List<Long>, Long> finalizeAccountDomainForList(Account caller, String accountName, Long domainId, Long projectId);
87-
8879
Account getActiveAccountByName(String accountName, Long domainId);
8980

90-
Account getActiveAccountById(Long accountId);
81+
Account getActiveAccountById(long accountId);
9182

92-
Account getAccount(Long accountId);
83+
Account getAccount(long accountId);
9384

9485
User getActiveUser(long userId);
9586

server/src/com/cloud/api/ApiServer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ private String queueCommand(BaseCmd cmdObj, Map<String, String> params) throws E
551551
}
552552
}
553553

554+
@SuppressWarnings("unchecked")
554555
private void buildAsyncListResponse(BaseListCmd command, Account account) {
555556
List<ResponseObject> responses = ((ListResponse) command.getResponseObject()).getResponses();
556557
if (responses != null && responses.size() > 0) {
@@ -845,7 +846,7 @@ public void loginUser(HttpSession session, String username, String password, Lon
845846

846847
@Override
847848
public void logoutUser(long userId) {
848-
_accountMgr.logoutUser(Long.valueOf(userId));
849+
_accountMgr.logoutUser(userId);
849850
return;
850851
}
851852

server/src/com/cloud/user/AccountManager.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,15 @@ public interface AccountManager extends AccountService {
4747

4848
boolean deleteAccount(AccountVO account, long callerUserId, Account caller);
4949

50-
boolean cleanupAccount(AccountVO account, long callerUserId, Account caller);
51-
5250
Long checkAccessAndSpecifyAuthority(Account caller, Long zoneId);
5351

5452
Account createAccount(String accountName, short accountType, Long domainId, String networkDomain, Map<String, String> details, String uuid);
55-
56-
UserVO createUser(long accountId, String userName, String password, String firstName, String lastName, String email, String timezone, String userUUID);
57-
53+
5854
/**
5955
* Logs out a user
6056
* @param userId
6157
*/
62-
void logoutUser(Long userId);
63-
64-
UserAccount getUserAccount(String username, Long domainId);
58+
void logoutUser(long userId);
6559

6660
/**
6761
* Authenticates a user when s/he logs in.
@@ -87,9 +81,7 @@ public interface AccountManager extends AccountService {
8781
* @return the user/account pair if one exact match was found, null otherwise
8882
*/
8983
Pair<User, Account> findUserByApiKey(String apiKey);
90-
91-
boolean lockAccount(long accountId);
92-
84+
9385
boolean enableAccount(long accountId);
9486

9587
void buildACLSearchBuilder(SearchBuilder<? extends ControlledEntity> sb, Long domainId,

server/src/com/cloud/user/AccountManagerImpl.java

Lines changed: 10 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import org.apache.log4j.Logger;
5151

5252
import com.cloud.api.ApiDBUtils;
53-
import com.cloud.api.query.dao.UserAccountJoinDao;
5453
import com.cloud.api.query.vo.ControlledViewEntity;
5554
import com.cloud.configuration.Config;
5655
import com.cloud.configuration.ConfigurationManager;
@@ -105,7 +104,6 @@
105104
import com.cloud.projects.dao.ProjectAccountDao;
106105
import com.cloud.projects.dao.ProjectDao;
107106
import com.cloud.server.auth.UserAuthenticator;
108-
import com.cloud.storage.StorageManager;
109107
import com.cloud.storage.VMTemplateVO;
110108
import com.cloud.storage.Volume;
111109
import com.cloud.storage.VolumeManager;
@@ -164,8 +162,6 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
164162
@Inject
165163
private UserAccountDao _userAccountDao;
166164
@Inject
167-
private UserAccountJoinDao _userAccountJoinDao;
168-
@Inject
169165
private VolumeDao _volumeDao;
170166
@Inject
171167
private UserVmDao _userVmDao;
@@ -190,8 +186,6 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
190186
@Inject
191187
private UserVmManager _vmMgr;
192188
@Inject
193-
private StorageManager _storageMgr;
194-
@Inject
195189
private TemplateManager _tmpltMgr;
196190
@Inject
197191
private ConfigurationManager _configMgr;
@@ -505,8 +499,8 @@ public boolean enableAccount(long accountId) {
505499
return success;
506500
}
507501

508-
@Override
509-
public boolean lockAccount(long accountId) {
502+
503+
protected boolean lockAccount(long accountId) {
510504
boolean success = false;
511505
Account account = _accountDao.findById(accountId);
512506
if (account != null) {
@@ -544,8 +538,8 @@ public boolean deleteAccount(AccountVO account, long callerUserId, Account calle
544538
return cleanupAccount(account, callerUserId, caller);
545539
}
546540

547-
@Override
548-
public boolean cleanupAccount(AccountVO account, long callerUserId, Account caller) {
541+
542+
protected boolean cleanupAccount(AccountVO account, long callerUserId, Account caller) {
549543
long accountId = account.getId();
550544
boolean accountCleanupNeeded = false;
551545

@@ -1617,21 +1611,13 @@ public Account getActiveAccountByName(String accountName, Long domainId) {
16171611
}
16181612

16191613
@Override
1620-
public Account getActiveAccountById(Long accountId) {
1621-
if (accountId == null) {
1622-
throw new InvalidParameterValueException("AccountId is required by account search");
1623-
} else {
1624-
return _accountDao.findById(accountId);
1625-
}
1614+
public Account getActiveAccountById(long accountId) {
1615+
return _accountDao.findById(accountId);
16261616
}
16271617

16281618
@Override
1629-
public Account getAccount(Long accountId) {
1630-
if (accountId == null) {
1631-
throw new InvalidParameterValueException("AccountId is required by account search");
1632-
} else {
1633-
return _accountDao.findByIdIncludingRemoved(accountId);
1634-
}
1619+
public Account getAccount(long accountId) {
1620+
return _accountDao.findByIdIncludingRemoved(accountId);
16351621
}
16361622

16371623
@Override
@@ -1669,62 +1655,6 @@ public User getUserIncludingRemoved(long userId) {
16691655
return _userDao.findByIdIncludingRemoved(userId);
16701656
}
16711657

1672-
@Override
1673-
public Pair<List<Long>, Long> finalizeAccountDomainForList(Account caller, String accountName, Long domainId, Long projectId) {
1674-
List<Long> permittedAccounts = new ArrayList<Long>();
1675-
1676-
if (isAdmin(caller.getType())) {
1677-
if (domainId == null && accountName != null) {
1678-
throw new InvalidParameterValueException("accountName and domainId might be specified together");
1679-
} else if (domainId != null) {
1680-
Domain domain = _domainMgr.getDomain(domainId);
1681-
if (domain == null) {
1682-
throw new InvalidParameterValueException("Unable to find the domain by id=" + domainId);
1683-
}
1684-
1685-
checkAccess(caller, domain);
1686-
1687-
if (accountName != null) {
1688-
Account owner = getActiveAccountByName(accountName, domainId);
1689-
if (owner == null) {
1690-
throw new InvalidParameterValueException("Unable to find account with name " + accountName + " in domain id=" + domainId);
1691-
}
1692-
1693-
permittedAccounts.add(owner.getId());
1694-
}
1695-
}
1696-
} else if (accountName != null && domainId != null) {
1697-
if (!accountName.equals(caller.getAccountName()) || domainId.longValue() != caller.getDomainId()) {
1698-
throw new PermissionDeniedException("Can't list port forwarding rules for account " + accountName + " in domain " + domainId + ", permission denied");
1699-
}
1700-
permittedAccounts.add(getActiveAccountByName(accountName, domainId).getId());
1701-
} else {
1702-
permittedAccounts.add(caller.getAccountId());
1703-
}
1704-
1705-
if (domainId == null && caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
1706-
domainId = caller.getDomainId();
1707-
}
1708-
1709-
// set project information
1710-
if (projectId != null) {
1711-
if (projectId.longValue() == -1) {
1712-
permittedAccounts.addAll(_projectMgr.listPermittedProjectAccounts(caller.getId()));
1713-
} else {
1714-
permittedAccounts.clear();
1715-
Project project = _projectMgr.getProject(projectId);
1716-
if (project == null) {
1717-
throw new InvalidParameterValueException("Unable to find project by id " + projectId);
1718-
}
1719-
if (!_projectMgr.canAccessProjectAccount(caller, project.getProjectAccountId())) {
1720-
throw new InvalidParameterValueException("Account " + caller + " can't access project id=" + projectId);
1721-
}
1722-
permittedAccounts.add(project.getProjectAccountId());
1723-
}
1724-
}
1725-
1726-
return new Pair<List<Long>, Long>(permittedAccounts, domainId);
1727-
}
17281658

17291659
@Override
17301660
public User getActiveUserByRegistrationToken(String registrationToken) {
@@ -1806,9 +1736,8 @@ public AccountVO createAccount(String accountName, short accountType, Long domai
18061736
return account;
18071737
}
18081738

1809-
@Override
18101739
@ActionEvent(eventType = EventTypes.EVENT_USER_CREATE, eventDescription = "creating User")
1811-
public UserVO createUser(long accountId, String userName, String password, String firstName, String lastName, String email, String timezone, String userUUID) {
1740+
protected UserVO createUser(long accountId, String userName, String password, String firstName, String lastName, String email, String timezone, String userUUID) {
18121741
if (s_logger.isDebugEnabled()) {
18131742
s_logger.debug("Creating user: " + userName + ", accountId: " + accountId + " timezone:" + timezone);
18141743
}
@@ -1833,29 +1762,13 @@ public UserVO createUser(long accountId, String userName, String password, Strin
18331762
}
18341763

18351764
@Override
1836-
public void logoutUser(Long userId) {
1765+
public void logoutUser(long userId) {
18371766
UserAccount userAcct = _userAccountDao.findById(userId);
18381767
if (userAcct != null) {
18391768
ActionEventUtils.onActionEvent(userId, userAcct.getAccountId(), userAcct.getDomainId(), EventTypes.EVENT_USER_LOGOUT, "user has logged out");
18401769
} // else log some kind of error event? This likely means the user doesn't exist, or has been deleted...
18411770
}
18421771

1843-
@Override
1844-
public UserAccount getUserAccount(String username, Long domainId) {
1845-
if (s_logger.isDebugEnabled()) {
1846-
s_logger.debug("Retrieiving user: " + username + " in domain " + domainId);
1847-
}
1848-
1849-
UserAccount userAccount = _userAccountDao.getUserAccount(username, domainId);
1850-
if (userAccount == null) {
1851-
if (s_logger.isDebugEnabled()) {
1852-
s_logger.debug("Unable to find user with name " + username + " in domain " + domainId);
1853-
}
1854-
return null;
1855-
}
1856-
1857-
return userAccount;
1858-
}
18591772

18601773
@Override
18611774
public UserAccount authenticateUser(String username, String password, Long domainId, String loginIpAddress, Map<String, Object[]> requestParameters) {

server/test/com/cloud/network/MockRulesManagerImpl.java

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,6 @@ public boolean disableStaticNat(long ipId)
135135
return false;
136136
}
137137

138-
@Override
139-
public boolean applyPortForwardingRules(long ipAddressId,
140-
boolean continueOnError, Account caller) {
141-
// TODO Auto-generated method stub
142-
return false;
143-
}
144-
145-
@Override
146-
public boolean applyStaticNatRulesForIp(long sourceIpId,
147-
boolean continueOnError, Account caller, boolean forRevoke) {
148-
// TODO Auto-generated method stub
149-
return false;
150-
}
151138

152139
@Override
153140
public boolean applyPortForwardingRulesForNetwork(long networkId,
@@ -163,13 +150,6 @@ public boolean applyStaticNatRulesForNetwork(long networkId,
163150
return false;
164151
}
165152

166-
@Override
167-
public void checkIpAndUserVm(IpAddress ipAddress, UserVm userVm,
168-
Account caller) {
169-
// TODO Auto-generated method stub
170-
171-
}
172-
173153
@Override
174154
public void checkRuleAndUserVm(FirewallRule rule, UserVm userVm,
175155
Account caller) {
@@ -191,37 +171,13 @@ public boolean revokeAllPFStaticNatRulesForNetwork(long networkId,
191171
return false;
192172
}
193173

194-
@Override
195-
public List<? extends FirewallRule> listFirewallRulesByIp(long ipAddressId) {
196-
// TODO Auto-generated method stub
197-
return null;
198-
}
199-
200-
@Override
201-
public List<? extends PortForwardingRule> listPortForwardingRulesForApplication(
202-
long ipId) {
203-
// TODO Auto-generated method stub
204-
return null;
205-
}
206-
207-
@Override
208-
public List<? extends PortForwardingRule> gatherPortForwardingRulesForApplication(
209-
List<? extends IpAddress> addrs) {
210-
// TODO Auto-generated method stub
211-
return null;
212-
}
213174

214175
@Override
215176
public boolean revokePortForwardingRulesForVm(long vmId) {
216177
// TODO Auto-generated method stub
217178
return false;
218179
}
219180

220-
@Override
221-
public boolean revokeStaticNatRulesForVm(long vmId) {
222-
// TODO Auto-generated method stub
223-
return false;
224-
}
225181

226182
@Override
227183
public FirewallRule[] reservePorts(IpAddress ip, String protocol,
@@ -231,25 +187,6 @@ public FirewallRule[] reservePorts(IpAddress ip, String protocol,
231187
return null;
232188
}
233189

234-
@Override
235-
public boolean releasePorts(long ipId, String protocol, Purpose purpose,
236-
int... ports) {
237-
// TODO Auto-generated method stub
238-
return false;
239-
}
240-
241-
@Override
242-
public List<PortForwardingRuleVO> listByNetworkId(long networkId) {
243-
// TODO Auto-generated method stub
244-
return null;
245-
}
246-
247-
@Override
248-
public boolean applyStaticNatForIp(long sourceIpId,
249-
boolean continueOnError, Account caller, boolean forRevoke) {
250-
// TODO Auto-generated method stub
251-
return false;
252-
}
253190

254191
@Override
255192
public boolean applyStaticNatsForNetwork(long networkId,

0 commit comments

Comments
 (0)