You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bh...@apache.org on 2016/06/07 00:37:37 UTC
[1/2] git commit: updated refs/heads/4.6 to d9f5cc7
Repository: cloudstack
Updated Branches:
refs/heads/4.6 7c446f038 -> d9f5cc721
CLOUDSTACK-9369: Restrict default login to ldap/native users
- Restricts default login auth handler to ldap and native-cloudstack users
- Refactors and create re-usable method to find domain by id/path
Signed-off-by: Rohit Yadav <ro...@shapeblue.com>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/828cadb8
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/828cadb8
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/828cadb8
Branch: refs/heads/4.6
Commit: 828cadb8b44563b6dd8130a0493dbf068288205f
Parents: 7c446f0
Author: Rohit Yadav <ro...@shapeblue.com>
Authored: Wed Apr 27 00:02:11 2016 +0530
Committer: Rohit Yadav <ro...@shapeblue.com>
Committed: Tue Jun 7 06:06:28 2016 +0530
----------------------------------------------------------------------
api/src/com/cloud/user/DomainService.java | 10 ++++++++++
server/src/com/cloud/api/ApiServer.java | 16 +++++-----------
.../auth/DefaultLoginAPIAuthenticatorCmd.java | 13 +++++++++++++
.../src/com/cloud/user/DomainManagerImpl.java | 20 ++++++++++++++++++++
.../com/cloud/user/MockDomainManagerImpl.java | 5 +++++
5 files changed, 53 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/828cadb8/api/src/com/cloud/user/DomainService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/user/DomainService.java b/api/src/com/cloud/user/DomainService.java
index 4c1f93d..3ccfcbc 100644
--- a/api/src/com/cloud/user/DomainService.java
+++ b/api/src/com/cloud/user/DomainService.java
@@ -56,4 +56,14 @@ public interface DomainService {
*/
Domain findDomainByPath(String domainPath);
+ /**
+ * finds the domain by either id or provided path
+ *
+ * @param id the domain id
+ * @param domainPath the domain path use to lookup a domain
+ *
+ * @return domainId the long value of the domain ID, or null if no domain id exists with provided id/path
+ */
+ Domain findDomainByIdOrPath(Long id, String domainPath);
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/828cadb8/server/src/com/cloud/api/ApiServer.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java
index 1459dc2..6600557 100644
--- a/server/src/com/cloud/api/ApiServer.java
+++ b/server/src/com/cloud/api/ApiServer.java
@@ -998,17 +998,11 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
final Map<String, Object[]> requestParameters) throws CloudAuthenticationException {
// We will always use domainId first. If that does not exist, we will use domain name. If THAT doesn't exist
// we will default to ROOT
- if (domainId == null) {
- if (domainPath == null || domainPath.trim().length() == 0) {
- domainId = Domain.ROOT_DOMAIN;
- } else {
- final Domain domainObj = _domainMgr.findDomainByPath(domainPath);
- if (domainObj != null) {
- domainId = domainObj.getId();
- } else { // if an unknown path is passed in, fail the login call
- throw new CloudAuthenticationException("Unable to find the domain from the path " + domainPath);
- }
- }
+ final Domain userDomain = _domainMgr.findDomainByIdOrPath(domainId, domainPath);
+ if (userDomain == null || userDomain.getId() < 1L) {
+ throw new CloudAuthenticationException("Unable to find the domain from the path " + domainPath);
+ } else {
+ domainId = userDomain.getId();
}
final UserAccount userAcct = _accountMgr.authenticateUser(username, password, domainId, loginIpAddress, requestParameters);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/828cadb8/server/src/com/cloud/api/auth/DefaultLoginAPIAuthenticatorCmd.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/auth/DefaultLoginAPIAuthenticatorCmd.java b/server/src/com/cloud/api/auth/DefaultLoginAPIAuthenticatorCmd.java
index d6eac78..c83e708 100644
--- a/server/src/com/cloud/api/auth/DefaultLoginAPIAuthenticatorCmd.java
+++ b/server/src/com/cloud/api/auth/DefaultLoginAPIAuthenticatorCmd.java
@@ -16,6 +16,9 @@
// under the License.
package com.cloud.api.auth;
+import com.cloud.domain.Domain;
+import com.cloud.user.User;
+import com.cloud.user.UserAccount;
import org.apache.cloudstack.api.ApiServerService;
import com.cloud.api.response.ApiResponseSerializer;
import com.cloud.exception.CloudAuthenticationException;
@@ -156,6 +159,16 @@ public class DefaultLoginAPIAuthenticatorCmd extends BaseCmd implements APIAuthe
if (username != null) {
final String pwd = ((password == null) ? null : password[0]);
try {
+ final Domain userDomain = _domainService.findDomainByIdOrPath(domainId, domain);
+ if (userDomain != null) {
+ domainId = userDomain.getId();
+ } else {
+ throw new CloudAuthenticationException("Unable to find the domain from the path " + domain);
+ }
+ final UserAccount userAccount = _accountService.getActiveUserAccount(username[0], domainId);
+ if (userAccount == null || !(User.Source.UNKNOWN.equals(userAccount.getSource()) || User.Source.LDAP.equals(userAccount.getSource()))) {
+ throw new CloudAuthenticationException("User is not allowed CloudStack login");
+ }
return ApiResponseSerializer.toSerializedString(_apiServer.loginUser(session, username[0], pwd, domainId, domain, remoteAddress, params),
responseType);
} catch (final CloudAuthenticationException ex) {
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/828cadb8/server/src/com/cloud/user/DomainManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/DomainManagerImpl.java b/server/src/com/cloud/user/DomainManagerImpl.java
index fbbe0c2..aa54412 100644
--- a/server/src/com/cloud/user/DomainManagerImpl.java
+++ b/server/src/com/cloud/user/DomainManagerImpl.java
@@ -24,6 +24,7 @@ import java.util.UUID;
import javax.ejb.Local;
import javax.inject.Inject;
+import com.google.common.base.Strings;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@@ -221,6 +222,25 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
}
@Override
+ public Domain findDomainByIdOrPath(final Long id, final String domainPath) {
+ Long domainId = id;
+ if (domainId == null) {
+ if (Strings.isNullOrEmpty(domainPath) || domainPath.trim().isEmpty()) {
+ domainId = Domain.ROOT_DOMAIN;
+ } else {
+ final Domain domainVO = findDomainByPath(domainPath);
+ if (domainVO != null) {
+ domainId = domainVO.getId();
+ }
+ }
+ }
+ if (domainId != null) {
+ return _domainDao.findById(domainId);
+ }
+ return null;
+ }
+
+ @Override
public Set<Long> getDomainParentIds(long domainId) {
return _domainDao.getDomainParentIds(domainId);
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/828cadb8/server/test/com/cloud/user/MockDomainManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/user/MockDomainManagerImpl.java b/server/test/com/cloud/user/MockDomainManagerImpl.java
index 7dddefb..f44ab08 100644
--- a/server/test/com/cloud/user/MockDomainManagerImpl.java
+++ b/server/test/com/cloud/user/MockDomainManagerImpl.java
@@ -94,6 +94,11 @@ public class MockDomainManagerImpl extends ManagerBase implements DomainManager,
}
@Override
+ public DomainVO findDomainByIdOrPath(Long id, String domainPath) {
+ return null;
+ }
+
+ @Override
public Set<Long> getDomainParentIds(long domainId) {
// TODO Auto-generated method stub
return null;
[2/2] git commit: updated refs/heads/4.6 to d9f5cc7
Posted by bh...@apache.org.
CLOUDSTACK-9376: Restrict listTemplates API with filter=all for root admin
Restricts use of listemplates API with templatefilter=all for root admin only.
Signed-off-by: Rohit Yadav <ro...@shapeblue.com>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/d9f5cc72
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/d9f5cc72
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/d9f5cc72
Branch: refs/heads/4.6
Commit: d9f5cc72175ab5ab98d8f0eb4ca87a94d42eb40f
Parents: 828cadb
Author: Rohit Yadav <ro...@shapeblue.com>
Authored: Wed May 25 11:52:58 2016 +0530
Committer: Rohit Yadav <ro...@shapeblue.com>
Committed: Tue Jun 7 06:07:22 2016 +0530
----------------------------------------------------------------------
.../com/cloud/api/query/QueryManagerImpl.java | 4 +-
test/integration/component/test_templates.py | 76 ++++++++++++++++++++
2 files changed, 78 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d9f5cc72/server/src/com/cloud/api/query/QueryManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java
index d64b2ac..b2edd2e 100644
--- a/server/src/com/cloud/api/query/QueryManagerImpl.java
+++ b/server/src/com/cloud/api/query/QueryManagerImpl.java
@@ -3055,9 +3055,9 @@ public class QueryManagerImpl extends ManagerBase implements QueryService, Confi
boolean listAll = false;
if (templateFilter != null && templateFilter == TemplateFilter.all) {
- if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {
+ if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
throw new InvalidParameterValueException("Filter " + TemplateFilter.all
- + " can be specified by admin only");
+ + " can be specified by root admin only");
}
listAll = true;
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d9f5cc72/test/integration/component/test_templates.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_templates.py b/test/integration/component/test_templates.py
index b1e7e7c..c8384d9 100644
--- a/test/integration/component/test_templates.py
+++ b/test/integration/component/test_templates.py
@@ -22,6 +22,7 @@ from marvin.cloudstackTestCase import cloudstackTestCase, unittest
from marvin.cloudstackAPI import listZones
from marvin.lib.utils import (cleanup_resources)
from marvin.lib.base import (Account,
+ Domain,
Template,
ServiceOffering,
VirtualMachine,
@@ -51,6 +52,7 @@ class Services:
# username
"password": "password",
},
+ "testdomain": {"name": "test"},
"service_offering": {
"name": "Tiny Instance",
"displaytext": "Tiny Instance",
@@ -602,3 +604,77 @@ class TestTemplates(cloudstackTestCase):
"Check the state of VM created from Template"
)
return
+
+
+class TestListTemplate(cloudstackTestCase):
+
+ def setUp(self):
+ self.apiclient = self.testClient.getApiClient()
+ self.hypervisor = self.testClient.getHypervisorInfo()
+ self.dbclient = self.testClient.getDbConnection()
+ self.cleanup = []
+
+ self.services = Services().services
+ # Get Zone, Domain and templates
+ self.domain = get_domain(self.apiclient)
+ self.account = Account.create(
+ self.apiclient,
+ self.services["account"],
+ domainid=self.domain.id
+ )
+ self.newdomain = Domain.create(
+ self.apiclient,
+ self.services["testdomain"],
+ parentdomainid=self.domain.id
+ )
+ self.newdomain_account = Account.create(
+ self.apiclient,
+ self.services["account"],
+ admin=True,
+ domainid=self.newdomain.id
+ )
+ self.cleanup = [
+ self.account,
+ self.newdomain_account,
+ self.newdomain,
+ ]
+
+
+ def tearDown(self):
+ try:
+ # Clean up, terminate the created templates
+ cleanup_resources(self.apiclient, self.cleanup)
+ except Exception as e:
+ raise Exception("Warning: Exception during cleanup : %s" % e)
+
+
+ @attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="false")
+ def test_01_list_templates_with_templatefilter_all_normal_user(self):
+ """
+ Test list templates with templatefilter=all is not permitted for normal user
+ """
+
+ user_api_client = self.testClient.getUserApiClient(
+ UserName=self.account.name,
+ DomainName=self.account.domain)
+ try:
+ list_template_response = Template.list(self.user_api_client, templatefilter='all')
+ self.fail("Regular User is able to use templatefilter='all' in listTemplates API call")
+ except Exception as e:
+ self.debug("ListTemplates API with templatefilter='all' is not permitted for normal user")
+
+
+ @attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], required_hardware="false")
+ def test_02_list_templates_with_templatefilter_all_domain_admin(self):
+ """
+ Test list templates with templatefilter=all is not permitted for domain admin
+ """
+
+ domain_user_api_client = self.testClient.getUserApiClient(
+ UserName=self.newdomain_account.name,
+ DomainName=self.newdomain_account.domain)
+ try:
+ list_template_response = Template.list(self.domain_user_api_client, templatefilter='all')
+ self.fail("Domain admin is able to use templatefilter='all' in listTemplates API call")
+ except Exception as e:
+ self.debug("ListTemplates API with templatefilter='all' is not permitted for domain admin user")