Skip to content

Commit a75ff23

Browse files
committed
CLOUDSTACK-8273: fix baremetal account creation
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com> (cherry picked from commit e000646) Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com> Conflicts: plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManagerImpl.java
1 parent 6f4db0c commit a75ff23

5 files changed

Lines changed: 38 additions & 5 deletions

File tree

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

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

106106
public String[] createApiKeyAndSecretKey(RegisterCmd cmd);
107107

108+
public String[] createApiKeyAndSecretKey(final long userId);
109+
108110
UserAccount getUserByApiKey(String apiKey);
109111

110112
RoleType getRoleType(Account account);

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@
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;
46-
import org.apache.cloudstack.utils.baremetal.BaremetalUtils;
45+
import org.apache.cloudstack.utils.baremetal.BaremetalUtils;
4746
import org.springframework.web.client.RestTemplate;
4847

4948
import javax.inject.Inject;
@@ -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
@@ -115,6 +115,12 @@ public String[] createApiKeyAndSecretKey(RegisterCmd arg0) {
115115
return null;
116116
}
117117

118+
@Override
119+
public String[] createApiKeyAndSecretKey(final long userId) {
120+
// TODO Auto-generated method stub
121+
return null;
122+
}
123+
118124
@Override
119125
public User createUser(String arg0, String arg1, String arg2, String arg3, String arg4, String arg5, String arg6, Long arg7, String arg8) {
120126
// 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
@@ -2079,6 +2079,11 @@ public UserAccount authenticateUser(String username, String password, Long domai
20792079
s_logger.error("Failed to authenticate user: " + username + " in domain " + domainId);
20802080
return null;
20812081
}
2082+
// don't allow baremetal system user
2083+
if (BaremetalUtils.BAREMETAL_SYSTEM_ACCOUNT_NAME.equals(user.getUsername())) {
2084+
s_logger.error("Won't authenticate user: " + username + " in domain " + domainId);
2085+
return null;
2086+
}
20822087

20832088
if (s_logger.isDebugEnabled()) {
20842089
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
@@ -277,6 +277,11 @@ public String[] createApiKeyAndSecretKey(RegisterCmd cmd) {
277277
return null;
278278
}
279279

280+
@Override
281+
public String[] createApiKeyAndSecretKey(final long userId) {
282+
return null;
283+
}
284+
280285
@Override
281286
public boolean enableAccount(long accountId) {
282287
// TODO Auto-generated method stub

0 commit comments

Comments
 (0)