Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1C26510082 for ; Sat, 8 Mar 2014 00:23:51 +0000 (UTC) Received: (qmail 98568 invoked by uid 500); 8 Mar 2014 00:22:56 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 97846 invoked by uid 500); 8 Mar 2014 00:22:38 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 97730 invoked by uid 99); 8 Mar 2014 00:22:34 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 08 Mar 2014 00:22:34 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 73D5E93ACA5; Sat, 8 Mar 2014 00:22:34 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mlsorensen@apache.org To: commits@cloudstack.apache.org Date: Sat, 08 Mar 2014 00:22:38 -0000 Message-Id: <4386b22b298e452f84a0e7509758be05@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [05/50] [abbrv] CLOUDSTACK-5920: IAM service server. http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupPolicyMapDao.java ---------------------------------------------------------------------- diff --git a/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupPolicyMapDao.java b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupPolicyMapDao.java new file mode 100644 index 0000000..6a2df89 --- /dev/null +++ b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupPolicyMapDao.java @@ -0,0 +1,16 @@ +package org.apache.cloudstack.iam.server.dao; + +import java.util.List; + +import org.apache.cloudstack.iam.server.IAMGroupPolicyMapVO; +import com.cloud.utils.db.GenericDao; + +public interface IAMGroupPolicyMapDao extends GenericDao { + + List listByGroupId(long groupId); + + List listByPolicyId(long policyId); + + IAMGroupPolicyMapVO findByGroupAndPolicy(long groupId, long policyId); + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupPolicyMapDaoImpl.java ---------------------------------------------------------------------- diff --git a/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupPolicyMapDaoImpl.java b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupPolicyMapDaoImpl.java new file mode 100644 index 0000000..95b6bac --- /dev/null +++ b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupPolicyMapDaoImpl.java @@ -0,0 +1,61 @@ +package org.apache.cloudstack.iam.server.dao; + +import java.util.List; +import java.util.Map; + +import javax.naming.ConfigurationException; + +import org.apache.cloudstack.iam.server.IAMGroupPolicyMapVO; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +public class IAMGroupPolicyMapDaoImpl extends GenericDaoBase implements IAMGroupPolicyMapDao { + + private SearchBuilder ListByGroupId; + private SearchBuilder ListByPolicyId; + private SearchBuilder findByPolicyGroupId; + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + super.configure(name, params); + + ListByGroupId = createSearchBuilder(); + ListByGroupId.and("groupId", ListByGroupId.entity().getAclGroupId(), SearchCriteria.Op.EQ); + ListByGroupId.done(); + + ListByPolicyId = createSearchBuilder(); + ListByPolicyId.and("policyId", ListByPolicyId.entity().getAclPolicyId(), SearchCriteria.Op.EQ); + ListByPolicyId.done(); + + findByPolicyGroupId = createSearchBuilder(); + findByPolicyGroupId.and("policyId", findByPolicyGroupId.entity().getAclPolicyId(), SearchCriteria.Op.EQ); + findByPolicyGroupId.and("groupId", findByPolicyGroupId.entity().getAclGroupId(), SearchCriteria.Op.EQ); + findByPolicyGroupId.done(); + + return true; + } + + @Override + public List listByGroupId(long groupId) { + SearchCriteria sc = ListByGroupId.create(); + sc.setParameters("groupId", groupId); + return listBy(sc); + } + + @Override + public List listByPolicyId(long policyId) { + SearchCriteria sc = ListByPolicyId.create(); + sc.setParameters("policyId", policyId); + return listBy(sc); + } + + @Override + public IAMGroupPolicyMapVO findByGroupAndPolicy(long groupId, long policyId) { + SearchCriteria sc = findByPolicyGroupId.create(); + sc.setParameters("policyId", policyId); + sc.setParameters("groupId", groupId); + return findOneBy(sc); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMPolicyDao.java ---------------------------------------------------------------------- diff --git a/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMPolicyDao.java b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMPolicyDao.java new file mode 100644 index 0000000..ace7d85 --- /dev/null +++ b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMPolicyDao.java @@ -0,0 +1,28 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.iam.server.dao; + +import org.apache.cloudstack.iam.api.IAMPolicy; +import org.apache.cloudstack.iam.server.IAMPolicyVO; + +import com.cloud.utils.db.GenericDao; + +public interface IAMPolicyDao extends GenericDao { + + IAMPolicy findByName(String policyName); + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMPolicyDaoImpl.java ---------------------------------------------------------------------- diff --git a/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMPolicyDaoImpl.java b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMPolicyDaoImpl.java new file mode 100644 index 0000000..293cf6f --- /dev/null +++ b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMPolicyDaoImpl.java @@ -0,0 +1,57 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.iam.server.dao; + +import java.util.Map; + +import javax.naming.ConfigurationException; + +import org.apache.cloudstack.iam.api.IAMPolicy; +import org.apache.cloudstack.iam.server.IAMPolicyVO; +import org.springframework.stereotype.Component; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +@Component +public class IAMPolicyDaoImpl extends GenericDaoBase implements IAMPolicyDao { + private SearchBuilder nameSearch; + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + super.configure(name, params); + + nameSearch = createSearchBuilder(); + nameSearch.and("name", nameSearch.entity().getName(), SearchCriteria.Op.EQ); + // nameSearch.and("domainId", nameSearch.entity().getDomainId(), + // SearchCriteria.Op.EQ); + nameSearch.done(); + + + return true; + } + + @Override + public IAMPolicy findByName(String name) { + SearchCriteria sc = nameSearch.create(); + sc.setParameters("name", name); + + return findOneBy(sc); + } + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMPolicyPermissionDao.java ---------------------------------------------------------------------- diff --git a/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMPolicyPermissionDao.java b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMPolicyPermissionDao.java new file mode 100644 index 0000000..cdcb02b --- /dev/null +++ b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMPolicyPermissionDao.java @@ -0,0 +1,39 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.iam.server.dao; +import java.util.List; + +import org.apache.cloudstack.iam.api.IAMPolicyPermission.Permission; +import org.apache.cloudstack.iam.server.IAMPolicyPermissionVO; + +import com.cloud.utils.db.GenericDao; + +public interface IAMPolicyPermissionDao extends GenericDao { + + List listByPolicy(long policyId); + + IAMPolicyPermissionVO findByPolicyAndEntity(long policyId, String entityType, String scope, Long scopeId, + String action, Permission perm); + + List listGrantedByActionAndScope(long policyId, String action, String scope); + + List listByPolicyActionAndEntity(long policyId, String action, String entityType); + + List listByPolicyAccessAndEntity(long policyId, String accessType, String entityType); + + List listByEntity(String entityType, Long entityId); +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMPolicyPermissionDaoImpl.java ---------------------------------------------------------------------- diff --git a/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMPolicyPermissionDaoImpl.java b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMPolicyPermissionDaoImpl.java new file mode 100644 index 0000000..3f976cf --- /dev/null +++ b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMPolicyPermissionDaoImpl.java @@ -0,0 +1,129 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.iam.server.dao; + +import java.util.List; +import java.util.Map; + +import javax.naming.ConfigurationException; + +import org.apache.cloudstack.iam.api.IAMPolicyPermission.Permission; +import org.apache.cloudstack.iam.server.IAMPolicyPermissionVO; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +public class IAMPolicyPermissionDaoImpl extends GenericDaoBase implements + IAMPolicyPermissionDao { + + private SearchBuilder policyIdSearch; + private SearchBuilder fullSearch; + private SearchBuilder actionScopeSearch; + private SearchBuilder entitySearch; + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + super.configure(name, params); + + policyIdSearch = createSearchBuilder(); + policyIdSearch.and("policyId", policyIdSearch.entity().getAclPolicyId(), SearchCriteria.Op.EQ); + policyIdSearch.done(); + + fullSearch = createSearchBuilder(); + fullSearch.and("policyId", fullSearch.entity().getAclPolicyId(), SearchCriteria.Op.EQ); + fullSearch.and("entityType", fullSearch.entity().getEntityType(), SearchCriteria.Op.EQ); + fullSearch.and("scope", fullSearch.entity().getScope(), SearchCriteria.Op.EQ); + fullSearch.and("scopeId", fullSearch.entity().getScopeId(), SearchCriteria.Op.EQ); + fullSearch.and("action", fullSearch.entity().getAction(), SearchCriteria.Op.EQ); + fullSearch.and("permission", fullSearch.entity().getPermission(), SearchCriteria.Op.EQ); + fullSearch.and("accessType", fullSearch.entity().getAccessType(), SearchCriteria.Op.EQ); + fullSearch.done(); + + actionScopeSearch = createSearchBuilder(); + actionScopeSearch.and("policyId", actionScopeSearch.entity().getAclPolicyId(), SearchCriteria.Op.EQ); + actionScopeSearch.and("scope", actionScopeSearch.entity().getScope(), SearchCriteria.Op.EQ); + actionScopeSearch.and("action", actionScopeSearch.entity().getAction(), SearchCriteria.Op.EQ); + actionScopeSearch.and("permission", actionScopeSearch.entity().getPermission(), SearchCriteria.Op.EQ); + actionScopeSearch.done(); + + entitySearch = createSearchBuilder(); + entitySearch.and("entityType", entitySearch.entity().getEntityType(), SearchCriteria.Op.EQ); + entitySearch.and("scopeId", entitySearch.entity().getScopeId(), SearchCriteria.Op.EQ); + entitySearch.done(); + + return true; + } + + @Override + public List listByPolicy(long policyId) { + SearchCriteria sc = policyIdSearch.create(); + sc.setParameters("policyId", policyId); + return listBy(sc); + } + + @Override + public IAMPolicyPermissionVO findByPolicyAndEntity(long policyId, String entityType, String scope, Long scopeId, + String action, Permission perm) { + SearchCriteria sc = fullSearch.create(); + sc.setParameters("policyId", policyId); + sc.setParameters("entityType", entityType); + sc.setParameters("scope", scope); + sc.setParameters("scopeId", scopeId); + sc.setParameters("action", action); + sc.setParameters("permission", perm); + return findOneBy(sc); + } + + @Override + public List listGrantedByActionAndScope(long policyId, String action, String scope) { + SearchCriteria sc = actionScopeSearch.create(); + sc.setParameters("policyId", policyId); + sc.setParameters("action", action); + sc.setParameters("scope", scope); + sc.setParameters("permission", Permission.Allow); + return listBy(sc); + } + + @Override + public List listByPolicyActionAndEntity(long policyId, String action, String entityType) { + SearchCriteria sc = fullSearch.create(); + sc.setParameters("policyId", policyId); + sc.setParameters("entityType", entityType); + sc.setParameters("action", action); + return listBy(sc); + } + + @Override + public List listByPolicyAccessAndEntity(long policyId, String accessType, + String entityType) { + SearchCriteria sc = fullSearch.create(); + sc.setParameters("policyId", policyId); + sc.setParameters("entityType", entityType); + sc.setParameters("accessType", accessType); + return listBy(sc); + } + + @Override + public List listByEntity(String entityType, Long entityId) { + SearchCriteria sc = fullSearch.create(); + sc.setParameters("entityType", entityType); + sc.setParameters("scopeId", entityId); + return listBy(sc); + } + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/test/org/apache/cloudstack/iam/IAMServiceUnitTest.java ---------------------------------------------------------------------- diff --git a/services/iam/server/test/org/apache/cloudstack/iam/IAMServiceUnitTest.java b/services/iam/server/test/org/apache/cloudstack/iam/IAMServiceUnitTest.java new file mode 100644 index 0000000..53cfc71 --- /dev/null +++ b/services/iam/server/test/org/apache/cloudstack/iam/IAMServiceUnitTest.java @@ -0,0 +1,211 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.iam; + +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Inject; +import javax.naming.ConfigurationException; + +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.ComponentScan.Filter; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.FilterType; +import org.springframework.core.type.classreading.MetadataReader; +import org.springframework.core.type.classreading.MetadataReaderFactory; +import org.springframework.core.type.filter.TypeFilter; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +import org.apache.cloudstack.iam.api.IAMGroup; +import org.apache.cloudstack.iam.api.IAMPolicy; +import org.apache.cloudstack.iam.api.IAMService; +import org.apache.cloudstack.iam.server.IAMGroupVO; +import org.apache.cloudstack.iam.server.IAMPolicyVO; +import org.apache.cloudstack.iam.server.IAMServiceImpl; +import org.apache.cloudstack.iam.server.dao.IAMAccountPolicyMapDao; +import org.apache.cloudstack.iam.server.dao.IAMGroupAccountMapDao; +import org.apache.cloudstack.iam.server.dao.IAMGroupDao; +import org.apache.cloudstack.iam.server.dao.IAMGroupPolicyMapDao; +import org.apache.cloudstack.iam.server.dao.IAMPolicyDao; +import org.apache.cloudstack.iam.server.dao.IAMPolicyPermissionDao; +import org.apache.cloudstack.test.utils.SpringUtils; + +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.utils.component.ComponentContext; +import com.cloud.utils.db.EntityManager; +import com.cloud.utils.db.SearchCriteria; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(loader = AnnotationConfigContextLoader.class) +public class IAMServiceUnitTest { + + @Inject + IAMService _iamService; + + @Inject + IAMPolicyDao _aclPolicyDao; + + @Inject + IAMGroupDao _aclGroupDao; + + @Inject + EntityManager _entityMgr; + + @Inject + IAMGroupPolicyMapDao _aclGroupPolicyMapDao; + + @Inject + IAMGroupAccountMapDao _aclGroupAccountMapDao; + + @Inject + IAMPolicyPermissionDao _policyPermissionDao; + + @BeforeClass + public static void setUpClass() throws ConfigurationException { + } + + @Before + public void setUp() { + ComponentContext.initComponentsLifeCycle(); + IAMGroupVO group = new IAMGroupVO("group1", "my first group"); + Mockito.when(_aclGroupDao.persist(Mockito.any(IAMGroupVO.class))).thenReturn(group); + List groups = new ArrayList(); + groups.add(group); + when(_aclGroupDao.search(Mockito.any(SearchCriteria.class), Mockito.any(com.cloud.utils.db.Filter.class))) + .thenReturn(groups); + + IAMPolicyVO policy = new IAMPolicyVO("policy1", "my first policy"); + Mockito.when(_aclPolicyDao.persist(Mockito.any(IAMPolicyVO.class))).thenReturn(policy); + + } + + @After + public void tearDown() { + } + + @Test(expected = InvalidParameterValueException.class) + public void createAclGroupTest() { + IAMGroup group = _iamService.createIAMGroup("group1", "my first group", "/root/mydomain"); + assertNotNull("Acl group 'group1' failed to create ", group); + + IAMGroupVO group2 = new IAMGroupVO("group1", "my second group"); + when(_aclGroupDao.findByName(eq("/root/mydomain"), eq("group1"))).thenReturn(group2); + + IAMGroup group3 = _iamService.createIAMGroup("group1", "my first group", "/root/mydomain"); + } + + @Test(expected = InvalidParameterValueException.class) + public void deleteAclGroupInvalidIdTest() { + when(_aclGroupDao.findById(20L)).thenReturn(null); + _iamService.deleteIAMGroup(20L); + } + + @Test + public void accountGroupMaptest() { + // create group + IAMGroupVO group = new IAMGroupVO("group1", "my first group"); + + // add account to group + List accountIds = new ArrayList(); + accountIds.add(100L); + when(_aclGroupDao.findById(20L)).thenReturn(group); + _iamService.addAccountsToGroup(accountIds, 20L); + + _iamService.removeAccountsFromGroup(accountIds, 20L); + } + + @Test(expected = InvalidParameterValueException.class) + public void createAclPolicyTest() { + IAMPolicy policy = _iamService.createIAMPolicy("policy1", "my first policy", null, "/root/mydomain"); + assertNotNull("Acl policy 'policy1' failed to create ", policy); + + IAMPolicyVO rvo = new IAMPolicyVO("policy2", "second policy"); + when(_aclPolicyDao.findByName(eq("policy2"))).thenReturn(rvo); + + _iamService.createIAMPolicy("policy2", "second policy", null, "/root/mydomain"); + } + + @Test(expected = InvalidParameterValueException.class) + public void deleteAclPolicyInvalidIdTest() { + when(_aclPolicyDao.findById(34L)).thenReturn(null); + _iamService.deleteIAMPolicy(34L); + } + + @Configuration + @ComponentScan(basePackageClasses = {IAMServiceImpl.class}, includeFilters = {@Filter(value = TestConfiguration.Library.class, type = FilterType.CUSTOM)}, useDefaultFilters = false) + public static class TestConfiguration extends SpringUtils.CloudStackTestConfiguration { + + @Bean + public IAMPolicyDao aclPolicyDao() { + return Mockito.mock(IAMPolicyDao.class); + } + + @Bean + public IAMGroupDao aclGroupDao() { + return Mockito.mock(IAMGroupDao.class); + } + + @Bean + public EntityManager entityManager() { + return Mockito.mock(EntityManager.class); + } + + @Bean + public IAMGroupPolicyMapDao aclGroupPolicyMapDao() { + return Mockito.mock(IAMGroupPolicyMapDao.class); + } + + @Bean + public IAMGroupAccountMapDao aclGroupAccountMapDao() { + return Mockito.mock(IAMGroupAccountMapDao.class); + } + + @Bean + public IAMAccountPolicyMapDao aclAccountPolicyMapDao() { + return Mockito.mock(IAMAccountPolicyMapDao.class); + } + + @Bean + public IAMPolicyPermissionDao aclPolicyPermissionDao() { + return Mockito.mock(IAMPolicyPermissionDao.class); + } + + public static class Library implements TypeFilter { + + @Override + public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException { + ComponentScan cs = TestConfiguration.class.getAnnotation(ComponentScan.class); + return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs); + } + } + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/test/resources/db.properties ---------------------------------------------------------------------- diff --git a/services/iam/server/test/resources/db.properties b/services/iam/server/test/resources/db.properties new file mode 100644 index 0000000..e1b5fe9 --- /dev/null +++ b/services/iam/server/test/resources/db.properties @@ -0,0 +1,75 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + + +# management server clustering parameters, change cluster.node.IP to the machine IP address +# in which the management server(Tomcat) is running +cluster.node.IP=127.0.0.1 +cluster.servlet.port=9090 +region.id=1 + +# CloudStack database settings +db.cloud.username=cloud +db.cloud.password=cloud +db.root.password= +db.cloud.host=localhost +db.cloud.port=3306 +db.cloud.name=cloud + +# CloudStack database tuning parameters +db.cloud.maxActive=250 +db.cloud.maxIdle=30 +db.cloud.maxWait=10000 +db.cloud.autoReconnect=true +db.cloud.validationQuery=SELECT 1 +db.cloud.testOnBorrow=true +db.cloud.testWhileIdle=true +db.cloud.timeBetweenEvictionRunsMillis=40000 +db.cloud.minEvictableIdleTimeMillis=240000 +db.cloud.poolPreparedStatements=false +db.cloud.url.params=prepStmtCacheSize=517&cachePrepStmts=true&prepStmtCacheSqlLimit=4096 + +# usage database settings +db.usage.username=cloud +db.usage.password=cloud +db.usage.host=localhost +db.usage.port=3306 +db.usage.name=cloud_usage + +# usage database tuning parameters +db.usage.maxActive=100 +db.usage.maxIdle=30 +db.usage.maxWait=10000 +db.usage.autoReconnect=true + +# awsapi database settings +db.awsapi.username=cloud +db.awsapi.password=cloud +db.awsapi.host=localhost +db.awsapi.port=3306 +db.awsapi.name=cloudbridge + +# Simulator database settings +db.simulator.username=cloud +db.simulator.password=cloud +db.simulator.host=localhost +db.simulator.port=3306 +db.simulator.name=simulator +db.simulator.maxActive=250 +db.simulator.maxIdle=30 +db.simulator.maxWait=10000 +db.simulator.autoReconnect=true