Skip to content

Commit e000646

Browse files
committed
CLOUDSTACK-8273: fix baremetal account creation
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 9533c54 commit e000646

5 files changed

Lines changed: 37 additions & 4 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ UserAccount createUserAccount(String userName, String password, String firstName
103103

104104
public String[] createApiKeyAndSecretKey(RegisterCmd cmd);
105105

106+
public String[] createApiKeyAndSecretKey(final long userId);
107+
106108
UserAccount getUserByApiKey(String apiKey);
107109

108110
RoleType getRoleType(Account account);

plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManagerImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.apache.cloudstack.api.AddBaremetalRctCmd;
4343
import org.apache.cloudstack.api.DeleteBaremetalRctCmd;
4444
import org.apache.cloudstack.api.ListBaremetalRctCmd;
45-
import org.apache.cloudstack.api.command.admin.user.RegisterCmd;
4645
import org.apache.cloudstack.utils.baremetal.BaremetalUtils;
4746
import org.springframework.web.client.RestTemplate;
4847

@@ -259,9 +258,7 @@ public boolean start() {
259258
user.setPassword(UUID.randomUUID().toString());
260259
user = userDao.persist(user);
261260

262-
RegisterCmd cmd = new RegisterCmd();
263-
cmd.setId(user.getId());
264-
String[] keys = acntMgr.createApiKeyAndSecretKey(cmd);
261+
String[] keys = acntMgr.createApiKeyAndSecretKey(user.getId());
265262
user.setApiKey(keys[0]);
266263
user.setSecretKey(keys[1]);
267264
userDao.update(user.getId(), user);

plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/MockAccountManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ public String[] createApiKeyAndSecretKey(RegisterCmd arg0) {
112112
return null;
113113
}
114114

115+
@Override
116+
public String[] createApiKeyAndSecretKey(final long userId) {
117+
// TODO Auto-generated method stub
118+
return null;
119+
}
120+
115121
@Override
116122
public User createUser(String arg0, String arg1, String arg2, String arg3, String arg4, String arg5, String arg6, Long arg7, String arg8) {
117123
// TODO Auto-generated method stub

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,6 +2076,11 @@ public UserAccount authenticateUser(String username, String password, Long domai
20762076
s_logger.error("Failed to authenticate user: " + username + " in domain " + domainId);
20772077
return null;
20782078
}
2079+
// don't allow baremetal system user
2080+
if (BaremetalUtils.BAREMETAL_SYSTEM_ACCOUNT_NAME.equals(user.getUsername())) {
2081+
s_logger.error("Won't authenticate user: " + username + " in domain " + domainId);
2082+
return null;
2083+
}
20792084

20802085
if (s_logger.isDebugEnabled()) {
20812086
s_logger.debug("User: " + username + " in domain " + domainId + " has successfully logged in");
@@ -2210,6 +2215,24 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
22102215
return keys;
22112216
}
22122217

2218+
@Override
2219+
@DB
2220+
@ActionEvent(eventType = EventTypes.EVENT_REGISTER_FOR_SECRET_API_KEY, eventDescription = "register for the developer API keys")
2221+
public String[] createApiKeyAndSecretKey(final long userId) {
2222+
User user = getUserIncludingRemoved(userId);
2223+
if (user == null) {
2224+
throw new InvalidParameterValueException("Unable to find user by id");
2225+
}
2226+
final String[] keys = new String[2];
2227+
Transaction.execute(new TransactionCallbackNoReturn() {
2228+
public void doInTransactionWithoutResult(TransactionStatus status) {
2229+
keys[0] = AccountManagerImpl.this.createUserApiKey(userId);
2230+
keys[1] = AccountManagerImpl.this.createUserSecretKey(userId);
2231+
}
2232+
});
2233+
return keys;
2234+
}
2235+
22132236
private String createUserApiKey(long userId) {
22142237
try {
22152238
UserVO updatedUser = _userDao.createForUpdate();

server/test/com/cloud/user/MockAccountManagerImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ public String[] createApiKeyAndSecretKey(RegisterCmd cmd) {
264264
return null;
265265
}
266266

267+
@Override
268+
public String[] createApiKeyAndSecretKey(final long userId) {
269+
return null;
270+
}
271+
267272
@Override
268273
public boolean enableAccount(long accountId) {
269274
// TODO Auto-generated method stub

0 commit comments

Comments
 (0)