Repository: cloudstack
Updated Branches:
  refs/heads/master 6f4db0ce4 -> a75ff2313


CLOUDSTACK-8273: fix baremetal account creation

Signed-off-by: Rohit Yadav <rohit.ya...@shapeblue.com>
(cherry picked from commit e000646790597cb6c245311f57761b41d23a4e34)
Signed-off-by: Rohit Yadav <rohit.ya...@shapeblue.com>

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


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/a75ff231
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/a75ff231
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/a75ff231

Branch: refs/heads/master
Commit: a75ff231315e045d441c25e6b368ad2e863cc004
Parents: 6f4db0c
Author: Rohit Yadav <rohit.ya...@shapeblue.com>
Authored: Fri Feb 27 15:52:25 2015 +0530
Committer: Rohit Yadav <rohit.ya...@shapeblue.com>
Committed: Fri Feb 27 15:55:09 2015 +0530

----------------------------------------------------------------------
 api/src/com/cloud/user/AccountService.java      |  2 ++
 .../manager/BaremetalVlanManagerImpl.java       |  7 ++----
 .../contrail/management/MockAccountManager.java |  6 +++++
 .../src/com/cloud/user/AccountManagerImpl.java  | 23 ++++++++++++++++++++
 .../com/cloud/user/MockAccountManagerImpl.java  |  5 +++++
 5 files changed, 38 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a75ff231/api/src/com/cloud/user/AccountService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/user/AccountService.java 
b/api/src/com/cloud/user/AccountService.java
index 75f95ce..c483d05 100644
--- a/api/src/com/cloud/user/AccountService.java
+++ b/api/src/com/cloud/user/AccountService.java
@@ -105,6 +105,8 @@ public interface AccountService {
 
     public String[] createApiKeyAndSecretKey(RegisterCmd cmd);
 
+    public String[] createApiKeyAndSecretKey(final long userId);
+
     UserAccount getUserByApiKey(String apiKey);
 
     RoleType getRoleType(Account account);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a75ff231/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManagerImpl.java
----------------------------------------------------------------------
diff --git 
a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManagerImpl.java
 
b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManagerImpl.java
index 3169597..d3ea3d2 100644
--- 
a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManagerImpl.java
+++ 
b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalVlanManagerImpl.java
@@ -42,8 +42,7 @@ 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.apache.cloudstack.utils.baremetal.BaremetalUtils;
 import org.springframework.web.client.RestTemplate;
 
 import javax.inject.Inject;
@@ -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);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a75ff231/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/MockAccountManager.java
----------------------------------------------------------------------
diff --git 
a/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/MockAccountManager.java
 
b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/MockAccountManager.java
index daeb6bd..9bc11d6 100644
--- 
a/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/MockAccountManager.java
+++ 
b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/MockAccountManager.java
@@ -116,6 +116,12 @@ public class MockAccountManager extends ManagerBase 
implements AccountManager {
     }
 
     @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
         return null;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a75ff231/server/src/com/cloud/user/AccountManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/AccountManagerImpl.java 
b/server/src/com/cloud/user/AccountManagerImpl.java
index 78a8733..29ea9aa 100644
--- a/server/src/com/cloud/user/AccountManagerImpl.java
+++ b/server/src/com/cloud/user/AccountManagerImpl.java
@@ -2079,6 +2079,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();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a75ff231/server/test/com/cloud/user/MockAccountManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/user/MockAccountManagerImpl.java 
b/server/test/com/cloud/user/MockAccountManagerImpl.java
index 35eb94a..26f8904 100644
--- a/server/test/com/cloud/user/MockAccountManagerImpl.java
+++ b/server/test/com/cloud/user/MockAccountManagerImpl.java
@@ -278,6 +278,11 @@ public class MockAccountManagerImpl extends ManagerBase 
implements Manager, Acco
     }
 
     @Override
+    public String[] createApiKeyAndSecretKey(final long userId) {
+        return null;
+    }
+
+    @Override
     public boolean enableAccount(long accountId) {
         // TODO Auto-generated method stub
         return false;

Reply via email to