mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
CLOUDSTACK-8273: fix baremetal account creation
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
parent
9533c54db6
commit
e000646790
@ -103,6 +103,8 @@ public interface AccountService {
|
||||
|
||||
public String[] createApiKeyAndSecretKey(RegisterCmd cmd);
|
||||
|
||||
public String[] createApiKeyAndSecretKey(final long userId);
|
||||
|
||||
UserAccount getUserByApiKey(String apiKey);
|
||||
|
||||
RoleType getRoleType(Account account);
|
||||
|
||||
@ -42,7 +42,6 @@ import com.google.gson.Gson;
|
||||
import org.apache.cloudstack.api.AddBaremetalRctCmd;
|
||||
import org.apache.cloudstack.api.DeleteBaremetalRctCmd;
|
||||
import org.apache.cloudstack.api.ListBaremetalRctCmd;
|
||||
import org.apache.cloudstack.api.command.admin.user.RegisterCmd;
|
||||
import org.apache.cloudstack.utils.baremetal.BaremetalUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@ -259,9 +258,7 @@ public class BaremetalVlanManagerImpl extends ManagerBase implements BaremetalVl
|
||||
user.setPassword(UUID.randomUUID().toString());
|
||||
user = userDao.persist(user);
|
||||
|
||||
RegisterCmd cmd = new RegisterCmd();
|
||||
cmd.setId(user.getId());
|
||||
String[] keys = acntMgr.createApiKeyAndSecretKey(cmd);
|
||||
String[] keys = acntMgr.createApiKeyAndSecretKey(user.getId());
|
||||
user.setApiKey(keys[0]);
|
||||
user.setSecretKey(keys[1]);
|
||||
userDao.update(user.getId(), user);
|
||||
|
||||
@ -112,6 +112,12 @@ public class MockAccountManager extends ManagerBase implements AccountManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] createApiKeyAndSecretKey(final long userId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User createUser(String arg0, String arg1, String arg2, String arg3, String arg4, String arg5, String arg6, Long arg7, String arg8) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
@ -2076,6 +2076,11 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
s_logger.error("Failed to authenticate user: " + username + " in domain " + domainId);
|
||||
return null;
|
||||
}
|
||||
// don't allow baremetal system user
|
||||
if (BaremetalUtils.BAREMETAL_SYSTEM_ACCOUNT_NAME.equals(user.getUsername())) {
|
||||
s_logger.error("Won't authenticate user: " + username + " in domain " + domainId);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("User: " + username + " in domain " + domainId + " has successfully logged in");
|
||||
@ -2210,6 +2215,24 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
return keys;
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_REGISTER_FOR_SECRET_API_KEY, eventDescription = "register for the developer API keys")
|
||||
public String[] createApiKeyAndSecretKey(final long userId) {
|
||||
User user = getUserIncludingRemoved(userId);
|
||||
if (user == null) {
|
||||
throw new InvalidParameterValueException("Unable to find user by id");
|
||||
}
|
||||
final String[] keys = new String[2];
|
||||
Transaction.execute(new TransactionCallbackNoReturn() {
|
||||
public void doInTransactionWithoutResult(TransactionStatus status) {
|
||||
keys[0] = AccountManagerImpl.this.createUserApiKey(userId);
|
||||
keys[1] = AccountManagerImpl.this.createUserSecretKey(userId);
|
||||
}
|
||||
});
|
||||
return keys;
|
||||
}
|
||||
|
||||
private String createUserApiKey(long userId) {
|
||||
try {
|
||||
UserVO updatedUser = _userDao.createForUpdate();
|
||||
|
||||
@ -264,6 +264,11 @@ public class MockAccountManagerImpl extends ManagerBase implements Manager, Acco
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] createApiKeyAndSecretKey(final long userId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enableAccount(long accountId) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user