You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mc...@apache.org on 2014/03/05 19:06:30 UTC
[1/9] CLOUDSTACK-5920: IAM service plugin.
Repository: cloudstack
Updated Branches:
refs/heads/master b8413b941 -> 63e3eea79
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/test/org/apache/cloudstack/iam/test/IAMApiServiceTest.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/test/org/apache/cloudstack/iam/test/IAMApiServiceTest.java b/services/iam/plugin/test/org/apache/cloudstack/iam/test/IAMApiServiceTest.java
new file mode 100644
index 0000000..dc5c168
--- /dev/null
+++ b/services/iam/plugin/test/org/apache/cloudstack/iam/test/IAMApiServiceTest.java
@@ -0,0 +1,369 @@
+package org.apache.cloudstack.iam.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+
+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.acl.IAMEntityType;
+import org.apache.cloudstack.acl.PermissionScope;
+import org.apache.cloudstack.acl.SecurityChecker.AccessType;
+import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.iam.IAMGroupResponse;
+import org.apache.cloudstack.api.response.iam.IAMPermissionResponse;
+import org.apache.cloudstack.api.response.iam.IAMPolicyResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.framework.messagebus.MessageBus;
+import org.apache.cloudstack.iam.IAMApiService;
+import org.apache.cloudstack.iam.IAMApiServiceImpl;
+import org.apache.cloudstack.iam.api.IAMGroup;
+import org.apache.cloudstack.iam.api.IAMPolicy;
+import org.apache.cloudstack.iam.api.IAMPolicyPermission;
+import org.apache.cloudstack.iam.api.IAMPolicyPermission.Permission;
+import org.apache.cloudstack.iam.api.IAMService;
+import org.apache.cloudstack.iam.server.IAMGroupVO;
+import org.apache.cloudstack.iam.server.IAMPolicyPermissionVO;
+import org.apache.cloudstack.iam.server.IAMPolicyVO;
+import org.apache.cloudstack.test.utils.SpringUtils;
+
+import com.cloud.api.ApiServerService;
+import com.cloud.domain.DomainVO;
+import com.cloud.domain.dao.DomainDao;
+import com.cloud.network.dao.NetworkDomainDao;
+import com.cloud.user.Account;
+import com.cloud.user.AccountManager;
+import com.cloud.user.AccountVO;
+import com.cloud.user.UserVO;
+import com.cloud.user.dao.AccountDao;
+import com.cloud.utils.Pair;
+import com.cloud.utils.component.ComponentContext;
+import com.cloud.utils.db.EntityManager;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
+public class IAMApiServiceTest {
+
+ @Inject
+ IAMService _iamSrv;
+
+ @Inject
+ DomainDao _domainDao;
+
+ @Inject
+ IAMApiService _aclSrv;
+
+ @Inject
+ AccountManager _accountMgr;
+
+ @Inject
+ AccountDao _accountDao;
+
+ @Inject
+ ApiServerService _apiServer;
+
+ private static Account caller;
+ private static Long callerId;
+ private static String callerAccountName = "tester";
+ private static Long callerDomainId = 3L;
+ private static String callerDomainPath = "/root/testdomain";
+ private static DomainVO callerDomain;
+
+ @BeforeClass
+ public static void setUpClass() throws ConfigurationException {
+ }
+
+ @Before
+ public void setUp() {
+ ComponentContext.initComponentsLifeCycle();
+ caller = new AccountVO(callerAccountName, callerDomainId, null, Account.ACCOUNT_TYPE_ADMIN, UUID.randomUUID().toString());
+ callerId = caller.getId();
+ callerDomain = new DomainVO();
+ callerDomain.setPath(callerDomainPath);
+ UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString());
+ CallContext.register(user, caller);
+
+ when(_domainDao.findById(callerDomainId)).thenReturn(callerDomain);
+ doNothing().when(_accountMgr).checkAccess(caller, callerDomain);
+ }
+
+ @Test
+ public void createIAMGroupTest() {
+ IAMGroup group = new IAMGroupVO("group1", "tester group1");
+ List<IAMGroup> groups = new ArrayList<IAMGroup>();
+ groups.add(group);
+ Pair<List<IAMGroup>, Integer> grpList = new Pair<List<IAMGroup>, Integer>(groups, 1);
+ when(_iamSrv.createIAMGroup("group1", "tester group1", callerDomainPath)).thenReturn(group);
+ when(_iamSrv.listIAMGroups(null, null, callerDomainPath, 0L, 20L)).thenReturn(grpList);
+
+ IAMGroup createdGrp = _aclSrv.createIAMGroup(caller, "group1", "tester group1");
+ assertNotNull("IAM group 'group1' failed to create ", createdGrp);
+ ListResponse<IAMGroupResponse> grpResp = _aclSrv.listIAMGroups(null, null, callerDomainId, 0L, 20L);
+ assertTrue("No. of response items should be one", grpResp.getCount() == 1);
+ IAMGroupResponse resp = grpResp.getResponses().get(0);
+ assertEquals("Error in created group name", "group1", resp.getName());
+ }
+
+ @Test
+ public void deleteIAMGroupTest() {
+ when(_iamSrv.deleteIAMGroup(1L)).thenReturn(true);
+ assertTrue("failed to delete acl group 1", _aclSrv.deleteIAMGroup(1L));
+ }
+
+ @Test
+ public void listIAMGroupTest() {
+ IAMGroup group = new IAMGroupVO("group1", "tester group1");
+ List<IAMGroup> groups = new ArrayList<IAMGroup>();
+ groups.add(group);
+ when(_iamSrv.listIAMGroups(callerId)).thenReturn(groups);
+ List<IAMGroup> grps = _aclSrv.listIAMGroups(callerId);
+ assertTrue(grps != null && grps.size() == 1);
+ IAMGroup grp = grps.get(0);
+ assertEquals("Error to retrieve group", "group1", grp.getName());
+ }
+
+ @Test
+ public void addRemoveAccountToGroupTest() {
+ IAMGroup group = new IAMGroupVO("group1", "tester group1");
+ List<IAMGroup> groups = new ArrayList<IAMGroup>();
+ groups.add(group);
+ Long groupId = group.getId();
+ List<Long> acctIds = new ArrayList<Long>();
+ AccountVO acct1 = new AccountVO(100L);
+ acct1.setAccountName("account1");
+ AccountVO acct2 = new AccountVO(200L);
+ acct2.setAccountName("account2");
+ acctIds.add(acct1.getId());
+ acctIds.add(acct2.getId());
+ when(_accountDao.findById(acct1.getId())).thenReturn(acct1);
+ when(_accountDao.findById(acct2.getId())).thenReturn(acct2);
+ when(_iamSrv.addAccountsToGroup(acctIds, groupId)).thenReturn(group);
+ when(_iamSrv.listAccountsByGroup(groupId)).thenReturn(acctIds);
+ Pair<List<IAMGroup>, Integer> grpList = new Pair<List<IAMGroup>, Integer>(groups, 1);
+ when(_iamSrv.listIAMGroups(null, "group1", callerDomainPath, 0L, 20L)).thenReturn(grpList);
+ _aclSrv.addAccountsToGroup(acctIds, groupId);
+ ListResponse<IAMGroupResponse> grpResp = _aclSrv.listIAMGroups(null, "group1", callerDomainId, 0L, 20L);
+ assertTrue("No. of response items should be one", grpResp.getCount() == 1);
+ IAMGroupResponse resp = grpResp.getResponses().get(0);
+ Set<String> acctNames = resp.getAccountNameList();
+ assertEquals("There should be 2 accounts in the group", 2, acctNames.size());
+ assertTrue("account1 should be assigned to the group", acctNames.contains("account1"));
+ assertTrue("account2 should be assigned to the group", acctNames.contains("account2"));
+ // remove "account2" from group1
+ acctIds.remove(1);
+ List<Long> rmAccts = new ArrayList<Long>();
+ rmAccts.add(acct2.getId());
+ when(_iamSrv.removeAccountsFromGroup(rmAccts, groupId)).thenReturn(group);
+ _aclSrv.removeAccountsFromGroup(acctIds, groupId);
+ grpResp = _aclSrv.listIAMGroups(null, "group1", callerDomainId, 0L, 20L);
+ assertTrue("No. of response items should be one", grpResp.getCount() == 1);
+ resp = grpResp.getResponses().get(0);
+ acctNames = resp.getAccountNameList();
+ assertEquals("There should be 1 accounts in the group", 1, acctNames.size());
+ assertFalse("account2 should not belong to the group anymore", acctNames.contains("account2"));
+ }
+
+ @Test
+ public void createIAMPolicyTest() {
+ IAMPolicy policy = new IAMPolicyVO("policy1", "tester policy1");
+ List<IAMPolicy> policies = new ArrayList<IAMPolicy>();
+ policies.add(policy);
+ Pair<List<IAMPolicy>, Integer> policyList = new Pair<List<IAMPolicy>, Integer>(policies, 1);
+ when(_iamSrv.createIAMPolicy("policy1", "tester policy1", null, callerDomainPath)).thenReturn(policy);
+ when(_iamSrv.listIAMPolicies(null, null, callerDomainPath, 0L, 20L)).thenReturn(policyList);
+
+ IAMPolicy createdPolicy = _aclSrv.createIAMPolicy(caller, "policy1", "tester policy1", null);
+ assertNotNull("IAM policy 'policy1' failed to create ", createdPolicy);
+ ListResponse<IAMPolicyResponse> policyResp = _aclSrv.listIAMPolicies(null, null, callerDomainId, 0L, 20L);
+ assertTrue("No. of response items should be one", policyResp.getCount() == 1);
+ IAMPolicyResponse resp = policyResp.getResponses().get(0);
+ assertEquals("Error in created group name", "policy1", resp.getName());
+ }
+
+ @Test
+ public void deleteIAMPolicyTest() {
+ when(_iamSrv.deleteIAMPolicy(1L)).thenReturn(true);
+ assertTrue("failed to delete acl policy 1", _aclSrv.deleteIAMPolicy(1L));
+ }
+
+ @Test
+ public void listIAMPolicyTest() {
+ IAMPolicy policy = new IAMPolicyVO("policy1", "tester policy1");
+ List<IAMPolicy> policies = new ArrayList<IAMPolicy>();
+ policies.add(policy);
+ when(_iamSrv.listIAMPolicies(callerId)).thenReturn(policies);
+ List<IAMPolicy> polys = _aclSrv.listIAMPolicies(callerId);
+ assertTrue(polys != null && polys.size() == 1);
+ IAMPolicy p = polys.get(0);
+ assertEquals("Error to retrieve group", "policy1", p.getName());
+ }
+
+ @Test
+ public void addRemovePolicyToGroupTest() {
+ IAMGroup group = new IAMGroupVO("group1", "tester group1");
+ List<IAMGroup> groups = new ArrayList<IAMGroup>();
+ groups.add(group);
+ Long groupId = group.getId();
+ List<Long> policyIds = new ArrayList<Long>();
+ policyIds.add(100L);
+ policyIds.add(200L);
+ IAMPolicy policy1 = new IAMPolicyVO("policy1", "my first policy");
+ IAMPolicy policy2 = new IAMPolicyVO("policy2", "my second policy");
+ List<IAMPolicy> policies = new ArrayList<IAMPolicy>();
+ policies.add(policy1);
+ policies.add(policy2);
+ when(_iamSrv.attachIAMPoliciesToGroup(policyIds, groupId)).thenReturn(group);
+ when(_iamSrv.listIAMPoliciesByGroup(groupId)).thenReturn(policies);
+ Pair<List<IAMGroup>, Integer> grpList = new Pair<List<IAMGroup>, Integer>(groups, 1);
+ when(_iamSrv.listIAMGroups(null, "group1", callerDomainPath, 0L, 20L)).thenReturn(grpList);
+ _aclSrv.attachIAMPoliciesToGroup(policyIds, groupId);
+ ListResponse<IAMGroupResponse> grpResp = _aclSrv.listIAMGroups(null, "group1", callerDomainId, 0L, 20L);
+ assertTrue("No. of response items should be one", grpResp.getCount() == 1);
+ IAMGroupResponse resp = grpResp.getResponses().get(0);
+ Set<String> policyNames = resp.getPolicyList();
+ assertEquals("There should be 2 policies in the group", 2, policyNames.size());
+ assertTrue("policy1 should be assigned to the group", policyNames.contains("policy1"));
+ assertTrue("policy2 should be assigned to the group", policyNames.contains("policy2"));
+ // remove "policy2" from group1
+ policyIds.remove(1);
+ policies.remove(policy2);
+ when(_iamSrv.removeIAMPoliciesFromGroup(policyIds, groupId)).thenReturn(group);
+ _aclSrv.removeIAMPoliciesFromGroup(policyIds, groupId);
+ grpResp = _aclSrv.listIAMGroups(null, "group1", callerDomainId, 0L, 20L);
+ assertTrue("No. of response items should be one", grpResp.getCount() == 1);
+ resp = grpResp.getResponses().get(0);
+ policyNames = resp.getPolicyList();
+ assertEquals("There should be 1 policy attached to the group", 1, policyNames.size());
+ assertFalse("policy2 should not belong to the group anymore", policyNames.contains("policy2"));
+ }
+
+ @Test
+ public void addRemovePermissionToPolicyTest() {
+ IAMPolicy policy = new IAMPolicyVO("policy1", "tester policy1");
+ List<IAMPolicy> policies = new ArrayList<IAMPolicy>();
+ policies.add(policy);
+ Long policyId = policy.getId();
+ Long resId = 200L;
+ Class clz = ListVMsCmd.class;
+ when(_apiServer.getCmdClass("listVirtualMachines")).thenReturn(clz);
+ when(
+ _iamSrv.addIAMPermissionToIAMPolicy(policyId, IAMEntityType.VirtualMachine.toString(),
+ PermissionScope.RESOURCE.toString(), resId, "listVirtualMachines",
+ AccessType.UseEntry.toString(), Permission.Allow, false)).thenReturn(policy);
+ _aclSrv.addIAMPermissionToIAMPolicy(policyId, IAMEntityType.VirtualMachine.toString(),
+ PermissionScope.RESOURCE, resId, "listVirtualMachines", Permission.Allow, false);
+ Pair<List<IAMPolicy>, Integer> policyList = new Pair<List<IAMPolicy>, Integer>(policies, 1);
+ List<IAMPolicyPermission> policyPerms = new ArrayList<IAMPolicyPermission>();
+ IAMPolicyPermission perm = new IAMPolicyPermissionVO(policyId, "listVirtualMachines",
+ IAMEntityType.VirtualMachine.toString(), AccessType.UseEntry.toString(),
+ PermissionScope.RESOURCE.toString(),
+ resId, Permission.Allow, false);
+ policyPerms.add(perm);
+ when(_iamSrv.listIAMPolicies(null, "policy1", callerDomainPath, 0L, 20L)).thenReturn(policyList);
+ when(_iamSrv.listPolicyPermissions(policyId)).thenReturn(policyPerms);
+ ListResponse<IAMPolicyResponse> policyResp = _aclSrv.listIAMPolicies(null, "policy1", callerDomainId, 0L, 20L);
+ assertTrue("No. of response items should be one", policyResp.getCount() == 1);
+ IAMPolicyResponse resp = policyResp.getResponses().get(0);
+ Set<IAMPermissionResponse> permList = resp.getPermissionList();
+ assertTrue("Permission list should not be empty", permList != null && permList.size() > 0);
+ IAMPermissionResponse permResp = permList.iterator().next();
+ assertEquals("There should be one permission for listVirtualMachines", "listVirtualMachines", permResp.getAction());
+
+ //remove permission from policy
+ policyPerms.remove(perm);
+ _aclSrv.removeIAMPermissionFromIAMPolicy(policyId, IAMEntityType.VirtualMachine.toString(),
+ PermissionScope.RESOURCE, resId, "listVirtualMachines");
+ policyResp = _aclSrv.listIAMPolicies(null, "policy1", callerDomainId, 0L, 20L);
+ assertTrue("No. of response items should be one", policyResp.getCount() == 1);
+ resp = policyResp.getResponses().get(0);
+ permList = resp.getPermissionList();
+ assertTrue("Permission list should be empty", permList != null && permList.size() == 0);
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ @Configuration
+ @ComponentScan(basePackageClasses = {IAMApiServiceImpl.class}, includeFilters = {@Filter(value = TestConfiguration.Library.class, type = FilterType.CUSTOM)}, useDefaultFilters = false)
+ public static class TestConfiguration extends SpringUtils.CloudStackTestConfiguration {
+
+ @Bean
+ public DomainDao domainDao() {
+ return Mockito.mock(DomainDao.class);
+ }
+
+ @Bean
+ public IAMService iamService() {
+ return Mockito.mock(IAMService.class);
+ }
+
+ @Bean
+ public AccountDao accountDao() {
+ return Mockito.mock(AccountDao.class);
+ }
+
+ @Bean
+ public NetworkDomainDao networkDomainDao() {
+ return Mockito.mock(NetworkDomainDao.class);
+ }
+
+ @Bean
+ public AccountManager accountManager() {
+ return Mockito.mock(AccountManager.class);
+ }
+
+ @Bean
+ public MessageBus messageBus() {
+ return Mockito.mock(MessageBus.class);
+ }
+
+ @Bean
+ public EntityManager entityMgr() {
+ return Mockito.mock(EntityManager.class);
+ }
+
+ @Bean
+ public ApiServerService apiServerService() {
+ return Mockito.mock(ApiServerService.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/c28450c1/services/iam/plugin/test/resources/db.properties
----------------------------------------------------------------------
diff --git a/services/iam/plugin/test/resources/db.properties b/services/iam/plugin/test/resources/db.properties
new file mode 100644
index 0000000..e1b5fe9
--- /dev/null
+++ b/services/iam/plugin/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
[6/9] CLOUDSTACK-5920:Add interface to ControlledEntity to return IAM
entity type.
Posted by mc...@apache.org.
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/vm/snapshot/VMSnapshotVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/snapshot/VMSnapshotVO.java b/engine/schema/src/com/cloud/vm/snapshot/VMSnapshotVO.java
index 79fd274..042b276 100644
--- a/engine/schema/src/com/cloud/vm/snapshot/VMSnapshotVO.java
+++ b/engine/schema/src/com/cloud/vm/snapshot/VMSnapshotVO.java
@@ -33,6 +33,7 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
+import org.apache.cloudstack.acl.IAMEntityType;
import org.apache.cloudstack.engine.subsystem.api.storage.VMSnapshotOptions;
import com.cloud.utils.db.GenericDao;
@@ -133,10 +134,10 @@ public class VMSnapshotVO implements VMSnapshot {
this.accountId = accountId;
this.domainId = domainId;
this.vmId = vmId;
- this.state = State.Allocated;
+ state = State.Allocated;
this.description = description;
- this.name = vmSnapshotName;
- this.displayName = vsDisplayName;
+ name = vmSnapshotName;
+ displayName = vsDisplayName;
this.type = type;
this.current = current;
}
@@ -227,7 +228,7 @@ public class VMSnapshotVO implements VMSnapshot {
@Override
public void incrUpdatedCount() {
- this.updatedCount++;
+ updatedCount++;
}
@Override
@@ -243,4 +244,9 @@ public class VMSnapshotVO implements VMSnapshot {
public void setRemoved(Date removed) {
this.removed = removed;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.VMSnapshot;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/org/apache/cloudstack/affinity/AffinityGroupVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/affinity/AffinityGroupVO.java b/engine/schema/src/org/apache/cloudstack/affinity/AffinityGroupVO.java
index 86a2e6a..b9fda8e 100644
--- a/engine/schema/src/org/apache/cloudstack/affinity/AffinityGroupVO.java
+++ b/engine/schema/src/org/apache/cloudstack/affinity/AffinityGroupVO.java
@@ -28,6 +28,7 @@ import javax.persistence.Id;
import javax.persistence.Table;
import org.apache.cloudstack.acl.ControlledEntity;
+import org.apache.cloudstack.acl.IAMEntityType;
@Entity
@Table(name = ("affinity_group"))
@@ -60,7 +61,7 @@ public class AffinityGroupVO implements AffinityGroup {
ControlledEntity.ACLType aclType;
public AffinityGroupVO() {
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
public AffinityGroupVO(String name, String type, String description, long domainId, long accountId, ACLType aclType) {
@@ -68,7 +69,7 @@ public class AffinityGroupVO implements AffinityGroup {
this.description = description;
this.domainId = domainId;
this.accountId = accountId;
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
this.type = type;
this.aclType = aclType;
}
@@ -100,7 +101,7 @@ public class AffinityGroupVO implements AffinityGroup {
@Override
public String getUuid() {
- return this.uuid;
+ return uuid;
}
public void setUuid(String uuid) {
@@ -124,4 +125,9 @@ public class AffinityGroupVO implements AffinityGroup {
return buf.toString();
}
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.AffinityGroup;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java b/engine/schema/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java
index 19d608b..7403d62 100644
--- a/engine/schema/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java
+++ b/engine/schema/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java
@@ -37,6 +37,8 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.utils.db.Encrypt;
import com.cloud.utils.db.GenericDao;
@@ -179,28 +181,28 @@ public class VMEntityVO implements VirtualMachine, FiniteStateObject<State, Virt
public VMEntityVO(long id, long serviceOfferingId, String name, String instanceName, Type type, Long vmTemplateId, HypervisorType hypervisorType, long guestOSId,
long domainId, long accountId, boolean haEnabled, Long diskOfferingId) {
this.id = id;
- this.hostName = name != null ? name : this.uuid;
+ hostName = name != null ? name : uuid;
if (vmTemplateId != null) {
- this.templateId = vmTemplateId;
+ templateId = vmTemplateId;
}
this.instanceName = instanceName;
this.type = type;
this.guestOSId = guestOSId;
this.haEnabled = haEnabled;
- this.vncPassword = Long.toHexString(new Random().nextLong());
- this.state = State.Stopped;
+ vncPassword = Long.toHexString(new Random().nextLong());
+ state = State.Stopped;
this.accountId = accountId;
this.domainId = domainId;
this.serviceOfferingId = serviceOfferingId;
this.hypervisorType = hypervisorType;
- this.limitCpuUse = false;
+ limitCpuUse = false;
this.diskOfferingId = diskOfferingId;
}
public VMEntityVO(long id, long serviceOfferingId, String name, String instanceName, Type type, Long vmTemplateId, HypervisorType hypervisorType, long guestOSId,
long domainId, long accountId, boolean haEnabled, boolean limitResourceUse) {
this(id, serviceOfferingId, name, instanceName, type, vmTemplateId, hypervisorType, guestOSId, domainId, accountId, haEnabled, null);
- this.limitCpuUse = limitResourceUse;
+ limitCpuUse = limitResourceUse;
}
protected VMEntityVO() {
@@ -316,11 +318,11 @@ public class VMEntityVO implements VirtualMachine, FiniteStateObject<State, Virt
}
public Date getProxyAssignTime() {
- return this.proxyAssignTime;
+ return proxyAssignTime;
}
public void setProxyAssignTime(Date time) {
- this.proxyAssignTime = time;
+ proxyAssignTime = time;
}
@Override
@@ -396,7 +398,7 @@ public class VMEntityVO implements VirtualMachine, FiniteStateObject<State, Virt
}
public void setPodId(long podId) {
- this.podIdToDeployIn = podId;
+ podIdToDeployIn = podId;
}
public void setPrivateMacAddress(String privateMacAddress) {
@@ -404,7 +406,7 @@ public class VMEntityVO implements VirtualMachine, FiniteStateObject<State, Virt
}
public void setDataCenterId(long dataCenterId) {
- this.dataCenterIdToDeployIn = dataCenterId;
+ dataCenterIdToDeployIn = dataCenterId;
}
public boolean isRemoved() {
@@ -420,7 +422,7 @@ public class VMEntityVO implements VirtualMachine, FiniteStateObject<State, Virt
}
public String getReservationId() {
- return this.reservationId;
+ return reservationId;
}
@Override
@@ -535,4 +537,8 @@ public class VMEntityVO implements VirtualMachine, FiniteStateObject<State, Virt
this.vmReservation = vmReservation;
}
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.VirtualMachine;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerRuleVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerRuleVO.java b/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerRuleVO.java
index b7b720d..a37fec2 100644
--- a/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerRuleVO.java
+++ b/engine/schema/src/org/apache/cloudstack/region/gslb/GlobalLoadBalancerRuleVO.java
@@ -28,6 +28,8 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.region.ha.GlobalLoadBalancerRule;
@Entity
@@ -74,21 +76,21 @@ public class GlobalLoadBalancerRuleVO implements GlobalLoadBalancerRule {
GlobalLoadBalancerRule.State state;
public GlobalLoadBalancerRuleVO() {
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
public GlobalLoadBalancerRuleVO(String name, String description, String gslbDomain, String algorithm, String persistence, String serviceType, int regionId,
long accountId, long domainId, State state) {
this.name = name;
this.description = description;
- this.region = regionId;
+ region = regionId;
this.algorithm = algorithm;
this.gslbDomain = gslbDomain;
this.persistence = persistence;
this.accountId = accountId;
this.domainId = domainId;
this.serviceType = serviceType;
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
this.state = state;
}
@@ -163,7 +165,7 @@ public class GlobalLoadBalancerRuleVO implements GlobalLoadBalancerRule {
@Override
public String getUuid() {
- return this.uuid;
+ return uuid;
}
public void setUuid(String uuid) {
@@ -187,4 +189,9 @@ public class GlobalLoadBalancerRuleVO implements GlobalLoadBalancerRule {
public GlobalLoadBalancerRule.State getState() {
return state;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.GlobalLoadBalancerRule;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java
----------------------------------------------------------------------
diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java b/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java
index 503d372..8db21cc 100644
--- a/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java
+++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java
@@ -25,6 +25,7 @@ import javax.inject.Inject;
import org.apache.log4j.Logger;
+import org.apache.cloudstack.acl.IAMEntityType;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
@@ -436,4 +437,8 @@ public class TemplateObject implements TemplateInfo {
return true;
}
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.VirtualMachineTemplate;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java
----------------------------------------------------------------------
diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java
index 669a075..2ff24ca 100644
--- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java
+++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java
@@ -24,6 +24,7 @@ import javax.inject.Inject;
import org.apache.log4j.Logger;
+import org.apache.cloudstack.acl.IAMEntityType;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
@@ -380,4 +381,9 @@ public class SnapshotObject implements SnapshotInfo {
}
return true;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.Snapshot;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/storage/src/org/apache/cloudstack/storage/image/TemplateEntityImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/TemplateEntityImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/TemplateEntityImpl.java
index ed6b509..fd90ac9 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/TemplateEntityImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/TemplateEntityImpl.java
@@ -23,6 +23,7 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
+import org.apache.cloudstack.acl.IAMEntityType;
import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
import org.apache.cloudstack.storage.image.datastore.ImageStoreInfo;
@@ -285,4 +286,8 @@ public class TemplateEntityImpl implements TemplateEntity {
return 0;
}
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.VirtualMachineTemplate;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/storage/src/org/apache/cloudstack/storage/snapshot/SnapshotEntityImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/snapshot/SnapshotEntityImpl.java b/engine/storage/src/org/apache/cloudstack/storage/snapshot/SnapshotEntityImpl.java
index fb3ec48..848b165 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/snapshot/SnapshotEntityImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/snapshot/SnapshotEntityImpl.java
@@ -21,6 +21,7 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
+import org.apache.cloudstack.acl.IAMEntityType;
import org.apache.cloudstack.engine.cloud.entity.api.SnapshotEntity;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
@@ -183,4 +184,8 @@ public class SnapshotEntityImpl implements SnapshotEntity {
return null;
}
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.Snapshot;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java
----------------------------------------------------------------------
diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java
index 1653dcb..1f05be2 100644
--- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java
+++ b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java
@@ -22,9 +22,7 @@ import javax.inject.Inject;
import org.apache.log4j.Logger;
-import com.cloud.storage.DiskOfferingVO;
-import com.cloud.storage.dao.DiskOfferingDao;
-import com.cloud.vm.VirtualMachine;
+import org.apache.cloudstack.acl.IAMEntityType;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
@@ -43,9 +41,11 @@ import com.cloud.agent.api.to.DataTO;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.offering.DiskOffering.DiskCacheMode;
import com.cloud.storage.DataStoreRole;
+import com.cloud.storage.DiskOfferingVO;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.Volume;
import com.cloud.storage.VolumeVO;
+import com.cloud.storage.dao.DiskOfferingDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.utils.component.ComponentContext;
import com.cloud.utils.exception.CloudRuntimeException;
@@ -53,6 +53,7 @@ import com.cloud.utils.fsm.NoTransitionException;
import com.cloud.utils.fsm.StateMachine2;
import com.cloud.utils.storage.encoding.EncodingType;
import com.cloud.vm.VMInstanceVO;
+import com.cloud.vm.VirtualMachine;
import com.cloud.vm.dao.VMInstanceDao;
public class VolumeObject implements VolumeInfo {
@@ -89,7 +90,7 @@ public class VolumeObject implements VolumeInfo {
@Override
public String getAttachedVmName() {
- Long vmId = this.volumeVO.getInstanceId();
+ Long vmId = volumeVO.getInstanceId();
if (vmId != null) {
VMInstanceVO vm = vmInstanceDao.findById(vmId);
@@ -103,7 +104,7 @@ public class VolumeObject implements VolumeInfo {
@Override
public VirtualMachine getAttachedVM() {
- Long vmId = this.volumeVO.getInstanceId();
+ Long vmId = volumeVO.getInstanceId();
if (vmId != null) {
VMInstanceVO vm = vmInstanceDao.findById(vmId);
return vm;
@@ -179,7 +180,7 @@ public class VolumeObject implements VolumeInfo {
result = _volStateMachine.transitTo(volumeVO, event, null, volumeDao);
volumeVO = volumeDao.findById(volumeVO.getId());
} catch (NoTransitionException e) {
- String errorMessage = "Failed to transit volume: " + this.getVolumeId() + ", due to: " + e.toString();
+ String errorMessage = "Failed to transit volume: " + getVolumeId() + ", due to: " + e.toString();
s_logger.debug(errorMessage);
throw new CloudRuntimeException(errorMessage);
}
@@ -246,25 +247,25 @@ public class VolumeObject implements VolumeInfo {
@Override
public long getId() {
- return this.volumeVO.getId();
+ return volumeVO.getId();
}
@Override
public boolean isAttachedVM() {
- return (this.volumeVO.getInstanceId() == null) ? false : true;
+ return (volumeVO.getInstanceId() == null) ? false : true;
}
@Override
public String getUri() {
- if (this.dataStore == null) {
+ if (dataStore == null) {
throw new CloudRuntimeException("datastore must be set before using this object");
}
- DataObjectInStore obj = objectInStoreMgr.findObject(this.volumeVO.getId(), DataObjectType.VOLUME, this.dataStore.getId(), this.dataStore.getRole());
+ DataObjectInStore obj = objectInStoreMgr.findObject(volumeVO.getId(), DataObjectType.VOLUME, dataStore.getId(), dataStore.getRole());
if (obj.getState() != ObjectInDataStoreStateMachine.State.Ready) {
- return this.dataStore.getUri() + "&" + EncodingType.OBJTYPE + "=" + DataObjectType.VOLUME + "&" + EncodingType.SIZE + "=" + this.volumeVO.getSize() + "&" +
- EncodingType.NAME + "=" + this.volumeVO.getName();
+ return dataStore.getUri() + "&" + EncodingType.OBJTYPE + "=" + DataObjectType.VOLUME + "&" + EncodingType.SIZE + "=" + volumeVO.getSize() + "&" +
+ EncodingType.NAME + "=" + volumeVO.getName();
} else {
- return this.dataStore.getUri() + "&" + EncodingType.OBJTYPE + "=" + DataObjectType.VOLUME + "&" + EncodingType.PATH + "=" + obj.getInstallPath();
+ return dataStore.getUri() + "&" + EncodingType.OBJTYPE + "=" + DataObjectType.VOLUME + "&" + EncodingType.PATH + "=" + obj.getInstallPath();
}
}
@@ -275,19 +276,19 @@ public class VolumeObject implements VolumeInfo {
@Override
public void processEvent(ObjectInDataStoreStateMachine.Event event) {
- if (this.dataStore == null) {
+ if (dataStore == null) {
return;
}
try {
Volume.Event volEvent = null;
- if (this.dataStore.getRole() == DataStoreRole.ImageCache) {
+ if (dataStore.getRole() == DataStoreRole.ImageCache) {
objectInStoreMgr.update(this, event);
return;
}
- if (this.dataStore.getRole() == DataStoreRole.Image) {
+ if (dataStore.getRole() == DataStoreRole.Image) {
objectInStoreMgr.update(this, event);
- if (this.volumeVO.getState() == Volume.State.Migrating || this.volumeVO.getState() == Volume.State.Copying ||
- this.volumeVO.getState() == Volume.State.Uploaded || this.volumeVO.getState() == Volume.State.Expunged) {
+ if (volumeVO.getState() == Volume.State.Migrating || volumeVO.getState() == Volume.State.Copying ||
+ volumeVO.getState() == Volume.State.Uploaded || volumeVO.getState() == Volume.State.Expunged) {
return;
}
if (event == ObjectInDataStoreStateMachine.Event.CreateOnlyRequested) {
@@ -316,14 +317,14 @@ public class VolumeObject implements VolumeInfo {
} else if (event == ObjectInDataStoreStateMachine.Event.ResizeRequested) {
volEvent = Volume.Event.ResizeRequested;
}
- this.stateTransit(volEvent);
+ stateTransit(volEvent);
} catch (Exception e) {
s_logger.debug("Failed to update state", e);
throw new CloudRuntimeException("Failed to update state:" + e.toString());
} finally {
// in case of OperationFailed, expunge the entry
if (event == ObjectInDataStoreStateMachine.Event.OperationFailed &&
- (this.volumeVO.getState() != Volume.State.Copying && this.volumeVO.getState() != Volume.State.Uploaded)) {
+ (volumeVO.getState() != Volume.State.Copying && volumeVO.getState() != Volume.State.Uploaded)) {
objectInStoreMgr.deleteIfNotReady(this);
}
}
@@ -347,25 +348,25 @@ public class VolumeObject implements VolumeInfo {
@Override
public String getName() {
- return this.volumeVO.getName();
+ return volumeVO.getName();
}
@Override
public Long getInstanceId() {
- return this.volumeVO.getInstanceId();
+ return volumeVO.getInstanceId();
}
@Override
public String getFolder() {
- return this.volumeVO.getFolder();
+ return volumeVO.getFolder();
}
@Override
public String getPath() {
- if (this.dataStore.getRole() == DataStoreRole.Primary) {
- return this.volumeVO.getPath();
+ if (dataStore.getRole() == DataStoreRole.Primary) {
+ return volumeVO.getPath();
} else {
- DataObjectInStore objInStore = this.objectInStoreMgr.findObject(this, dataStore);
+ DataObjectInStore objInStore = objectInStoreMgr.findObject(this, dataStore);
if (objInStore != null) {
return objInStore.getInstallPath();
} else {
@@ -376,121 +377,121 @@ public class VolumeObject implements VolumeInfo {
@Override
public Long getPodId() {
- return this.volumeVO.getPodId();
+ return volumeVO.getPodId();
}
@Override
public long getDataCenterId() {
- return this.volumeVO.getDataCenterId();
+ return volumeVO.getDataCenterId();
}
@Override
public Type getVolumeType() {
- return this.volumeVO.getVolumeType();
+ return volumeVO.getVolumeType();
}
@Override
public Long getPoolId() {
- return this.volumeVO.getPoolId();
+ return volumeVO.getPoolId();
}
@Override
public Date getAttached() {
- return this.volumeVO.getAttached();
+ return volumeVO.getAttached();
}
@Override
public Long getDeviceId() {
- return this.volumeVO.getDeviceId();
+ return volumeVO.getDeviceId();
}
@Override
public Date getCreated() {
- return this.volumeVO.getCreated();
+ return volumeVO.getCreated();
}
@Override
public Long getDiskOfferingId() {
- return this.volumeVO.getDiskOfferingId();
+ return volumeVO.getDiskOfferingId();
}
@Override
public String getChainInfo() {
- return this.volumeVO.getChainInfo();
+ return volumeVO.getChainInfo();
}
@Override
public boolean isRecreatable() {
- return this.volumeVO.isRecreatable();
+ return volumeVO.isRecreatable();
}
@Override
public long getUpdatedCount() {
- return this.volumeVO.getUpdatedCount();
+ return volumeVO.getUpdatedCount();
}
@Override
public void incrUpdatedCount() {
- this.volumeVO.incrUpdatedCount();
+ volumeVO.incrUpdatedCount();
}
@Override
public Date getUpdated() {
- return this.volumeVO.getUpdated();
+ return volumeVO.getUpdated();
}
@Override
public String getReservationId() {
- return this.volumeVO.getReservationId();
+ return volumeVO.getReservationId();
}
@Override
public void setReservationId(String reserv) {
- this.volumeVO.setReservationId(reserv);
+ volumeVO.setReservationId(reserv);
}
@Override
public long getAccountId() {
- return this.volumeVO.getAccountId();
+ return volumeVO.getAccountId();
}
@Override
public long getDomainId() {
- return this.volumeVO.getDomainId();
+ return volumeVO.getDomainId();
}
@Override
public Long getTemplateId() {
- return this.volumeVO.getTemplateId();
+ return volumeVO.getTemplateId();
}
@Override
public void addPayload(Object data) {
- this.payload = data;
+ payload = data;
}
@Override
public Object getpayload() {
- return this.payload;
+ return payload;
}
public VolumeVO getVolume() {
- return this.volumeVO;
+ return volumeVO;
}
@Override
public HypervisorType getHypervisorType() {
- return this.volumeDao.getHypervisorType(this.volumeVO.getId());
+ return volumeDao.getHypervisorType(volumeVO.getId());
}
@Override
public Long getLastPoolId() {
- return this.volumeVO.getLastPoolId();
+ return volumeVO.getLastPoolId();
}
@Override
public DataTO getTO() {
- DataTO to = this.getDataStore().getDriver().getTO(this);
+ DataTO to = getDataStore().getDriver().getTO(this);
if (to == null) {
to = new VolumeObjectTO(this);
}
@@ -500,10 +501,10 @@ public class VolumeObject implements VolumeInfo {
@Override
public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answer) {
try {
- if (this.dataStore.getRole() == DataStoreRole.Primary) {
+ if (dataStore.getRole() == DataStoreRole.Primary) {
if (answer instanceof CopyCmdAnswer) {
CopyCmdAnswer cpyAnswer = (CopyCmdAnswer)answer;
- VolumeVO vol = this.volumeDao.findById(this.getId());
+ VolumeVO vol = volumeDao.findById(getId());
VolumeObjectTO newVol = (VolumeObjectTO)cpyAnswer.getNewData();
vol.setPath(newVol.getPath());
if (newVol.getSize() != null) {
@@ -512,17 +513,17 @@ public class VolumeObject implements VolumeInfo {
if (newVol.getFormat() != null) {
vol.setFormat(newVol.getFormat());
}
- vol.setPoolId(this.getDataStore().getId());
+ vol.setPoolId(getDataStore().getId());
volumeDao.update(vol.getId(), vol);
} else if (answer instanceof CreateObjectAnswer) {
CreateObjectAnswer createAnswer = (CreateObjectAnswer)answer;
VolumeObjectTO newVol = (VolumeObjectTO)createAnswer.getData();
- VolumeVO vol = this.volumeDao.findById(this.getId());
+ VolumeVO vol = volumeDao.findById(getId());
vol.setPath(newVol.getPath());
if (newVol.getSize() != null) {
vol.setSize(newVol.getSize());
}
- vol.setPoolId(this.getDataStore().getId());
+ vol.setPoolId(getDataStore().getId());
if (newVol.getFormat() != null) {
vol.setFormat(newVol.getFormat());
}
@@ -532,19 +533,19 @@ public class VolumeObject implements VolumeInfo {
// image store or imageCache store
if (answer instanceof DownloadAnswer) {
DownloadAnswer dwdAnswer = (DownloadAnswer)answer;
- VolumeDataStoreVO volStore = this.volumeStoreDao.findByStoreVolume(this.dataStore.getId(), this.getId());
+ VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
volStore.setInstallPath(dwdAnswer.getInstallPath());
volStore.setChecksum(dwdAnswer.getCheckSum());
- this.volumeStoreDao.update(volStore.getId(), volStore);
+ volumeStoreDao.update(volStore.getId(), volStore);
} else if (answer instanceof CopyCmdAnswer) {
CopyCmdAnswer cpyAnswer = (CopyCmdAnswer)answer;
- VolumeDataStoreVO volStore = this.volumeStoreDao.findByStoreVolume(this.dataStore.getId(), this.getId());
+ VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
VolumeObjectTO newVol = (VolumeObjectTO)cpyAnswer.getNewData();
volStore.setInstallPath(newVol.getPath());
if (newVol.getSize() != null) {
volStore.setSize(newVol.getSize());
}
- this.volumeStoreDao.update(volStore.getId(), volStore);
+ volumeStoreDao.update(volStore.getId(), volStore);
}
}
} catch (RuntimeException ex) {
@@ -559,12 +560,12 @@ public class VolumeObject implements VolumeInfo {
@Override
public void incRefCount() {
- if (this.dataStore == null) {
+ if (dataStore == null) {
return;
}
- if (this.dataStore.getRole() == DataStoreRole.Image || this.dataStore.getRole() == DataStoreRole.ImageCache) {
- VolumeDataStoreVO store = volumeStoreDao.findByStoreVolume(this.dataStore.getId(), this.getId());
+ if (dataStore.getRole() == DataStoreRole.Image || dataStore.getRole() == DataStoreRole.ImageCache) {
+ VolumeDataStoreVO store = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
store.incrRefCnt();
store.setLastUpdated(new Date());
volumeStoreDao.update(store.getId(), store);
@@ -573,11 +574,11 @@ public class VolumeObject implements VolumeInfo {
@Override
public void decRefCount() {
- if (this.dataStore == null) {
+ if (dataStore == null) {
return;
}
- if (this.dataStore.getRole() == DataStoreRole.Image || this.dataStore.getRole() == DataStoreRole.ImageCache) {
- VolumeDataStoreVO store = volumeStoreDao.findByStoreVolume(this.dataStore.getId(), this.getId());
+ if (dataStore.getRole() == DataStoreRole.Image || dataStore.getRole() == DataStoreRole.ImageCache) {
+ VolumeDataStoreVO store = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
store.decrRefCnt();
store.setLastUpdated(new Date());
volumeStoreDao.update(store.getId(), store);
@@ -586,11 +587,11 @@ public class VolumeObject implements VolumeInfo {
@Override
public Long getRefCount() {
- if (this.dataStore == null) {
+ if (dataStore == null) {
return null;
}
- if (this.dataStore.getRole() == DataStoreRole.Image || this.dataStore.getRole() == DataStoreRole.ImageCache) {
- VolumeDataStoreVO store = volumeStoreDao.findByStoreVolume(this.dataStore.getId(), this.getId());
+ if (dataStore.getRole() == DataStoreRole.Image || dataStore.getRole() == DataStoreRole.ImageCache) {
+ VolumeDataStoreVO store = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
return store.getRefCnt();
}
return null;
@@ -599,45 +600,45 @@ public class VolumeObject implements VolumeInfo {
@Override
public void processEventOnly(ObjectInDataStoreStateMachine.Event event, Answer answer) {
try {
- if (this.dataStore.getRole() == DataStoreRole.Primary) {
+ if (dataStore.getRole() == DataStoreRole.Primary) {
if (answer instanceof CopyCmdAnswer) {
CopyCmdAnswer cpyAnswer = (CopyCmdAnswer)answer;
- VolumeVO vol = this.volumeDao.findById(this.getId());
+ VolumeVO vol = volumeDao.findById(getId());
VolumeObjectTO newVol = (VolumeObjectTO)cpyAnswer.getNewData();
vol.setPath(newVol.getPath());
if (newVol.getSize() != null) {
vol.setSize(newVol.getSize());
}
- vol.setPoolId(this.getDataStore().getId());
+ vol.setPoolId(getDataStore().getId());
volumeDao.update(vol.getId(), vol);
} else if (answer instanceof CreateObjectAnswer) {
CreateObjectAnswer createAnswer = (CreateObjectAnswer)answer;
VolumeObjectTO newVol = (VolumeObjectTO)createAnswer.getData();
- VolumeVO vol = this.volumeDao.findById(this.getId());
+ VolumeVO vol = volumeDao.findById(getId());
vol.setPath(newVol.getPath());
if (newVol.getSize() != null) {
vol.setSize(newVol.getSize());
}
- vol.setPoolId(this.getDataStore().getId());
+ vol.setPoolId(getDataStore().getId());
volumeDao.update(vol.getId(), vol);
}
} else {
// image store or imageCache store
if (answer instanceof DownloadAnswer) {
DownloadAnswer dwdAnswer = (DownloadAnswer)answer;
- VolumeDataStoreVO volStore = this.volumeStoreDao.findByStoreVolume(this.dataStore.getId(), this.getId());
+ VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
volStore.setInstallPath(dwdAnswer.getInstallPath());
volStore.setChecksum(dwdAnswer.getCheckSum());
- this.volumeStoreDao.update(volStore.getId(), volStore);
+ volumeStoreDao.update(volStore.getId(), volStore);
} else if (answer instanceof CopyCmdAnswer) {
CopyCmdAnswer cpyAnswer = (CopyCmdAnswer)answer;
- VolumeDataStoreVO volStore = this.volumeStoreDao.findByStoreVolume(this.dataStore.getId(), this.getId());
+ VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
VolumeObjectTO newVol = (VolumeObjectTO)cpyAnswer.getNewData();
volStore.setInstallPath(newVol.getPath());
if (newVol.getSize() != null) {
volStore.setSize(newVol.getSize());
}
- this.volumeStoreDao.update(volStore.getId(), volStore);
+ volumeStoreDao.update(volStore.getId(), volStore);
}
}
} catch (RuntimeException ex) {
@@ -652,7 +653,7 @@ public class VolumeObject implements VolumeInfo {
@Override
public ImageFormat getFormat() {
- return this.volumeVO.getFormat();
+ return volumeVO.getFormat();
}
@Override
@@ -665,6 +666,11 @@ public class VolumeObject implements VolumeInfo {
@Override
public Long getVmSnapshotChainSize() {
- return this.volumeVO.getVmSnapshotChainSize();
+ return volumeVO.getVmSnapshotChainSize();
+ }
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.Volume;
}
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/server/src/com/cloud/api/query/vo/AffinityGroupJoinVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/vo/AffinityGroupJoinVO.java b/server/src/com/cloud/api/query/vo/AffinityGroupJoinVO.java
index 047d1b3..f659ed9 100644
--- a/server/src/com/cloud/api/query/vo/AffinityGroupJoinVO.java
+++ b/server/src/com/cloud/api/query/vo/AffinityGroupJoinVO.java
@@ -24,6 +24,7 @@ import javax.persistence.Id;
import javax.persistence.Table;
import org.apache.cloudstack.acl.ControlledEntity;
+import org.apache.cloudstack.acl.IAMEntityType;
import com.cloud.vm.VirtualMachine;
@@ -192,4 +193,9 @@ public class AffinityGroupJoinVO extends BaseViewVO implements ControlledViewEnt
return aclType;
}
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.AffinityGroup;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/server/src/com/cloud/api/query/vo/DomainRouterJoinVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/vo/DomainRouterJoinVO.java b/server/src/com/cloud/api/query/vo/DomainRouterJoinVO.java
index 72c7222..c0c07eb 100644
--- a/server/src/com/cloud/api/query/vo/DomainRouterJoinVO.java
+++ b/server/src/com/cloud/api/query/vo/DomainRouterJoinVO.java
@@ -26,6 +26,8 @@ import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.network.Network.GuestType;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.router.VirtualRouter;
@@ -510,4 +512,10 @@ public class DomainRouterJoinVO extends BaseViewVO implements ControlledViewEnti
public VirtualRouter.Role getRole() {
return role;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.VirtualMachine;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/server/src/com/cloud/api/query/vo/EventJoinVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/vo/EventJoinVO.java b/server/src/com/cloud/api/query/vo/EventJoinVO.java
index 6571269..696221d 100644
--- a/server/src/com/cloud/api/query/vo/EventJoinVO.java
+++ b/server/src/com/cloud/api/query/vo/EventJoinVO.java
@@ -25,6 +25,8 @@ import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.event.Event.State;
import com.cloud.utils.db.GenericDao;
@@ -223,4 +225,10 @@ public class EventJoinVO extends BaseViewVO implements ControlledViewEntity {
public boolean getDisplayEvent() {
return displayEvent;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.Event;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/server/src/com/cloud/api/query/vo/InstanceGroupJoinVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/vo/InstanceGroupJoinVO.java b/server/src/com/cloud/api/query/vo/InstanceGroupJoinVO.java
index cd1ba12..38b7229 100644
--- a/server/src/com/cloud/api/query/vo/InstanceGroupJoinVO.java
+++ b/server/src/com/cloud/api/query/vo/InstanceGroupJoinVO.java
@@ -23,6 +23,8 @@ import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.utils.db.GenericDao;
@Entity
@@ -156,4 +158,10 @@ public class InstanceGroupJoinVO extends BaseViewVO implements ControlledViewEnt
public Date getCreated() {
return created;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.InstanceGroup;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/server/src/com/cloud/api/query/vo/ProjectInvitationJoinVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/vo/ProjectInvitationJoinVO.java b/server/src/com/cloud/api/query/vo/ProjectInvitationJoinVO.java
index 34f3929..7ff1779 100644
--- a/server/src/com/cloud/api/query/vo/ProjectInvitationJoinVO.java
+++ b/server/src/com/cloud/api/query/vo/ProjectInvitationJoinVO.java
@@ -25,6 +25,8 @@ import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.projects.ProjectInvitation.State;
import com.cloud.utils.db.GenericDao;
@@ -160,4 +162,10 @@ public class ProjectInvitationJoinVO extends BaseViewVO implements ControlledVie
public String getDomainPath() {
return domainPath;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.ProjectInvitation;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/server/src/com/cloud/api/query/vo/ResourceTagJoinVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/vo/ResourceTagJoinVO.java b/server/src/com/cloud/api/query/vo/ResourceTagJoinVO.java
index 72f9b77..1dca46b 100644
--- a/server/src/com/cloud/api/query/vo/ResourceTagJoinVO.java
+++ b/server/src/com/cloud/api/query/vo/ResourceTagJoinVO.java
@@ -23,6 +23,8 @@ import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.server.ResourceTag.ResourceObjectType;
@Entity
@@ -178,4 +180,10 @@ public class ResourceTagJoinVO extends BaseViewVO implements ControlledViewEntit
public String getCustomer() {
return customer;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.ResourceTag;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/server/src/com/cloud/api/query/vo/SecurityGroupJoinVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/vo/SecurityGroupJoinVO.java b/server/src/com/cloud/api/query/vo/SecurityGroupJoinVO.java
index d51d111..cf2df98 100644
--- a/server/src/com/cloud/api/query/vo/SecurityGroupJoinVO.java
+++ b/server/src/com/cloud/api/query/vo/SecurityGroupJoinVO.java
@@ -23,6 +23,8 @@ import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.network.security.SecurityRule.SecurityRuleType;
import com.cloud.server.ResourceTag.ResourceObjectType;
@@ -302,4 +304,10 @@ public class SecurityGroupJoinVO extends BaseViewVO implements ControlledViewEnt
public String getTagCustomer() {
return tagCustomer;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.SecurityGroup;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/server/src/com/cloud/api/query/vo/TemplateJoinVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/vo/TemplateJoinVO.java b/server/src/com/cloud/api/query/vo/TemplateJoinVO.java
index c096279..21c0a2e 100644
--- a/server/src/com/cloud/api/query/vo/TemplateJoinVO.java
+++ b/server/src/com/cloud/api/query/vo/TemplateJoinVO.java
@@ -27,7 +27,7 @@ import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
-import com.cloud.template.VirtualMachineTemplate.State;
+import org.apache.cloudstack.acl.IAMEntityType;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
@@ -35,6 +35,7 @@ import com.cloud.server.ResourceTag.ResourceObjectType;
import com.cloud.storage.ScopeType;
import com.cloud.storage.Storage;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
+import com.cloud.template.VirtualMachineTemplate.State;
import com.cloud.utils.db.GenericDao;
@Entity
@@ -539,4 +540,10 @@ public class TemplateJoinVO extends BaseViewVO implements ControlledViewEntity {
}
public State getTemplateState() { return templateState; }
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.VirtualMachineTemplate;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/server/src/com/cloud/api/query/vo/UserVmJoinVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/vo/UserVmJoinVO.java b/server/src/com/cloud/api/query/vo/UserVmJoinVO.java
index 2df49ec..302b4ec 100644
--- a/server/src/com/cloud/api/query/vo/UserVmJoinVO.java
+++ b/server/src/com/cloud/api/query/vo/UserVmJoinVO.java
@@ -28,6 +28,8 @@ import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.Network.GuestType;
import com.cloud.network.Networks.TrafficType;
@@ -909,4 +911,10 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity {
public String getDetailValue() {
return detailValue;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.VirtualMachine;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/server/src/com/cloud/api/query/vo/VolumeJoinVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/vo/VolumeJoinVO.java b/server/src/com/cloud/api/query/vo/VolumeJoinVO.java
index 1d1b37d..ce26c1f 100644
--- a/server/src/com/cloud/api/query/vo/VolumeJoinVO.java
+++ b/server/src/com/cloud/api/query/vo/VolumeJoinVO.java
@@ -27,6 +27,8 @@ import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.server.ResourceTag.ResourceObjectType;
import com.cloud.storage.Storage;
@@ -573,4 +575,10 @@ public class VolumeJoinVO extends BaseViewVO implements ControlledViewEntity {
public String getChainInfo() {
return chainInfo;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.Volume;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/server/src/com/cloud/api/response/SecurityGroupResultObject.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/response/SecurityGroupResultObject.java b/server/src/com/cloud/api/response/SecurityGroupResultObject.java
index 9697495..66ba487 100644
--- a/server/src/com/cloud/api/response/SecurityGroupResultObject.java
+++ b/server/src/com/cloud/api/response/SecurityGroupResultObject.java
@@ -22,6 +22,7 @@ import java.util.List;
import java.util.Map;
import org.apache.cloudstack.acl.ControlledEntity;
+import org.apache.cloudstack.acl.IAMEntityType;
import org.apache.cloudstack.api.InternalIdentity;
import com.cloud.api.ApiDBUtils;
@@ -63,7 +64,7 @@ public class SecurityGroupResultObject implements ControlledEntity, InternalIden
this.domainId = domainId;
this.accountId = accountId;
this.accountName = accountName;
- this.securityGroupRules = ingressRules;
+ securityGroupRules = ingressRules;
}
@Override
@@ -209,4 +210,9 @@ public class SecurityGroupResultObject implements ControlledEntity, InternalIden
}
return resultObjects;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.SecurityGroup;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/server/src/com/cloud/network/vpc/PrivateGatewayProfile.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpc/PrivateGatewayProfile.java b/server/src/com/cloud/network/vpc/PrivateGatewayProfile.java
index e183cdb..b912e22 100644
--- a/server/src/com/cloud/network/vpc/PrivateGatewayProfile.java
+++ b/server/src/com/cloud/network/vpc/PrivateGatewayProfile.java
@@ -16,6 +16,8 @@
// under the License.
package com.cloud.network.vpc;
+import org.apache.cloudstack.acl.IAMEntityType;
+
public class PrivateGatewayProfile implements PrivateGateway {
VpcGateway vpcGateway;
long physicalNetworkId;
@@ -110,4 +112,8 @@ public class PrivateGatewayProfile implements PrivateGateway {
return vpcGateway.getNetworkACLId();
}
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.VpcGateway;
+ }
}
[7/9] git commit: updated refs/heads/master to 63e3eea
Posted by mc...@apache.org.
CLOUDSTACK-5920:Add interface to ControlledEntity to return IAM
entity type.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/d0ae4d9a
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/d0ae4d9a
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/d0ae4d9a
Branch: refs/heads/master
Commit: d0ae4d9a9f7dc2ef39ee24f09c36f67ccb7502d7
Parents: b8413b9
Author: Min Chen <mi...@citrix.com>
Authored: Tue Mar 4 17:14:25 2014 -0800
Committer: Min Chen <mi...@citrix.com>
Committed: Wed Mar 5 09:40:55 2014 -0800
----------------------------------------------------------------------
api/src/com/cloud/network/NetworkProfile.java | 7 +
.../cloud/network/vpc/StaticRouteProfile.java | 28 ++--
.../apache/cloudstack/acl/ControlledEntity.java | 1 +
.../apache/cloudstack/acl/IAMEntityType.java | 45 +++++
.../firewall/CreateEgressFirewallRuleCmd.java | 11 +-
.../user/firewall/CreateFirewallRuleCmd.java | 12 +-
.../firewall/CreatePortForwardingRuleCmd.java | 10 +-
.../user/nat/CreateIpForwardingRuleCmd.java | 18 +-
.../src/com/cloud/network/addr/PublicIp.java | 7 +
.../cloud/network/rules/StaticNatRuleImpl.java | 33 ++--
engine/schema/src/com/cloud/event/EventVO.java | 12 +-
.../com/cloud/network/UserIpv6AddressVO.java | 17 +-
.../schema/src/com/cloud/network/VpnUserVO.java | 19 ++-
.../com/cloud/network/as/AutoScalePolicyVO.java | 9 +-
.../cloud/network/as/AutoScaleVmGroupVO.java | 11 +-
.../cloud/network/as/AutoScaleVmProfileVO.java | 11 +-
.../src/com/cloud/network/as/ConditionVO.java | 11 +-
.../src/com/cloud/network/dao/IPAddressVO.java | 45 ++---
.../cloud/network/dao/MonitoringServiceVO.java | 7 +
.../src/com/cloud/network/dao/NetworkVO.java | 46 +++---
.../cloud/network/dao/RemoteAccessVpnVO.java | 17 +-
.../network/dao/Site2SiteCustomerGatewayVO.java | 9 +-
.../network/dao/Site2SiteVpnConnectionVO.java | 14 +-
.../network/dao/Site2SiteVpnGatewayVO.java | 13 +-
.../src/com/cloud/network/dao/SslCertVO.java | 14 +-
.../com/cloud/network/rules/FirewallRuleVO.java | 24 ++-
.../cloud/network/security/SecurityGroupVO.java | 13 +-
.../com/cloud/network/vpc/StaticRouteVO.java | 15 +-
.../src/com/cloud/network/vpc/VpcGatewayVO.java | 17 +-
.../schema/src/com/cloud/network/vpc/VpcVO.java | 15 +-
.../com/cloud/projects/ProjectInvitationVO.java | 17 +-
.../src/com/cloud/storage/SnapshotVO.java | 19 ++-
.../src/com/cloud/storage/VMTemplateVO.java | 6 +
.../schema/src/com/cloud/storage/VolumeVO.java | 101 ++++++------
.../src/com/cloud/tags/ResourceTagVO.java | 11 +-
engine/schema/src/com/cloud/user/AccountVO.java | 16 +-
.../schema/src/com/cloud/user/SSHKeyPairVO.java | 6 +
.../src/com/cloud/vm/InstanceGroupVO.java | 11 +-
.../schema/src/com/cloud/vm/VMInstanceVO.java | 28 ++--
.../src/com/cloud/vm/dao/NicIpAliasVO.java | 14 +-
.../src/com/cloud/vm/dao/NicSecondaryIpVO.java | 9 +-
.../src/com/cloud/vm/snapshot/VMSnapshotVO.java | 14 +-
.../cloudstack/affinity/AffinityGroupVO.java | 12 +-
.../engine/cloud/entity/api/db/VMEntityVO.java | 28 ++--
.../region/gslb/GlobalLoadBalancerRuleVO.java | 15 +-
.../storage/image/store/TemplateObject.java | 5 +
.../storage/snapshot/SnapshotObject.java | 6 +
.../storage/image/TemplateEntityImpl.java | 5 +
.../storage/snapshot/SnapshotEntityImpl.java | 5 +
.../cloudstack/storage/volume/VolumeObject.java | 164 ++++++++++---------
.../cloud/api/query/vo/AffinityGroupJoinVO.java | 6 +
.../cloud/api/query/vo/DomainRouterJoinVO.java | 8 +
.../src/com/cloud/api/query/vo/EventJoinVO.java | 8 +
.../cloud/api/query/vo/InstanceGroupJoinVO.java | 8 +
.../api/query/vo/ProjectInvitationJoinVO.java | 8 +
.../cloud/api/query/vo/ResourceTagJoinVO.java | 8 +
.../cloud/api/query/vo/SecurityGroupJoinVO.java | 8 +
.../com/cloud/api/query/vo/TemplateJoinVO.java | 9 +-
.../com/cloud/api/query/vo/UserVmJoinVO.java | 8 +
.../com/cloud/api/query/vo/VolumeJoinVO.java | 8 +
.../api/response/SecurityGroupResultObject.java | 8 +-
.../network/vpc/PrivateGatewayProfile.java | 6 +
62 files changed, 778 insertions(+), 318 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/api/src/com/cloud/network/NetworkProfile.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/NetworkProfile.java b/api/src/com/cloud/network/NetworkProfile.java
index 1b66c7c..3f57694 100644
--- a/api/src/com/cloud/network/NetworkProfile.java
+++ b/api/src/com/cloud/network/NetworkProfile.java
@@ -18,6 +18,8 @@ package com.cloud.network;
import java.net.URI;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.Mode;
import com.cloud.network.Networks.TrafficType;
@@ -275,4 +277,9 @@ public class NetworkProfile implements Network {
public String getIp6Cidr() {
return ip6Cidr;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.Network;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/api/src/com/cloud/network/vpc/StaticRouteProfile.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/vpc/StaticRouteProfile.java b/api/src/com/cloud/network/vpc/StaticRouteProfile.java
index 05cff49..b38d5ea 100644
--- a/api/src/com/cloud/network/vpc/StaticRouteProfile.java
+++ b/api/src/com/cloud/network/vpc/StaticRouteProfile.java
@@ -16,6 +16,8 @@
// under the License.
package com.cloud.network.vpc;
+import org.apache.cloudstack.acl.IAMEntityType;
+
public class StaticRouteProfile implements StaticRoute {
private long id;
private String uuid;
@@ -31,18 +33,18 @@ public class StaticRouteProfile implements StaticRoute {
String ipAddress;
public StaticRouteProfile(StaticRoute staticRoute, VpcGateway gateway) {
- this.id = staticRoute.getId();
- this.uuid = staticRoute.getUuid();
- this.targetCidr = staticRoute.getCidr();
- this.accountId = staticRoute.getAccountId();
- this.domainId = staticRoute.getDomainId();
- this.gatewayId = staticRoute.getVpcGatewayId();
- this.state = staticRoute.getState();
- this.vpcId = staticRoute.getVpcId();
- this.vlanTag = gateway.getBroadcastUri();
+ id = staticRoute.getId();
+ uuid = staticRoute.getUuid();
+ targetCidr = staticRoute.getCidr();
+ accountId = staticRoute.getAccountId();
+ domainId = staticRoute.getDomainId();
+ gatewayId = staticRoute.getVpcGatewayId();
+ state = staticRoute.getState();
+ vpcId = staticRoute.getVpcId();
+ vlanTag = gateway.getBroadcastUri();
this.gateway = gateway.getGateway();
- this.netmask = gateway.getNetmask();
- this.ipAddress = gateway.getIp4Address();
+ netmask = gateway.getNetmask();
+ ipAddress = gateway.getIp4Address();
}
@Override
@@ -101,4 +103,8 @@ public class StaticRouteProfile implements StaticRoute {
return netmask;
}
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.StaticRoute;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/api/src/org/apache/cloudstack/acl/ControlledEntity.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/acl/ControlledEntity.java b/api/src/org/apache/cloudstack/acl/ControlledEntity.java
index 5957576..2572705 100644
--- a/api/src/org/apache/cloudstack/acl/ControlledEntity.java
+++ b/api/src/org/apache/cloudstack/acl/ControlledEntity.java
@@ -29,4 +29,5 @@ public interface ControlledEntity extends OwnedBy, PartOf {
Account, Domain
}
+ IAMEntityType getEntityType();
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/api/src/org/apache/cloudstack/acl/IAMEntityType.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/acl/IAMEntityType.java b/api/src/org/apache/cloudstack/acl/IAMEntityType.java
new file mode 100644
index 0000000..9299ae9
--- /dev/null
+++ b/api/src/org/apache/cloudstack/acl/IAMEntityType.java
@@ -0,0 +1,45 @@
+package org.apache.cloudstack.acl;
+
+public enum IAMEntityType {
+ // currently supported entity, to be added one by one after we support acl on the entity
+ VirtualMachine,
+ Volume,
+ ResourceTag,
+ Account,
+ AffinityGroup,
+ AutoScalePolicy,
+ AutoScaleVmGroup,
+ AutoScaleVmProfile,
+ Condition,
+ Vpc,
+ VpcGateway,
+ PrivateGateway,
+ VpnUser,
+ VMSnapshot,
+ VirtualMachineTemplate,
+ UserIpv6Address,
+ StaticRoute,
+ SSHKeyPair,
+ Snapshot,
+ Site2SiteVpnGateway,
+ Site2SiteVpnConnection,
+ Site2SiteCustomerGateway,
+ SecurityGroup,
+ RemoteAccessVpn,
+ PublicIpAddress,
+ ProjectInvitation,
+ NicSecondaryIp,
+ NicIpAlias,
+ Network,
+ IpAddress,
+ InstanceGroup,
+ GlobalLoadBalancerRule,
+ FirewallRule,
+ PortForwardingRule,
+ Event,
+ AsyncJob,
+ IAMPolicy,
+ IAMGroup,
+ MonitorService,
+ SSLCert
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/api/src/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java
index ca78755..d15ea4b 100644
--- a/api/src/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java
@@ -20,6 +20,9 @@ package org.apache.cloudstack.api.command.user.firewall;
import java.util.ArrayList;
import java.util.List;
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.acl.IAMEntityType;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiCommandJobType;
@@ -32,7 +35,6 @@ import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.FirewallResponse;
import org.apache.cloudstack.api.response.NetworkResponse;
import org.apache.cloudstack.context.CallContext;
-import org.apache.log4j.Logger;
import com.cloud.event.EventTypes;
import com.cloud.exception.InvalidParameterValueException;
@@ -275,7 +277,7 @@ public class CreateEgressFirewallRuleCmd extends BaseAsyncCreateCmd implements F
@Override
public String getEventDescription() {
Network network = _networkService.getNetwork(networkId);
- return ("Creating firewall rule for network: " + network + " for protocol:" + this.getProtocol());
+ return ("Creating firewall rule for network: " + network + " for protocol:" + getProtocol());
}
@Override
@@ -354,4 +356,9 @@ public class CreateEgressFirewallRuleCmd extends BaseAsyncCreateCmd implements F
}
}
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.FirewallRule;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/api/src/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java
index 0b342f2..76c6e74 100644
--- a/api/src/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java
@@ -19,6 +19,9 @@ package org.apache.cloudstack.api.command.user.firewall;
import java.util.ArrayList;
import java.util.List;
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.acl.IAMEntityType;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiCommandJobType;
@@ -31,7 +34,6 @@ import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.FirewallResponse;
import org.apache.cloudstack.api.response.IPAddressResponse;
import org.apache.cloudstack.context.CallContext;
-import org.apache.log4j.Logger;
import com.cloud.event.EventTypes;
import com.cloud.exception.InvalidParameterValueException;
@@ -266,7 +268,7 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal
@Override
public String getEventDescription() {
IpAddress ip = _networkService.getIp(ipAddressId);
- return ("Creating firewall rule for Ip: " + ip.getAddress() + " for protocol:" + this.getProtocol());
+ return ("Creating firewall rule for Ip: " + ip.getAddress() + " for protocol:" + getProtocol());
}
@Override
@@ -346,4 +348,10 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal
return true;
}
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.FirewallRule;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/api/src/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java
index 61d5856..53945a6 100644
--- a/api/src/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java
@@ -18,6 +18,9 @@ package org.apache.cloudstack.api.command.user.firewall;
import java.util.List;
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.acl.IAMEntityType;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiCommandJobType;
@@ -32,7 +35,6 @@ import org.apache.cloudstack.api.response.IPAddressResponse;
import org.apache.cloudstack.api.response.NetworkResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.context.CallContext;
-import org.apache.log4j.Logger;
import com.cloud.event.EventTypes;
import com.cloud.exception.InvalidParameterValueException;
@@ -428,4 +430,10 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P
return true;
}
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.FirewallRule;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/api/src/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java
index 70be167..77edbfc 100644
--- a/api/src/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java
@@ -18,6 +18,9 @@ package org.apache.cloudstack.api.command.user.nat;
import java.util.List;
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.acl.IAMEntityType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiCommandJobType;
import org.apache.cloudstack.api.ApiConstants;
@@ -30,7 +33,6 @@ import org.apache.cloudstack.api.response.FirewallRuleResponse;
import org.apache.cloudstack.api.response.IPAddressResponse;
import org.apache.cloudstack.api.response.IpForwardingRuleResponse;
import org.apache.cloudstack.context.CallContext;
-import org.apache.log4j.Logger;
import com.cloud.event.EventTypes;
import com.cloud.exception.InvalidParameterValueException;
@@ -126,7 +128,7 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Sta
StaticNatRule staticNatRule = _rulesService.buildStaticNatRule(rule, false);
IpForwardingRuleResponse fwResponse = _responseGenerator.createIpForwardingRuleResponse(staticNatRule);
fwResponse.setResponseName(getCommandName());
- this.setResponseObject(fwResponse);
+ setResponseObject(fwResponse);
} finally {
if (!result || rule == null) {
@@ -152,8 +154,8 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Sta
try {
StaticNatRule rule = _rulesService.createStaticNatRule(this, getOpenFirewall());
- this.setEntityId(rule.getId());
- this.setEntityUuid(rule.getUuid());
+ setEntityId(rule.getId());
+ setEntityUuid(rule.getUuid());
} catch (NetworkRuleConflictException e) {
s_logger.info("Unable to create Static Nat Rule due to ", e);
throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
@@ -179,7 +181,7 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Sta
@Override
public String getEventDescription() {
IpAddress ip = _networkService.getIp(ipAddressId);
- return ("Applying an ipforwarding 1:1 NAT rule for Ip: " + ip.getAddress() + " with virtual machine:" + this.getVirtualMachineId());
+ return ("Applying an ipforwarding 1:1 NAT rule for Ip: " + ip.getAddress() + " with virtual machine:" + getVirtualMachineId());
}
private long getVirtualMachineId() {
@@ -321,4 +323,10 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Sta
public boolean isDisplay() {
return true;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.FirewallRule;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/components-api/src/com/cloud/network/addr/PublicIp.java
----------------------------------------------------------------------
diff --git a/engine/components-api/src/com/cloud/network/addr/PublicIp.java b/engine/components-api/src/com/cloud/network/addr/PublicIp.java
index 9a1b663..12e4d34 100644
--- a/engine/components-api/src/com/cloud/network/addr/PublicIp.java
+++ b/engine/components-api/src/com/cloud/network/addr/PublicIp.java
@@ -18,6 +18,8 @@ package com.cloud.network.addr;
import java.util.Date;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.dc.VlanVO;
import com.cloud.network.PublicIpAddress;
import com.cloud.network.dao.IPAddressVO;
@@ -236,4 +238,9 @@ public class PublicIp implements PublicIpAddress {
public boolean isDisplay() {
return _addr.isDisplay();
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.PublicIpAddress;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/components-api/src/com/cloud/network/rules/StaticNatRuleImpl.java
----------------------------------------------------------------------
diff --git a/engine/components-api/src/com/cloud/network/rules/StaticNatRuleImpl.java b/engine/components-api/src/com/cloud/network/rules/StaticNatRuleImpl.java
index 7104715..bdaf2bc 100644
--- a/engine/components-api/src/com/cloud/network/rules/StaticNatRuleImpl.java
+++ b/engine/components-api/src/com/cloud/network/rules/StaticNatRuleImpl.java
@@ -18,6 +18,8 @@ package com.cloud.network.rules;
import java.util.List;
+import org.apache.cloudstack.acl.IAMEntityType;
+
public class StaticNatRuleImpl implements StaticNatRule {
long id;
String xid;
@@ -34,19 +36,19 @@ public class StaticNatRuleImpl implements StaticNatRule {
boolean forDisplay;
public StaticNatRuleImpl(FirewallRuleVO rule, String dstIp) {
- this.id = rule.getId();
- this.xid = rule.getXid();
- this.uuid = rule.getUuid();
- this.protocol = rule.getProtocol();
- this.portStart = rule.getSourcePortStart();
- this.portEnd = rule.getSourcePortEnd();
- this.state = rule.getState();
- this.accountId = rule.getAccountId();
- this.domainId = rule.getDomainId();
- this.networkId = rule.getNetworkId();
- this.sourceIpAddressId = rule.getSourceIpAddressId();
- this.destIpAddress = dstIp;
- this.forDisplay = rule.isDisplay();
+ id = rule.getId();
+ xid = rule.getXid();
+ uuid = rule.getUuid();
+ protocol = rule.getProtocol();
+ portStart = rule.getSourcePortStart();
+ portEnd = rule.getSourcePortEnd();
+ state = rule.getState();
+ accountId = rule.getAccountId();
+ domainId = rule.getDomainId();
+ networkId = rule.getNetworkId();
+ sourceIpAddressId = rule.getSourceIpAddressId();
+ destIpAddress = dstIp;
+ forDisplay = rule.isDisplay();
}
@Override
@@ -148,4 +150,9 @@ public class StaticNatRuleImpl implements StaticNatRule {
public boolean isDisplay() {
return forDisplay;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.FirewallRule;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/event/EventVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/event/EventVO.java b/engine/schema/src/com/cloud/event/EventVO.java
index 91174fc..6fecaa6 100644
--- a/engine/schema/src/com/cloud/event/EventVO.java
+++ b/engine/schema/src/com/cloud/event/EventVO.java
@@ -29,6 +29,8 @@ import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.utils.db.GenericDao;
@Entity
@@ -87,7 +89,7 @@ public class EventVO implements Event {
public static final String LEVEL_ERROR = "ERROR";
public EventVO() {
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
@Override
@@ -196,7 +198,7 @@ public class EventVO implements Event {
@Override
public String getUuid() {
- return this.uuid;
+ return uuid;
}
public void setUuid(String uuid) {
@@ -219,4 +221,10 @@ public class EventVO implements Event {
public void setDisplayEventEnabled(boolean displayEventEnabled) {
isDisplayEventEnabled = displayEventEnabled;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.Event;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/network/UserIpv6AddressVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/UserIpv6AddressVO.java b/engine/schema/src/com/cloud/network/UserIpv6AddressVO.java
index 3098a68..9314993 100644
--- a/engine/schema/src/com/cloud/network/UserIpv6AddressVO.java
+++ b/engine/schema/src/com/cloud/network/UserIpv6AddressVO.java
@@ -28,6 +28,8 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.utils.db.GenericDao;
@Entity
@@ -76,16 +78,16 @@ public class UserIpv6AddressVO implements UserIpv6Address {
Date created;
protected UserIpv6AddressVO() {
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
public UserIpv6AddressVO(String address, long dataCenterId, String macAddress, long vlanDbId) {
this.address = address;
this.dataCenterId = dataCenterId;
- this.vlanId = vlanDbId;
- this.state = State.Free;
- this.setMacAddress(macAddress);
- this.uuid = UUID.randomUUID().toString();
+ vlanId = vlanDbId;
+ state = State.Free;
+ setMacAddress(macAddress);
+ uuid = UUID.randomUUID().toString();
}
@Override
@@ -184,4 +186,9 @@ public class UserIpv6AddressVO implements UserIpv6Address {
public void setCreated(Date created) {
this.created = created;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.UserIpv6Address;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/network/VpnUserVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/VpnUserVO.java b/engine/schema/src/com/cloud/network/VpnUserVO.java
index 07b6326..695aac0 100644
--- a/engine/schema/src/com/cloud/network/VpnUserVO.java
+++ b/engine/schema/src/com/cloud/network/VpnUserVO.java
@@ -27,6 +27,8 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.utils.db.Encrypt;
@Entity
@@ -58,16 +60,16 @@ public class VpnUserVO implements VpnUser {
private String uuid;
public VpnUserVO() {
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
public VpnUserVO(long accountId, long domainId, String userName, String password) {
this.accountId = accountId;
this.domainId = domainId;
- this.username = userName;
+ username = userName;
this.password = password;
- this.state = State.Add;
- this.uuid = UUID.randomUUID().toString();
+ state = State.Add;
+ uuid = UUID.randomUUID().toString();
}
@Override
@@ -86,7 +88,7 @@ public class VpnUserVO implements VpnUser {
}
public void setUsername(String userName) {
- this.username = userName;
+ username = userName;
}
@Override
@@ -119,10 +121,15 @@ public class VpnUserVO implements VpnUser {
@Override
public String getUuid() {
- return this.uuid;
+ return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.VpnUser;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/network/as/AutoScalePolicyVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/as/AutoScalePolicyVO.java b/engine/schema/src/com/cloud/network/as/AutoScalePolicyVO.java
index b69907c..bde38f8 100644
--- a/engine/schema/src/com/cloud/network/as/AutoScalePolicyVO.java
+++ b/engine/schema/src/com/cloud/network/as/AutoScalePolicyVO.java
@@ -30,6 +30,7 @@ import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
+import org.apache.cloudstack.acl.IAMEntityType;
import org.apache.cloudstack.api.InternalIdentity;
import com.cloud.utils.db.GenericDao;
@@ -77,7 +78,7 @@ public class AutoScalePolicyVO implements AutoScalePolicy, InternalIdentity {
public AutoScalePolicyVO(long domainId, long accountId, int duration,
int quietTime, Date lastQuiteTime, String action) {
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
this.domainId = domainId;
this.accountId = accountId;
this.duration = duration;
@@ -150,4 +151,10 @@ public class AutoScalePolicyVO implements AutoScalePolicy, InternalIdentity {
public void setLastQuiteTime(Date lastQuiteTime) {
this.lastQuiteTime = lastQuiteTime;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.AutoScalePolicy;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/network/as/AutoScaleVmGroupVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/as/AutoScaleVmGroupVO.java b/engine/schema/src/com/cloud/network/as/AutoScaleVmGroupVO.java
index 6694f64..89d079d 100644
--- a/engine/schema/src/com/cloud/network/as/AutoScaleVmGroupVO.java
+++ b/engine/schema/src/com/cloud/network/as/AutoScaleVmGroupVO.java
@@ -30,6 +30,7 @@ import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
+import org.apache.cloudstack.acl.IAMEntityType;
import org.apache.cloudstack.api.InternalIdentity;
import com.cloud.utils.db.GenericDao;
@@ -97,8 +98,8 @@ public class AutoScaleVmGroupVO implements AutoScaleVmGroup, InternalIdentity {
long accountId, int minMembers, int maxMembers, int memberPort,
int interval, Date lastInterval, long profileId, String state) {
- this.uuid = UUID.randomUUID().toString();
- this.loadBalancerId = lbRuleId;
+ uuid = UUID.randomUUID().toString();
+ loadBalancerId = lbRuleId;
this.minMembers = minMembers;
this.maxMembers = maxMembers;
this.memberPort = memberPort;
@@ -224,4 +225,10 @@ public class AutoScaleVmGroupVO implements AutoScaleVmGroup, InternalIdentity {
public boolean isDisplay() {
return display;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.AutoScaleVmGroup;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/network/as/AutoScaleVmProfileVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/as/AutoScaleVmProfileVO.java b/engine/schema/src/com/cloud/network/as/AutoScaleVmProfileVO.java
index 40dbe90..0b59394 100644
--- a/engine/schema/src/com/cloud/network/as/AutoScaleVmProfileVO.java
+++ b/engine/schema/src/com/cloud/network/as/AutoScaleVmProfileVO.java
@@ -33,6 +33,7 @@ import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
@@ -94,7 +95,7 @@ public class AutoScaleVmProfileVO implements AutoScaleVmProfile, Identity, Inter
public AutoScaleVmProfileVO(long zoneId, long domainId, long accountId, long serviceOfferingId, long templateId, String otherDeployParams, Map counterParamList,
Integer destroyVmGraceperiod, long autoscaleUserId) {
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
this.zoneId = zoneId;
this.domainId = domainId;
this.accountId = accountId;
@@ -149,7 +150,7 @@ public class AutoScaleVmProfileVO implements AutoScaleVmProfile, Identity, Inter
}
public void setCounterParams(String counterParam) {
- this.counterParams = counterParam;
+ counterParams = counterParam;
}
public void setCounterParamsForUpdate(Map counterParamList) {
@@ -232,4 +233,10 @@ public class AutoScaleVmProfileVO implements AutoScaleVmProfile, Identity, Inter
public boolean isDisplay() {
return display;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.AutoScaleVmProfile;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/network/as/ConditionVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/as/ConditionVO.java b/engine/schema/src/com/cloud/network/as/ConditionVO.java
index 8d7e776..e8c1d0b 100644
--- a/engine/schema/src/com/cloud/network/as/ConditionVO.java
+++ b/engine/schema/src/com/cloud/network/as/ConditionVO.java
@@ -29,6 +29,7 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
@@ -77,7 +78,7 @@ public class ConditionVO implements Condition, Identity, InternalIdentity {
this.relationalOperator = relationalOperator;
this.accountId = accountId;
this.domainId = domainId;
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
public Date getCreated() {
@@ -121,10 +122,16 @@ public class ConditionVO implements Condition, Identity, InternalIdentity {
@Override
public String getUuid() {
- return this.uuid;
+ return uuid;
}
public Date getRemoved() {
return removed;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.Condition;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/network/dao/IPAddressVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/IPAddressVO.java b/engine/schema/src/com/cloud/network/dao/IPAddressVO.java
index 9abecbe..d06b8c5 100644
--- a/engine/schema/src/com/cloud/network/dao/IPAddressVO.java
+++ b/engine/schema/src/com/cloud/network/dao/IPAddressVO.java
@@ -31,6 +31,8 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.network.IpAddress;
import com.cloud.utils.net.Ip;
@@ -118,7 +120,7 @@ public class IPAddressVO implements IpAddress {
protected boolean display = true;
protected IPAddressVO() {
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
@Override
@@ -129,26 +131,26 @@ public class IPAddressVO implements IpAddress {
public IPAddressVO(Ip address, long dataCenterId, long macAddress, long vlanDbId, boolean sourceNat) {
this.address = address;
this.dataCenterId = dataCenterId;
- this.vlanId = vlanDbId;
+ vlanId = vlanDbId;
this.sourceNat = sourceNat;
- this.allocatedInDomainId = null;
- this.allocatedToAccountId = null;
- this.allocatedTime = null;
- this.state = State.Free;
+ allocatedInDomainId = null;
+ allocatedToAccountId = null;
+ allocatedTime = null;
+ state = State.Free;
this.macAddress = macAddress;
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
public IPAddressVO(Ip address, long dataCenterId, Long networkId, Long vpcId, long physicalNetworkId, long sourceNetworkId, long vlanDbId, boolean portable) {
this.address = address;
this.dataCenterId = dataCenterId;
- this.associatedWithNetworkId = networkId;
+ associatedWithNetworkId = networkId;
this.vpcId = vpcId;
this.physicalNetworkId = physicalNetworkId;
this.sourceNetworkId = sourceNetworkId;
- this.vlanId = vlanDbId;
+ vlanId = vlanDbId;
this.portable = portable;
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
public long getMacAddress() {
@@ -161,7 +163,7 @@ public class IPAddressVO implements IpAddress {
}
public void setDataCenterId(long dcId) {
- this.dataCenterId = dcId;
+ dataCenterId = dcId;
}
@Override
@@ -185,7 +187,7 @@ public class IPAddressVO implements IpAddress {
}
public void setAssociatedWithNetworkId(Long networkId) {
- this.associatedWithNetworkId = networkId;
+ associatedWithNetworkId = networkId;
}
@Override
@@ -203,11 +205,11 @@ public class IPAddressVO implements IpAddress {
}
public void setAllocatedToAccountId(Long accountId) {
- this.allocatedToAccountId = accountId;
+ allocatedToAccountId = accountId;
}
public void setAllocatedInDomainId(Long domainId) {
- this.allocatedInDomainId = domainId;
+ allocatedInDomainId = domainId;
}
public void setSourceNat(boolean sourceNat) {
@@ -220,16 +222,16 @@ public class IPAddressVO implements IpAddress {
}
public void setAllocatedTime(Date allocated) {
- this.allocatedTime = allocated;
+ allocatedTime = allocated;
}
@Override
public long getVlanId() {
- return this.vlanId;
+ return vlanId;
}
public void setVlanId(long vlanDbId) {
- this.vlanId = vlanDbId;
+ vlanId = vlanDbId;
}
@Override
@@ -281,7 +283,7 @@ public class IPAddressVO implements IpAddress {
@Override
public String getUuid() {
- return this.uuid;
+ return uuid;
}
public void setUuid(String uuid) {
@@ -303,7 +305,7 @@ public class IPAddressVO implements IpAddress {
}
public void setSystem(boolean isSystem) {
- this.system = isSystem;
+ system = isSystem;
}
@Override
@@ -346,4 +348,9 @@ public class IPAddressVO implements IpAddress {
public void setDisplay(boolean display) {
this.display = display;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.IpAddress;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/network/dao/MonitoringServiceVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/MonitoringServiceVO.java b/engine/schema/src/com/cloud/network/dao/MonitoringServiceVO.java
index f9967ec..999fdfc 100644
--- a/engine/schema/src/com/cloud/network/dao/MonitoringServiceVO.java
+++ b/engine/schema/src/com/cloud/network/dao/MonitoringServiceVO.java
@@ -25,6 +25,8 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.network.MonitoringService;
@Entity
@@ -116,4 +118,9 @@ public class MonitoringServiceVO implements MonitoringService {
public String getProcessName() {
return processName;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.MonitorService;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/network/dao/NetworkVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkVO.java b/engine/schema/src/com/cloud/network/dao/NetworkVO.java
index f3776df..13e8dbf 100644
--- a/engine/schema/src/com/cloud/network/dao/NetworkVO.java
+++ b/engine/schema/src/com/cloud/network/dao/NetworkVO.java
@@ -30,6 +30,7 @@ import javax.persistence.TableGenerator;
import javax.persistence.Transient;
import org.apache.cloudstack.acl.ControlledEntity;
+import org.apache.cloudstack.acl.IAMEntityType;
import com.cloud.network.Network;
import com.cloud.network.Networks.BroadcastDomainType;
@@ -167,7 +168,7 @@ public class NetworkVO implements Network {
Long networkACLId;
public NetworkVO() {
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
/**
@@ -193,8 +194,8 @@ public class NetworkVO implements Network {
} else {
this.state = state;
}
- this.id = -1;
- this.uuid = UUID.randomUUID().toString();
+ id = -1;
+ uuid = UUID.randomUUID().toString();
}
public NetworkVO(long id, Network that, long offeringId, String guruName, long domainId, long accountId, long related, String name, String displayText,
@@ -216,19 +217,19 @@ public class NetworkVO implements Network {
aclType,
specifyIpRanges,
vpcId);
- this.gateway = that.getGateway();
- this.cidr = that.getCidr();
- this.networkCidr = that.getNetworkCidr();
- this.broadcastUri = that.getBroadcastUri();
- this.broadcastDomainType = that.getBroadcastDomainType();
+ gateway = that.getGateway();
+ cidr = that.getCidr();
+ networkCidr = that.getNetworkCidr();
+ broadcastUri = that.getBroadcastUri();
+ broadcastDomainType = that.getBroadcastDomainType();
this.guruName = guruName;
- this.state = that.getState();
+ state = that.getState();
if (state == null) {
state = State.Allocated;
}
- this.uuid = UUID.randomUUID().toString();
- this.ip6Gateway = that.getIp6Gateway();
- this.ip6Cidr = that.getIp6Cidr();
+ uuid = UUID.randomUUID().toString();
+ ip6Gateway = that.getIp6Gateway();
+ ip6Cidr = that.getIp6Cidr();
}
/**
@@ -260,7 +261,7 @@ public class NetworkVO implements Network {
this.displayText = displayText;
this.aclType = aclType;
this.networkDomain = networkDomain;
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
this.guestType = guestType;
this.specifyIpRanges = specifyIpRanges;
this.vpcId = vpcId;
@@ -436,7 +437,7 @@ public class NetworkVO implements Network {
}
public void setDns1(String dns) {
- this.dns1 = dns;
+ dns1 = dns;
}
public String getDns2() {
@@ -444,7 +445,7 @@ public class NetworkVO implements Network {
}
public void setDns2(String dns) {
- this.dns2 = dns;
+ dns2 = dns;
}
@Override
@@ -492,19 +493,19 @@ public class NetworkVO implements Network {
return false;
}
NetworkVO that = (NetworkVO)obj;
- if (this.trafficType != that.trafficType) {
+ if (trafficType != that.trafficType) {
return false;
}
- if ((this.cidr == null && that.cidr != null) || (this.cidr != null && that.cidr == null)) {
+ if ((cidr == null && that.cidr != null) || (cidr != null && that.cidr == null)) {
return false;
}
- if (this.cidr == null && that.cidr == null) {
+ if (cidr == null && that.cidr == null) {
return true;
}
- return NetUtils.isNetworkAWithinNetworkB(this.cidr, that.cidr);
+ return NetUtils.isNetworkAWithinNetworkB(cidr, that.cidr);
}
@Override
@@ -516,7 +517,7 @@ public class NetworkVO implements Network {
@Override
public String getUuid() {
- return this.uuid;
+ return uuid;
}
public void setUuid(String uuid) {
@@ -583,4 +584,9 @@ public class NetworkVO implements Network {
public Long getNetworkACLId() {
return networkACLId;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.Network;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/network/dao/RemoteAccessVpnVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/RemoteAccessVpnVO.java b/engine/schema/src/com/cloud/network/dao/RemoteAccessVpnVO.java
index 3d416f2..827b59b 100644
--- a/engine/schema/src/com/cloud/network/dao/RemoteAccessVpnVO.java
+++ b/engine/schema/src/com/cloud/network/dao/RemoteAccessVpnVO.java
@@ -25,6 +25,8 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.network.RemoteAccessVpn;
@Entity
@@ -69,19 +71,19 @@ public class RemoteAccessVpnVO implements RemoteAccessVpn {
protected boolean display = true;
public RemoteAccessVpnVO() {
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
public RemoteAccessVpnVO(long accountId, long domainId, Long networkId, long publicIpId, Long vpcId, String localIp, String ipRange, String presharedKey) {
this.accountId = accountId;
- this.serverAddressId = publicIpId;
+ serverAddressId = publicIpId;
this.ipRange = ipRange;
- this.ipsecPresharedKey = presharedKey;
+ ipsecPresharedKey = presharedKey;
this.localIp = localIp;
this.domainId = domainId;
this.networkId = networkId;
- this.state = State.Added;
- this.uuid = UUID.randomUUID().toString();
+ state = State.Added;
+ uuid = UUID.randomUUID().toString();
this.vpcId = vpcId;
}
@@ -164,4 +166,9 @@ public class RemoteAccessVpnVO implements RemoteAccessVpn {
public boolean isDisplay() {
return display;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.RemoteAccessVpn;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/network/dao/Site2SiteCustomerGatewayVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/Site2SiteCustomerGatewayVO.java b/engine/schema/src/com/cloud/network/dao/Site2SiteCustomerGatewayVO.java
index c922855..4a32b31 100644
--- a/engine/schema/src/com/cloud/network/dao/Site2SiteCustomerGatewayVO.java
+++ b/engine/schema/src/com/cloud/network/dao/Site2SiteCustomerGatewayVO.java
@@ -26,6 +26,8 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.network.Site2SiteCustomerGateway;
import com.cloud.utils.db.Encrypt;
import com.cloud.utils.db.GenericDao;
@@ -92,7 +94,7 @@ public class Site2SiteCustomerGatewayVO implements Site2SiteCustomerGateway {
this.ikeLifetime = ikeLifetime;
this.espLifetime = espLifetime;
this.dpd = dpd;
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
this.accountId = accountId;
this.domainId = domainId;
}
@@ -206,4 +208,9 @@ public class Site2SiteCustomerGatewayVO implements Site2SiteCustomerGateway {
public long getAccountId() {
return accountId;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.Site2SiteCustomerGateway;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/network/dao/Site2SiteVpnConnectionVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/Site2SiteVpnConnectionVO.java b/engine/schema/src/com/cloud/network/dao/Site2SiteVpnConnectionVO.java
index beba999..c515fc2 100644
--- a/engine/schema/src/com/cloud/network/dao/Site2SiteVpnConnectionVO.java
+++ b/engine/schema/src/com/cloud/network/dao/Site2SiteVpnConnectionVO.java
@@ -28,6 +28,7 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
import org.apache.cloudstack.api.InternalIdentity;
import com.cloud.network.Site2SiteVpnConnection;
@@ -76,10 +77,10 @@ public class Site2SiteVpnConnectionVO implements Site2SiteVpnConnection, Interna
}
public Site2SiteVpnConnectionVO(long accountId, long domainId, long vpnGatewayId, long customerGatewayId, boolean passive) {
- this.uuid = UUID.randomUUID().toString();
- this.setVpnGatewayId(vpnGatewayId);
- this.setCustomerGatewayId(customerGatewayId);
- this.setState(State.Pending);
+ uuid = UUID.randomUUID().toString();
+ setVpnGatewayId(vpnGatewayId);
+ setCustomerGatewayId(customerGatewayId);
+ setState(State.Pending);
this.accountId = accountId;
this.domainId = domainId;
this.passive = passive;
@@ -171,4 +172,9 @@ public class Site2SiteVpnConnectionVO implements Site2SiteVpnConnection, Interna
public boolean isDisplay() {
return display;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.Site2SiteVpnConnection;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/network/dao/Site2SiteVpnGatewayVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/Site2SiteVpnGatewayVO.java b/engine/schema/src/com/cloud/network/dao/Site2SiteVpnGatewayVO.java
index 226f608..c465334 100644
--- a/engine/schema/src/com/cloud/network/dao/Site2SiteVpnGatewayVO.java
+++ b/engine/schema/src/com/cloud/network/dao/Site2SiteVpnGatewayVO.java
@@ -26,6 +26,8 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.network.Site2SiteVpnGateway;
import com.cloud.utils.db.GenericDao;
@@ -62,9 +64,9 @@ public class Site2SiteVpnGatewayVO implements Site2SiteVpnGateway {
}
public Site2SiteVpnGatewayVO(long accountId, long domainId, long addrId, long vpcId) {
- this.uuid = UUID.randomUUID().toString();
- this.setAddrId(addrId);
- this.setVpcId(vpcId);
+ uuid = UUID.randomUUID().toString();
+ setAddrId(addrId);
+ setVpcId(vpcId);
this.accountId = accountId;
this.domainId = domainId;
}
@@ -128,4 +130,9 @@ public class Site2SiteVpnGatewayVO implements Site2SiteVpnGateway {
public boolean isDisplay() {
return display;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.Site2SiteVpnGateway;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/network/dao/SslCertVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/SslCertVO.java b/engine/schema/src/com/cloud/network/dao/SslCertVO.java
index 7d73f49..6ef7afd 100644
--- a/engine/schema/src/com/cloud/network/dao/SslCertVO.java
+++ b/engine/schema/src/com/cloud/network/dao/SslCertVO.java
@@ -23,6 +23,8 @@ import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.network.lb.SslCert;
import com.cloud.utils.db.Encrypt;
@@ -61,18 +63,18 @@ public class SslCertVO implements SslCert {
String fingerPrint;
public SslCertVO() {
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
public SslCertVO(String cert, String key, String password, String chain, Long accountId, Long domainId, String fingerPrint) {
- this.certificate = cert;
+ certificate = cert;
this.key = key;
this.chain = chain;
this.password = password;
this.accountId = accountId;
this.domainId = domainId;
this.fingerPrint = fingerPrint;
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
// Getters
@@ -120,4 +122,10 @@ public class SslCertVO implements SslCert {
public String getFingerPrint() {
return fingerPrint;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.SSLCert;
+ }
+
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/network/rules/FirewallRuleVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/rules/FirewallRuleVO.java b/engine/schema/src/com/cloud/network/rules/FirewallRuleVO.java
index 4fa751d..0acc24a 100644
--- a/engine/schema/src/com/cloud/network/rules/FirewallRuleVO.java
+++ b/engine/schema/src/com/cloud/network/rules/FirewallRuleVO.java
@@ -34,6 +34,8 @@ import javax.persistence.InheritanceType;
import javax.persistence.Table;
import javax.persistence.Transient;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.utils.db.GenericDao;
import com.cloud.utils.net.NetUtils;
@@ -191,7 +193,7 @@ public class FirewallRuleVO implements FirewallRule {
}
protected FirewallRuleVO() {
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
public FirewallRuleVO(String xId, Long ipAddressId, Integer portStart, Integer portEnd, String protocol, long networkId, long accountId, long domainId,
@@ -202,13 +204,13 @@ public class FirewallRuleVO implements FirewallRule {
}
this.accountId = accountId;
this.domainId = domainId;
- this.sourceIpAddressId = ipAddressId;
- this.sourcePortStart = portStart;
- this.sourcePortEnd = portEnd;
+ sourceIpAddressId = ipAddressId;
+ sourcePortStart = portStart;
+ sourcePortEnd = portEnd;
this.protocol = protocol;
this.purpose = purpose;
this.networkId = networkId;
- this.state = State.Staged;
+ state = State.Staged;
this.icmpCode = icmpCode;
this.icmpType = icmpType;
this.sourceCidrs = sourceCidrs;
@@ -218,8 +220,8 @@ public class FirewallRuleVO implements FirewallRule {
}
this.related = related;
- this.uuid = UUID.randomUUID().toString();
- this.type = FirewallRuleType.User;
+ uuid = UUID.randomUUID().toString();
+ type = FirewallRuleType.User;
this.trafficType = trafficType;
}
@@ -256,7 +258,7 @@ public class FirewallRuleVO implements FirewallRule {
@Override
public String getUuid() {
- return this.uuid;
+ return uuid;
}
public void setUuid(String uuid) {
@@ -280,4 +282,10 @@ public class FirewallRuleVO implements FirewallRule {
public boolean isDisplay() {
return display;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.FirewallRule;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/network/security/SecurityGroupVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/security/SecurityGroupVO.java b/engine/schema/src/com/cloud/network/security/SecurityGroupVO.java
index df8427c..26859f7 100644
--- a/engine/schema/src/com/cloud/network/security/SecurityGroupVO.java
+++ b/engine/schema/src/com/cloud/network/security/SecurityGroupVO.java
@@ -25,6 +25,8 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
@Entity
@Table(name = ("security_group"))
public class SecurityGroupVO implements SecurityGroup {
@@ -49,7 +51,7 @@ public class SecurityGroupVO implements SecurityGroup {
private String uuid;
public SecurityGroupVO() {
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
public SecurityGroupVO(String name, String description, long domainId, long accountId) {
@@ -57,7 +59,7 @@ public class SecurityGroupVO implements SecurityGroup {
this.description = description;
this.domainId = domainId;
this.accountId = accountId;
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
@Override
@@ -87,10 +89,15 @@ public class SecurityGroupVO implements SecurityGroup {
@Override
public String getUuid() {
- return this.uuid;
+ return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.SecurityGroup;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/network/vpc/StaticRouteVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/StaticRouteVO.java b/engine/schema/src/com/cloud/network/vpc/StaticRouteVO.java
index 08e3965..a9ba051 100644
--- a/engine/schema/src/com/cloud/network/vpc/StaticRouteVO.java
+++ b/engine/schema/src/com/cloud/network/vpc/StaticRouteVO.java
@@ -28,6 +28,8 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.utils.db.GenericDao;
@Entity
@@ -64,7 +66,7 @@ public class StaticRouteVO implements StaticRoute {
Date created;
protected StaticRouteVO() {
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
/**
@@ -78,11 +80,11 @@ public class StaticRouteVO implements StaticRoute {
super();
this.vpcGatewayId = vpcGatewayId;
this.cidr = cidr;
- this.state = State.Staged;
+ state = State.Staged;
this.vpcId = vpcId;
this.accountId = accountId;
this.domainId = domainId;
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
@Override
@@ -107,7 +109,7 @@ public class StaticRouteVO implements StaticRoute {
@Override
public String getUuid() {
- return this.uuid;
+ return uuid;
}
@Override
@@ -135,4 +137,9 @@ public class StaticRouteVO implements StaticRoute {
buf.append(uuid).append("|").append(cidr).append("|").append(vpcGatewayId).append("]");
return buf.toString();
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.StaticRoute;
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/network/vpc/VpcGatewayVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/VpcGatewayVO.java b/engine/schema/src/com/cloud/network/vpc/VpcGatewayVO.java
index 5f15660..48238b1 100644
--- a/engine/schema/src/com/cloud/network/vpc/VpcGatewayVO.java
+++ b/engine/schema/src/com/cloud/network/vpc/VpcGatewayVO.java
@@ -28,6 +28,8 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.utils.db.GenericDao;
@Entity
@@ -90,7 +92,7 @@ public class VpcGatewayVO implements VpcGateway {
long networkACLId;
protected VpcGatewayVO() {
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
/**
@@ -117,10 +119,10 @@ public class VpcGatewayVO implements VpcGateway {
this.broadcastUri = broadcastUri;
this.gateway = gateway;
this.netmask = netmask;
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
this.accountId = accountId;
this.domainId = domainId;
- this.state = State.Creating;
+ state = State.Creating;
this.sourceNat = sourceNat;
this.networkACLId = networkACLId;
@@ -128,7 +130,7 @@ public class VpcGatewayVO implements VpcGateway {
@Override
public String getUuid() {
- return this.uuid;
+ return uuid;
}
@Override
@@ -204,7 +206,7 @@ public class VpcGatewayVO implements VpcGateway {
@Override
public boolean getSourceNat() {
- return this.sourceNat;
+ return sourceNat;
}
public void setNetworkACLId(long networkACLId) {
@@ -215,4 +217,9 @@ public class VpcGatewayVO implements VpcGateway {
public long getNetworkACLId() {
return networkACLId;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.VpcGateway;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/network/vpc/VpcVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/VpcVO.java b/engine/schema/src/com/cloud/network/vpc/VpcVO.java
index 7d1933a..d1cfd7c 100644
--- a/engine/schema/src/com/cloud/network/vpc/VpcVO.java
+++ b/engine/schema/src/com/cloud/network/vpc/VpcVO.java
@@ -26,6 +26,8 @@ import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.utils.db.GenericDao;
@Entity
@@ -80,7 +82,7 @@ public class VpcVO implements Vpc {
protected boolean display = true;
public VpcVO() {
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
public VpcVO(long zoneId, String name, String displayText, long accountId, long domainId, long vpcOffId, String cidr, String networkDomain) {
@@ -90,10 +92,10 @@ public class VpcVO implements Vpc {
this.accountId = accountId;
this.domainId = domainId;
this.cidr = cidr;
- this.uuid = UUID.randomUUID().toString();
- this.state = State.Enabled;
+ uuid = UUID.randomUUID().toString();
+ state = State.Enabled;
this.networkDomain = networkDomain;
- this.vpcOfferingId = vpcOffId;
+ vpcOfferingId = vpcOffId;
}
@Override
@@ -194,4 +196,9 @@ public class VpcVO implements Vpc {
public boolean isDisplay() {
return display;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.Vpc;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/projects/ProjectInvitationVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/projects/ProjectInvitationVO.java b/engine/schema/src/com/cloud/projects/ProjectInvitationVO.java
index 6136862..885c148 100644
--- a/engine/schema/src/com/cloud/projects/ProjectInvitationVO.java
+++ b/engine/schema/src/com/cloud/projects/ProjectInvitationVO.java
@@ -28,6 +28,8 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.utils.db.GenericDao;
@Entity
@@ -64,16 +66,16 @@ public class ProjectInvitationVO implements ProjectInvitation {
private String uuid;
protected ProjectInvitationVO() {
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
public ProjectInvitationVO(long projectId, Long accountId, Long domainId, String email, String token) {
- this.forAccountId = accountId;
- this.inDomainId = domainId;
+ forAccountId = accountId;
+ inDomainId = domainId;
this.projectId = projectId;
this.email = email;
this.token = token;
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
@Override
@@ -129,7 +131,7 @@ public class ProjectInvitationVO implements ProjectInvitation {
@Override
public String getUuid() {
- return this.uuid;
+ return uuid;
}
public void setUuid(String uuid) {
@@ -145,4 +147,9 @@ public class ProjectInvitationVO implements ProjectInvitation {
public long getAccountId() {
return forAccountId == null ? -1 : forAccountId;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.ProjectInvitation;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/storage/SnapshotVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/SnapshotVO.java b/engine/schema/src/com/cloud/storage/SnapshotVO.java
index 8521636..4c8ceb7 100644
--- a/engine/schema/src/com/cloud/storage/SnapshotVO.java
+++ b/engine/schema/src/com/cloud/storage/SnapshotVO.java
@@ -30,6 +30,8 @@ import javax.persistence.Table;
import com.google.gson.annotations.Expose;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.utils.db.GenericDao;
@@ -93,12 +95,12 @@ public class SnapshotVO implements Snapshot {
String uuid;
public SnapshotVO() {
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
public SnapshotVO(long dcId, long accountId, long domainId, Long volumeId, Long diskOfferingId, String name, short snapshotType, String typeDescription, long size,
HypervisorType hypervisorType) {
- this.dataCenterId = dcId;
+ dataCenterId = dcId;
this.accountId = accountId;
this.domainId = domainId;
this.volumeId = volumeId;
@@ -107,10 +109,10 @@ public class SnapshotVO implements Snapshot {
this.snapshotType = snapshotType;
this.typeDescription = typeDescription;
this.size = size;
- this.state = State.Allocated;
+ state = State.Allocated;
this.hypervisorType = hypervisorType;
- this.version = "2.2";
- this.uuid = UUID.randomUUID().toString();
+ version = "2.2";
+ uuid = UUID.randomUUID().toString();
}
@Override
@@ -229,10 +231,15 @@ public class SnapshotVO implements Snapshot {
@Override
public String getUuid() {
- return this.uuid;
+ return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.Snapshot;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/storage/VMTemplateVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/VMTemplateVO.java b/engine/schema/src/com/cloud/storage/VMTemplateVO.java
index da93735..e619f68 100755
--- a/engine/schema/src/com/cloud/storage/VMTemplateVO.java
+++ b/engine/schema/src/com/cloud/storage/VMTemplateVO.java
@@ -31,6 +31,8 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.Storage.TemplateType;
@@ -632,4 +634,8 @@ public class VMTemplateVO implements VirtualMachineTemplate {
this.updated = updated;
}
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.VirtualMachineTemplate;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/storage/VolumeVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/VolumeVO.java b/engine/schema/src/com/cloud/storage/VolumeVO.java
index fb79c13..82f47d4 100755
--- a/engine/schema/src/com/cloud/storage/VolumeVO.java
+++ b/engine/schema/src/com/cloud/storage/VolumeVO.java
@@ -32,6 +32,8 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.db.GenericDao;
@@ -164,18 +166,18 @@ public class VolumeVO implements Volume {
// Real Constructor
public VolumeVO(Type type, String name, long dcId, long domainId, long accountId, long diskOfferingId, long size, Long minIops, Long maxIops, String iScsiName) {
- this.volumeType = type;
+ volumeType = type;
this.name = name;
- this.dataCenterId = dcId;
+ dataCenterId = dcId;
this.accountId = accountId;
this.domainId = domainId;
this.size = size;
this.minIops = minIops;
this.maxIops = maxIops;
- this._iScsiName = iScsiName;
+ _iScsiName = iScsiName;
this.diskOfferingId = diskOfferingId;
- this.state = State.Allocated;
- this.uuid = UUID.randomUUID().toString();
+ state = State.Allocated;
+ uuid = UUID.randomUUID().toString();
}
public VolumeVO(String name, long dcId, Long podId, long accountId, long domainId, Long instanceId, String folder, String path, long size, Long minIops,
@@ -189,13 +191,13 @@ public class VolumeVO implements Volume {
this.size = size;
this.minIops = minIops;
this.maxIops = maxIops;
- this._iScsiName = iScsiName;
+ _iScsiName = iScsiName;
this.podId = podId;
- this.dataCenterId = dcId;
- this.volumeType = vType;
- this.state = Volume.State.Allocated;
- this.recreatable = false;
- this.uuid = UUID.randomUUID().toString();
+ dataCenterId = dcId;
+ volumeType = vType;
+ state = Volume.State.Allocated;
+ recreatable = false;
+ uuid = UUID.randomUUID().toString();
}
public VolumeVO(String name, long dcId, long podId, long accountId, long domainId, Long instanceId, String folder, String path, long size, Volume.Type vType) {
@@ -206,15 +208,15 @@ public class VolumeVO implements Volume {
this.folder = folder;
this.path = path;
this.size = size;
- this.minIops = null;
- this.maxIops = null;
- this._iScsiName = null;
+ minIops = null;
+ maxIops = null;
+ _iScsiName = null;
this.podId = podId;
- this.dataCenterId = dcId;
- this.volumeType = vType;
- this.state = Volume.State.Allocated;
- this.recreatable = false;
- this.uuid = UUID.randomUUID().toString();
+ dataCenterId = dcId;
+ volumeType = vType;
+ state = Volume.State.Allocated;
+ recreatable = false;
+ uuid = UUID.randomUUID().toString();
}
// Copy Constructor
@@ -232,34 +234,34 @@ public class VolumeVO implements Volume {
that.getMaxIops(),
that.get_iScsiName(),
that.getVolumeType());
- this.recreatable = that.isRecreatable();
- this.state = that.getState();
- this.size = that.getSize();
- this.minIops = that.getMinIops();
- this.maxIops = that.getMaxIops();
- this._iScsiName = that.get_iScsiName();
- this.diskOfferingId = that.getDiskOfferingId();
- this.poolId = that.getPoolId();
- this.attached = that.getAttached();
- this.chainInfo = that.getChainInfo();
- this.templateId = that.getTemplateId();
- this.deviceId = that.getDeviceId();
- this.format = that.getFormat();
- this.uuid = UUID.randomUUID().toString();
+ recreatable = that.isRecreatable();
+ state = that.getState();
+ size = that.getSize();
+ minIops = that.getMinIops();
+ maxIops = that.getMaxIops();
+ _iScsiName = that.get_iScsiName();
+ diskOfferingId = that.getDiskOfferingId();
+ poolId = that.getPoolId();
+ attached = that.getAttached();
+ chainInfo = that.getChainInfo();
+ templateId = that.getTemplateId();
+ deviceId = that.getDeviceId();
+ format = that.getFormat();
+ uuid = UUID.randomUUID().toString();
}
@Override
public long getUpdatedCount() {
- return this.updatedCount;
+ return updatedCount;
}
@Override
public void incrUpdatedCount() {
- this.updatedCount++;
+ updatedCount++;
}
public void decrUpdatedCount() {
- this.updatedCount--;
+ updatedCount--;
}
@Override
@@ -481,7 +483,7 @@ public class VolumeVO implements Volume {
@Override
public Date getAttached() {
- return this.attached;
+ return attached;
}
public void setAttached(Date attached) {
@@ -490,7 +492,7 @@ public class VolumeVO implements Volume {
@Override
public String getChainInfo() {
- return this.chainInfo;
+ return chainInfo;
}
public void setChainInfo(String chainInfo) {
@@ -498,11 +500,11 @@ public class VolumeVO implements Volume {
}
public Long getLastPoolId() {
- return this.lastPoolId;
+ return lastPoolId;
}
public void setLastPoolId(Long poolId) {
- this.lastPoolId = poolId;
+ lastPoolId = poolId;
}
@Override
@@ -521,17 +523,17 @@ public class VolumeVO implements Volume {
@Override
public String getReservationId() {
- return this.reservationId;
+ return reservationId;
}
@Override
public void setReservationId(String reserv) {
- this.reservationId = reserv;
+ reservationId = reserv;
}
@Override
public String getUuid() {
- return this.uuid;
+ return uuid;
}
public void setUuid(String uuid) {
@@ -540,11 +542,11 @@ public class VolumeVO implements Volume {
@Override
public String get_iScsiName() {
- return this._iScsiName;
+ return _iScsiName;
}
public void set_iScsiName(String iScsiName) {
- this._iScsiName = iScsiName;
+ _iScsiName = iScsiName;
}
@Override
@@ -571,11 +573,11 @@ public class VolumeVO implements Volume {
@Override
public Long getVmSnapshotChainSize() {
- return this.vmSnapshotChainSize;
+ return vmSnapshotChainSize;
}
public Long getIsoId() {
- return this.isoId;
+ return isoId;
}
public void setIsoId(Long isoId) {
@@ -596,4 +598,9 @@ public class VolumeVO implements Volume {
public Integer getHypervisorSnapshotReserve() {
return hypervisorSnapshotReserve;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.Volume;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/tags/ResourceTagVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/tags/ResourceTagVO.java b/engine/schema/src/com/cloud/tags/ResourceTagVO.java
index ca790bd..45e7b27 100644
--- a/engine/schema/src/com/cloud/tags/ResourceTagVO.java
+++ b/engine/schema/src/com/cloud/tags/ResourceTagVO.java
@@ -27,6 +27,8 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.server.ResourceTag;
@Entity
@@ -67,7 +69,7 @@ public class ResourceTagVO implements ResourceTag {
String customer;
protected ResourceTagVO() {
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
/**
@@ -88,7 +90,7 @@ public class ResourceTagVO implements ResourceTag {
this.accountId = accountId;
this.resourceId = resourceId;
this.resourceType = resourceType;
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
this.customer = customer;
this.resourceUuid = resourceUuid;
}
@@ -161,4 +163,9 @@ public class ResourceTagVO implements ResourceTag {
public String getResourceUuid() {
return resourceUuid;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.ResourceTag;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/user/AccountVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/user/AccountVO.java b/engine/schema/src/com/cloud/user/AccountVO.java
index 7fa9fe2..fb1b58a 100644
--- a/engine/schema/src/com/cloud/user/AccountVO.java
+++ b/engine/schema/src/com/cloud/user/AccountVO.java
@@ -28,6 +28,8 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.utils.db.GenericDao;
@Entity
@@ -70,12 +72,12 @@ public class AccountVO implements Account {
boolean isDefault;
public AccountVO() {
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
public AccountVO(long id) {
this.id = id;
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
public AccountVO(String accountName, long domainId, String networkDomain, short type, String uuid) {
@@ -83,7 +85,7 @@ public class AccountVO implements Account {
this.domainId = domainId;
this.networkDomain = networkDomain;
this.type = type;
- this.state = State.enabled;
+ state = State.enabled;
this.uuid = uuid;
}
@@ -175,7 +177,7 @@ public class AccountVO implements Account {
@Override
public String getUuid() {
- return this.uuid;
+ return uuid;
}
public void setUuid(String uuid) {
@@ -186,4 +188,10 @@ public class AccountVO implements Account {
public boolean isDefault() {
return isDefault;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.Account;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/user/SSHKeyPairVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/user/SSHKeyPairVO.java b/engine/schema/src/com/cloud/user/SSHKeyPairVO.java
index 9fb035d..4dc03c4 100644
--- a/engine/schema/src/com/cloud/user/SSHKeyPairVO.java
+++ b/engine/schema/src/com/cloud/user/SSHKeyPairVO.java
@@ -24,6 +24,8 @@ import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
+import org.apache.cloudstack.acl.IAMEntityType;
+
@Entity
@Table(name = "ssh_keypairs")
public class SSHKeyPairVO implements SSHKeyPair {
@@ -114,4 +116,8 @@ public class SSHKeyPairVO implements SSHKeyPair {
this.privateKey = privateKey;
}
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.SSHKeyPair;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/vm/InstanceGroupVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/InstanceGroupVO.java b/engine/schema/src/com/cloud/vm/InstanceGroupVO.java
index 1089017..9b463d3 100644
--- a/engine/schema/src/com/cloud/vm/InstanceGroupVO.java
+++ b/engine/schema/src/com/cloud/vm/InstanceGroupVO.java
@@ -28,6 +28,8 @@ import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.SecondaryTable;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.utils.db.GenericDao;
@Entity
@@ -63,7 +65,7 @@ public class InstanceGroupVO implements InstanceGroup {
public InstanceGroupVO(String name, long accountId) {
this.name = name;
this.accountId = accountId;
- this.uuid = UUID.randomUUID().toString();
+ uuid = UUID.randomUUID().toString();
}
protected InstanceGroupVO() {
@@ -105,7 +107,7 @@ public class InstanceGroupVO implements InstanceGroup {
@Override
public String getUuid() {
- return this.uuid;
+ return uuid;
}
public void setUuid(String uuid) {
@@ -116,4 +118,9 @@ public class InstanceGroupVO implements InstanceGroup {
public Short getAccountType() {
return accountType;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.InstanceGroup;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/vm/VMInstanceVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/VMInstanceVO.java b/engine/schema/src/com/cloud/vm/VMInstanceVO.java
index 30ef60f..437db54 100644
--- a/engine/schema/src/com/cloud/vm/VMInstanceVO.java
+++ b/engine/schema/src/com/cloud/vm/VMInstanceVO.java
@@ -36,6 +36,8 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.utils.db.Encrypt;
import com.cloud.utils.db.GenericDao;
@@ -183,27 +185,27 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
public VMInstanceVO(long id, long serviceOfferingId, String name, String instanceName, Type type, Long vmTemplateId, HypervisorType hypervisorType, long guestOSId,
long domainId, long accountId, boolean haEnabled) {
this.id = id;
- this.hostName = name != null ? name : this.uuid;
+ hostName = name != null ? name : uuid;
if (vmTemplateId != null) {
- this.templateId = vmTemplateId;
+ templateId = vmTemplateId;
}
this.instanceName = instanceName;
this.type = type;
this.guestOSId = guestOSId;
this.haEnabled = haEnabled;
- this.vncPassword = Long.toHexString(new Random().nextLong());
- this.state = State.Stopped;
+ vncPassword = Long.toHexString(new Random().nextLong());
+ state = State.Stopped;
this.accountId = accountId;
this.domainId = domainId;
this.serviceOfferingId = serviceOfferingId;
this.hypervisorType = hypervisorType;
- this.limitCpuUse = false;
+ limitCpuUse = false;
}
public VMInstanceVO(long id, long serviceOfferingId, String name, String instanceName, Type type, Long vmTemplateId, HypervisorType hypervisorType, long guestOSId,
long domainId, long accountId, boolean haEnabled, boolean limitResourceUse, Long diskOfferingId) {
this(id, serviceOfferingId, name, instanceName, type, vmTemplateId, hypervisorType, guestOSId, domainId, accountId, haEnabled);
- this.limitCpuUse = limitResourceUse;
+ limitCpuUse = limitResourceUse;
this.diskOfferingId = diskOfferingId;
}
@@ -324,11 +326,11 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
}
public Date getProxyAssignTime() {
- return this.proxyAssignTime;
+ return proxyAssignTime;
}
public void setProxyAssignTime(Date time) {
- this.proxyAssignTime = time;
+ proxyAssignTime = time;
}
@Override
@@ -412,7 +414,7 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
}
public void setPodId(long podId) {
- this.podIdToDeployIn = podId;
+ podIdToDeployIn = podId;
}
public void setPrivateMacAddress(String privateMacAddress) {
@@ -436,7 +438,7 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
}
public String getReservationId() {
- return this.reservationId;
+ return reservationId;
}
@Override
@@ -500,7 +502,7 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
}
public Boolean isDynamicallyScalable() {
- return this.dynamicallyScalable;
+ return dynamicallyScalable;
}
public VirtualMachine.PowerState getPowerState() {
@@ -535,4 +537,8 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
powerHostId = hostId;
}
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.VirtualMachine;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/vm/dao/NicIpAliasVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/dao/NicIpAliasVO.java b/engine/schema/src/com/cloud/vm/dao/NicIpAliasVO.java
index 37aa0e3..b03492a 100644
--- a/engine/schema/src/com/cloud/vm/dao/NicIpAliasVO.java
+++ b/engine/schema/src/com/cloud/vm/dao/NicIpAliasVO.java
@@ -28,6 +28,8 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.utils.db.GenericDao;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.NicIpAlias;
@@ -39,18 +41,18 @@ public class NicIpAliasVO implements NicIpAlias {
public NicIpAliasVO(Long nicId, String ipaddr, Long vmId, Long accountId, Long domainId, Long networkId, String gateway, String netmask) {
this.nicId = nicId;
this.vmId = vmId;
- this.ip4Address = ipaddr;
+ ip4Address = ipaddr;
this.accountId = accountId;
this.domainId = domainId;
this.networkId = networkId;
this.netmask = netmask;
this.gateway = gateway;
- this.state = NicIpAlias.state.active;
+ state = NicIpAlias.state.active;
String cidr = NetUtils.getCidrFromGatewayAndNetmask(gateway, netmask);
String[] cidrPair = cidr.split("\\/");
String cidrAddress = cidrPair[0];
long cidrSize = Long.parseLong(cidrPair[1]);
- this.startIpOfSubnet = NetUtils.getIpRangeStartIpFromCidr(cidrAddress, cidrSize);
+ startIpOfSubnet = NetUtils.getIpRangeStartIpFromCidr(cidrAddress, cidrSize);
}
protected NicIpAliasVO() {
@@ -199,7 +201,7 @@ public class NicIpAliasVO implements NicIpAlias {
}
public void setAliasCount(long count) {
- this.aliasCount = count;
+ aliasCount = count;
}
public void setNetmask(String netmask) {
@@ -232,4 +234,8 @@ public class NicIpAliasVO implements NicIpAlias {
return startIpOfSubnet;
}
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.NicIpAlias;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d0ae4d9a/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpVO.java b/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpVO.java
index 142de8a..995da17 100644
--- a/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpVO.java
+++ b/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpVO.java
@@ -26,6 +26,8 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.cloudstack.acl.IAMEntityType;
+
import com.cloud.utils.db.GenericDao;
import com.cloud.vm.NicSecondaryIp;
@@ -36,7 +38,7 @@ public class NicSecondaryIpVO implements NicSecondaryIp {
public NicSecondaryIpVO(long nicId, String ipaddr, long vmId, long accountId, long domainId, long networkId) {
this.nicId = nicId;
this.vmId = vmId;
- this.ip4Address = ipaddr;
+ ip4Address = ipaddr;
this.accountId = accountId;
this.domainId = domainId;
this.networkId = networkId;
@@ -124,4 +126,9 @@ public class NicSecondaryIpVO implements NicSecondaryIp {
public long getVmId() {
return vmId;
}
+
+ @Override
+ public IAMEntityType getEntityType() {
+ return IAMEntityType.NicSecondaryIp;
+ }
}
[5/9] git commit: updated refs/heads/master to 63e3eea
Posted by mc...@apache.org.
CLOUDSTACK-5920: IAM service server.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/adb29b21
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/adb29b21
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/adb29b21
Branch: refs/heads/master
Commit: adb29b21402d4b446471c2d2741e09cd7b2106aa
Parents: 793becf
Author: Min Chen <mi...@citrix.com>
Authored: Tue Mar 4 17:51:17 2014 -0800
Committer: Min Chen <mi...@citrix.com>
Committed: Wed Mar 5 09:40:55 2014 -0800
----------------------------------------------------------------------
services/iam/server/pom.xml | 52 ++
.../core/spring-iam-server-context.xml | 40 +
.../org/apache/cloudstack/iam/api/IAMGroup.java | 37 +
.../apache/cloudstack/iam/api/IAMPolicy.java | 41 +
.../cloudstack/iam/api/IAMPolicyPermission.java | 53 ++
.../apache/cloudstack/iam/api/IAMService.java | 92 +++
.../iam/server/IAMAccountPolicyMapVO.java | 77 ++
.../iam/server/IAMGroupAccountMapVO.java | 78 ++
.../iam/server/IAMGroupPolicyMapVO.java | 79 ++
.../cloudstack/iam/server/IAMGroupVO.java | 122 +++
.../iam/server/IAMPolicyPermissionVO.java | 181 ++++
.../cloudstack/iam/server/IAMPolicyVO.java | 138 ++++
.../cloudstack/iam/server/IAMServiceImpl.java | 815 +++++++++++++++++++
.../iam/server/dao/IAMAccountPolicyMapDao.java | 17 +
.../server/dao/IAMAccountPolicyMapDaoImpl.java | 61 ++
.../iam/server/dao/IAMGroupAccountMapDao.java | 40 +
.../server/dao/IAMGroupAccountMapDaoImpl.java | 119 +++
.../cloudstack/iam/server/dao/IAMGroupDao.java | 28 +
.../iam/server/dao/IAMGroupDaoImpl.java | 59 ++
.../iam/server/dao/IAMGroupPolicyMapDao.java | 16 +
.../server/dao/IAMGroupPolicyMapDaoImpl.java | 61 ++
.../cloudstack/iam/server/dao/IAMPolicyDao.java | 28 +
.../iam/server/dao/IAMPolicyDaoImpl.java | 57 ++
.../iam/server/dao/IAMPolicyPermissionDao.java | 39 +
.../server/dao/IAMPolicyPermissionDaoImpl.java | 129 +++
.../cloudstack/iam/IAMServiceUnitTest.java | 211 +++++
.../iam/server/test/resources/db.properties | 75 ++
27 files changed, 2745 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/pom.xml
----------------------------------------------------------------------
diff --git a/services/iam/server/pom.xml b/services/iam/server/pom.xml
new file mode 100644
index 0000000..bed8811
--- /dev/null
+++ b/services/iam/server/pom.xml
@@ -0,0 +1,52 @@
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>cloud-iam</artifactId>
+ <name>Apache CloudStack IAM - Server</name>
+ <parent>
+ <groupId>org.apache.cloudstack</groupId>
+ <artifactId>cloudstack-service-iam</artifactId>
+ <version>4.4.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <dependencies>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cloudstack</groupId>
+ <artifactId>cloud-utils</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cloudstack</groupId>
+ <artifactId>cloud-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cloudstack</groupId>
+ <artifactId>cloud-api</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/resources/META-INF/cloudstack/core/spring-iam-server-context.xml
----------------------------------------------------------------------
diff --git a/services/iam/server/resources/META-INF/cloudstack/core/spring-iam-server-context.xml b/services/iam/server/resources/META-INF/cloudstack/core/spring-iam-server-context.xml
new file mode 100644
index 0000000..c9f383f
--- /dev/null
+++ b/services/iam/server/resources/META-INF/cloudstack/core/spring-iam-server-context.xml
@@ -0,0 +1,40 @@
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:aop="http://www.springframework.org/schema/aop"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd"
+ >
+
+ <bean id="IAMGroupDaoImpl" class="org.apache.cloudstack.iam.server.dao.IAMGroupDaoImpl" />
+ <bean id="IAMPolicyDaoImpl" class="org.apache.cloudstack.iam.server.dao.IAMPolicyDaoImpl" />
+ <bean id="IAMGroupAccountMapDaoImpl" class="org.apache.cloudstack.iam.server.dao.IAMGroupAccountMapDaoImpl" />
+ <bean id="IAMGroupPolicyMapDaoImpl" class="org.apache.cloudstack.iam.server.dao.IAMGroupPolicyMapDaoImpl" />
+ <bean id="IAMPolicyPermissionDaoImpl" class="org.apache.cloudstack.iam.server.dao.IAMPolicyPermissionDaoImpl" />
+ <bean id="IAMAccountPolicyMapDaoImpl" class="org.apache.cloudstack.iam.server.dao.IAMAccountPolicyMapDaoImpl" />
+
+
+ <bean id="IAMServiceImpl" class="org.apache.cloudstack.iam.server.IAMServiceImpl" />
+
+</beans>
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/src/org/apache/cloudstack/iam/api/IAMGroup.java
----------------------------------------------------------------------
diff --git a/services/iam/server/src/org/apache/cloudstack/iam/api/IAMGroup.java b/services/iam/server/src/org/apache/cloudstack/iam/api/IAMGroup.java
new file mode 100644
index 0000000..868d0a0
--- /dev/null
+++ b/services/iam/server/src/org/apache/cloudstack/iam/api/IAMGroup.java
@@ -0,0 +1,37 @@
+// 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.api;
+
+import org.apache.cloudstack.api.Identity;
+import org.apache.cloudstack.api.InternalIdentity;
+
+public interface IAMGroup extends InternalIdentity, Identity {
+
+ String getName();
+
+ String getDescription();
+
+ @Override
+ long getId();
+
+ @Override
+ String getUuid();
+
+ String getPath();
+
+ long getAccountId();
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/src/org/apache/cloudstack/iam/api/IAMPolicy.java
----------------------------------------------------------------------
diff --git a/services/iam/server/src/org/apache/cloudstack/iam/api/IAMPolicy.java b/services/iam/server/src/org/apache/cloudstack/iam/api/IAMPolicy.java
new file mode 100644
index 0000000..e6daeb1
--- /dev/null
+++ b/services/iam/server/src/org/apache/cloudstack/iam/api/IAMPolicy.java
@@ -0,0 +1,41 @@
+// 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.api;
+
+import org.apache.cloudstack.api.Identity;
+import org.apache.cloudstack.api.InternalIdentity;
+
+public interface IAMPolicy extends InternalIdentity, Identity {
+
+ String getName();
+
+ String getDescription();
+
+ public enum PolicyType {
+ Static, Dynamic
+ }
+
+ @Override
+ long getId();
+
+ @Override
+ String getUuid();
+
+ String getPath();
+
+ long getAccountId();
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/src/org/apache/cloudstack/iam/api/IAMPolicyPermission.java
----------------------------------------------------------------------
diff --git a/services/iam/server/src/org/apache/cloudstack/iam/api/IAMPolicyPermission.java b/services/iam/server/src/org/apache/cloudstack/iam/api/IAMPolicyPermission.java
new file mode 100644
index 0000000..b91086f
--- /dev/null
+++ b/services/iam/server/src/org/apache/cloudstack/iam/api/IAMPolicyPermission.java
@@ -0,0 +1,53 @@
+// 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.api;
+
+
+public interface IAMPolicyPermission {
+
+ String getAction();
+
+ long getAclPolicyId();
+
+ String getEntityType();
+
+ String getAccessType();
+
+ String getScope();
+
+ Long getScopeId();
+
+ Permission getPermission();
+
+ public enum Permission {
+ Allow(true), Deny(false);
+
+ boolean result;
+
+ Permission(boolean result) {
+ this.result = result;
+ }
+
+ public boolean isGranted() {
+ return result;
+ }
+ }
+
+ long getId();
+
+ public static final long PERMISSION_SCOPE_ID_CURRENT_CALLER = -1;
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/src/org/apache/cloudstack/iam/api/IAMService.java
----------------------------------------------------------------------
diff --git a/services/iam/server/src/org/apache/cloudstack/iam/api/IAMService.java b/services/iam/server/src/org/apache/cloudstack/iam/api/IAMService.java
new file mode 100644
index 0000000..74a0885
--- /dev/null
+++ b/services/iam/server/src/org/apache/cloudstack/iam/api/IAMService.java
@@ -0,0 +1,92 @@
+// 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.api;
+
+import java.util.List;
+
+import org.apache.cloudstack.iam.api.IAMPolicyPermission.Permission;
+
+import com.cloud.utils.Pair;
+
+public interface IAMService {
+
+ /* IAM group related interfaces */
+ IAMGroup createIAMGroup(String iamGroupName, String description, String path);
+
+ boolean deleteIAMGroup(Long iamGroupId);
+
+ List<IAMGroup> listIAMGroups(long accountId);
+
+ IAMGroup addAccountsToGroup(List<Long> acctIds, Long groupId);
+
+ IAMGroup removeAccountsFromGroup(List<Long> acctIds, Long groupId);
+
+ List<Long> listAccountsByGroup(long groupId);
+
+ Pair<List<IAMGroup>, Integer> listIAMGroups(Long iamGroupId, String iamGroupName, String path, Long startIndex, Long pageSize);
+
+ /* IAM Policy related interfaces */
+ IAMPolicy createIAMPolicy(String iamPolicyName, String description, Long parentPolicyId, String path);
+
+ boolean deleteIAMPolicy(long iamPolicyId);
+
+ List<IAMPolicy> listIAMPolicies(long accountId);
+
+ List<IAMPolicy> listIAMPoliciesByGroup(long groupId);
+
+ Pair<List<IAMPolicy>, Integer> listIAMPolicies(Long iamPolicyId, String iamPolicyName, String path, Long startIndex, Long pageSize);
+
+ IAMGroup attachIAMPoliciesToGroup(List<Long> policyIds, Long groupId);
+
+ IAMGroup removeIAMPoliciesFromGroup(List<Long> policyIds, Long groupId);
+
+ void attachIAMPolicyToAccounts(Long policyId, List<Long> acctIds);
+
+ void removeIAMPolicyFromAccounts(Long policyId, List<Long> acctIds);
+
+ IAMPolicy addIAMPermissionToIAMPolicy(long iamPolicyId, String entityType, String scope, Long scopeId,
+ String action, String accessType, Permission perm, Boolean recursive);
+
+ IAMPolicy removeIAMPermissionFromIAMPolicy(long iamPolicyId, String entityType, String scope, Long scopeId,
+ String action);
+
+ void removeIAMPermissionForEntity(final String entityType, final Long entityId);
+
+ IAMPolicy getResourceGrantPolicy(String entityType, Long entityId, String accessType, String action);
+
+ IAMPolicy getResourceOwnerPolicy();
+
+ List<IAMPolicyPermission> listPolicyPermissions(long policyId);
+
+ List<IAMPolicyPermission> listPolicyPermissionsByScope(long policyId, String action, String scope);
+
+ List<IAMPolicyPermission> listPolicyPermissionByActionAndEntity(long policyId, String action, String entityType);
+
+ boolean isActionAllowedForPolicies(String action, List<IAMPolicy> policies);
+
+ List<Long> getGrantedEntities(long accountId, String action, String scope);
+
+ IAMPolicy resetIAMPolicy(long iamPolicyId);
+
+ List<IAMPolicyPermission> listPolicyPermissionByAccessAndEntity(long policyId, String accessType,
+ String entityType);
+
+ List<IAMGroup> listParentIAMGroups(long groupId);
+
+ List<IAMPolicy> listRecursiveIAMPoliciesByGroup(long groupId);
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/src/org/apache/cloudstack/iam/server/IAMAccountPolicyMapVO.java
----------------------------------------------------------------------
diff --git a/services/iam/server/src/org/apache/cloudstack/iam/server/IAMAccountPolicyMapVO.java b/services/iam/server/src/org/apache/cloudstack/iam/server/IAMAccountPolicyMapVO.java
new file mode 100644
index 0000000..18f085a
--- /dev/null
+++ b/services/iam/server/src/org/apache/cloudstack/iam/server/IAMAccountPolicyMapVO.java
@@ -0,0 +1,77 @@
+// 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;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import com.cloud.utils.db.GenericDao;
+
+@Entity
+@Table(name = ("iam_account_policy_map"))
+public class IAMAccountPolicyMapVO {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "id")
+ private Long id;
+
+ @Column(name = "account_id")
+ private long accountId;
+
+ @Column(name = "policy_id")
+ private long iamPolicyId;
+
+ @Column(name = GenericDao.REMOVED_COLUMN)
+ private Date removed;
+
+ @Column(name = GenericDao.CREATED_COLUMN)
+ private Date created;
+
+ public IAMAccountPolicyMapVO() {
+ }
+
+ public IAMAccountPolicyMapVO(long accountId, long iamPolicyId) {
+ this.accountId = accountId;
+ this.iamPolicyId = iamPolicyId;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public long getAccountId() {
+ return accountId;
+ }
+
+ public long getIamPolicyId() {
+ return iamPolicyId;
+ }
+
+ public Date getRemoved() {
+ return removed;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/src/org/apache/cloudstack/iam/server/IAMGroupAccountMapVO.java
----------------------------------------------------------------------
diff --git a/services/iam/server/src/org/apache/cloudstack/iam/server/IAMGroupAccountMapVO.java b/services/iam/server/src/org/apache/cloudstack/iam/server/IAMGroupAccountMapVO.java
new file mode 100644
index 0000000..dac7d35
--- /dev/null
+++ b/services/iam/server/src/org/apache/cloudstack/iam/server/IAMGroupAccountMapVO.java
@@ -0,0 +1,78 @@
+// 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;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import com.cloud.utils.db.GenericDao;
+
+@Entity
+@Table(name = ("iam_group_account_map"))
+public class IAMGroupAccountMapVO {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "id")
+ private Long id;
+
+ @Column(name = "group_id")
+ private long aclGroupId;
+
+ @Column(name = "account_id")
+ private long accountId;
+
+ @Column(name = GenericDao.REMOVED_COLUMN)
+ private Date removed;
+
+ @Column(name = GenericDao.CREATED_COLUMN)
+ private Date created;
+
+ public IAMGroupAccountMapVO() {
+ }
+
+ public IAMGroupAccountMapVO(long aclGroupId, long accountId) {
+ this.aclGroupId = aclGroupId;
+ this.accountId = accountId;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public long getAclGroupId() {
+ return aclGroupId;
+ }
+
+
+ public long getAccountId() {
+ return accountId;
+ }
+
+ public Date getRemoved() {
+ return removed;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/src/org/apache/cloudstack/iam/server/IAMGroupPolicyMapVO.java
----------------------------------------------------------------------
diff --git a/services/iam/server/src/org/apache/cloudstack/iam/server/IAMGroupPolicyMapVO.java b/services/iam/server/src/org/apache/cloudstack/iam/server/IAMGroupPolicyMapVO.java
new file mode 100644
index 0000000..946d1f7
--- /dev/null
+++ b/services/iam/server/src/org/apache/cloudstack/iam/server/IAMGroupPolicyMapVO.java
@@ -0,0 +1,79 @@
+// 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;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+
+import com.cloud.utils.db.GenericDao;
+
+@Entity
+@Table(name = ("iam_group_policy_map"))
+public class IAMGroupPolicyMapVO {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "id")
+ private Long id;
+
+ @Column(name = "group_id")
+ private long aclGroupId;
+
+ @Column(name = "policy_id")
+ private long aclPolicyId;
+
+ @Column(name = GenericDao.REMOVED_COLUMN)
+ private Date removed;
+
+ @Column(name = GenericDao.CREATED_COLUMN)
+ private Date created;
+
+ public IAMGroupPolicyMapVO() {
+ }
+
+ public IAMGroupPolicyMapVO(long aclGroupId, long aclPolicyId) {
+ this.aclGroupId = aclGroupId;
+ this.aclPolicyId = aclPolicyId;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public long getAclGroupId() {
+ return aclGroupId;
+ }
+
+
+ public long getAclPolicyId() {
+ return aclPolicyId;
+ }
+
+ public Date getRemoved() {
+ return removed;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/src/org/apache/cloudstack/iam/server/IAMGroupVO.java
----------------------------------------------------------------------
diff --git a/services/iam/server/src/org/apache/cloudstack/iam/server/IAMGroupVO.java b/services/iam/server/src/org/apache/cloudstack/iam/server/IAMGroupVO.java
new file mode 100644
index 0000000..80edb89
--- /dev/null
+++ b/services/iam/server/src/org/apache/cloudstack/iam/server/IAMGroupVO.java
@@ -0,0 +1,122 @@
+// 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;
+
+import java.util.Date;
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import org.apache.cloudstack.iam.api.IAMGroup;
+
+import com.cloud.utils.db.GenericDao;
+
+@Entity
+@Table(name = ("iam_group"))
+public class IAMGroupVO implements IAMGroup {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "id")
+ private long id;
+
+ @Column(name = "name")
+ private String name;
+
+ @Column(name = "description")
+ private String description;
+
+ @Column(name = "uuid")
+ private String uuid;
+
+ @Column(name = "path")
+ private String path;
+
+ @Column(name = "account_id")
+ private long accountId;
+
+ @Column(name = GenericDao.REMOVED_COLUMN)
+ private Date removed;
+
+ @Column(name = GenericDao.CREATED_COLUMN)
+ private Date created;
+
+ public IAMGroupVO() {
+ uuid = UUID.randomUUID().toString();
+ }
+
+ public IAMGroupVO(String name, String description) {
+ this.name = name;
+ this.description = description;
+ uuid = UUID.randomUUID().toString();
+ path = "/";
+ }
+
+ @Override
+ public long getId() {
+ return id;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ @Override
+ public long getAccountId() {
+ return accountId;
+ }
+
+ public void setAccountId(long acctId) {
+ accountId = acctId;
+ }
+
+ @Override
+ public String getUuid() {
+ return uuid;
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+
+ public Date getRemoved() {
+ return removed;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/src/org/apache/cloudstack/iam/server/IAMPolicyPermissionVO.java
----------------------------------------------------------------------
diff --git a/services/iam/server/src/org/apache/cloudstack/iam/server/IAMPolicyPermissionVO.java b/services/iam/server/src/org/apache/cloudstack/iam/server/IAMPolicyPermissionVO.java
new file mode 100644
index 0000000..13d6b81
--- /dev/null
+++ b/services/iam/server/src/org/apache/cloudstack/iam/server/IAMPolicyPermissionVO.java
@@ -0,0 +1,181 @@
+// 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;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import org.apache.cloudstack.iam.api.IAMPolicyPermission;
+import com.cloud.utils.db.GenericDao;
+
+@Entity
+@Table(name = ("iam_policy_permission"))
+public class IAMPolicyPermissionVO implements IAMPolicyPermission {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "id")
+ private long id;
+
+ @Column(name = "policy_id")
+ private long aclPolicyId;
+
+ @Column(name = "action")
+ private String action;
+
+ @Column(name = "resource_type")
+ private String entityType;
+
+ @Column(name = "access_type")
+ private String accessType;
+
+ @Column(name = "scope")
+ private String scope;
+
+ @Column(name = "scope_id")
+ private Long scopeId;
+
+ @Column(name = "permission")
+ @Enumerated(value = EnumType.STRING)
+ private Permission permission;
+
+ @Column(name = "recursive")
+ private Boolean recursive;
+
+ @Column(name = GenericDao.REMOVED_COLUMN)
+ private Date removed;
+
+ @Column(name = GenericDao.CREATED_COLUMN)
+ private Date created;
+
+ public IAMPolicyPermissionVO() {
+
+ }
+
+ public IAMPolicyPermissionVO(long aclPolicyId, String action, String entityType, String accessType, String scope,
+ Long scopeId, Permission permission, Boolean recursive) {
+ this.aclPolicyId = aclPolicyId;
+ this.action = action;
+ this.entityType = entityType;
+ this.accessType = accessType;
+ this.scope = scope;
+ this.scopeId = scopeId;
+ this.permission = permission;
+ this.recursive = recursive;
+ }
+
+ @Override
+ public long getId() {
+ return id;
+ }
+
+ @Override
+ public long getAclPolicyId() {
+ return aclPolicyId;
+ }
+
+
+ public void setAclPolicyId(long aclPolicyId) {
+ this.aclPolicyId = aclPolicyId;
+ }
+
+ @Override
+ public String getEntityType() {
+ return entityType;
+ }
+
+ @Override
+ public String getAccessType() {
+ return accessType;
+ }
+
+
+ public void setEntityType(String entityType) {
+ this.entityType = entityType;
+ }
+
+ public void setAccessType(String accessType) {
+ this.accessType = accessType;
+ }
+
+ @Override
+ public String getScope() {
+ return scope;
+ }
+
+ public void setScope(String scope) {
+ this.scope = scope;
+ }
+
+
+ @Override
+ public String getAction() {
+ return action;
+ }
+
+ @Override
+ public Long getScopeId() {
+ // TODO
+ // handle special -1 scopeId, current caller domain, account
+ /*
+ * if ( scopeId < 0 ){ Account caller =
+ * CallContext.current().getCallingAccount(); if ( scope ==
+ * PermissionScope.DOMAIN){ return caller.getDomainId(); } else if
+ * (scope == PermissionScope.ACCOUNT) { return caller.getAccountId(); }
+ * }
+ */
+ return scopeId;
+ }
+
+ @Override
+ public Permission getPermission() {
+ return permission;
+ }
+
+ public void setAction(String action) {
+ this.action = action;
+ }
+
+ public void setScopeId(Long scopeId) {
+ this.scopeId = scopeId;
+ }
+
+ public void setPermission(Permission permission) {
+ this.permission = permission;
+ }
+
+ public Date getRemoved() {
+ return removed;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+
+ public Boolean isRecursive() {
+ return recursive;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/src/org/apache/cloudstack/iam/server/IAMPolicyVO.java
----------------------------------------------------------------------
diff --git a/services/iam/server/src/org/apache/cloudstack/iam/server/IAMPolicyVO.java b/services/iam/server/src/org/apache/cloudstack/iam/server/IAMPolicyVO.java
new file mode 100644
index 0000000..25ebd01
--- /dev/null
+++ b/services/iam/server/src/org/apache/cloudstack/iam/server/IAMPolicyVO.java
@@ -0,0 +1,138 @@
+// 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;
+
+import java.util.Date;
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import org.apache.cloudstack.iam.api.IAMPolicy;
+
+import com.cloud.utils.db.GenericDao;
+
+@Entity
+@Table(name = ("iam_policy"))
+public class IAMPolicyVO implements IAMPolicy {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "id")
+ private long id;
+
+ @Column(name = "name")
+ private String name;
+
+ @Column(name = "description")
+ private String description;
+
+ @Column(name = "uuid")
+ private String uuid;
+
+ @Column(name = "path")
+ private String path;
+
+ @Column(name = "account_id")
+ private long accountId;
+
+ @Column(name = GenericDao.REMOVED_COLUMN)
+ private Date removed;
+
+ @Column(name = GenericDao.CREATED_COLUMN)
+ private Date created;
+
+ @Column(name = "policy_type")
+ @Enumerated(value = EnumType.STRING)
+ private IAMPolicy.PolicyType policyType;
+
+ public IAMPolicyVO() {
+ uuid = UUID.randomUUID().toString();
+ }
+
+ public IAMPolicyVO(String name, String description) {
+ this.name = name;
+ this.description = description;
+ uuid = UUID.randomUUID().toString();
+ policyType = IAMPolicy.PolicyType.Static;
+ }
+
+ @Override
+ public long getId() {
+ return id;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+
+ @Override
+ public String getUuid() {
+ return uuid;
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+
+ public Date getRemoved() {
+ return removed;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+
+ @Override
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ @Override
+ public long getAccountId() {
+ return accountId;
+ }
+
+ public void setAccountId(long accountId) {
+ this.accountId = accountId;
+ }
+
+ public IAMPolicy.PolicyType getPolicyType() {
+ return policyType;
+ }
+
+ public void setPolicyType(IAMPolicy.PolicyType policyType) {
+ this.policyType = policyType;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/src/org/apache/cloudstack/iam/server/IAMServiceImpl.java
----------------------------------------------------------------------
diff --git a/services/iam/server/src/org/apache/cloudstack/iam/server/IAMServiceImpl.java b/services/iam/server/src/org/apache/cloudstack/iam/server/IAMServiceImpl.java
new file mode 100644
index 0000000..097d84f
--- /dev/null
+++ b/services/iam/server/src/org/apache/cloudstack/iam/server/IAMServiceImpl.java
@@ -0,0 +1,815 @@
+// 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;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.acl.PermissionScope;
+import org.apache.cloudstack.iam.api.IAMGroup;
+import org.apache.cloudstack.iam.api.IAMPolicy;
+import org.apache.cloudstack.iam.api.IAMPolicyPermission;
+import org.apache.cloudstack.iam.api.IAMPolicyPermission.Permission;
+import org.apache.cloudstack.iam.api.IAMService;
+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 com.cloud.exception.InvalidParameterValueException;
+import com.cloud.utils.Pair;
+import com.cloud.utils.component.Manager;
+import com.cloud.utils.component.ManagerBase;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.EntityManager;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.JoinBuilder;
+import com.cloud.utils.db.JoinBuilder.JoinType;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionCallback;
+import com.cloud.utils.db.TransactionCallbackNoReturn;
+import com.cloud.utils.db.TransactionStatus;
+
+@Local(value = {IAMService.class})
+public class IAMServiceImpl extends ManagerBase implements IAMService, Manager {
+
+ public static final Logger s_logger = Logger.getLogger(IAMServiceImpl.class);
+ private String _name;
+
+ @Inject
+ IAMPolicyDao _aclPolicyDao;
+
+ @Inject
+ IAMGroupDao _aclGroupDao;
+
+ @Inject
+ EntityManager _entityMgr;
+
+ @Inject
+ IAMGroupPolicyMapDao _aclGroupPolicyMapDao;
+
+ @Inject
+ IAMAccountPolicyMapDao _aclAccountPolicyMapDao;
+
+ @Inject
+ IAMGroupAccountMapDao _aclGroupAccountMapDao;
+
+ @Inject
+ IAMPolicyPermissionDao _policyPermissionDao;
+
+ @DB
+ @Override
+ public IAMGroup createIAMGroup(String iamGroupName, String description, String path) {
+ // check if the group is already existing
+ IAMGroup grp = _aclGroupDao.findByName(path, iamGroupName);
+ if (grp != null) {
+ throw new InvalidParameterValueException(
+ "Unable to create acl group with name " + iamGroupName
+ + " already exisits for path " + path);
+ }
+ IAMGroupVO rvo = new IAMGroupVO(iamGroupName, description);
+ rvo.setPath(path);
+
+ return _aclGroupDao.persist(rvo);
+ }
+
+ @DB
+ @Override
+ public boolean deleteIAMGroup(final Long iamGroupId) {
+ // get the Acl Group entity
+ final IAMGroup grp = _aclGroupDao.findById(iamGroupId);
+ if (grp == null) {
+ throw new InvalidParameterValueException("Unable to find acl group: " + iamGroupId
+ + "; failed to delete acl group.");
+ }
+
+ Transaction.execute(new TransactionCallbackNoReturn() {
+ @Override
+ public void doInTransactionWithoutResult(TransactionStatus status) {
+ // remove this group related entry in acl_group_role_map
+ List<IAMGroupPolicyMapVO> groupPolicyMap = _aclGroupPolicyMapDao.listByGroupId(grp.getId());
+ if (groupPolicyMap != null) {
+ for (IAMGroupPolicyMapVO gr : groupPolicyMap) {
+ _aclGroupPolicyMapDao.remove(gr.getId());
+ }
+ }
+
+ // remove this group related entry in acl_group_account table
+ List<IAMGroupAccountMapVO> groupAcctMap = _aclGroupAccountMapDao.listByGroupId(grp.getId());
+ if (groupAcctMap != null) {
+ for (IAMGroupAccountMapVO grpAcct : groupAcctMap) {
+ _aclGroupAccountMapDao.remove(grpAcct.getId());
+ }
+ }
+
+ // remove this group from acl_group table
+ _aclGroupDao.remove(iamGroupId);
+ }
+ });
+
+ return true;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<IAMGroup> listIAMGroups(long accountId) {
+
+ GenericSearchBuilder<IAMGroupAccountMapVO, Long> groupSB = _aclGroupAccountMapDao.createSearchBuilder(Long.class);
+ groupSB.selectFields(groupSB.entity().getAclGroupId());
+ groupSB.and("account", groupSB.entity().getAccountId(), Op.EQ);
+ SearchCriteria<Long> groupSc = groupSB.create();
+ groupSc.setParameters("account", accountId);
+
+ List<Long> groupIds = _aclGroupAccountMapDao.customSearch(groupSc, null);
+
+ SearchBuilder<IAMGroupVO> sb = _aclGroupDao.createSearchBuilder();
+ sb.and("ids", sb.entity().getId(), Op.IN);
+ SearchCriteria<IAMGroupVO> sc = sb.create();
+ sc.setParameters("ids", groupIds.toArray(new Object[groupIds.size()]));
+ @SuppressWarnings("rawtypes")
+ List groups = _aclGroupDao.search(sc, null);
+ return groups;
+ }
+
+ @DB
+ @Override
+ public IAMGroup addAccountsToGroup(final List<Long> acctIds, final Long groupId) {
+ // get the Acl Group entity
+ IAMGroup group = _aclGroupDao.findById(groupId);
+ if (group == null) {
+ throw new InvalidParameterValueException("Unable to find acl group: " + groupId
+ + "; failed to add accounts to acl group.");
+ }
+
+ Transaction.execute(new TransactionCallbackNoReturn() {
+ @Override
+ public void doInTransactionWithoutResult(TransactionStatus status) {
+ // add entries in acl_group_account_map table
+ for (Long acctId : acctIds) {
+ // check account permissions
+ IAMGroupAccountMapVO grMap = _aclGroupAccountMapDao.findByGroupAndAccount(groupId, acctId);
+ if (grMap == null) {
+ // not there already
+ grMap = new IAMGroupAccountMapVO(groupId, acctId);
+ _aclGroupAccountMapDao.persist(grMap);
+ }
+ }
+ }
+ });
+ return group;
+ }
+
+ @DB
+ @Override
+ public IAMGroup removeAccountsFromGroup(final List<Long> acctIds, final Long groupId) {
+ // get the Acl Group entity
+ IAMGroup group = _aclGroupDao.findById(groupId);
+ if (group == null) {
+ throw new InvalidParameterValueException("Unable to find acl group: " + groupId
+ + "; failed to remove accounts from acl group.");
+ }
+
+ Transaction.execute(new TransactionCallbackNoReturn() {
+ @Override
+ public void doInTransactionWithoutResult(TransactionStatus status) {
+ // remove entries from acl_group_account_map table
+ for (Long acctId : acctIds) {
+ IAMGroupAccountMapVO grMap = _aclGroupAccountMapDao.findByGroupAndAccount(groupId, acctId);
+ if (grMap != null) {
+ // not removed yet
+ _aclGroupAccountMapDao.remove(grMap.getId());
+ }
+ }
+ }
+ });
+ return group;
+ }
+
+ @Override
+ public List<Long> listAccountsByGroup(long groupId) {
+ List<IAMGroupAccountMapVO> grpAcctMap = _aclGroupAccountMapDao.listByGroupId(groupId);
+ if (grpAcctMap == null || grpAcctMap.size() == 0) {
+ return new ArrayList<Long>();
+ }
+
+ List<Long> accts = new ArrayList<Long>();
+ for (IAMGroupAccountMapVO grpAcct : grpAcctMap) {
+ accts.add(grpAcct.getAccountId());
+ }
+ return accts;
+ }
+
+ @Override
+ public Pair<List<IAMGroup>, Integer> listIAMGroups(Long iamGroupId, String iamGroupName, String path, Long startIndex, Long pageSize) {
+ if (iamGroupId != null) {
+ IAMGroup group = _aclGroupDao.findById(iamGroupId);
+ if (group == null) {
+ throw new InvalidParameterValueException("Unable to find acl group by id " + iamGroupId);
+ }
+ }
+
+ Filter searchFilter = new Filter(IAMGroupVO.class, "id", true, startIndex, pageSize);
+
+ SearchBuilder<IAMGroupVO> sb = _aclGroupDao.createSearchBuilder();
+ sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
+ sb.and("path", sb.entity().getPath(), SearchCriteria.Op.LIKE);
+ sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
+
+ SearchCriteria<IAMGroupVO> sc = sb.create();
+
+ if (iamGroupName != null) {
+ sc.setParameters("name", iamGroupName);
+ }
+
+ if (iamGroupId != null) {
+ sc.setParameters("id", iamGroupId);
+ }
+
+ sc.setParameters("path", path + "%");
+
+ Pair<List<IAMGroupVO>, Integer> groups = _aclGroupDao.searchAndCount(sc, searchFilter);
+ return new Pair<List<IAMGroup>, Integer>(new ArrayList<IAMGroup>(groups.first()), groups.second());
+ }
+
+ @Override
+ public List<IAMGroup> listParentIAMGroups(long groupId) {
+ IAMGroup group = _aclGroupDao.findById(groupId);
+ if (group == null) {
+ throw new InvalidParameterValueException("Unable to find acl group by id " + groupId);
+ }
+
+ String path = group.getPath();
+ List<String> pathList = new ArrayList<String>();
+
+ String[] parts = path.split("/");
+
+ for (String part : parts) {
+ int start = path.indexOf(part);
+ if (start > 0) {
+ String subPath = path.substring(0, start);
+ pathList.add(subPath);
+ }
+ }
+
+ if (pathList.isEmpty()) {
+ return new ArrayList<IAMGroup>();
+ }
+
+ SearchBuilder<IAMGroupVO> sb = _aclGroupDao.createSearchBuilder();
+ sb.and("paths", sb.entity().getPath(), SearchCriteria.Op.IN);
+
+ SearchCriteria<IAMGroupVO> sc = sb.create();
+ sc.setParameters("paths", pathList.toArray());
+
+ List<IAMGroupVO> groups = _aclGroupDao.search(sc, null);
+
+ return new ArrayList<IAMGroup>(groups);
+
+ }
+
+ @DB
+ @Override
+ public IAMPolicy createIAMPolicy(final String iamPolicyName, final String description, final Long parentPolicyId, final String path) {
+
+ // check if the policy is already existing
+ IAMPolicy ro = _aclPolicyDao.findByName(iamPolicyName);
+ if (ro != null) {
+ throw new InvalidParameterValueException(
+ "Unable to create acl policy with name " + iamPolicyName
+ + " already exisits");
+ }
+
+ IAMPolicy role = Transaction.execute(new TransactionCallback<IAMPolicy>() {
+ @Override
+ public IAMPolicy doInTransaction(TransactionStatus status) {
+ IAMPolicyVO rvo = new IAMPolicyVO(iamPolicyName, description);
+ rvo.setPath(path);
+
+ IAMPolicy role = _aclPolicyDao.persist(rvo);
+ if (parentPolicyId != null) {
+ // copy parent role permissions
+ List<IAMPolicyPermissionVO> perms = _policyPermissionDao.listByPolicy(parentPolicyId);
+ if (perms != null) {
+ for (IAMPolicyPermissionVO perm : perms) {
+ perm.setAclPolicyId(role.getId());
+ _policyPermissionDao.persist(perm);
+ }
+ }
+ }
+ return role;
+ }
+ });
+
+
+ return role;
+ }
+
+ @DB
+ @Override
+ public boolean deleteIAMPolicy(final long iamPolicyId) {
+ // get the Acl Policy entity
+ final IAMPolicy policy = _aclPolicyDao.findById(iamPolicyId);
+ if (policy == null) {
+ throw new InvalidParameterValueException("Unable to find acl policy: " + iamPolicyId
+ + "; failed to delete acl policy.");
+ }
+
+ Transaction.execute(new TransactionCallbackNoReturn() {
+ @Override
+ public void doInTransactionWithoutResult(TransactionStatus status) {
+ // remove this role related entry in acl_group_role_map
+ List<IAMGroupPolicyMapVO> groupPolicyMap = _aclGroupPolicyMapDao.listByPolicyId(policy.getId());
+ if (groupPolicyMap != null) {
+ for (IAMGroupPolicyMapVO gr : groupPolicyMap) {
+ _aclGroupPolicyMapDao.remove(gr.getId());
+ }
+ }
+
+ // remove this policy related entry in acl_account_policy_map table
+ List<IAMAccountPolicyMapVO> policyAcctMap = _aclAccountPolicyMapDao.listByPolicyId(policy.getId());
+ if (policyAcctMap != null) {
+ for (IAMAccountPolicyMapVO policyAcct : policyAcctMap) {
+ _aclAccountPolicyMapDao.remove(policyAcct.getId());
+ }
+ }
+
+ // remove this policy related entry in acl_policy_permission table
+ List<IAMPolicyPermissionVO> policyPermMap = _policyPermissionDao.listByPolicy(policy.getId());
+ if (policyPermMap != null) {
+ for (IAMPolicyPermissionVO policyPerm : policyPermMap) {
+ _policyPermissionDao.remove(policyPerm.getId());
+ }
+ }
+
+ // remove this role from acl_role table
+ _aclPolicyDao.remove(iamPolicyId);
+ }
+ });
+
+ return true;
+ }
+
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<IAMPolicy> listIAMPolicies(long accountId) {
+
+ // static policies of the account
+ SearchBuilder<IAMGroupAccountMapVO> groupSB = _aclGroupAccountMapDao.createSearchBuilder();
+ groupSB.and("account", groupSB.entity().getAccountId(), Op.EQ);
+
+ GenericSearchBuilder<IAMGroupPolicyMapVO, Long> policySB = _aclGroupPolicyMapDao.createSearchBuilder(Long.class);
+ policySB.selectFields(policySB.entity().getAclPolicyId());
+ policySB.join("accountgroupjoin", groupSB, groupSB.entity().getAclGroupId(), policySB.entity().getAclGroupId(),
+ JoinType.INNER);
+ policySB.done();
+ SearchCriteria<Long> policySc = policySB.create();
+ policySc.setJoinParameters("accountgroupjoin", "account", accountId);
+
+ List<Long> policyIds = _aclGroupPolicyMapDao.customSearch(policySc, null);
+ // add policies directly attached to the account
+ List<IAMAccountPolicyMapVO> acctPolicies = _aclAccountPolicyMapDao.listByAccountId(accountId);
+ for (IAMAccountPolicyMapVO p : acctPolicies) {
+ policyIds.add(p.getIamPolicyId());
+ }
+ if (policyIds.size() == 0) {
+ return new ArrayList<IAMPolicy>();
+ }
+ SearchBuilder<IAMPolicyVO> sb = _aclPolicyDao.createSearchBuilder();
+ sb.and("ids", sb.entity().getId(), Op.IN);
+ SearchCriteria<IAMPolicyVO> sc = sb.create();
+ sc.setParameters("ids", policyIds.toArray(new Object[policyIds.size()]));
+ @SuppressWarnings("rawtypes")
+ List policies = _aclPolicyDao.customSearch(sc, null);
+
+ return policies;
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<IAMPolicy> listIAMPoliciesByGroup(long groupId) {
+ List<IAMGroupPolicyMapVO> policyGrpMap = _aclGroupPolicyMapDao.listByGroupId(groupId);
+ if (policyGrpMap == null || policyGrpMap.size() == 0) {
+ return new ArrayList<IAMPolicy>();
+ }
+
+ List<Long> policyIds = new ArrayList<Long>();
+ for (IAMGroupPolicyMapVO pg : policyGrpMap) {
+ policyIds.add(pg.getAclPolicyId());
+ }
+
+ SearchBuilder<IAMPolicyVO> sb = _aclPolicyDao.createSearchBuilder();
+ sb.and("ids", sb.entity().getId(), Op.IN);
+ SearchCriteria<IAMPolicyVO> sc = sb.create();
+ sc.setParameters("ids", policyIds.toArray(new Object[policyIds.size()]));
+ @SuppressWarnings("rawtypes")
+ List policies = _aclPolicyDao.customSearch(sc, null);
+
+ return policies;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<IAMPolicy> listRecursiveIAMPoliciesByGroup(long groupId) {
+ List<IAMGroupPolicyMapVO> policyGrpMap = _aclGroupPolicyMapDao.listByGroupId(groupId);
+ if (policyGrpMap == null || policyGrpMap.size() == 0) {
+ return new ArrayList<IAMPolicy>();
+ }
+
+ List<Long> policyIds = new ArrayList<Long>();
+ for (IAMGroupPolicyMapVO pg : policyGrpMap) {
+ policyIds.add(pg.getAclPolicyId());
+ }
+
+ SearchBuilder<IAMPolicyPermissionVO> permSb = _policyPermissionDao.createSearchBuilder();
+ permSb.and("isRecursive", permSb.entity().isRecursive(), Op.EQ);
+
+ SearchBuilder<IAMPolicyVO> sb = _aclPolicyDao.createSearchBuilder();
+ sb.and("ids", sb.entity().getId(), Op.IN);
+ sb.join("recursivePerm", permSb, sb.entity().getId(), permSb.entity().getAclPolicyId(),
+ JoinBuilder.JoinType.INNER);
+
+ SearchCriteria<IAMPolicyVO> sc = sb.create();
+ sc.setParameters("ids", policyIds.toArray(new Object[policyIds.size()]));
+ sc.setJoinParameters("recursivePerm", "isRecursive", true);
+
+ @SuppressWarnings("rawtypes")
+ List policies = _aclPolicyDao.customSearch(sc, null);
+
+ return policies;
+ }
+
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Pair<List<IAMPolicy>, Integer> listIAMPolicies(Long iamPolicyId, String iamPolicyName, String path, Long startIndex, Long pageSize) {
+
+ if (iamPolicyId != null) {
+ IAMPolicy policy = _aclPolicyDao.findById(iamPolicyId);
+ if (policy == null) {
+ throw new InvalidParameterValueException("Unable to find acl policy by id " + iamPolicyId);
+ }
+ }
+
+ Filter searchFilter = new Filter(IAMPolicyVO.class, "id", true, startIndex, pageSize);
+
+ SearchBuilder<IAMPolicyVO> sb = _aclPolicyDao.createSearchBuilder();
+ sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
+ sb.and("path", sb.entity().getPath(), SearchCriteria.Op.LIKE);
+ sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
+
+ SearchCriteria<IAMPolicyVO> sc = sb.create();
+
+ if (iamPolicyName != null) {
+ sc.setParameters("name", iamPolicyName);
+ }
+
+ if (iamPolicyId != null) {
+ sc.setParameters("id", iamPolicyId);
+ }
+
+ sc.setParameters("path", path + "%");
+
+ Pair<List<IAMPolicyVO>, Integer> policies = _aclPolicyDao.searchAndCount(sc, searchFilter);
+ @SuppressWarnings("rawtypes")
+ List policyList = policies.first();
+ return new Pair<List<IAMPolicy>, Integer>(policyList, policies.second());
+ }
+
+ @DB
+ @Override
+ public IAMGroup attachIAMPoliciesToGroup(final List<Long> policyIds, final Long groupId) {
+ // get the Acl Group entity
+ IAMGroup group = _aclGroupDao.findById(groupId);
+ if (group == null) {
+ throw new InvalidParameterValueException("Unable to find acl group: " + groupId
+ + "; failed to add roles to acl group.");
+ }
+
+ Transaction.execute(new TransactionCallbackNoReturn() {
+ @Override
+ public void doInTransactionWithoutResult(TransactionStatus status) {
+ // add entries in acl_group_policy_map table
+ for (Long policyId : policyIds) {
+ IAMPolicy policy = _aclPolicyDao.findById(policyId);
+ if (policy == null) {
+ throw new InvalidParameterValueException("Unable to find acl policy: " + policyId
+ + "; failed to add policies to acl group.");
+ }
+
+ IAMGroupPolicyMapVO grMap = _aclGroupPolicyMapDao.findByGroupAndPolicy(groupId, policyId);
+ if (grMap == null) {
+ // not there already
+ grMap = new IAMGroupPolicyMapVO(groupId, policyId);
+ _aclGroupPolicyMapDao.persist(grMap);
+ }
+ }
+ }
+ });
+
+ return group;
+ }
+
+ @DB
+ @Override
+ public IAMGroup removeIAMPoliciesFromGroup(final List<Long> policyIds, final Long groupId) {
+ // get the Acl Group entity
+ IAMGroup group = _aclGroupDao.findById(groupId);
+ if (group == null) {
+ throw new InvalidParameterValueException("Unable to find acl group: " + groupId
+ + "; failed to remove roles from acl group.");
+ }
+
+ Transaction.execute(new TransactionCallbackNoReturn() {
+ @Override
+ public void doInTransactionWithoutResult(TransactionStatus status) {
+ // add entries in acl_group_role_map table
+ for (Long policyId : policyIds) {
+ IAMPolicy policy = _aclPolicyDao.findById(policyId);
+ if (policy == null) {
+ throw new InvalidParameterValueException("Unable to find acl policy: " + policyId
+ + "; failed to add policies to acl group.");
+ }
+
+ IAMGroupPolicyMapVO grMap = _aclGroupPolicyMapDao.findByGroupAndPolicy(groupId, policyId);
+ if (grMap != null) {
+ // not removed yet
+ _aclGroupPolicyMapDao.remove(grMap.getId());
+ }
+ }
+ }
+ });
+ return group;
+ }
+
+
+ @Override
+ public void attachIAMPolicyToAccounts(final Long policyId, final List<Long> acctIds) {
+ IAMPolicy policy = _aclPolicyDao.findById(policyId);
+ if (policy == null) {
+ throw new InvalidParameterValueException("Unable to find acl policy: " + policyId
+ + "; failed to add policy to account.");
+ }
+
+ Transaction.execute(new TransactionCallbackNoReturn() {
+ @Override
+ public void doInTransactionWithoutResult(TransactionStatus status) {
+ // add entries in acl_group_policy_map table
+ for (Long acctId : acctIds) {
+ IAMAccountPolicyMapVO acctMap = _aclAccountPolicyMapDao.findByAccountAndPolicy(acctId, policyId);
+ if (acctMap == null) {
+ // not there already
+ acctMap = new IAMAccountPolicyMapVO(acctId, policyId);
+ _aclAccountPolicyMapDao.persist(acctMap);
+ }
+ }
+ }
+ });
+ }
+
+ @Override
+ public void removeIAMPolicyFromAccounts(final Long policyId, final List<Long> acctIds) {
+ IAMPolicy policy = _aclPolicyDao.findById(policyId);
+ if (policy == null) {
+ throw new InvalidParameterValueException("Unable to find acl policy: " + policyId
+ + "; failed to add policy to account.");
+ }
+
+ Transaction.execute(new TransactionCallbackNoReturn() {
+ @Override
+ public void doInTransactionWithoutResult(TransactionStatus status) {
+ // add entries in acl_group_policy_map table
+ for (Long acctId : acctIds) {
+ IAMAccountPolicyMapVO acctMap = _aclAccountPolicyMapDao.findByAccountAndPolicy(acctId, policyId);
+ if (acctMap != null) {
+ // exists
+ _aclAccountPolicyMapDao.remove(acctMap.getId());
+ }
+ }
+ }
+ });
+ }
+
+ @DB
+ @Override
+ public IAMPolicy addIAMPermissionToIAMPolicy(long iamPolicyId, String entityType, String scope, Long scopeId,
+ String action, String accessType, Permission perm, Boolean recursive) {
+ // get the Acl Policy entity
+ IAMPolicy policy = _aclPolicyDao.findById(iamPolicyId);
+ if (policy == null) {
+ throw new InvalidParameterValueException("Unable to find acl policy: " + iamPolicyId
+ + "; failed to add permission to policy.");
+ }
+
+ // add entry in acl_policy_permission table
+ IAMPolicyPermissionVO permit = _policyPermissionDao.findByPolicyAndEntity(iamPolicyId, entityType, scope, scopeId, action, perm);
+ if (permit == null) {
+ // not there already
+ permit = new IAMPolicyPermissionVO(iamPolicyId, action, entityType, accessType, scope, scopeId, perm,
+ recursive);
+ _policyPermissionDao.persist(permit);
+ }
+ return policy;
+
+ }
+
+ @DB
+ @Override
+ public IAMPolicy removeIAMPermissionFromIAMPolicy(long iamPolicyId, String entityType, String scope, Long scopeId,
+ String action) {
+ // get the Acl Policy entity
+ IAMPolicy policy = _aclPolicyDao.findById(iamPolicyId);
+ if (policy == null) {
+ throw new InvalidParameterValueException("Unable to find acl policy: " + iamPolicyId
+ + "; failed to revoke permission from policy.");
+ }
+ // remove entry from acl_entity_permission table
+ IAMPolicyPermissionVO permit = _policyPermissionDao.findByPolicyAndEntity(iamPolicyId, entityType, scope, scopeId, action, Permission.Allow);
+ if (permit != null) {
+ // not removed yet
+ _policyPermissionDao.remove(permit.getId());
+ }
+ return policy;
+ }
+
+ @DB
+ @Override
+ public void removeIAMPermissionForEntity(final String entityType, final Long entityId) {
+ Transaction.execute(new TransactionCallbackNoReturn() {
+ @Override
+ public void doInTransactionWithoutResult(TransactionStatus status) {
+ // remove entry from acl_entity_permission table
+ List<IAMPolicyPermissionVO> permitList = _policyPermissionDao.listByEntity(entityType, entityId);
+ for (IAMPolicyPermissionVO permit : permitList) {
+ long policyId = permit.getAclPolicyId();
+ _policyPermissionDao.remove(permit.getId());
+
+ // remove the policy if there are no other permissions
+ if ((_policyPermissionDao.listByPolicy(policyId)).isEmpty()) {
+ deleteIAMPolicy(policyId);
+ }
+ }
+ }
+ });
+ }
+
+ @DB
+ @Override
+ public IAMPolicy resetIAMPolicy(long iamPolicyId) {
+ // get the Acl Policy entity
+ IAMPolicy policy = _aclPolicyDao.findById(iamPolicyId);
+ if (policy == null) {
+ throw new InvalidParameterValueException("Unable to find acl policy: " + iamPolicyId
+ + "; failed to reset the policy.");
+ }
+
+ SearchBuilder<IAMPolicyPermissionVO> sb = _policyPermissionDao.createSearchBuilder();
+ sb.and("policyId", sb.entity().getAclPolicyId(), SearchCriteria.Op.EQ);
+ sb.and("scope", sb.entity().getScope(), SearchCriteria.Op.EQ);
+ sb.done();
+ SearchCriteria<IAMPolicyPermissionVO> permissionSC = sb.create();
+ permissionSC.setParameters("policyId", iamPolicyId);
+ _policyPermissionDao.expunge(permissionSC);
+
+ return policy;
+ }
+
+ @Override
+ public boolean isActionAllowedForPolicies(String action, List<IAMPolicy> policies) {
+
+ boolean allowed = false;
+
+ if (policies == null || policies.size() == 0) {
+ return allowed;
+ }
+
+ List<Long> policyIds = new ArrayList<Long>();
+ for (IAMPolicy policy : policies) {
+ policyIds.add(policy.getId());
+ }
+
+ SearchBuilder<IAMPolicyPermissionVO> sb = _policyPermissionDao.createSearchBuilder();
+ sb.and("action", sb.entity().getAction(), Op.EQ);
+ sb.and("policyId", sb.entity().getAclPolicyId(), Op.IN);
+
+ SearchCriteria<IAMPolicyPermissionVO> sc = sb.create();
+ sc.setParameters("policyId", policyIds.toArray(new Object[policyIds.size()]));
+ sc.setParameters("action", action);
+
+ List<IAMPolicyPermissionVO> permissions = _policyPermissionDao.customSearch(sc, null);
+
+ if (permissions != null && !permissions.isEmpty()) {
+ allowed = true;
+ }
+
+ return allowed;
+ }
+
+
+ @Override
+ public List<Long> getGrantedEntities(long accountId, String action, String scope) {
+ // Get the static Policies of the Caller
+ List<IAMPolicy> policies = listIAMPolicies(accountId);
+ // for each policy, find granted permission within the given scope
+ List<Long> entityIds = new ArrayList<Long>();
+ for (IAMPolicy policy : policies) {
+ List<IAMPolicyPermissionVO> pp = _policyPermissionDao.listGrantedByActionAndScope(policy.getId(), action,
+ scope);
+ if (pp != null) {
+ for (IAMPolicyPermissionVO p : pp) {
+ if (p.getScopeId() != null) {
+ entityIds.add(p.getScopeId());
+ }
+ }
+ }
+ }
+ return entityIds;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public List<IAMPolicyPermission> listPolicyPermissions(long policyId) {
+ @SuppressWarnings("rawtypes")
+ List pp = _policyPermissionDao.listByPolicy(policyId);
+ return pp;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<IAMPolicyPermission> listPolicyPermissionsByScope(long policyId, String action, String scope) {
+ @SuppressWarnings("rawtypes")
+ List pp = _policyPermissionDao.listGrantedByActionAndScope(policyId, action, scope);
+ return pp;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<IAMPolicyPermission> listPolicyPermissionByActionAndEntity(long policyId, String action,
+ String entityType) {
+ @SuppressWarnings("rawtypes")
+ List pp = _policyPermissionDao.listByPolicyActionAndEntity(policyId, action, entityType);
+ return pp;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<IAMPolicyPermission> listPolicyPermissionByAccessAndEntity(long policyId, String accessType,
+ String entityType) {
+ @SuppressWarnings("rawtypes")
+ List pp = _policyPermissionDao.listByPolicyAccessAndEntity(policyId, accessType, entityType);
+ return pp;
+ }
+
+ @Override
+ public IAMPolicy getResourceOwnerPolicy() {
+ return _aclPolicyDao.findByName("RESOURCE_OWNER");
+ }
+
+ // search for policy with only one resource grant permission
+ @Override
+ public IAMPolicy getResourceGrantPolicy(String entityType, Long entityId, String accessType, String action) {
+ List<IAMPolicyVO> policyList = _aclPolicyDao.listAll();
+ for (IAMPolicyVO policy : policyList){
+ List<IAMPolicyPermission> pp = listPolicyPermissions(policy.getId());
+ if ( pp != null && pp.size() == 1){
+ // resource grant policy should only have one ACL permission assigned
+ IAMPolicyPermission permit = pp.get(0);
+ if ( permit.getEntityType().equals(entityType) && permit.getScope().equals(PermissionScope.RESOURCE.toString()) && permit.getScopeId().longValue() == entityId.longValue()){
+ if (accessType != null && permit.getAccessType().equals(accessType)){
+ return policy;
+ } else if (action != null && permit.getAction().equals(action)) {
+ return policy;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMAccountPolicyMapDao.java
----------------------------------------------------------------------
diff --git a/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMAccountPolicyMapDao.java b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMAccountPolicyMapDao.java
new file mode 100644
index 0000000..4caf659
--- /dev/null
+++ b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMAccountPolicyMapDao.java
@@ -0,0 +1,17 @@
+package org.apache.cloudstack.iam.server.dao;
+
+import java.util.List;
+
+import org.apache.cloudstack.iam.server.IAMAccountPolicyMapVO;
+
+import com.cloud.utils.db.GenericDao;
+
+public interface IAMAccountPolicyMapDao extends GenericDao<IAMAccountPolicyMapVO, Long> {
+
+ List<IAMAccountPolicyMapVO> listByAccountId(long acctId);
+
+ List<IAMAccountPolicyMapVO> listByPolicyId(long policyId);
+
+ IAMAccountPolicyMapVO findByAccountAndPolicy(long acctId, long policyId);
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMAccountPolicyMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMAccountPolicyMapDaoImpl.java b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMAccountPolicyMapDaoImpl.java
new file mode 100644
index 0000000..3ecca3b
--- /dev/null
+++ b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMAccountPolicyMapDaoImpl.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.IAMAccountPolicyMapVO;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+
+public class IAMAccountPolicyMapDaoImpl extends GenericDaoBase<IAMAccountPolicyMapVO, Long> implements IAMAccountPolicyMapDao {
+
+ private SearchBuilder<IAMAccountPolicyMapVO> ListByAccountId;
+ private SearchBuilder<IAMAccountPolicyMapVO> ListByPolicyId;
+ private SearchBuilder<IAMAccountPolicyMapVO> findByPolicyAccountId;
+
+ @Override
+ public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+ super.configure(name, params);
+
+ ListByAccountId = createSearchBuilder();
+ ListByAccountId.and("accountId", ListByAccountId.entity().getAccountId(), SearchCriteria.Op.EQ);
+ ListByAccountId.done();
+
+ ListByPolicyId = createSearchBuilder();
+ ListByPolicyId.and("policyId", ListByPolicyId.entity().getIamPolicyId(), SearchCriteria.Op.EQ);
+ ListByPolicyId.done();
+
+ findByPolicyAccountId = createSearchBuilder();
+ findByPolicyAccountId.and("policyId", findByPolicyAccountId.entity().getIamPolicyId(), SearchCriteria.Op.EQ);
+ findByPolicyAccountId.and("accountId", findByPolicyAccountId.entity().getAccountId(), SearchCriteria.Op.EQ);
+ findByPolicyAccountId.done();
+
+ return true;
+ }
+
+ @Override
+ public List<IAMAccountPolicyMapVO> listByAccountId(long acctId) {
+ SearchCriteria<IAMAccountPolicyMapVO> sc = ListByAccountId.create();
+ sc.setParameters("accountId", acctId);
+ return listBy(sc);
+ }
+
+ @Override
+ public List<IAMAccountPolicyMapVO> listByPolicyId(long policyId) {
+ SearchCriteria<IAMAccountPolicyMapVO> sc = ListByPolicyId.create();
+ sc.setParameters("policyId", policyId);
+ return listBy(sc);
+ }
+
+ @Override
+ public IAMAccountPolicyMapVO findByAccountAndPolicy(long acctId, long policyId) {
+ SearchCriteria<IAMAccountPolicyMapVO> sc = findByPolicyAccountId.create();
+ sc.setParameters("policyId", policyId);
+ sc.setParameters("accountId", acctId);
+ 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/IAMGroupAccountMapDao.java
----------------------------------------------------------------------
diff --git a/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupAccountMapDao.java b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupAccountMapDao.java
new file mode 100644
index 0000000..a94dbaa
--- /dev/null
+++ b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupAccountMapDao.java
@@ -0,0 +1,40 @@
+// 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.server.IAMGroupAccountMapVO;
+
+import com.cloud.utils.db.GenericDao;
+
+public interface IAMGroupAccountMapDao extends GenericDao<IAMGroupAccountMapVO, Long> {
+
+ List<IAMGroupAccountMapVO> listByGroupId(long groupId);
+
+ List<IAMGroupAccountMapVO> listByAccountId(long accountId);
+
+ IAMGroupAccountMapVO findAccountInAdminGroup(long accountId);
+
+ IAMGroupAccountMapVO findByGroupAndAccount(long groupId, long acctId);
+
+ void removeAccountFromGroups(long accountId);
+
+ IAMGroupAccountMapVO findAccountInDomainAdminGroup(long accountId);
+
+ IAMGroupAccountMapVO findAccountInUserGroup(long accountId);
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupAccountMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupAccountMapDaoImpl.java b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupAccountMapDaoImpl.java
new file mode 100644
index 0000000..4bb5d1a
--- /dev/null
+++ b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupAccountMapDaoImpl.java
@@ -0,0 +1,119 @@
+// 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.server.IAMGroupAccountMapVO;
+import org.apache.log4j.Logger;
+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 IAMGroupAccountMapDaoImpl extends GenericDaoBase<IAMGroupAccountMapVO, Long> implements IAMGroupAccountMapDao {
+ private SearchBuilder<IAMGroupAccountMapVO> ListByGroupId;
+ private SearchBuilder<IAMGroupAccountMapVO> ListByAccountId;
+ private SearchBuilder<IAMGroupAccountMapVO> _findByAccountAndGroupId;
+
+ public static final Logger s_logger = Logger.getLogger(IAMGroupAccountMapDaoImpl.class.getName());
+
+ @Override
+ public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+ super.configure(name, params);
+
+ ListByGroupId = createSearchBuilder();
+ ListByGroupId.and("groupId", ListByGroupId.entity().getAclGroupId(), SearchCriteria.Op.EQ);
+ ListByGroupId.done();
+
+ ListByAccountId = createSearchBuilder();
+ ListByAccountId.and("accountId", ListByAccountId.entity().getAccountId(), SearchCriteria.Op.EQ);
+ ListByAccountId.done();
+
+ _findByAccountAndGroupId = createSearchBuilder();
+ _findByAccountAndGroupId
+ .and("groupId", _findByAccountAndGroupId.entity().getAclGroupId(), SearchCriteria.Op.EQ);
+ _findByAccountAndGroupId.and("accountId", _findByAccountAndGroupId.entity().getAccountId(),
+ SearchCriteria.Op.EQ);
+ _findByAccountAndGroupId.done();
+
+ return true;
+ }
+
+ @Override
+ public List<IAMGroupAccountMapVO> listByGroupId(long groupId) {
+ SearchCriteria<IAMGroupAccountMapVO> sc = ListByGroupId.create();
+ sc.setParameters("groupId", groupId);
+ return listBy(sc);
+ }
+
+ @Override
+ public List<IAMGroupAccountMapVO> listByAccountId(long accountId) {
+ SearchCriteria<IAMGroupAccountMapVO> sc = ListByAccountId.create();
+ sc.setParameters("accountId", accountId);
+ return listBy(sc);
+ }
+
+ @Override
+ public IAMGroupAccountMapVO findAccountInAdminGroup(long accountId) {
+ SearchCriteria<IAMGroupAccountMapVO> sc = _findByAccountAndGroupId.create();
+ sc.setParameters("accountId", accountId);
+ sc.setParameters("groupId", 2);
+ return findOneBy(sc);
+ }
+
+ @Override
+ public IAMGroupAccountMapVO findAccountInDomainAdminGroup(long accountId) {
+ SearchCriteria<IAMGroupAccountMapVO> sc = _findByAccountAndGroupId.create();
+ sc.setParameters("accountId", accountId);
+ sc.setParameters("groupId", 3);
+ return findOneBy(sc);
+ }
+
+ @Override
+ public IAMGroupAccountMapVO findAccountInUserGroup(long accountId) {
+ SearchCriteria<IAMGroupAccountMapVO> sc = _findByAccountAndGroupId.create();
+ sc.setParameters("accountId", accountId);
+ sc.setParameters("groupId", 1);
+ return findOneBy(sc);
+ }
+
+ @Override
+ public IAMGroupAccountMapVO findByGroupAndAccount(long groupId, long acctId) {
+ SearchCriteria<IAMGroupAccountMapVO> sc = _findByAccountAndGroupId.create();
+ sc.setParameters("accountId", acctId);
+ sc.setParameters("groupId", groupId);
+ return findOneBy(sc);
+ }
+
+ @Override
+ public void removeAccountFromGroups(long accountId) {
+ SearchCriteria<IAMGroupAccountMapVO> sc = ListByAccountId.create();
+ sc.setParameters("accountId", accountId);
+
+ int rowsRemoved = remove(sc);
+ if (rowsRemoved > 0) {
+ s_logger.debug("Removed account id=" + accountId + " from " + rowsRemoved + " groups");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupDao.java
----------------------------------------------------------------------
diff --git a/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupDao.java b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupDao.java
new file mode 100644
index 0000000..54408a6
--- /dev/null
+++ b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupDao.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.IAMGroup;
+import org.apache.cloudstack.iam.server.IAMGroupVO;
+
+import com.cloud.utils.db.GenericDao;
+
+public interface IAMGroupDao extends GenericDao<IAMGroupVO, Long> {
+
+ IAMGroup findByName(String path, String groupName);
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adb29b21/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupDaoImpl.java
----------------------------------------------------------------------
diff --git a/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupDaoImpl.java b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupDaoImpl.java
new file mode 100644
index 0000000..45be0b3
--- /dev/null
+++ b/services/iam/server/src/org/apache/cloudstack/iam/server/dao/IAMGroupDaoImpl.java
@@ -0,0 +1,59 @@
+// 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.IAMGroup;
+import org.apache.cloudstack.iam.server.IAMGroupVO;
+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 IAMGroupDaoImpl extends GenericDaoBase<IAMGroupVO, Long> implements IAMGroupDao {
+ private SearchBuilder<IAMGroupVO> nameSearch;
+
+ @Override
+ public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+ super.configure(name, params);
+
+ nameSearch = createSearchBuilder();
+ nameSearch.and("name", nameSearch.entity().getName(), SearchCriteria.Op.EQ);
+ nameSearch.and("path", nameSearch.entity().getPath(), SearchCriteria.Op.EQ);
+ nameSearch.done();
+
+
+ return true;
+ }
+
+ @Override
+ public IAMGroup findByName(String path, String name) {
+ SearchCriteria<IAMGroupVO> sc = nameSearch.create();
+ sc.setParameters("name", name);
+ if (path != null) {
+ sc.setParameters("path", path);
+ }
+ return findOneBy(sc);
+ }
+
+}
[4/9] CLOUDSTACK-5920: IAM service server.
Posted by mc...@apache.org.
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<IAMGroupPolicyMapVO, Long> {
+
+ List<IAMGroupPolicyMapVO> listByGroupId(long groupId);
+
+ List<IAMGroupPolicyMapVO> 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<IAMGroupPolicyMapVO, Long> implements IAMGroupPolicyMapDao {
+
+ private SearchBuilder<IAMGroupPolicyMapVO> ListByGroupId;
+ private SearchBuilder<IAMGroupPolicyMapVO> ListByPolicyId;
+ private SearchBuilder<IAMGroupPolicyMapVO> findByPolicyGroupId;
+
+ @Override
+ public boolean configure(String name, Map<String, Object> 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<IAMGroupPolicyMapVO> listByGroupId(long groupId) {
+ SearchCriteria<IAMGroupPolicyMapVO> sc = ListByGroupId.create();
+ sc.setParameters("groupId", groupId);
+ return listBy(sc);
+ }
+
+ @Override
+ public List<IAMGroupPolicyMapVO> listByPolicyId(long policyId) {
+ SearchCriteria<IAMGroupPolicyMapVO> sc = ListByPolicyId.create();
+ sc.setParameters("policyId", policyId);
+ return listBy(sc);
+ }
+
+ @Override
+ public IAMGroupPolicyMapVO findByGroupAndPolicy(long groupId, long policyId) {
+ SearchCriteria<IAMGroupPolicyMapVO> 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<IAMPolicyVO, Long> {
+
+ 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<IAMPolicyVO, Long> implements IAMPolicyDao {
+ private SearchBuilder<IAMPolicyVO> nameSearch;
+
+ @Override
+ public boolean configure(String name, Map<String, Object> 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<IAMPolicyVO> 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<IAMPolicyPermissionVO, Long> {
+
+ List<IAMPolicyPermissionVO> listByPolicy(long policyId);
+
+ IAMPolicyPermissionVO findByPolicyAndEntity(long policyId, String entityType, String scope, Long scopeId,
+ String action, Permission perm);
+
+ List<IAMPolicyPermissionVO> listGrantedByActionAndScope(long policyId, String action, String scope);
+
+ List<IAMPolicyPermissionVO> listByPolicyActionAndEntity(long policyId, String action, String entityType);
+
+ List<IAMPolicyPermissionVO> listByPolicyAccessAndEntity(long policyId, String accessType, String entityType);
+
+ List<IAMPolicyPermissionVO> 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<IAMPolicyPermissionVO, Long> implements
+ IAMPolicyPermissionDao {
+
+ private SearchBuilder<IAMPolicyPermissionVO> policyIdSearch;
+ private SearchBuilder<IAMPolicyPermissionVO> fullSearch;
+ private SearchBuilder<IAMPolicyPermissionVO> actionScopeSearch;
+ private SearchBuilder<IAMPolicyPermissionVO> entitySearch;
+
+ @Override
+ public boolean configure(String name, Map<String, Object> 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<IAMPolicyPermissionVO> listByPolicy(long policyId) {
+ SearchCriteria<IAMPolicyPermissionVO> 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<IAMPolicyPermissionVO> 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<IAMPolicyPermissionVO> listGrantedByActionAndScope(long policyId, String action, String scope) {
+ SearchCriteria<IAMPolicyPermissionVO> 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<IAMPolicyPermissionVO> listByPolicyActionAndEntity(long policyId, String action, String entityType) {
+ SearchCriteria<IAMPolicyPermissionVO> sc = fullSearch.create();
+ sc.setParameters("policyId", policyId);
+ sc.setParameters("entityType", entityType);
+ sc.setParameters("action", action);
+ return listBy(sc);
+ }
+
+ @Override
+ public List<IAMPolicyPermissionVO> listByPolicyAccessAndEntity(long policyId, String accessType,
+ String entityType) {
+ SearchCriteria<IAMPolicyPermissionVO> sc = fullSearch.create();
+ sc.setParameters("policyId", policyId);
+ sc.setParameters("entityType", entityType);
+ sc.setParameters("accessType", accessType);
+ return listBy(sc);
+ }
+
+ @Override
+ public List<IAMPolicyPermissionVO> listByEntity(String entityType, Long entityId) {
+ SearchCriteria<IAMPolicyPermissionVO> 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<IAMGroupVO> groups = new ArrayList<IAMGroupVO>();
+ 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<Long> accountIds = new ArrayList<Long>();
+ 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
[2/9] CLOUDSTACK-5920: IAM service plugin.
Posted by mc...@apache.org.
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/src/org/apache/cloudstack/api/response/iam/IAMPermissionResponse.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/api/response/iam/IAMPermissionResponse.java b/services/iam/plugin/src/org/apache/cloudstack/api/response/iam/IAMPermissionResponse.java
new file mode 100644
index 0000000..b7af4da
--- /dev/null
+++ b/services/iam/plugin/src/org/apache/cloudstack/api/response/iam/IAMPermissionResponse.java
@@ -0,0 +1,125 @@
+// 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.api.response.iam;
+
+import com.google.gson.annotations.SerializedName;
+
+import org.apache.cloudstack.acl.IAMEntityType;
+import org.apache.cloudstack.acl.PermissionScope;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseResponse;
+import org.apache.cloudstack.iam.api.IAMPolicyPermission;
+
+import com.cloud.serializer.Param;
+
+public class IAMPermissionResponse extends BaseResponse {
+
+ @SerializedName(ApiConstants.IAM_ACTION)
+ @Param(description = "action of this permission")
+ private String action;
+
+ @SerializedName(ApiConstants.ENTITY_TYPE)
+ @Param(description = "the entity type of this permission")
+ private IAMEntityType entityType;
+
+ @SerializedName(ApiConstants.IAM_SCOPE)
+ @Param(description = "scope of this permission")
+ private PermissionScope scope;
+
+ @SerializedName(ApiConstants.IAM_SCOPE_ID)
+ @Param(description = "scope id of this permission")
+ private Long scopeId;
+
+ @SerializedName(ApiConstants.IAM_ALLOW_DENY)
+ @Param(description = "allow or deny of this permission")
+ private IAMPolicyPermission.Permission permission;
+
+ public IAMEntityType getEntityType() {
+ return entityType;
+ }
+
+ public void setEntityType(IAMEntityType entityType) {
+ this.entityType = entityType;
+ }
+
+ public String getAction() {
+ return action;
+ }
+
+ public void setAction(String action) {
+ this.action = action;
+ }
+
+ public PermissionScope getScope() {
+ return scope;
+ }
+
+ public void setScope(PermissionScope scope) {
+ this.scope = scope;
+ }
+
+ public Long getScopeId() {
+ return scopeId;
+ }
+
+ public void setScopeId(Long scopeId) {
+ this.scopeId = scopeId;
+ }
+
+ public IAMPolicyPermission.Permission getPermission() {
+ return permission;
+ }
+
+ public void setPermission(IAMPolicyPermission.Permission permission) {
+ this.permission = permission;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((action == null) ? 0 : action.hashCode());
+ result = prime * result + ((entityType == null) ? 0 : entityType.hashCode());
+ result = prime * result + ((scope == null) ? 0 : scope.hashCode());
+ result = prime * result + ((scopeId == null) ? 0 : scopeId.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ IAMPermissionResponse other = (IAMPermissionResponse) obj;
+ if ((entityType == null && other.entityType != null) || !entityType.equals(other.entityType)) {
+ return false;
+ } else if ((action == null && other.action != null) || !action.equals(other.action)) {
+ return false;
+ } else if ((scope == null && other.scope != null) || !scope.equals(other.scope)) {
+ return false;
+ } else if ((scopeId == null && other.scopeId != null) || !scopeId.equals(other.scopeId)) {
+ return false;
+ }
+ return true;
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/src/org/apache/cloudstack/api/response/iam/IAMPolicyResponse.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/api/response/iam/IAMPolicyResponse.java b/services/iam/plugin/src/org/apache/cloudstack/api/response/iam/IAMPolicyResponse.java
new file mode 100644
index 0000000..dc29369
--- /dev/null
+++ b/services/iam/plugin/src/org/apache/cloudstack/api/response/iam/IAMPolicyResponse.java
@@ -0,0 +1,177 @@
+// 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.api.response.iam;
+
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import com.google.gson.annotations.SerializedName;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseResponse;
+import org.apache.cloudstack.api.EntityReference;
+import org.apache.cloudstack.api.response.ControlledViewEntityResponse;
+import org.apache.cloudstack.iam.api.IAMPolicy;
+
+import com.cloud.serializer.Param;
+
+@SuppressWarnings("unused")
+@EntityReference(value = IAMPolicy.class)
+public class IAMPolicyResponse extends BaseResponse implements ControlledViewEntityResponse {
+
+ @SerializedName(ApiConstants.ID)
+ @Param(description = "the ID of the iam policy")
+ private String id;
+
+ @SerializedName(ApiConstants.NAME)
+ @Param(description = "the name of the iam policy")
+ private String name;
+
+ @SerializedName(ApiConstants.DESCRIPTION)
+ @Param(description = "the description of the iam policy")
+ private String description;
+
+ @SerializedName(ApiConstants.DOMAIN_ID)
+ @Param(description = "the domain ID of the iam policy")
+ private String domainId;
+
+ @SerializedName(ApiConstants.DOMAIN)
+ @Param(description = "the domain name of the iam policy")
+ private String domainName;
+
+ @SerializedName(ApiConstants.ACCOUNT)
+ @Param(description = "the account owning the policy")
+ private String accountName;
+
+ @SerializedName(ApiConstants.IAM_PERMISSIONS)
+ @Param(description = "set of permissions for the iam policy")
+ private Set<IAMPermissionResponse> permissionList;
+
+ public IAMPolicyResponse() {
+ permissionList = new LinkedHashSet<IAMPermissionResponse>();
+ }
+
+ @Override
+ public String getObjectId() {
+ return getId();
+ }
+
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ @Override
+ public void setDomainId(String domainId) {
+ this.domainId = domainId;
+ }
+
+ @Override
+ public void setDomainName(String domainName) {
+ this.domainName = domainName;
+ }
+
+ public Set<IAMPermissionResponse> getPermissionList() {
+ return permissionList;
+ }
+
+ public void setPermissionList(Set<IAMPermissionResponse> perms) {
+ permissionList = perms;
+ }
+
+ public void addPermission(IAMPermissionResponse perm) {
+ permissionList.add(perm);
+ }
+
+ @Override
+ public void setAccountName(String accountName) {
+ this.accountName = accountName;
+ }
+
+ @Override
+ public void setProjectId(String projectId) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setProjectName(String projectName) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getDomainId() {
+ return domainId;
+ }
+
+ public String getDomainName() {
+ return domainName;
+ }
+
+ public String getAccountName() {
+ return accountName;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ IAMPolicyResponse other = (IAMPolicyResponse) obj;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ return true;
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/src/org/apache/cloudstack/iam/IAMApiService.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/iam/IAMApiService.java b/services/iam/plugin/src/org/apache/cloudstack/iam/IAMApiService.java
new file mode 100644
index 0000000..bb8f03b
--- /dev/null
+++ b/services/iam/plugin/src/org/apache/cloudstack/iam/IAMApiService.java
@@ -0,0 +1,87 @@
+// 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 java.util.List;
+
+import org.apache.cloudstack.acl.PermissionScope;
+import org.apache.cloudstack.acl.SecurityChecker.AccessType;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.iam.IAMGroupResponse;
+import org.apache.cloudstack.api.response.iam.IAMPolicyResponse;
+import org.apache.cloudstack.iam.api.IAMGroup;
+import org.apache.cloudstack.iam.api.IAMPolicy;
+import org.apache.cloudstack.iam.api.IAMPolicyPermission;
+import org.apache.cloudstack.iam.api.IAMPolicyPermission.Permission;
+
+import com.cloud.user.Account;
+import com.cloud.utils.component.PluggableService;
+
+public interface IAMApiService extends PluggableService {
+
+ /* ACL group related interfaces */
+ IAMGroup createIAMGroup(Account caller, String iamGroupName, String description);
+
+ boolean deleteIAMGroup(Long iamGroupId);
+
+ List<IAMGroup> listIAMGroups(long accountId);
+
+ IAMGroup addAccountsToGroup(List<Long> acctIds, Long groupId);
+
+ IAMGroup removeAccountsFromGroup(List<Long> acctIds, Long groupId);
+
+ /* IAM Policy related interfaces */
+ IAMPolicy createIAMPolicy(Account caller, String iamPolicyName, String description, Long parentPolicyId);
+
+ boolean deleteIAMPolicy(long iamPolicyId);
+
+ List<IAMPolicy> listIAMPolicies(long accountId);
+
+ IAMGroup attachIAMPoliciesToGroup(List<Long> policyIds, Long groupId);
+
+ IAMGroup removeIAMPoliciesFromGroup(List<Long> policyIds, Long groupId);
+
+ void attachIAMPolicyToAccounts(Long policyId, List<Long> accountIds);
+
+ void removeIAMPolicyFromAccounts(Long policyId, List<Long> accountIds);
+
+ IAMPolicy addIAMPermissionToIAMPolicy(long iamPolicyId, String entityType, PermissionScope scope, Long scopeId,
+ String action, Permission perm, Boolean recursive);
+
+ IAMPolicy removeIAMPermissionFromIAMPolicy(long iamPolicyId, String entityType, PermissionScope scope, Long scopeId, String action);
+
+ IAMPolicyPermission getIAMPolicyPermission(long accountId, String entityType, String action);
+
+ /* Utility routine to grant/revoke invidivual resource to list of accounts */
+ void grantEntityPermissioinToAccounts(String entityType, Long entityId, AccessType accessType, String action, List<Long> accountIds);
+
+ void revokeEntityPermissioinFromAccounts(String entityType, Long entityId, AccessType accessType, String action, List<Long> accountIds);
+
+ /* Response Generation */
+ IAMPolicyResponse createIAMPolicyResponse(IAMPolicy policy);
+
+ IAMGroupResponse createIAMGroupResponse(IAMGroup group);
+
+ ListResponse<IAMGroupResponse> listIAMGroups(Long iamGroupId, String iamGroupName,
+ Long domainId, Long startIndex, Long pageSize);
+
+ ListResponse<IAMPolicyResponse> listIAMPolicies(Long iamPolicyId, String iamPolicyName,
+ Long domainId, Long startIndex, Long pageSize);
+
+ // Convert passed scope uuid to internal scope long id
+ Long getPermissionScopeId(String scope, String entityType, String scopeId);
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/src/org/apache/cloudstack/iam/IAMApiServiceImpl.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/iam/IAMApiServiceImpl.java b/services/iam/plugin/src/org/apache/cloudstack/iam/IAMApiServiceImpl.java
new file mode 100644
index 0000000..97519f2
--- /dev/null
+++ b/services/iam/plugin/src/org/apache/cloudstack/iam/IAMApiServiceImpl.java
@@ -0,0 +1,800 @@
+// 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 java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.acl.IAMEntityType;
+import org.apache.cloudstack.acl.PermissionScope;
+import org.apache.cloudstack.acl.SecurityChecker.AccessType;
+import org.apache.cloudstack.affinity.AffinityGroupVO;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseListCmd;
+import org.apache.cloudstack.api.InternalIdentity;
+import org.apache.cloudstack.api.command.iam.AddAccountToIAMGroupCmd;
+import org.apache.cloudstack.api.command.iam.AddIAMPermissionToIAMPolicyCmd;
+import org.apache.cloudstack.api.command.iam.AttachIAMPolicyToAccountCmd;
+import org.apache.cloudstack.api.command.iam.AttachIAMPolicyToIAMGroupCmd;
+import org.apache.cloudstack.api.command.iam.CreateIAMGroupCmd;
+import org.apache.cloudstack.api.command.iam.CreateIAMPolicyCmd;
+import org.apache.cloudstack.api.command.iam.DeleteIAMGroupCmd;
+import org.apache.cloudstack.api.command.iam.DeleteIAMPolicyCmd;
+import org.apache.cloudstack.api.command.iam.ListIAMGroupsCmd;
+import org.apache.cloudstack.api.command.iam.ListIAMPoliciesCmd;
+import org.apache.cloudstack.api.command.iam.RemoveAccountFromIAMGroupCmd;
+import org.apache.cloudstack.api.command.iam.RemoveIAMPermissionFromIAMPolicyCmd;
+import org.apache.cloudstack.api.command.iam.RemoveIAMPolicyFromAccountCmd;
+import org.apache.cloudstack.api.command.iam.RemoveIAMPolicyFromIAMGroupCmd;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.iam.IAMGroupResponse;
+import org.apache.cloudstack.api.response.iam.IAMPermissionResponse;
+import org.apache.cloudstack.api.response.iam.IAMPolicyResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO;
+import org.apache.cloudstack.framework.messagebus.MessageBus;
+import org.apache.cloudstack.framework.messagebus.MessageSubscriber;
+import org.apache.cloudstack.iam.api.IAMGroup;
+import org.apache.cloudstack.iam.api.IAMPolicy;
+import org.apache.cloudstack.iam.api.IAMPolicyPermission;
+import org.apache.cloudstack.iam.api.IAMPolicyPermission.Permission;
+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.region.gslb.GlobalLoadBalancerRuleVO;
+
+import com.cloud.api.ApiServerService;
+import com.cloud.domain.Domain;
+import com.cloud.domain.DomainVO;
+import com.cloud.domain.dao.DomainDao;
+import com.cloud.event.ActionEvent;
+import com.cloud.event.EventTypes;
+import com.cloud.event.EventVO;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.network.UserIpv6AddressVO;
+import com.cloud.network.VpnUserVO;
+import com.cloud.network.as.AutoScalePolicyVO;
+import com.cloud.network.as.AutoScaleVmGroupVO;
+import com.cloud.network.as.AutoScaleVmProfileVO;
+import com.cloud.network.as.ConditionVO;
+import com.cloud.network.dao.IPAddressVO;
+import com.cloud.network.dao.MonitoringServiceVO;
+import com.cloud.network.dao.NetworkVO;
+import com.cloud.network.dao.RemoteAccessVpnVO;
+import com.cloud.network.dao.Site2SiteCustomerGatewayVO;
+import com.cloud.network.dao.Site2SiteVpnConnectionVO;
+import com.cloud.network.dao.Site2SiteVpnGatewayVO;
+import com.cloud.network.dao.SslCertVO;
+import com.cloud.network.rules.FirewallRuleVO;
+import com.cloud.network.rules.PortForwardingRuleVO;
+import com.cloud.network.security.SecurityGroupVO;
+import com.cloud.network.vpc.StaticRouteVO;
+import com.cloud.network.vpc.VpcGatewayVO;
+import com.cloud.network.vpc.VpcVO;
+import com.cloud.projects.ProjectInvitationVO;
+import com.cloud.storage.SnapshotVO;
+import com.cloud.storage.VMTemplateVO;
+import com.cloud.storage.VolumeVO;
+import com.cloud.tags.ResourceTagVO;
+import com.cloud.template.TemplateManager;
+import com.cloud.user.Account;
+import com.cloud.user.AccountManager;
+import com.cloud.user.AccountVO;
+import com.cloud.user.DomainManager;
+import com.cloud.user.SSHKeyPairVO;
+import com.cloud.user.dao.AccountDao;
+import com.cloud.utils.Pair;
+import com.cloud.utils.component.Manager;
+import com.cloud.utils.component.ManagerBase;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.EntityManager;
+import com.cloud.vm.InstanceGroupVO;
+import com.cloud.vm.VMInstanceVO;
+import com.cloud.vm.dao.NicIpAliasVO;
+import com.cloud.vm.dao.NicSecondaryIpVO;
+import com.cloud.vm.snapshot.VMSnapshotVO;
+
+@Local(value = {IAMApiService.class})
+public class IAMApiServiceImpl extends ManagerBase implements IAMApiService, Manager {
+
+ public static final Logger s_logger = Logger.getLogger(IAMApiServiceImpl.class);
+ private String _name;
+
+ @Inject
+ ApiServerService _apiServer;
+
+ @Inject
+ IAMService _iamSrv;
+
+ @Inject
+ DomainDao _domainDao;
+
+ @Inject
+ AccountDao _accountDao;
+
+ @Inject
+ AccountManager _accountMgr;
+
+ @Inject
+ MessageBus _messageBus;
+
+ @Inject
+ EntityManager _entityMgr;
+
+ private static final Map<IAMEntityType, Class<?>> s_typeMap = new HashMap<IAMEntityType, Class<?>>();
+ static {
+ s_typeMap.put(IAMEntityType.VirtualMachine, VMInstanceVO.class);
+ s_typeMap.put(IAMEntityType.Volume, VolumeVO.class);
+ s_typeMap.put(IAMEntityType.ResourceTag, ResourceTagVO.class);
+ s_typeMap.put(IAMEntityType.Account, AccountVO.class);
+ s_typeMap.put(IAMEntityType.AffinityGroup, AffinityGroupVO.class);
+ s_typeMap.put(IAMEntityType.AutoScalePolicy, AutoScalePolicyVO.class);
+ s_typeMap.put(IAMEntityType.AutoScaleVmProfile, AutoScaleVmProfileVO.class);
+ s_typeMap.put(IAMEntityType.AutoScaleVmGroup, AutoScaleVmGroupVO.class);
+ s_typeMap.put(IAMEntityType.Condition, ConditionVO.class);
+ s_typeMap.put(IAMEntityType.Vpc, VpcVO.class);
+ s_typeMap.put(IAMEntityType.VpcGateway, VpcGatewayVO.class);
+ s_typeMap.put(IAMEntityType.PrivateGateway, RemoteAccessVpnVO.class);
+ s_typeMap.put(IAMEntityType.VpnUser, VpnUserVO.class);
+ s_typeMap.put(IAMEntityType.VMSnapshot, VMSnapshotVO.class);
+ s_typeMap.put(IAMEntityType.VirtualMachineTemplate, VMTemplateVO.class);
+ s_typeMap.put(IAMEntityType.UserIpv6Address, UserIpv6AddressVO.class);
+ s_typeMap.put(IAMEntityType.StaticRoute, StaticRouteVO.class);
+ s_typeMap.put(IAMEntityType.SSHKeyPair, SSHKeyPairVO.class);
+ s_typeMap.put(IAMEntityType.Snapshot, SnapshotVO.class);
+ s_typeMap.put(IAMEntityType.Site2SiteVpnGateway, Site2SiteVpnGatewayVO.class);
+ s_typeMap.put(IAMEntityType.Site2SiteCustomerGateway, Site2SiteCustomerGatewayVO.class);
+ s_typeMap.put(IAMEntityType.Site2SiteVpnConnection, Site2SiteVpnConnectionVO.class);
+ s_typeMap.put(IAMEntityType.SecurityGroup, SecurityGroupVO.class);
+ s_typeMap.put(IAMEntityType.RemoteAccessVpn, RemoteAccessVpnVO.class);
+ s_typeMap.put(IAMEntityType.PublicIpAddress, IPAddressVO.class);
+ s_typeMap.put(IAMEntityType.ProjectInvitation, ProjectInvitationVO.class);
+ s_typeMap.put(IAMEntityType.NicSecondaryIp, NicSecondaryIpVO.class);
+ s_typeMap.put(IAMEntityType.NicIpAlias, NicIpAliasVO.class);
+ s_typeMap.put(IAMEntityType.Network, NetworkVO.class);
+ s_typeMap.put(IAMEntityType.IpAddress, IPAddressVO.class);
+ s_typeMap.put(IAMEntityType.InstanceGroup, InstanceGroupVO.class);
+ s_typeMap.put(IAMEntityType.GlobalLoadBalancerRule, GlobalLoadBalancerRuleVO.class);
+ s_typeMap.put(IAMEntityType.FirewallRule, FirewallRuleVO.class);
+ s_typeMap.put(IAMEntityType.PortForwardingRule, PortForwardingRuleVO.class);
+ s_typeMap.put(IAMEntityType.Event, EventVO.class);
+ s_typeMap.put(IAMEntityType.AsyncJob, AsyncJobVO.class);
+ s_typeMap.put(IAMEntityType.IAMGroup, IAMGroupVO.class);
+ s_typeMap.put(IAMEntityType.IAMPolicy, IAMPolicyVO.class);
+ s_typeMap.put(IAMEntityType.MonitorService, MonitoringServiceVO.class);
+ s_typeMap.put(IAMEntityType.SSLCert, SslCertVO.class);
+ }
+
+ @Override
+ public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
+ _messageBus.subscribe(AccountManager.MESSAGE_ADD_ACCOUNT_EVENT, new MessageSubscriber() {
+ @Override
+ public void onPublishMessage(String senderAddress, String subject, Object obj) {
+ HashMap<Long, Long> acctGroupMap = (HashMap<Long, Long>) obj;
+ for (Long accountId : acctGroupMap.keySet()) {
+ Long groupId = acctGroupMap.get(accountId);
+ s_logger.debug("MessageBus message: new Account Added: " + accountId + ", adding it to groupId :"
+ + groupId);
+ addAccountToIAMGroup(accountId, groupId);
+ // add it to domain group too
+ AccountVO account = _accountDao.findById(accountId);
+ Domain domain = _domainDao.findById(account.getDomainId());
+ if (domain != null) {
+ List<IAMGroup> domainGroups = listDomainGroup(domain);
+
+ if (domainGroups != null) {
+ for (IAMGroup group : domainGroups) {
+ addAccountToIAMGroup(accountId, new Long(group.getId()));
+ }
+ }
+ }
+ }
+ }
+ });
+
+ _messageBus.subscribe(AccountManager.MESSAGE_REMOVE_ACCOUNT_EVENT, new MessageSubscriber() {
+ @Override
+ public void onPublishMessage(String senderAddress, String subject, Object obj) {
+ Long accountId = ((Long) obj);
+ if (accountId != null) {
+ s_logger.debug("MessageBus message: Account removed: " + accountId
+ + ", releasing the group associations");
+ removeAccountFromIAMGroups(accountId);
+ }
+ }
+ });
+
+ _messageBus.subscribe(DomainManager.MESSAGE_ADD_DOMAIN_EVENT, new MessageSubscriber() {
+ @Override
+ public void onPublishMessage(String senderAddress, String subject, Object obj) {
+ Long domainId = ((Long) obj);
+ if (domainId != null) {
+ s_logger.debug("MessageBus message: new Domain created: " + domainId + ", creating a new group");
+ Domain domain = _domainDao.findById(domainId);
+ _iamSrv.createIAMGroup("DomainGrp-" + domain.getUuid(), "Domain group", domain.getPath());
+ }
+ }
+ });
+
+ _messageBus.subscribe(DomainManager.MESSAGE_REMOVE_DOMAIN_EVENT, new MessageSubscriber() {
+ @Override
+ public void onPublishMessage(String senderAddress, String subject, Object obj) {
+ Long domainId = ((Long) obj);
+ if (domainId != null) {
+ s_logger.debug("MessageBus message: Domain removed: " + domainId + ", removing the domain group");
+ Domain domain = _domainDao.findById(domainId);
+ List<IAMGroup> groups = listDomainGroup(domain);
+ for (IAMGroup group : groups) {
+ _iamSrv.deleteIAMGroup(group.getId());
+ }
+ }
+ }
+ });
+
+ _messageBus.subscribe(TemplateManager.MESSAGE_REGISTER_PUBLIC_TEMPLATE_EVENT, new MessageSubscriber() {
+ @Override
+ public void onPublishMessage(String senderAddress, String subject, Object obj) {
+ Long templateId = (Long)obj;
+ if (templateId != null) {
+ s_logger.debug("MessageBus message: new public template registered: " + templateId + ", grant permission to domain admin and normal user policies");
+ _iamSrv.addIAMPermissionToIAMPolicy(new Long(Account.ACCOUNT_TYPE_DOMAIN_ADMIN + 1), IAMEntityType.VirtualMachineTemplate.toString(),
+ PermissionScope.RESOURCE.toString(), templateId, "listTemplates", AccessType.UseEntry.toString(), Permission.Allow, false);
+ _iamSrv.addIAMPermissionToIAMPolicy(new Long(Account.ACCOUNT_TYPE_NORMAL + 1), IAMEntityType.VirtualMachineTemplate.toString(),
+ PermissionScope.RESOURCE.toString(), templateId, "listTemplates", AccessType.UseEntry.toString(), Permission.Allow, false);
+ }
+ }
+ });
+
+ _messageBus.subscribe(TemplateManager.MESSAGE_RESET_TEMPLATE_PERMISSION_EVENT, new MessageSubscriber() {
+ @Override
+ public void onPublishMessage(String senderAddress, String subject, Object obj) {
+ Long templateId = (Long)obj;
+ if (templateId != null) {
+ s_logger.debug("MessageBus message: reset template permission: " + templateId);
+ resetTemplatePermission(templateId);
+ }
+ }
+ });
+
+ _messageBus.subscribe(EntityManager.MESSAGE_REMOVE_ENTITY_EVENT, new MessageSubscriber() {
+ @Override
+ public void onPublishMessage(String senderAddress, String subject, Object obj) {
+ Pair<IAMEntityType, Long> entity = (Pair<IAMEntityType, Long>)obj;
+ if (entity != null) {
+ String entityType = entity.first().toString();
+ Long entityId = entity.second();
+ s_logger.debug("MessageBus message: delete an entity: (" + entityType + "," + entityId + "), remove its related permission");
+ _iamSrv.removeIAMPermissionForEntity(entityType, entityId);
+ }
+ }
+ });
+
+
+ _messageBus.subscribe(EntityManager.MESSAGE_GRANT_ENTITY_EVENT, new MessageSubscriber() {
+ @Override
+ public void onPublishMessage(String senderAddress, String subject, Object obj) {
+ Map<String, Object> permit = (Map<String, Object>)obj;
+ if (permit != null) {
+ String entityType = (String)permit.get(ApiConstants.ENTITY_TYPE);
+ Long entityId = (Long)permit.get(ApiConstants.ENTITY_ID);
+ AccessType accessType = (AccessType)permit.get(ApiConstants.ACCESS_TYPE);
+ String action = (String)permit.get(ApiConstants.IAM_ACTION);
+ List<Long> acctIds = (List<Long>)permit.get(ApiConstants.ACCOUNTS);
+ s_logger.debug("MessageBus message: grant accounts permission to an entity: (" + entityType + "," + entityId + ")");
+ grantEntityPermissioinToAccounts(entityType, entityId, accessType, action, acctIds);
+ }
+ }
+ });
+
+ _messageBus.subscribe(EntityManager.MESSAGE_REVOKE_ENTITY_EVENT, new MessageSubscriber() {
+ @Override
+ public void onPublishMessage(String senderAddress, String subject, Object obj) {
+ Map<String, Object> permit = (Map<String, Object>)obj;
+ if (permit != null) {
+ String entityType = (String)permit.get(ApiConstants.ENTITY_TYPE);
+ Long entityId = (Long)permit.get(ApiConstants.ENTITY_ID);
+ AccessType accessType = (AccessType)permit.get(ApiConstants.ACCESS_TYPE);
+ String action = (String)permit.get(ApiConstants.IAM_ACTION);
+ List<Long> acctIds = (List<Long>)permit.get(ApiConstants.ACCOUNTS);
+ s_logger.debug("MessageBus message: revoke from accounts permission to an entity: (" + entityType + "," + entityId + ")");
+ revokeEntityPermissioinFromAccounts(entityType, entityId, accessType, action, acctIds);
+ }
+ }
+ });
+
+ _messageBus.subscribe(EntityManager.MESSAGE_ADD_DOMAIN_WIDE_ENTITY_EVENT, new MessageSubscriber() {
+ @Override
+ public void onPublishMessage(String senderAddress, String subject, Object obj) {
+ Map<String, Object> params = (Map<String, Object>) obj;
+ if (params != null) {
+ addDomainWideResourceAccess(params);
+ }
+ }
+ });
+
+ return super.configure(name, params);
+ }
+
+ private void addDomainWideResourceAccess(Map<String, Object> params) {
+
+ IAMEntityType entityType = (IAMEntityType)params.get(ApiConstants.ENTITY_TYPE);
+ Long entityId = (Long) params.get(ApiConstants.ENTITY_ID);
+ Long domainId = (Long) params.get(ApiConstants.DOMAIN_ID);
+ Boolean isRecursive = (Boolean) params.get(ApiConstants.SUBDOMAIN_ACCESS);
+
+ if (entityType == IAMEntityType.Network) {
+ createPolicyAndAddToDomainGroup("DomainWideNetwork-" + entityId, "domain wide network", entityType.toString(),
+ entityId, "listNetworks", AccessType.UseEntry, domainId, isRecursive);
+ } else if (entityType == IAMEntityType.AffinityGroup) {
+ createPolicyAndAddToDomainGroup("DomainWideNetwork-" + entityId, "domain wide affinityGroup", entityType.toString(),
+ entityId, "listAffinityGroups", AccessType.UseEntry, domainId, isRecursive);
+ }
+
+ }
+
+ private void createPolicyAndAddToDomainGroup(String policyName, String description, String entityType,
+ Long entityId, String action, AccessType accessType, Long domainId, Boolean recursive) {
+
+ Domain domain = _domainDao.findById(domainId);
+ if (domain != null) {
+ IAMPolicy policy = _iamSrv.createIAMPolicy(policyName, description, null, domain.getPath());
+ _iamSrv.addIAMPermissionToIAMPolicy(policy.getId(), entityType, PermissionScope.RESOURCE.toString(),
+ entityId, action, accessType.toString(), Permission.Allow, recursive);
+ List<Long> policyList = new ArrayList<Long>();
+ policyList.add(new Long(policy.getId()));
+
+ List<IAMGroup> domainGroups = listDomainGroup(domain);
+ if (domainGroups != null) {
+ for (IAMGroup group : domainGroups) {
+ _iamSrv.attachIAMPoliciesToGroup(policyList, group.getId());
+ }
+ }
+ }
+ }
+
+ @DB
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_IAM_GROUP_CREATE, eventDescription = "Creating Acl Group", create = true)
+ public IAMGroup createIAMGroup(Account caller, String iamGroupName, String description) {
+ Long domainId = caller.getDomainId();
+ Domain callerDomain = _domainDao.findById(domainId);
+ if (callerDomain == null) {
+ throw new InvalidParameterValueException("Caller does not have a domain");
+ }
+ return _iamSrv.createIAMGroup(iamGroupName, description, callerDomain.getPath());
+ }
+
+ @DB
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_IAM_GROUP_DELETE, eventDescription = "Deleting Acl Group")
+ public boolean deleteIAMGroup(final Long iamGroupId) {
+ return _iamSrv.deleteIAMGroup(iamGroupId);
+ }
+
+ @Override
+ public List<IAMGroup> listIAMGroups(long accountId) {
+ return _iamSrv.listIAMGroups(accountId);
+ }
+
+
+ @DB
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_IAM_GROUP_UPDATE, eventDescription = "Adding accounts to acl group")
+ public IAMGroup addAccountsToGroup(final List<Long> acctIds, final Long groupId) {
+ return _iamSrv.addAccountsToGroup(acctIds, groupId);
+ }
+
+
+ private void removeAccountFromIAMGroups(long accountId) {
+ List<IAMGroup> groups = listIAMGroups(accountId);
+ List<Long> accts = new ArrayList<Long>();
+ accts.add(accountId);
+ if (groups != null) {
+ for (IAMGroup grp : groups) {
+ removeAccountsFromGroup(accts, grp.getId());
+ }
+ }
+ }
+
+ private void addAccountToIAMGroup(long accountId, long groupId) {
+ List<Long> accts = new ArrayList<Long>();
+ accts.add(accountId);
+ addAccountsToGroup(accts, groupId);
+ }
+
+ @DB
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_IAM_GROUP_UPDATE, eventDescription = "Removing accounts from acl group")
+ public IAMGroup removeAccountsFromGroup(final List<Long> acctIds, final Long groupId) {
+ return _iamSrv.removeAccountsFromGroup(acctIds, groupId);
+ }
+
+ @DB
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_IAM_POLICY_CREATE, eventDescription = "Creating IAM Policy", create = true)
+ public IAMPolicy createIAMPolicy(Account caller, final String iamPolicyName, final String description, final Long parentPolicyId) {
+ Long domainId = caller.getDomainId();
+ Domain callerDomain = _domainDao.findById(domainId);
+ if (callerDomain == null) {
+ throw new InvalidParameterValueException("Caller does not have a domain");
+ }
+ return _iamSrv.createIAMPolicy(iamPolicyName, description, parentPolicyId, callerDomain.getPath());
+ }
+
+ @DB
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_IAM_POLICY_DELETE, eventDescription = "Deleting IAM Policy")
+ public boolean deleteIAMPolicy(final long iamPolicyId) {
+ return _iamSrv.deleteIAMPolicy(iamPolicyId);
+ }
+
+
+ @Override
+ public List<IAMPolicy> listIAMPolicies(long accountId) {
+ return _iamSrv.listIAMPolicies(accountId);
+ }
+
+ @DB
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_IAM_GROUP_UPDATE, eventDescription = "Attaching policy to acl group")
+ public IAMGroup attachIAMPoliciesToGroup(final List<Long> policyIds, final Long groupId) {
+ return _iamSrv.attachIAMPoliciesToGroup(policyIds, groupId);
+ }
+
+ @DB
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_IAM_GROUP_UPDATE, eventDescription = "Removing policies from acl group")
+ public IAMGroup removeIAMPoliciesFromGroup(final List<Long> policyIds, final Long groupId) {
+ return _iamSrv.removeIAMPoliciesFromGroup(policyIds, groupId);
+ }
+
+
+ @DB
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_IAM_ACCOUNT_POLICY_UPDATE, eventDescription = "Attaching policy to accounts")
+ public void attachIAMPolicyToAccounts(final Long policyId, final List<Long> accountIds) {
+ _iamSrv.attachIAMPolicyToAccounts(policyId, accountIds);
+ }
+
+ @DB
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_IAM_ACCOUNT_POLICY_UPDATE, eventDescription = "Removing policy from accounts")
+ public void removeIAMPolicyFromAccounts(final Long policyId, final List<Long> accountIds) {
+ _iamSrv.removeIAMPolicyFromAccounts(policyId, accountIds);
+ }
+
+ @DB
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_IAM_POLICY_GRANT, eventDescription = "Granting acl permission to IAM Policy")
+ public IAMPolicy addIAMPermissionToIAMPolicy(long iamPolicyId, String entityType, PermissionScope scope,
+ Long scopeId, String action, Permission perm, Boolean recursive) {
+ Class<?> cmdClass = _apiServer.getCmdClass(action);
+ AccessType accessType = null;
+ if (BaseListCmd.class.isAssignableFrom(cmdClass)) {
+ accessType = AccessType.UseEntry;
+ }
+ return _iamSrv.addIAMPermissionToIAMPolicy(iamPolicyId, entityType, scope.toString(), scopeId, action,
+ accessType.toString(), perm, recursive);
+ }
+
+ @DB
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_IAM_POLICY_REVOKE, eventDescription = "Revoking acl permission from IAM Policy")
+ public IAMPolicy removeIAMPermissionFromIAMPolicy(long iamPolicyId, String entityType, PermissionScope scope, Long scopeId, String action) {
+ return _iamSrv.removeIAMPermissionFromIAMPolicy(iamPolicyId, entityType, scope.toString(), scopeId, action);
+ }
+
+ @Override
+ public IAMPolicyPermission getIAMPolicyPermission(long accountId, String entityType, String action) {
+ List<IAMPolicy> policies = _iamSrv.listIAMPolicies(accountId);
+ IAMPolicyPermission curPerm = null;
+ for (IAMPolicy policy : policies) {
+ List<IAMPolicyPermission> perms = _iamSrv.listPolicyPermissionByActionAndEntity(policy.getId(), action,
+ entityType);
+ if (perms == null || perms.size() == 0)
+ continue;
+ IAMPolicyPermission perm = perms.get(0); // just pick one
+ if (curPerm == null) {
+ curPerm = perm;
+ } else if (PermissionScope.valueOf(perm.getScope()).greaterThan(PermissionScope.valueOf(curPerm.getScope()))) {
+ // pick the more relaxed allowed permission
+ curPerm = perm;
+ }
+ }
+
+ return curPerm;
+ }
+
+
+ @Override
+ public IAMPolicyResponse createIAMPolicyResponse(IAMPolicy policy) {
+ IAMPolicyResponse response = new IAMPolicyResponse();
+ response.setId(policy.getUuid());
+ response.setName(policy.getName());
+ response.setDescription(policy.getDescription());
+ String domainPath = policy.getPath();
+ if (domainPath != null) {
+ DomainVO domain = _domainDao.findDomainByPath(domainPath);
+ if (domain != null) {
+ response.setDomainId(domain.getUuid());
+ response.setDomainName(domain.getName());
+ }
+ }
+ long accountId = policy.getAccountId();
+ AccountVO owner = _accountDao.findById(accountId);
+ if (owner != null) {
+ response.setAccountName(owner.getAccountName());
+ }
+ // find permissions associated with this policy
+ List<IAMPolicyPermission> permissions = _iamSrv.listPolicyPermissions(policy.getId());
+ if (permissions != null && permissions.size() > 0) {
+ for (IAMPolicyPermission permission : permissions) {
+ IAMPermissionResponse perm = new IAMPermissionResponse();
+ perm.setAction(permission.getAction());
+ if (permission.getEntityType() != null) {
+ perm.setEntityType(IAMEntityType.valueOf(permission.getEntityType()));
+ }
+ if (permission.getScope() != null) {
+ perm.setScope(PermissionScope.valueOf(permission.getScope()));
+ }
+ perm.setScopeId(permission.getScopeId());
+ perm.setPermission(permission.getPermission());
+ response.addPermission(perm);
+ }
+ }
+ response.setObjectName("aclpolicy");
+ return response;
+ }
+
+ @Override
+ public IAMGroupResponse createIAMGroupResponse(IAMGroup group) {
+ IAMGroupResponse response = new IAMGroupResponse();
+ response.setId(group.getUuid());
+ response.setName(group.getName());
+ response.setDescription(group.getDescription());
+ String domainPath = group.getPath();
+ if (domainPath != null) {
+ DomainVO domain = _domainDao.findDomainByPath(domainPath);
+ if (domain != null) {
+ response.setDomainId(domain.getUuid());
+ response.setDomainName(domain.getName());
+ }
+ }
+ long accountId = group.getAccountId();
+ AccountVO owner = _accountDao.findById(accountId);
+ if (owner != null) {
+ response.setAccountName(owner.getAccountName());
+ }
+ // find all the members in this group
+ List<Long> members = _iamSrv.listAccountsByGroup(group.getId());
+ if (members != null && members.size() > 0) {
+ for (Long member : members) {
+ AccountVO mem = _accountDao.findById(member);
+ if (mem != null) {
+ response.addMemberAccount(mem.getAccountName());
+ }
+ }
+ }
+
+ // find all the policies attached to this group
+ List<IAMPolicy> policies = _iamSrv.listIAMPoliciesByGroup(group.getId());
+ if (policies != null && policies.size() > 0) {
+ for (IAMPolicy policy : policies) {
+ response.addPolicy(policy.getName());
+ }
+ }
+
+ response.setObjectName("aclgroup");
+ return response;
+
+ }
+
+ public List<IAMGroup> listDomainGroup(Domain domain) {
+
+ if (domain != null) {
+ String domainPath = domain.getPath();
+ // search for groups
+ Pair<List<IAMGroup>, Integer> result = _iamSrv.listIAMGroups(null, "DomainGrp-" + domain.getUuid(),
+ domainPath, null, null);
+ return result.first();
+ }
+ return new ArrayList<IAMGroup>();
+
+ }
+
+ @Override
+ public ListResponse<IAMGroupResponse> listIAMGroups(Long iamGroupId, String iamGroupName, Long domainId, Long startIndex, Long pageSize) {
+ // acl check
+ Account caller = CallContext.current().getCallingAccount();
+
+ Domain domain = null;
+ if (domainId != null) {
+ domain = _domainDao.findById(domainId);
+ if (domain == null) {
+ throw new InvalidParameterValueException("Domain id=" + domainId + " doesn't exist");
+ }
+
+ _accountMgr.checkAccess(caller, domain);
+ } else {
+ domain = _domainDao.findById(caller.getDomainId());
+ }
+ String domainPath = domain.getPath();
+ // search for groups
+ Pair<List<IAMGroup>, Integer> result = _iamSrv.listIAMGroups(iamGroupId, iamGroupName, domainPath, startIndex, pageSize);
+ // generate group response
+ ListResponse<IAMGroupResponse> response = new ListResponse<IAMGroupResponse>();
+ List<IAMGroupResponse> groupResponses = new ArrayList<IAMGroupResponse>();
+ for (IAMGroup group : result.first()) {
+ IAMGroupResponse resp = createIAMGroupResponse(group);
+ groupResponses.add(resp);
+ }
+ response.setResponses(groupResponses, result.second());
+ return response;
+ }
+
+ @Override
+ public ListResponse<IAMPolicyResponse> listIAMPolicies(Long iamPolicyId, String iamPolicyName, Long domainId, Long startIndex,
+ Long pageSize) {
+ // acl check
+ Account caller = CallContext.current().getCallingAccount();
+
+ Domain domain = null;
+ if (domainId != null) {
+ domain = _domainDao.findById(domainId);
+ if (domain == null) {
+ throw new InvalidParameterValueException("Domain id=" + domainId + " doesn't exist");
+ }
+
+ _accountMgr.checkAccess(caller, domain);
+ } else {
+ domain = _domainDao.findById(caller.getDomainId());
+ }
+ String domainPath = domain.getPath();
+ // search for policies
+ Pair<List<IAMPolicy>, Integer> result = _iamSrv.listIAMPolicies(iamPolicyId, iamPolicyName, domainPath, startIndex, pageSize);
+ // generate policy response
+ ListResponse<IAMPolicyResponse> response = new ListResponse<IAMPolicyResponse>();
+ List<IAMPolicyResponse> policyResponses = new ArrayList<IAMPolicyResponse>();
+ for (IAMPolicy policy : result.first()) {
+ IAMPolicyResponse resp = createIAMPolicyResponse(policy);
+ policyResponses.add(resp);
+ }
+ response.setResponses(policyResponses, result.second());
+ return response;
+ }
+
+ @Override
+ public void grantEntityPermissioinToAccounts(String entityType, Long entityId, AccessType accessType, String action, List<Long> accountIds) {
+ // check if there is already a policy with only this permission added to it
+ IAMPolicy policy = _iamSrv.getResourceGrantPolicy(entityType, entityId, accessType.toString(), action);
+ if (policy == null) {
+ // not found, just create a policy with resource grant permission
+ Account caller = CallContext.current().getCallingAccount();
+ String aclPolicyName = "policyGrant" + entityType + entityId;
+ String description = "Policy to grant permission to " + entityType + entityId;
+ policy = createIAMPolicy(caller, aclPolicyName, description, null);
+ // add permission to this policy
+ addIAMPermissionToIAMPolicy(policy.getId(), entityType, PermissionScope.RESOURCE, entityId, action, Permission.Allow, false);
+ }
+ // attach this policy to list of accounts if not attached already
+ Long policyId = policy.getId();
+ for (Long acctId : accountIds) {
+ if (!isPolicyAttachedToAccount(policyId, acctId)) {
+ attachIAMPolicyToAccounts(policyId, Collections.singletonList(acctId));
+ }
+ }
+ }
+
+ @Override
+ public void revokeEntityPermissioinFromAccounts(String entityType, Long entityId, AccessType accessType, String action, List<Long> accountIds) {
+ // there should already a policy with only this permission added to it, this call is mainly used
+ IAMPolicy policy = _iamSrv.getResourceGrantPolicy(entityType, entityId, accessType.toString(), action);
+ if (policy == null) {
+ s_logger.warn("Cannot find a policy associated with this entity permissioin to be revoked, just return");
+ return;
+ }
+ // detach this policy from list of accounts if not detached already
+ Long policyId = policy.getId();
+ for (Long acctId : accountIds) {
+ if (isPolicyAttachedToAccount(policyId, acctId)) {
+ removeIAMPolicyFromAccounts(policyId, Collections.singletonList(acctId));
+ }
+ }
+
+ }
+
+ private boolean isPolicyAttachedToAccount(Long policyId, Long accountId) {
+ List<IAMPolicy> pList = listIAMPolicies(accountId);
+ for (IAMPolicy p : pList) {
+ if (p.getId() == policyId.longValue()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private void resetTemplatePermission(Long templateId){
+ // reset template will change template to private, so we need to remove its permission for domain admin and normal user group
+ _iamSrv.removeIAMPermissionFromIAMPolicy(new Long(Account.ACCOUNT_TYPE_DOMAIN_ADMIN + 1), IAMEntityType.VirtualMachineTemplate.toString(),
+ PermissionScope.RESOURCE.toString(), templateId, "listTemplates");
+ _iamSrv.removeIAMPermissionFromIAMPolicy(new Long(Account.ACCOUNT_TYPE_NORMAL + 1), IAMEntityType.VirtualMachineTemplate.toString(),
+ PermissionScope.RESOURCE.toString(), templateId, "listTemplates");
+ // check if there is a policy with only UseEntry permission for this template added
+ IAMPolicy policy = _iamSrv.getResourceGrantPolicy(IAMEntityType.VirtualMachineTemplate.toString(), templateId, AccessType.UseEntry.toString(), "listTemplates");
+ if ( policy == null ){
+ s_logger.info("No policy found for this template grant: " + templateId + ", no detach to be done");
+ return;
+ }
+ // delete the policy, which should detach it from groups and accounts
+ _iamSrv.deleteIAMPolicy(policy.getId());
+
+ }
+
+ @Override
+ public Long getPermissionScopeId(String scope, String entityType, String scopeId) {
+ if (scopeId.equals("-1")) {
+ return -1L;
+ }
+ PermissionScope permScope = PermissionScope.valueOf(scope);
+ InternalIdentity entity = null;
+ switch (permScope) {
+ case DOMAIN:
+ entity = _domainDao.findByUuid(scopeId);
+ break;
+ case ACCOUNT:
+ entity = _accountDao.findByUuid(scopeId);
+ break;
+ case RESOURCE:
+ Class<?> clazz = s_typeMap.get(IAMEntityType.valueOf(entityType));
+ entity = (InternalIdentity)_entityMgr.findByUuid(clazz, scopeId);
+ }
+
+ if (entity != null) {
+ return entity.getId();
+ }
+ throw new InvalidParameterValueException("Unable to find scopeId " + scopeId + " with scope " + scope + " and type " + entityType);
+ }
+
+ @Override
+ public List<Class<?>> getCommands() {
+ List<Class<?>> cmdList = new ArrayList<Class<?>>();
+ cmdList.add(CreateIAMPolicyCmd.class);
+ cmdList.add(DeleteIAMPolicyCmd.class);
+ cmdList.add(ListIAMPoliciesCmd.class);
+ cmdList.add(AddIAMPermissionToIAMPolicyCmd.class);
+ cmdList.add(RemoveIAMPermissionFromIAMPolicyCmd.class);
+ cmdList.add(AttachIAMPolicyToIAMGroupCmd.class);
+ cmdList.add(RemoveIAMPolicyFromIAMGroupCmd.class);
+ cmdList.add(CreateIAMGroupCmd.class);
+ cmdList.add(DeleteIAMGroupCmd.class);
+ cmdList.add(ListIAMGroupsCmd.class);
+ cmdList.add(AddAccountToIAMGroupCmd.class);
+ cmdList.add(RemoveAccountFromIAMGroupCmd.class);
+ cmdList.add(AttachIAMPolicyToAccountCmd.class);
+ cmdList.add(RemoveIAMPolicyFromAccountCmd.class);
+ return cmdList;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/src/org/apache/cloudstack/iam/RoleBasedAPIAccessChecker.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/iam/RoleBasedAPIAccessChecker.java b/services/iam/plugin/src/org/apache/cloudstack/iam/RoleBasedAPIAccessChecker.java
new file mode 100644
index 0000000..fb75db3
--- /dev/null
+++ b/services/iam/plugin/src/org/apache/cloudstack/iam/RoleBasedAPIAccessChecker.java
@@ -0,0 +1,273 @@
+// 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 java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.acl.APIChecker;
+import org.apache.cloudstack.acl.IAMEntityType;
+import org.apache.cloudstack.acl.PermissionScope;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.acl.SecurityChecker.AccessType;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.BaseAsyncCreateCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.BaseListCmd;
+import org.apache.cloudstack.iam.api.IAMPolicy;
+import org.apache.cloudstack.iam.api.IAMPolicyPermission;
+import org.apache.cloudstack.iam.api.IAMPolicyPermission.Permission;
+import org.apache.cloudstack.iam.api.IAMService;
+
+import com.cloud.api.ApiServerService;
+import com.cloud.exception.PermissionDeniedException;
+import com.cloud.storage.VMTemplateVO;
+import com.cloud.storage.dao.VMTemplateDao;
+import com.cloud.user.Account;
+import com.cloud.user.AccountService;
+import com.cloud.user.User;
+import com.cloud.utils.PropertiesUtil;
+import com.cloud.utils.component.AdapterBase;
+import com.cloud.utils.component.PluggableService;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+//This is the Role Based API access checker that grab's the account's roles
+//based on the set of roles, access is granted if any of the role has access to the api
+@Local(value=APIChecker.class)
+public class RoleBasedAPIAccessChecker extends AdapterBase implements APIChecker {
+
+ protected static final Logger s_logger = Logger.getLogger(RoleBasedAPIAccessChecker.class);
+
+ @Inject
+ AccountService _accountService;
+ @Inject
+ ApiServerService _apiServer;
+ @Inject
+ IAMService _iamSrv;
+ @Inject
+ VMTemplateDao _templateDao;
+
+ Set<String> commandsPropertiesOverrides = new HashSet<String>();
+ Map<RoleType, Set<String>> commandsPropertiesRoleBasedApisMap = new HashMap<RoleType, Set<String>>();
+
+ List<PluggableService> _services;
+
+ protected RoleBasedAPIAccessChecker() {
+ super();
+ for (RoleType roleType : RoleType.values()) {
+ commandsPropertiesRoleBasedApisMap.put(roleType, new HashSet<String>());
+ }
+ }
+
+ @Override
+ public boolean checkAccess(User user, String commandName) throws PermissionDeniedException {
+ Account account = _accountService.getAccount(user.getAccountId());
+ if (account == null) {
+ throw new PermissionDeniedException("The account id=" + user.getAccountId() + "for user id=" + user.getId()
+ + "is null");
+ }
+
+ List<IAMPolicy> policies = _iamSrv.listIAMPolicies(account.getAccountId());
+
+ boolean isAllowed = _iamSrv.isActionAllowedForPolicies(commandName, policies);
+ if (!isAllowed) {
+ throw new PermissionDeniedException("The API does not exist or is blacklisted. api: " + commandName);
+ }
+ return isAllowed;
+ }
+
+ @Override
+ public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+ super.configure(name, params);
+
+ processMapping(PropertiesUtil.processConfigFile(new String[] { "commands.properties" }));
+ return true;
+ }
+
+ @Override
+ public boolean start() {
+
+ // drop all default policy api permissions - we reload them every time
+ // to include any changes done to the @APICommand or
+ // commands.properties.
+
+ for (RoleType role : RoleType.values()) {
+ Long policyId = getDefaultPolicyId(role);
+ if (policyId != null) {
+ _iamSrv.resetIAMPolicy(policyId);
+ }
+ }
+
+ // add the system-domain capability
+
+ _iamSrv.addIAMPermissionToIAMPolicy(new Long(Account.ACCOUNT_TYPE_ADMIN + 1), null, null, null,
+ "SystemCapability", null, Permission.Allow, false);
+ _iamSrv.addIAMPermissionToIAMPolicy(new Long(Account.ACCOUNT_TYPE_DOMAIN_ADMIN + 1), null, null, null,
+ "DomainCapability", null, Permission.Allow, false);
+ _iamSrv.addIAMPermissionToIAMPolicy(new Long(Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN + 1), null, null, null,
+ "DomainResourceCapability", null, Permission.Allow, false);
+
+ // add permissions for public templates
+ List<VMTemplateVO> pTmplts = _templateDao.listByPublic();
+ for (VMTemplateVO tmpl : pTmplts){
+ _iamSrv.addIAMPermissionToIAMPolicy(new Long(Account.ACCOUNT_TYPE_DOMAIN_ADMIN + 1), IAMEntityType.VirtualMachineTemplate.toString(),
+ PermissionScope.RESOURCE.toString(), tmpl.getId(), "listTemplates", AccessType.UseEntry.toString(), Permission.Allow, false);
+ _iamSrv.addIAMPermissionToIAMPolicy(new Long(Account.ACCOUNT_TYPE_NORMAL + 1), IAMEntityType.VirtualMachineTemplate.toString(),
+ PermissionScope.RESOURCE.toString(), tmpl.getId(), "listTemplates", AccessType.UseEntry.toString(), Permission.Allow, false);
+ }
+
+ for (PluggableService service : _services) {
+ for (Class<?> cmdClass : service.getCommands()) {
+ APICommand command = cmdClass.getAnnotation(APICommand.class);
+ if (!commandsPropertiesOverrides.contains(command.name())) {
+ for (RoleType role : command.authorized()) {
+ addDefaultAclPolicyPermission(command.name(), cmdClass, role);
+ }
+ }
+ }
+ }
+
+ // read commands.properties and load api acl permissions -
+ // commands.properties overrides any @APICommand authorization
+
+ for (String apiName : commandsPropertiesOverrides) {
+ Class<?> cmdClass = _apiServer.getCmdClass(apiName);
+ for (RoleType role : RoleType.values()) {
+ if (commandsPropertiesRoleBasedApisMap.get(role).contains(apiName)) {
+ // insert permission for this role for this api
+ addDefaultAclPolicyPermission(apiName, cmdClass, role);
+ }
+ }
+ }
+
+ return super.start();
+ }
+
+ private Long getDefaultPolicyId(RoleType role) {
+ Long policyId = null;
+ switch (role) {
+ case User:
+ policyId = new Long(Account.ACCOUNT_TYPE_NORMAL + 1);
+ break;
+
+ case Admin:
+ policyId = new Long(Account.ACCOUNT_TYPE_ADMIN + 1);
+ break;
+
+ case DomainAdmin:
+ policyId = new Long(Account.ACCOUNT_TYPE_DOMAIN_ADMIN + 1);
+ break;
+
+ case ResourceAdmin:
+ policyId = new Long(Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN + 1);
+ break;
+ }
+
+ return policyId;
+ }
+
+ private void processMapping(Map<String, String> configMap) {
+ for (Map.Entry<String, String> entry : configMap.entrySet()) {
+ String apiName = entry.getKey();
+ String roleMask = entry.getValue();
+ commandsPropertiesOverrides.add(apiName);
+ try {
+ short cmdPermissions = Short.parseShort(roleMask);
+ for (RoleType roleType : RoleType.values()) {
+ if ((cmdPermissions & roleType.getValue()) != 0)
+ commandsPropertiesRoleBasedApisMap.get(roleType).add(apiName);
+ }
+ } catch (NumberFormatException nfe) {
+ s_logger.info("Malformed key=value pair for entry: " + entry.toString());
+ }
+ }
+ }
+
+ public List<PluggableService> getServices() {
+ return _services;
+ }
+
+ @Inject
+ public void setServices(List<PluggableService> services) {
+ _services = services;
+ }
+
+ private void addDefaultAclPolicyPermission(String apiName, Class<?> cmdClass, RoleType role) {
+
+ AccessType accessType = null;
+ IAMEntityType[] entityTypes = null;
+ if (cmdClass != null) {
+ BaseCmd cmdObj;
+ try {
+ cmdObj = (BaseCmd) cmdClass.newInstance();
+ if (cmdObj instanceof BaseListCmd) {
+ accessType = AccessType.UseEntry;
+ } else if (!(cmdObj instanceof BaseAsyncCreateCmd)) {
+ accessType = AccessType.OperateEntry;
+ }
+ } catch (Exception e) {
+ throw new CloudRuntimeException(String.format(
+ "%s is claimed as an API command, but it cannot be instantiated", cmdClass.getName()));
+ }
+
+ APICommand at = cmdClass.getAnnotation(APICommand.class);
+ entityTypes = at.entityType();
+ }
+
+ PermissionScope permissionScope = PermissionScope.ACCOUNT;
+ Long policyId = getDefaultPolicyId(role);
+ switch (role) {
+ case User:
+ permissionScope = PermissionScope.ACCOUNT;
+ break;
+
+ case Admin:
+ permissionScope = PermissionScope.ALL;
+ break;
+
+ case DomainAdmin:
+ permissionScope = PermissionScope.DOMAIN;
+ break;
+
+ case ResourceAdmin:
+ permissionScope = PermissionScope.DOMAIN;
+ break;
+ }
+
+
+ if (entityTypes == null || entityTypes.length == 0) {
+ _iamSrv.addIAMPermissionToIAMPolicy(policyId, null, permissionScope.toString(), new Long(IAMPolicyPermission.PERMISSION_SCOPE_ID_CURRENT_CALLER),
+ apiName, (accessType == null) ? null : accessType.toString(), Permission.Allow, false);
+ } else {
+ for (IAMEntityType entityType : entityTypes) {
+ _iamSrv.addIAMPermissionToIAMPolicy(policyId, entityType.toString(), permissionScope.toString(), new Long(IAMPolicyPermission.PERMISSION_SCOPE_ID_CURRENT_CALLER),
+ apiName, (accessType == null) ? null : accessType.toString(), Permission.Allow, false);
+ }
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/src/org/apache/cloudstack/iam/RoleBasedEntityAccessChecker.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/iam/RoleBasedEntityAccessChecker.java b/services/iam/plugin/src/org/apache/cloudstack/iam/RoleBasedEntityAccessChecker.java
new file mode 100644
index 0000000..d0d9d88
--- /dev/null
+++ b/services/iam/plugin/src/org/apache/cloudstack/iam/RoleBasedEntityAccessChecker.java
@@ -0,0 +1,186 @@
+// 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 java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.acl.ControlledEntity;
+import org.apache.cloudstack.acl.PermissionScope;
+import org.apache.cloudstack.acl.SecurityChecker;
+import org.apache.cloudstack.api.InternalIdentity;
+import org.apache.cloudstack.iam.api.IAMGroup;
+import org.apache.cloudstack.iam.api.IAMPolicy;
+import org.apache.cloudstack.iam.api.IAMPolicyPermission;
+import org.apache.cloudstack.iam.api.IAMService;
+
+import com.cloud.acl.DomainChecker;
+import com.cloud.domain.dao.DomainDao;
+import com.cloud.exception.PermissionDeniedException;
+import com.cloud.user.Account;
+import com.cloud.user.AccountService;
+
+public class RoleBasedEntityAccessChecker extends DomainChecker implements SecurityChecker {
+
+ private static final Logger s_logger = Logger.getLogger(RoleBasedEntityAccessChecker.class.getName());
+
+ @Inject
+ AccountService _accountService;
+
+ @Inject DomainDao _domainDao;
+
+ @Inject
+ IAMService _iamSrv;
+
+
+ @Override
+ public boolean checkAccess(Account caller, ControlledEntity entity, AccessType accessType)
+ throws PermissionDeniedException {
+ return checkAccess(caller, entity, accessType, null);
+ }
+
+ @Override
+ public boolean checkAccess(Account caller, ControlledEntity entity, AccessType accessType, String action)
+ throws PermissionDeniedException {
+
+ if (entity == null && action != null) {
+ // check if caller can do this action
+ List<IAMPolicy> policies = _iamSrv.listIAMPolicies(caller.getAccountId());
+
+ boolean isAllowed = _iamSrv.isActionAllowedForPolicies(action, policies);
+ if (!isAllowed) {
+ throw new PermissionDeniedException("The action '" + action + "' not allowed for account " + caller);
+ }
+ return true;
+ }
+
+ String entityType = entity.getEntityType().toString();
+
+ if (accessType == null) {
+ accessType = AccessType.UseEntry;
+ }
+
+ // get all Policies of this caller w.r.t the entity
+ List<IAMPolicy> policies = getEffectivePolicies(caller, entity);
+ HashMap<IAMPolicy, Boolean> policyPermissionMap = new HashMap<IAMPolicy, Boolean>();
+
+ for (IAMPolicy policy : policies) {
+ List<IAMPolicyPermission> permissions = new ArrayList<IAMPolicyPermission>();
+
+ if (action != null) {
+ permissions = _iamSrv.listPolicyPermissionByActionAndEntity(policy.getId(), action, entityType);
+ if (permissions.isEmpty()) {
+ if (accessType != null) {
+ permissions.addAll(_iamSrv.listPolicyPermissionByAccessAndEntity(policy.getId(),
+ accessType.toString(), entityType));
+ }
+ }
+ } else {
+ if (accessType != null) {
+ permissions.addAll(_iamSrv.listPolicyPermissionByAccessAndEntity(policy.getId(),
+ accessType.toString(), entityType));
+ }
+ }
+ for (IAMPolicyPermission permission : permissions) {
+ if (checkPermissionScope(caller, permission.getScope(), permission.getScopeId(), entity)) {
+ if (permission.getEntityType().equals(entityType)) {
+ policyPermissionMap.put(policy, permission.getPermission().isGranted());
+ break;
+ } else if (permission.getEntityType().equals("*")) {
+ policyPermissionMap.put(policy, permission.getPermission().isGranted());
+ }
+ }
+ }
+ if (policyPermissionMap.containsKey(policy) && policyPermissionMap.get(policy)) {
+ return true;
+ }
+ }
+
+ if (!policies.isEmpty()) { // Since we reach this point, none of the
+ // roles granted access
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Account " + caller + " does not have permission to access resource " + entity
+ + " for access type: " + accessType);
+ }
+ throw new PermissionDeniedException(caller + " does not have permission to access resource " + entity);
+ }
+
+ return false;
+ }
+
+ private boolean checkPermissionScope(Account caller, String scope, Long scopeId, ControlledEntity entity) {
+
+ if(scopeId != null && !scopeId.equals(new Long(IAMPolicyPermission.PERMISSION_SCOPE_ID_CURRENT_CALLER))){
+ //scopeId is set
+ if (scope.equals(PermissionScope.ACCOUNT.name())) {
+ if(scopeId == entity.getAccountId()){
+ return true;
+ }
+ } else if (scope.equals(PermissionScope.DOMAIN.name())) {
+ if (_domainDao.isChildDomain(scopeId, entity.getDomainId())) {
+ return true;
+ }
+ } else if (scope.equals(PermissionScope.RESOURCE.name())) {
+ if (entity instanceof InternalIdentity) {
+ InternalIdentity entityWithId = (InternalIdentity) entity;
+ if(scopeId.equals(entityWithId.getId())){
+ return true;
+ }
+ }
+ }
+ } else if (scopeId == null || scopeId.equals(new Long(IAMPolicyPermission.PERMISSION_SCOPE_ID_CURRENT_CALLER))) {
+ if (scope.equals(PermissionScope.ACCOUNT.name())) {
+ if(caller.getAccountId() == entity.getAccountId()){
+ return true;
+ }
+ } else if (scope.equals(PermissionScope.DOMAIN.name())) {
+ if (_domainDao.isChildDomain(caller.getDomainId(), entity.getDomainId())) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private List<IAMPolicy> getEffectivePolicies(Account caller, ControlledEntity entity) {
+
+ // Get the static Policies of the Caller
+ List<IAMPolicy> policies = _iamSrv.listIAMPolicies(caller.getId());
+
+ // add any dynamic policies w.r.t the entity
+ if (caller.getId() == entity.getAccountId()) {
+ // The caller owns the entity
+ policies.add(_iamSrv.getResourceOwnerPolicy());
+ }
+
+ List<IAMGroup> groups = _iamSrv.listIAMGroups(caller.getId());
+ for (IAMGroup group : groups) {
+ // for each group find the grand parent groups.
+ List<IAMGroup> parentGroups = _iamSrv.listParentIAMGroups(group.getId());
+ for (IAMGroup parentGroup : parentGroups) {
+ policies.addAll(_iamSrv.listRecursiveIAMPoliciesByGroup(parentGroup.getId()));
+ }
+ }
+
+ return policies;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/src/org/apache/cloudstack/iam/RoleBasedEntityQuerySelector.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/iam/RoleBasedEntityQuerySelector.java b/services/iam/plugin/src/org/apache/cloudstack/iam/RoleBasedEntityQuerySelector.java
new file mode 100644
index 0000000..23c57a1
--- /dev/null
+++ b/services/iam/plugin/src/org/apache/cloudstack/iam/RoleBasedEntityQuerySelector.java
@@ -0,0 +1,147 @@
+// 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 java.util.ArrayList;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.acl.PermissionScope;
+import org.apache.cloudstack.acl.QuerySelector;
+import org.apache.cloudstack.iam.api.IAMGroup;
+import org.apache.cloudstack.iam.api.IAMPolicy;
+import org.apache.cloudstack.iam.api.IAMPolicyPermission;
+import org.apache.cloudstack.iam.api.IAMService;
+
+import com.cloud.user.Account;
+import com.cloud.utils.component.AdapterBase;
+
+public class RoleBasedEntityQuerySelector extends AdapterBase implements QuerySelector {
+
+ private static final Logger s_logger = Logger.getLogger(RoleBasedEntityQuerySelector.class.getName());
+
+ @Inject
+ IAMService _iamService;
+
+ @Override
+ public List<Long> getAuthorizedDomains(Account caller, String action) {
+ long accountId = caller.getAccountId();
+ // Get the static Policies of the Caller
+ List<IAMPolicy> policies = _iamService.listIAMPolicies(accountId);
+ // for each policy, find granted permission with Domain scope
+ List<Long> domainIds = new ArrayList<Long>();
+ for (IAMPolicy policy : policies) {
+ List<IAMPolicyPermission> pp = _iamService.listPolicyPermissionsByScope(policy.getId(), action, PermissionScope.DOMAIN.toString());
+ if (pp != null) {
+ for (IAMPolicyPermission p : pp) {
+ if (p.getScopeId() != null) {
+ if (p.getScopeId().longValue() == -1) {
+ domainIds.add(caller.getDomainId());
+ } else {
+ domainIds.add(p.getScopeId());
+ }
+ }
+ }
+ }
+ }
+ return domainIds;
+ }
+
+ @Override
+ public List<Long> getAuthorizedAccounts(Account caller, String action) {
+ long accountId = caller.getAccountId();
+ // Get the static Policies of the Caller
+ List<IAMPolicy> policies = _iamService.listIAMPolicies(accountId);
+ // for each policy, find granted permission with Account scope
+ List<Long> accountIds = new ArrayList<Long>();
+ for (IAMPolicy policy : policies) {
+ List<IAMPolicyPermission> pp = _iamService.listPolicyPermissionsByScope(policy.getId(), action, PermissionScope.ACCOUNT.toString());
+ if (pp != null) {
+ for (IAMPolicyPermission p : pp) {
+ if (p.getScopeId() != null) {
+ if (p.getScopeId().longValue() == -1) {
+ accountIds.add(caller.getId());
+ } else {
+ accountIds.add(p.getScopeId());
+ }
+ }
+ }
+ }
+ }
+ return accountIds;
+ }
+
+ @Override
+ public List<Long> getAuthorizedResources(Account caller, String action) {
+ long accountId = caller.getAccountId();
+ // Get the static Policies of the Caller
+ List<IAMPolicy> policies = _iamService.listIAMPolicies(accountId);
+
+ // add the policies that grant recursive access
+ List<IAMGroup> groups = _iamService.listIAMGroups(caller.getId());
+ for (IAMGroup group : groups) {
+ // for each group find the grand parent groups.
+ List<IAMGroup> parentGroups = _iamService.listParentIAMGroups(group.getId());
+ for (IAMGroup parentGroup : parentGroups) {
+ policies.addAll(_iamService.listRecursiveIAMPoliciesByGroup(parentGroup.getId()));
+ }
+ }
+
+ // for each policy, find granted permission with Resource scope
+ List<Long> entityIds = new ArrayList<Long>();
+ for (IAMPolicy policy : policies) {
+ List<IAMPolicyPermission> pp = _iamService.listPolicyPermissionsByScope(policy.getId(), action, PermissionScope.RESOURCE.toString());
+ if (pp != null) {
+ for (IAMPolicyPermission p : pp) {
+ if (p.getScopeId() != null) {
+ entityIds.add(p.getScopeId());
+ }
+ }
+ }
+ }
+ return entityIds;
+ }
+
+ @Override
+ public boolean isGrantedAll(Account caller, String action) {
+ long accountId = caller.getAccountId();
+ // Get the static Policies of the Caller
+ List<IAMPolicy> policies = _iamService.listIAMPolicies(accountId);
+ // for each policy, find granted permission with ALL scope
+ for (IAMPolicy policy : policies) {
+ List<IAMPolicyPermission> pp = _iamService.listPolicyPermissionsByScope(policy.getId(), action, PermissionScope.ALL.toString());
+ if (pp != null && pp.size() > 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public List<String> listAclGroupsByAccount(long accountId) {
+ List<IAMGroup> groups = _iamService.listIAMGroups(accountId);
+ List<String> groupNames = new ArrayList<String>();
+ for (IAMGroup grp : groups) {
+ groupNames.add(grp.getName());
+ }
+ return groupNames;
+ }
+
+}
[8/9] git commit: updated refs/heads/master to 63e3eea
Posted by mc...@apache.org.
CLOUDSTACK-5920: Add some interface methods and constants required by
IAM.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/793becf5
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/793becf5
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/793becf5
Branch: refs/heads/master
Commit: 793becf524520c62fd5df35b22128db13347f6c9
Parents: d0ae4d9
Author: Min Chen <mi...@citrix.com>
Authored: Tue Mar 4 17:34:50 2014 -0800
Committer: Min Chen <mi...@citrix.com>
Committed: Wed Mar 5 09:40:55 2014 -0800
----------------------------------------------------------------------
api/src/com/cloud/event/EventTypes.java | 13 ++++
.../apache/cloudstack/acl/PermissionScope.java | 25 +++++++
.../apache/cloudstack/acl/QuerySelector.java | 72 ++++++++++++++++++++
.../apache/cloudstack/acl/SecurityChecker.java | 22 +++++-
.../org/apache/cloudstack/api/APICommand.java | 3 +
.../cloudstack/api/ApiCommandJobType.java | 4 +-
.../org/apache/cloudstack/api/ApiConstants.java | 18 +++++
.../src/com/cloud/template/TemplateManager.java | 3 +
server/src/com/cloud/acl/DomainChecker.java | 6 ++
server/src/com/cloud/api/ApiServer.java | 3 +-
server/src/com/cloud/api/ApiServerService.java | 2 +
server/src/com/cloud/user/AccountManager.java | 4 ++
server/src/com/cloud/user/DomainManager.java | 3 +
utils/src/com/cloud/utils/db/EntityManager.java | 6 ++
14 files changed, 181 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/793becf5/api/src/com/cloud/event/EventTypes.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java
index 7dd8772..ec54ea1 100755
--- a/api/src/com/cloud/event/EventTypes.java
+++ b/api/src/com/cloud/event/EventTypes.java
@@ -455,6 +455,19 @@ public class EventTypes {
public static final String EVENT_UCS_ASSOCIATED_PROFILE = "UCS.ASSOCIATEPROFILE";
+ // IAM events
+ public static final String EVENT_IAM_POLICY_CREATE = "IAMPOLICY.CREATE";
+ public static final String EVENT_IAM_POLICY_DELETE = "IAMPOLICY.DELETE";
+ public static final String EVENT_IAM_POLICY_GRANT = "IAMPOLICY.GRANT";
+ public static final String EVENT_IAM_POLICY_REVOKE = "IAMPOLICY.REVOKE";
+
+ public static final String EVENT_IAM_GROUP_UPDATE = "IAMGROUP.UPDATE";
+ public static final String EVENT_IAM_GROUP_CREATE = "IAMGROUP.CREATE";
+ public static final String EVENT_IAM_GROUP_DELETE = "IAMGROUP.DELETE";
+ public static final String EVENT_IAM_GROUP_GRANT = "IAMGROUP.GRANT";
+ public static final String EVENT_IAM_GROUP_REVOKE = "IAMGROUP.REVOKE";
+ public static final String EVENT_IAM_ACCOUNT_POLICY_UPDATE = "IAMACCOUNTPOLICY.UPDATE";
+
// Object store migration
public static final String EVENT_MIGRATE_PREPARE_SECONDARY_STORAGE = "MIGRATE.PREPARE.SS";
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/793becf5/api/src/org/apache/cloudstack/acl/PermissionScope.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/acl/PermissionScope.java b/api/src/org/apache/cloudstack/acl/PermissionScope.java
new file mode 100644
index 0000000..03dbc10
--- /dev/null
+++ b/api/src/org/apache/cloudstack/acl/PermissionScope.java
@@ -0,0 +1,25 @@
+package org.apache.cloudstack.acl;
+
+public enum PermissionScope {
+ RESOURCE(0),
+ ACCOUNT(1),
+ DOMAIN(2),
+ REGION(3), ALL(4);
+
+ private int _scale;
+
+ private PermissionScope(int scale) {
+ _scale = scale;
+ }
+
+ public int getScale() {
+ return _scale;
+ }
+
+ public boolean greaterThan(PermissionScope s) {
+ if (_scale > s.getScale())
+ return true;
+ else
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/793becf5/api/src/org/apache/cloudstack/acl/QuerySelector.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/acl/QuerySelector.java b/api/src/org/apache/cloudstack/acl/QuerySelector.java
new file mode 100644
index 0000000..b89aa4e
--- /dev/null
+++ b/api/src/org/apache/cloudstack/acl/QuerySelector.java
@@ -0,0 +1,72 @@
+// 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.acl;
+
+import java.util.List;
+
+import com.cloud.user.Account;
+import com.cloud.utils.component.Adapter;
+
+/**
+ * QueryChecker returns granted access at domain, account or resource level.
+ */
+public interface QuerySelector extends Adapter {
+
+ /**
+ * List granted domains for the caller, given a specific action.
+ *
+ * @param caller account to check against.
+ * @param action action
+ * @return list of domain Ids granted to the caller account.
+ */
+ List<Long> getAuthorizedDomains(Account caller, String action);
+
+ /**
+ * List granted accounts for the caller, given a specific action.
+ *
+ * @param caller account to check against.
+ * @param action action.
+ * @return list of domain Ids granted to the caller account.
+ */
+ List<Long> getAuthorizedAccounts(Account caller, String action);
+
+
+ /**
+ * List granted resources for the caller, given a specific action.
+ *
+ * @param caller account to check against.
+ * @param action action.
+ * @return list of domain Ids granted to the caller account.
+ */
+ List<Long> getAuthorizedResources(Account caller, String action);
+
+ /**
+ * Check if this account is associated with a policy with scope of ALL
+ * @param caller account to check
+ * @param action action.
+ * @return true if this account is attached with a policy for the given action of ALL scope.
+ */
+ boolean isGrantedAll(Account caller, String action);
+
+ /**
+ * List of ACL group the given account belongs to
+ * @param accountId account id.
+ * @return ACL group names
+ */
+ List<String> listAclGroupsByAccount(long accountId);
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/793becf5/api/src/org/apache/cloudstack/acl/SecurityChecker.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/acl/SecurityChecker.java b/api/src/org/apache/cloudstack/acl/SecurityChecker.java
index ab3f7c5..aab88fe 100644
--- a/api/src/org/apache/cloudstack/acl/SecurityChecker.java
+++ b/api/src/org/apache/cloudstack/acl/SecurityChecker.java
@@ -31,7 +31,7 @@ import com.cloud.utils.component.Adapter;
public interface SecurityChecker extends Adapter {
public enum AccessType {
- ListEntry, ModifyEntry, ModifyProject, UseNetwork
+ ListEntry, ModifyEntry, ModifyProject, UseNetwork, OperateEntry, UseEntry
}
/**
@@ -76,6 +76,26 @@ public interface SecurityChecker extends Adapter {
boolean checkAccess(Account caller, ControlledEntity entity, AccessType accessType) throws PermissionDeniedException;
/**
+ * Checks if the account can access the object.
+ *
+ * @param caller
+ * account to check against.
+ * @param entity
+ * object that the account is trying to access.
+ * @param accessType
+ * TODO
+ * @param action
+ * name of the API
+ * @return true if access allowed. false if this adapter cannot provide
+ * permission.
+ * @throws PermissionDeniedException
+ * if this adapter is suppose to authenticate ownership and the
+ * check failed.
+ */
+ boolean checkAccess(Account caller, ControlledEntity entity, AccessType accessType, String action) throws PermissionDeniedException;
+
+
+ /**
* Checks if the user belongs to an account that can access the object.
*
* @param user
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/793becf5/api/src/org/apache/cloudstack/api/APICommand.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/APICommand.java b/api/src/org/apache/cloudstack/api/APICommand.java
index f0b46a4..6211afc 100644
--- a/api/src/org/apache/cloudstack/api/APICommand.java
+++ b/api/src/org/apache/cloudstack/api/APICommand.java
@@ -22,6 +22,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import org.apache.cloudstack.acl.IAMEntityType;
import org.apache.cloudstack.acl.RoleType;
@Retention(RetentionPolicy.RUNTIME)
@@ -44,4 +45,6 @@ public @interface APICommand {
boolean responseHasSensitiveInfo() default true;
RoleType[] authorized() default {};
+
+ IAMEntityType[] entityType() default {};
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/793becf5/api/src/org/apache/cloudstack/api/ApiCommandJobType.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ApiCommandJobType.java b/api/src/org/apache/cloudstack/api/ApiCommandJobType.java
index 3067af8..f27f001 100644
--- a/api/src/org/apache/cloudstack/api/ApiCommandJobType.java
+++ b/api/src/org/apache/cloudstack/api/ApiCommandJobType.java
@@ -49,5 +49,7 @@ public enum ApiCommandJobType {
LoadBalancerRule,
AffinityGroup,
InternalLbVm,
- DedicatedGuestVlanRange
+ DedicatedGuestVlanRange,
+ IAMPolicy,
+ IAMGroup
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/793becf5/api/src/org/apache/cloudstack/api/ApiConstants.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java
index 7b7f9ca..14df653 100755
--- a/api/src/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/org/apache/cloudstack/api/ApiConstants.java
@@ -544,6 +544,24 @@ public class ApiConstants {
public static final String ROUTING = "isrouting";
public static final String MAX_CONNECTIONS = "maxconnections";
public static final String SERVICE_STATE = "servicestate";
+
+ public static final String IAM_ACCOUNT_IDS = "accountids";
+ public static final String IAM_MEMBER_ACCOUNTS = "memberaccounts";
+ public static final String IAM_PARENT_POLICY_ID = "parentpolicyid";
+ public static final String IAM_PARENT_POLICY_NAME = "parentpolicyname";
+ public static final String IAM_POLICY_IDS = "policyids";
+ public static final String IAM_POLICIES = "policies";
+ public static final String IAM_APIS = "apis";
+ public static final String IAM_GROUPS = "groups";
+ public static final String IAM_PERMISSIONS = "permission";
+ public static final String IAM_ACTION = "action";
+ public static final String IAM_SCOPE = "scope";
+ public static final String IAM_SCOPE_ID = "scopeid";
+ public static final String IAM_ALLOW_DENY = "permission";
+ public static final String ENTITY_TYPE = "entitytype";
+ public static final String ENTITY_ID = "entityid";
+ public static final String ACCESS_TYPE = "accesstype";
+
public static final String RESOURCE_DETAILS = "resourcedetails";
public static final String EXPUNGE = "expunge";
public static final String FOR_DISPLAY = "fordisplay";
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/793becf5/engine/components-api/src/com/cloud/template/TemplateManager.java
----------------------------------------------------------------------
diff --git a/engine/components-api/src/com/cloud/template/TemplateManager.java b/engine/components-api/src/com/cloud/template/TemplateManager.java
index 0557a29..5987ac0 100755
--- a/engine/components-api/src/com/cloud/template/TemplateManager.java
+++ b/engine/components-api/src/com/cloud/template/TemplateManager.java
@@ -122,4 +122,7 @@ public interface TemplateManager {
*/
void prepareIsoForVmProfile(VirtualMachineProfile profile);
+ public static final String MESSAGE_REGISTER_PUBLIC_TEMPLATE_EVENT = "Message.RegisterPublicTemplate.Event";
+ public static final String MESSAGE_RESET_TEMPLATE_PERMISSION_EVENT = "Message.ResetTemplatePermission.Event";
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/793becf5/server/src/com/cloud/acl/DomainChecker.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/acl/DomainChecker.java b/server/src/com/cloud/acl/DomainChecker.java
index 31b273f..f8acceb 100755
--- a/server/src/com/cloud/acl/DomainChecker.java
+++ b/server/src/com/cloud/acl/DomainChecker.java
@@ -319,4 +319,10 @@ public class DomainChecker extends AdapterBase implements SecurityChecker {
}
return false;
}
+
+ @Override
+ public boolean checkAccess(Account caller, ControlledEntity entity, AccessType accessType, String action)
+ throws PermissionDeniedException {
+ return checkAccess(caller, entity, accessType);
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/793becf5/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 3df599e..05fe6e8 100755
--- a/server/src/com/cloud/api/ApiServer.java
+++ b/server/src/com/cloud/api/ApiServer.java
@@ -891,7 +891,8 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
}
}
- private Class<?> getCmdClass(String cmdName) {
+ @Override
+ public Class<?> getCmdClass(String cmdName) {
return s_apiNameCmdClassMap.get(cmdName);
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/793becf5/server/src/com/cloud/api/ApiServerService.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiServerService.java b/server/src/com/cloud/api/ApiServerService.java
index 8e078c6..bf0ba23 100644
--- a/server/src/com/cloud/api/ApiServerService.java
+++ b/server/src/com/cloud/api/ApiServerService.java
@@ -41,4 +41,6 @@ public interface ApiServerService {
public String getSerializedApiError(ServerApiException ex, Map<String, Object[]> apiCommandParams, String responseType);
public String handleRequest(Map params, String responseType, StringBuffer auditTrailSb) throws ServerApiException;
+
+ public Class<?> getCmdClass(String cmdName);
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/793becf5/server/src/com/cloud/user/AccountManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/AccountManager.java b/server/src/com/cloud/user/AccountManager.java
index 1f191fc..983caf1 100755
--- a/server/src/com/cloud/user/AccountManager.java
+++ b/server/src/com/cloud/user/AccountManager.java
@@ -188,4 +188,8 @@ public interface AccountManager extends AccountService {
* @return account object
*/
Account lockAccount(String accountName, Long domainId, Long accountId);
+
+ public static final String MESSAGE_ADD_ACCOUNT_EVENT = "Message.AddAccount.Event";
+
+ public static final String MESSAGE_REMOVE_ACCOUNT_EVENT = "Message.RemoveAccount.Event";
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/793becf5/server/src/com/cloud/user/DomainManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/DomainManager.java b/server/src/com/cloud/user/DomainManager.java
index 41d9d34..f72b18a 100644
--- a/server/src/com/cloud/user/DomainManager.java
+++ b/server/src/com/cloud/user/DomainManager.java
@@ -47,4 +47,7 @@ public interface DomainManager extends DomainService {
* @return Domain object if the command succeeded
*/
Domain updateDomain(UpdateDomainCmd cmd);
+
+ public static final String MESSAGE_ADD_DOMAIN_EVENT = "Message.AddDomain.Event";
+ public static final String MESSAGE_REMOVE_DOMAIN_EVENT = "Message.RemoveDomain.Event";
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/793becf5/utils/src/com/cloud/utils/db/EntityManager.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/db/EntityManager.java b/utils/src/com/cloud/utils/db/EntityManager.java
index 7612a75..8f4e385 100644
--- a/utils/src/com/cloud/utils/db/EntityManager.java
+++ b/utils/src/com/cloud/utils/db/EntityManager.java
@@ -75,4 +75,10 @@ public interface EntityManager {
public <T, K extends Serializable> void remove(Class<T> entityType, K id);
public <T, K extends Serializable> T findByIdIncludingRemoved(Class<T> entityType, K id);
+
+ public static final String MESSAGE_REMOVE_ENTITY_EVENT = "Message.RemoveEntity.Event";
+
+ public static final String MESSAGE_GRANT_ENTITY_EVENT = "Message.GrantEntity.Event";
+ public static final String MESSAGE_REVOKE_ENTITY_EVENT = "Message.RevokeEntity.Event";
+ public static final String MESSAGE_ADD_DOMAIN_WIDE_ENTITY_EVENT = "Message.AddDomainWideEntity.Event";
}
[9/9] git commit: updated refs/heads/master to 63e3eea
Posted by mc...@apache.org.
CLOUDSTACK-5920: enable build of IAM services in pom.xml.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/63e3eea7
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/63e3eea7
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/63e3eea7
Branch: refs/heads/master
Commit: 63e3eea7905e22cab9466b28a2ab2a80b586aeed
Parents: c28450c
Author: Min Chen <mi...@citrix.com>
Authored: Tue Mar 4 17:53:10 2014 -0800
Committer: Min Chen <mi...@citrix.com>
Committed: Wed Mar 5 09:40:56 2014 -0800
----------------------------------------------------------------------
services/iam/pom.xml | 59 +++++++++++++++++++++++++++++++++++++++++++++++
services/pom.xml | 1 +
2 files changed, 60 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/63e3eea7/services/iam/pom.xml
----------------------------------------------------------------------
diff --git a/services/iam/pom.xml b/services/iam/pom.xml
new file mode 100644
index 0000000..d4bf3e7
--- /dev/null
+++ b/services/iam/pom.xml
@@ -0,0 +1,59 @@
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>cloudstack-service-iam</artifactId>
+ <name>Apache CloudStack IAM Service</name>
+ <packaging>pom</packaging>
+ <parent>
+ <groupId>org.apache.cloudstack</groupId>
+ <artifactId>cloudstack-services</artifactId>
+ <version>4.4.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <build>
+ <defaultGoal>install</defaultGoal>
+ </build>
+ <modules>
+ <module>plugin</module>
+ <module>server</module>
+ </modules>
+ <!--
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.cloudstack</groupId>
+ <artifactId>cloud-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cloudstack</groupId>
+ <artifactId>cloud-utils</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cloudstack</groupId>
+ <artifactId>cloud-api</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ -->
+
+</project>
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/63e3eea7/services/pom.xml
----------------------------------------------------------------------
diff --git a/services/pom.xml b/services/pom.xml
index def3027..0212437 100644
--- a/services/pom.xml
+++ b/services/pom.xml
@@ -47,5 +47,6 @@
<module>console-proxy</module>
<module>console-proxy-rdp/rdpconsole</module>
<module>secondary-storage</module>
+ <module>iam</module>
</modules>
</project>
[3/9] git commit: updated refs/heads/master to 63e3eea
Posted by mc...@apache.org.
CLOUDSTACK-5920: IAM service plugin.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/c28450c1
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/c28450c1
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/c28450c1
Branch: refs/heads/master
Commit: c28450c1cdb51fba035f8f8f864dd0450ea1e099
Parents: adb29b2
Author: Min Chen <mi...@citrix.com>
Authored: Tue Mar 4 17:52:19 2014 -0800
Committer: Min Chen <mi...@citrix.com>
Committed: Wed Mar 5 09:40:55 2014 -0800
----------------------------------------------------------------------
services/iam/plugin/pom.xml | 58 ++
.../iam-access-checkers/module.properties | 18 +
.../spring-iam-access-checkers-context.xml | 35 +
.../command/iam/AddAccountToIAMGroupCmd.java | 127 +++
.../iam/AddIAMPermissionToIAMPolicyCmd.java | 155 ++++
.../iam/AttachIAMPolicyToAccountCmd.java | 122 +++
.../iam/AttachIAMPolicyToIAMGroupCmd.java | 127 +++
.../api/command/iam/CreateIAMGroupCmd.java | 168 ++++
.../api/command/iam/CreateIAMPolicyCmd.java | 175 ++++
.../api/command/iam/DeleteIAMGroupCmd.java | 102 +++
.../api/command/iam/DeleteIAMPolicyCmd.java | 102 +++
.../api/command/iam/ListIAMGroupsCmd.java | 88 ++
.../api/command/iam/ListIAMPoliciesCmd.java | 88 ++
.../iam/RemoveAccountFromIAMGroupCmd.java | 127 +++
.../RemoveIAMPermissionFromIAMPolicyCmd.java | 148 ++++
.../iam/RemoveIAMPolicyFromAccountCmd.java | 122 +++
.../iam/RemoveIAMPolicyFromIAMGroupCmd.java | 127 +++
.../api/response/iam/IAMGroupResponse.java | 193 +++++
.../api/response/iam/IAMPermissionResponse.java | 125 +++
.../api/response/iam/IAMPolicyResponse.java | 177 ++++
.../apache/cloudstack/iam/IAMApiService.java | 87 ++
.../cloudstack/iam/IAMApiServiceImpl.java | 800 +++++++++++++++++++
.../iam/RoleBasedAPIAccessChecker.java | 273 +++++++
.../iam/RoleBasedEntityAccessChecker.java | 186 +++++
.../iam/RoleBasedEntityQuerySelector.java | 147 ++++
.../cloudstack/iam/test/IAMApiServiceTest.java | 369 +++++++++
.../iam/plugin/test/resources/db.properties | 75 ++
27 files changed, 4321 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/pom.xml
----------------------------------------------------------------------
diff --git a/services/iam/plugin/pom.xml b/services/iam/plugin/pom.xml
new file mode 100644
index 0000000..0650e43
--- /dev/null
+++ b/services/iam/plugin/pom.xml
@@ -0,0 +1,58 @@
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>cloud-plugin-iam</artifactId>
+ <name>Apache CloudStack IAM - Plugin</name>
+ <parent>
+ <groupId>org.apache.cloudstack</groupId>
+ <artifactId>cloudstack-service-iam</artifactId>
+ <version>4.4.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.cloudstack</groupId>
+ <artifactId>cloud-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cloudstack</groupId>
+ <artifactId>cloud-engine-schema</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cloudstack</groupId>
+ <artifactId>cloud-server</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cloudstack</groupId>
+ <artifactId>cloud-iam</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cloudstack</groupId>
+ <artifactId>cloud-api</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/resources/META-INF/cloudstack/iam-access-checkers/module.properties
----------------------------------------------------------------------
diff --git a/services/iam/plugin/resources/META-INF/cloudstack/iam-access-checkers/module.properties b/services/iam/plugin/resources/META-INF/cloudstack/iam-access-checkers/module.properties
new file mode 100644
index 0000000..c87480d
--- /dev/null
+++ b/services/iam/plugin/resources/META-INF/cloudstack/iam-access-checkers/module.properties
@@ -0,0 +1,18 @@
+# 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.
+name=iam-access-checkers
+parent=api
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/resources/META-INF/cloudstack/iam-access-checkers/spring-iam-access-checkers-context.xml
----------------------------------------------------------------------
diff --git a/services/iam/plugin/resources/META-INF/cloudstack/iam-access-checkers/spring-iam-access-checkers-context.xml b/services/iam/plugin/resources/META-INF/cloudstack/iam-access-checkers/spring-iam-access-checkers-context.xml
new file mode 100644
index 0000000..983bf08
--- /dev/null
+++ b/services/iam/plugin/resources/META-INF/cloudstack/iam-access-checkers/spring-iam-access-checkers-context.xml
@@ -0,0 +1,35 @@
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:aop="http://www.springframework.org/schema/aop"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd"
+ >
+
+ <bean id="RoleBasedAPIAccessChecker" class="org.apache.cloudstack.iam.RoleBasedAPIAccessChecker" />
+ <bean id="RoleBasedEntityAccessChecker" class="org.apache.cloudstack.iam.RoleBasedEntityAccessChecker" />
+ <bean id="RoleBasedEntityQuerySelector" class="org.apache.cloudstack.iam.RoleBasedEntityQuerySelector" />
+ <bean id="IAMApiServiceImpl" class="org.apache.cloudstack.iam.IAMApiServiceImpl" />
+
+</beans>
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/AddAccountToIAMGroupCmd.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/AddAccountToIAMGroupCmd.java b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/AddAccountToIAMGroupCmd.java
new file mode 100644
index 0000000..bea3fc9
--- /dev/null
+++ b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/AddAccountToIAMGroupCmd.java
@@ -0,0 +1,127 @@
+// 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.api.command.iam;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.iam.IAMApiService;
+import org.apache.cloudstack.api.ACL;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiCommandJobType;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.AccountResponse;
+import org.apache.cloudstack.api.response.iam.IAMGroupResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.iam.api.IAMGroup;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.user.Account;
+
+
+@APICommand(name = "addAccountToIAMGroup", description = "add account to an iam group", responseObject = IAMGroupResponse.class)
+public class AddAccountToIAMGroupCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(AddAccountToIAMGroupCmd.class.getName());
+ private static final String s_name = "addaccounttoiamgroupresponse";
+
+ @Inject
+ public IAMApiService _iamApiSrv;
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+
+ @ACL
+ @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = IAMGroupResponse.class,
+ required = true, description = "The ID of the iam group")
+ private Long id;
+
+ @ACL
+ @Parameter(name = ApiConstants.ACCOUNTS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = AccountResponse.class, description = "comma separated list of account id that are going to be assigned to the iam group.")
+ private List<Long> accountIdList;
+
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+
+ public Long getId() {
+ return id;
+ }
+
+
+ public List<Long> getAccountIdList() {
+ return accountIdList;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+ }
+
+ @Override
+ public void execute() throws ResourceUnavailableException,
+ InsufficientCapacityException, ServerApiException {
+ CallContext.current().setEventDetails("IAM group Id: " + getId());
+ IAMGroup result = _iamApiSrv.addAccountsToGroup(accountIdList, id);
+ if (result != null){
+ IAMGroupResponse response = _iamApiSrv.createIAMGroupResponse(result);
+ response.setResponseName(getCommandName());
+ setResponseObject(response);
+ } else {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add accounts to iam group");
+ }
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_IAM_GROUP_UPDATE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "adding accounts to iam group";
+ }
+
+ @Override
+ public ApiCommandJobType getInstanceType() {
+ return ApiCommandJobType.IAMGroup;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/AddIAMPermissionToIAMPolicyCmd.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/AddIAMPermissionToIAMPolicyCmd.java b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/AddIAMPermissionToIAMPolicyCmd.java
new file mode 100644
index 0000000..e991537
--- /dev/null
+++ b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/AddIAMPermissionToIAMPolicyCmd.java
@@ -0,0 +1,155 @@
+// 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.api.command.iam;
+
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.acl.PermissionScope;
+import org.apache.cloudstack.api.ACL;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiCommandJobType;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.iam.IAMPolicyResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.iam.IAMApiService;
+import org.apache.cloudstack.iam.api.IAMPolicy;
+import org.apache.cloudstack.iam.api.IAMPolicyPermission.Permission;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.user.Account;
+import com.cloud.utils.db.EntityManager;
+
+
+@APICommand(name = "addIAMPermissionToIAMPolicy", description = "Add IAM permission to an iam policy", responseObject = IAMPolicyResponse.class)
+public class AddIAMPermissionToIAMPolicyCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(AddIAMPermissionToIAMPolicyCmd.class.getName());
+ private static final String s_name = "addiampermissiontoiampolicyresponse";
+
+ @Inject
+ public IAMApiService _iamApiSrv;
+ @Inject
+ public EntityManager _entityMgr;
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+
+ @ACL
+ @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = IAMPolicyResponse.class,
+ required = true, description = "The ID of the iam policy")
+ private Long id;
+
+ @Parameter(name = ApiConstants.IAM_ACTION, type = CommandType.STRING, required = true, description = "action api name.")
+ private String action;
+
+ @Parameter(name = ApiConstants.ENTITY_TYPE, type = CommandType.STRING, required = false, description = "entity class simple name.")
+ private String entityType;
+
+ @Parameter(name = ApiConstants.IAM_SCOPE, type = CommandType.STRING,
+ required = false, description = "iam permission scope")
+ private String scope;
+
+ @Parameter(name = ApiConstants.IAM_SCOPE_ID, type = CommandType.STRING, required = false, description = "The UUID of the permission scope id")
+ private String scopeId;
+
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+
+ public Long getId() {
+ return id;
+ }
+
+
+ public String getAction() {
+ return action;
+ }
+
+ public String getEntityType() {
+ return entityType;
+ }
+
+ public String getScope() {
+ return scope;
+ }
+
+ public Long getScopeId() {
+ // here we will convert the passed String UUID to Long ID since internally we store it as entity internal ID.
+ return _iamApiSrv.getPermissionScopeId(scope, entityType, scopeId);
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+ }
+
+ @Override
+ public void execute() throws ResourceUnavailableException,
+ InsufficientCapacityException, ServerApiException {
+ CallContext.current().setEventDetails("IAM policy Id: " + getId());
+ // Only explicit ALLOW is supported for this release, no explicit deny
+ IAMPolicy result = _iamApiSrv.addIAMPermissionToIAMPolicy(id, entityType, PermissionScope.valueOf(scope),
+ getScopeId(), action, Permission.Allow, false);
+ if (result != null) {
+ IAMPolicyResponse response = _iamApiSrv.createIAMPolicyResponse(result);
+ response.setResponseName(getCommandName());
+ setResponseObject(response);
+ } else {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to grant permission to iam policy "
+ + getId());
+ }
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_IAM_POLICY_GRANT;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "granting permission to iam policy";
+ }
+
+ @Override
+ public ApiCommandJobType getInstanceType() {
+ return ApiCommandJobType.IAMPolicy;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/AttachIAMPolicyToAccountCmd.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/AttachIAMPolicyToAccountCmd.java b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/AttachIAMPolicyToAccountCmd.java
new file mode 100644
index 0000000..fc174cf
--- /dev/null
+++ b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/AttachIAMPolicyToAccountCmd.java
@@ -0,0 +1,122 @@
+// 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.api.command.iam;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.iam.IAMApiService;
+import org.apache.cloudstack.api.ACL;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiCommandJobType;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.AccountResponse;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.api.response.iam.IAMPolicyResponse;
+import org.apache.cloudstack.context.CallContext;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.user.Account;
+
+
+@APICommand(name = "attachIAMPolicyToAccount", description = "attach iam policy to accounts", responseObject = SuccessResponse.class)
+public class AttachIAMPolicyToAccountCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(AttachIAMPolicyToAccountCmd.class.getName());
+ private static final String s_name = "attachiampolicytoaccountresponse";
+
+ @Inject
+ public IAMApiService _iamApiSrv;
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+
+ @ACL
+ @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = IAMPolicyResponse.class,
+ required = true, description = "The ID of the iam policy")
+ private Long id;
+
+ @ACL
+ @Parameter(name = ApiConstants.ACCOUNTS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = AccountResponse.class, description = "comma separated list of account id that the policy will attach to.")
+ private List<Long> accountIdList;
+
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+
+ public Long getId() {
+ return id;
+ }
+
+
+ public List<Long> getAccountIdList() {
+ return accountIdList;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+ }
+
+ @Override
+ public void execute() throws ResourceUnavailableException,
+ InsufficientCapacityException, ServerApiException {
+ CallContext.current().setEventDetails("IAM policy Id: " + getId());
+ _iamApiSrv.attachIAMPolicyToAccounts(id, accountIdList);
+ SuccessResponse response = new SuccessResponse();
+ response.setResponseName(getCommandName());
+ setResponseObject(response);
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_IAM_ACCOUNT_POLICY_UPDATE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "adding IAM policy to accounts";
+ }
+
+ @Override
+ public ApiCommandJobType getInstanceType() {
+ return ApiCommandJobType.Account;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/AttachIAMPolicyToIAMGroupCmd.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/AttachIAMPolicyToIAMGroupCmd.java b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/AttachIAMPolicyToIAMGroupCmd.java
new file mode 100644
index 0000000..1705c4a
--- /dev/null
+++ b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/AttachIAMPolicyToIAMGroupCmd.java
@@ -0,0 +1,127 @@
+// 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.api.command.iam;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.iam.IAMApiService;
+import org.apache.cloudstack.api.ACL;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiCommandJobType;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.iam.IAMGroupResponse;
+import org.apache.cloudstack.api.response.iam.IAMPolicyResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.iam.api.IAMGroup;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.user.Account;
+
+
+@APICommand(name = "attachIAMPolicyToIAMGroup", description = "attach iam policy to an iam group", responseObject = IAMGroupResponse.class)
+public class AttachIAMPolicyToIAMGroupCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(AttachIAMPolicyToIAMGroupCmd.class.getName());
+ private static final String s_name = "attachiampolicytoiamgroupresponse";
+
+ @Inject
+ public IAMApiService _iamApiSrv;
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+
+ @ACL
+ @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = IAMGroupResponse.class,
+ required = true, description = "The ID of the iam group")
+ private Long id;
+
+ @ACL
+ @Parameter(name = ApiConstants.IAM_POLICIES, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = IAMPolicyResponse.class, description = "comma separated list of iam policy id that are going to be applied to the iam group.")
+ private List<Long> policyIdList;
+
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+
+ public Long getId() {
+ return id;
+ }
+
+
+ public List<Long> getPolicyIdList() {
+ return policyIdList;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+ }
+
+ @Override
+ public void execute() throws ResourceUnavailableException,
+ InsufficientCapacityException, ServerApiException {
+ CallContext.current().setEventDetails("IAM group Id: " + getId());
+ IAMGroup result = _iamApiSrv.attachIAMPoliciesToGroup(policyIdList, id);
+ if (result != null){
+ IAMGroupResponse response = _iamApiSrv.createIAMGroupResponse(result);
+ response.setResponseName(getCommandName());
+ setResponseObject(response);
+ } else {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add roles to iam group");
+ }
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_IAM_GROUP_UPDATE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "adding iam roles to iam group";
+ }
+
+ @Override
+ public ApiCommandJobType getInstanceType() {
+ return ApiCommandJobType.IAMGroup;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/CreateIAMGroupCmd.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/CreateIAMGroupCmd.java b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/CreateIAMGroupCmd.java
new file mode 100644
index 0000000..d0b9bc6
--- /dev/null
+++ b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/CreateIAMGroupCmd.java
@@ -0,0 +1,168 @@
+// 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.api.command.iam;
+
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.iam.IAMApiService;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiCommandJobType;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseAsyncCreateCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.api.response.iam.IAMGroupResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.iam.api.IAMGroup;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.user.Account;
+
+@APICommand(name = "createIAMGroup", responseObject = IAMGroupResponse.class, description = "Creates an IAM group")
+public class CreateIAMGroupCmd extends BaseAsyncCreateCmd {
+ public static final Logger s_logger = Logger.getLogger(CreateIAMGroupCmd.class.getName());
+
+ private static final String s_name = "createiamgroupresponse";
+
+ @Inject
+ public IAMApiService _iamApiSrv;
+
+ // ///////////////////////////////////////////////////
+ // ////////////// API parameters /////////////////////
+ // ///////////////////////////////////////////////////
+
+ @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "an account for the iam group. Must be used with domainId.")
+ private String accountName;
+
+ @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, description = "domainId of the account owning the iam group", entityType = DomainResponse.class)
+ private Long domainId;
+
+ @Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "optional description of the iam group")
+ private String description;
+
+ @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "name of the iam group")
+ private String name;
+
+
+ // ///////////////////////////////////////////////////
+ // ///////////////// Accessors ///////////////////////
+ // ///////////////////////////////////////////////////
+
+ public String getAccountName() {
+ return accountName;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public Long getDomainId() {
+ return domainId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+
+ // ///////////////////////////////////////////////////
+ // ///////////// API Implementation///////////////////
+ // ///////////////////////////////////////////////////
+
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Account account = CallContext.current().getCallingAccount();
+ if ((account == null) || _accountService.isAdmin(account.getType())) {
+ if ((domainId != null) && (accountName != null)) {
+ Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId);
+ if (userAccount != null) {
+ return userAccount.getId();
+ }
+ }
+ }
+
+ if (account != null) {
+ return account.getId();
+ }
+
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this
+ // command to SYSTEM so ERROR events
+ // are tracked
+ }
+
+ @Override
+ public void execute() {
+ IAMGroup grp = _entityMgr.findById(IAMGroup.class, getEntityId());
+ if (grp != null) {
+ IAMGroupResponse response = _iamApiSrv.createIAMGroupResponse(grp);
+ response.setResponseName(getCommandName());
+ setResponseObject(response);
+ } else {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create iam group:" + name);
+ }
+ }
+
+ @Override
+ public void create() throws ResourceAllocationException {
+ Account account = CallContext.current().getCallingAccount();
+ IAMGroup result = _iamApiSrv.createIAMGroup(account, name, description);
+ if (result != null) {
+ setEntityId(result.getId());
+ setEntityUuid(result.getUuid());
+ } else {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create iam group entity" + name);
+ }
+
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_IAM_GROUP_CREATE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "creating IAM group";
+ }
+
+ @Override
+ public String getCreateEventType() {
+ return EventTypes.EVENT_IAM_GROUP_CREATE;
+ }
+
+ @Override
+ public String getCreateEventDescription() {
+ return "creating IAM group";
+ }
+
+ @Override
+ public ApiCommandJobType getInstanceType() {
+ return ApiCommandJobType.IAMGroup;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/CreateIAMPolicyCmd.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/CreateIAMPolicyCmd.java b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/CreateIAMPolicyCmd.java
new file mode 100644
index 0000000..be863de
--- /dev/null
+++ b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/CreateIAMPolicyCmd.java
@@ -0,0 +1,175 @@
+// 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.api.command.iam;
+
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.iam.IAMApiService;
+import org.apache.cloudstack.api.ACL;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiCommandJobType;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseAsyncCreateCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.api.response.iam.IAMPolicyResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.iam.api.IAMPolicy;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.user.Account;
+
+@APICommand(name = "createIAMPolicy", responseObject = IAMPolicyResponse.class, description = "Creates an iam policy")
+public class CreateIAMPolicyCmd extends BaseAsyncCreateCmd {
+ public static final Logger s_logger = Logger.getLogger(CreateIAMPolicyCmd.class.getName());
+
+ private static final String s_name = "createiampolicyresponse";
+
+ @Inject
+ public IAMApiService _iamApiSrv;
+
+ // ///////////////////////////////////////////////////
+ // ////////////// API parameters /////////////////////
+ // ///////////////////////////////////////////////////
+
+ @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "an account for the iam policy. Must be used with domainId.")
+ private String accountName;
+
+ @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, description = "domainId of the account owning the iam policy", entityType = DomainResponse.class)
+ private Long domainId;
+
+ @Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "optional description of the iam policy")
+ private String description;
+
+ @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "name of the iam policy")
+ private String name;
+
+ @ACL
+ @Parameter(name = ApiConstants.IAM_PARENT_POLICY_ID, type = CommandType.UUID, description = "The ID of parent iam policy.", entityType = IAMPolicyResponse.class)
+ private Long parentPolicyId;
+
+
+ // ///////////////////////////////////////////////////
+ // ///////////////// Accessors ///////////////////////
+ // ///////////////////////////////////////////////////
+
+ public String getAccountName() {
+ return accountName;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public Long getDomainId() {
+ return domainId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Long getParentPolicyId() {
+ return parentPolicyId;
+ }
+
+ // ///////////////////////////////////////////////////
+ // ///////////// API Implementation///////////////////
+ // ///////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Account account = CallContext.current().getCallingAccount();
+ if ((account == null) || _accountService.isAdmin(account.getType())) {
+ if ((domainId != null) && (accountName != null)) {
+ Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId);
+ if (userAccount != null) {
+ return userAccount.getId();
+ }
+ }
+ }
+
+ if (account != null) {
+ return account.getId();
+ }
+
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this
+ // command to SYSTEM so ERROR events
+ // are tracked
+ }
+
+ @Override
+ public void execute() {
+ IAMPolicy policy = _entityMgr.findById(IAMPolicy.class, getEntityId());
+ if (policy != null) {
+ IAMPolicyResponse response = _iamApiSrv.createIAMPolicyResponse(policy);
+ response.setResponseName(getCommandName());
+ setResponseObject(response);
+ } else {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create iam policy:" + name);
+ }
+ }
+
+ @Override
+ public void create() throws ResourceAllocationException {
+ Account account = CallContext.current().getCallingAccount();
+ IAMPolicy result = _iamApiSrv.createIAMPolicy(account, name, description, parentPolicyId);
+ if (result != null) {
+ setEntityId(result.getId());
+ setEntityUuid(result.getUuid());
+ } else {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create iam policy entity" + name);
+ }
+
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_IAM_POLICY_CREATE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "creating IAM policy";
+ }
+
+ @Override
+ public String getCreateEventType() {
+ return EventTypes.EVENT_IAM_POLICY_CREATE;
+ }
+
+ @Override
+ public String getCreateEventDescription() {
+ return "creating IAM policy";
+ }
+
+ @Override
+ public ApiCommandJobType getInstanceType() {
+ return ApiCommandJobType.IAMPolicy;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/DeleteIAMGroupCmd.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/DeleteIAMGroupCmd.java b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/DeleteIAMGroupCmd.java
new file mode 100644
index 0000000..60b1e24
--- /dev/null
+++ b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/DeleteIAMGroupCmd.java
@@ -0,0 +1,102 @@
+// 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.api.command.iam;
+
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ACL;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiCommandJobType;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.api.response.iam.IAMGroupResponse;
+import org.apache.cloudstack.iam.IAMApiService;
+
+import com.cloud.event.EventTypes;
+import com.cloud.user.Account;
+
+@APICommand(name = "deleteIAMGroup", description = "Deletes acl group", responseObject = SuccessResponse.class)
+public class DeleteIAMGroupCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(DeleteIAMGroupCmd.class.getName());
+ private static final String s_name = "deleteaclgroupresponse";
+
+ @Inject
+ public IAMApiService _aclApiSrv;
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @ACL
+ @Parameter(name = ApiConstants.ID, type = CommandType.UUID, description = "The ID of the acl group.", required = true, entityType = IAMGroupResponse.class)
+ private Long id;
+
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getId() {
+ return id;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+ @Override
+ public void execute(){
+ boolean result = _aclApiSrv.deleteIAMGroup(id);
+ if (result) {
+ SuccessResponse response = new SuccessResponse(getCommandName());
+ setResponseObject(response);
+ } else {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete acl group");
+ }
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_IAM_GROUP_DELETE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "Deleting Acl group";
+ }
+
+ @Override
+ public ApiCommandJobType getInstanceType() {
+ return ApiCommandJobType.IAMGroup;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/DeleteIAMPolicyCmd.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/DeleteIAMPolicyCmd.java b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/DeleteIAMPolicyCmd.java
new file mode 100644
index 0000000..037f4cd
--- /dev/null
+++ b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/DeleteIAMPolicyCmd.java
@@ -0,0 +1,102 @@
+// 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.api.command.iam;
+
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.iam.IAMApiService;
+import org.apache.cloudstack.api.ACL;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiCommandJobType;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.api.response.iam.IAMPolicyResponse;
+
+import com.cloud.event.EventTypes;
+import com.cloud.user.Account;
+
+@APICommand(name = "deleteIAMPolicy", description = "Deletes iam policy", responseObject = SuccessResponse.class)
+public class DeleteIAMPolicyCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(DeleteIAMPolicyCmd.class.getName());
+ private static final String s_name = "deleteiampolicyresponse";
+
+ @Inject
+ public IAMApiService _iamApiSrv;
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @ACL
+ @Parameter(name = ApiConstants.ID, type = CommandType.UUID, description = "The ID of the iam policy.", required = true, entityType = IAMPolicyResponse.class)
+ private Long id;
+
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getId() {
+ return id;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+ @Override
+ public void execute(){
+ boolean result = _iamApiSrv.deleteIAMPolicy(id);
+ if (result) {
+ SuccessResponse response = new SuccessResponse(getCommandName());
+ setResponseObject(response);
+ } else {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete iam policy");
+ }
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_IAM_POLICY_DELETE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "Deleting IAM policy";
+ }
+
+ @Override
+ public ApiCommandJobType getInstanceType() {
+ return ApiCommandJobType.IAMPolicy;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/ListIAMGroupsCmd.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/ListIAMGroupsCmd.java b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/ListIAMGroupsCmd.java
new file mode 100644
index 0000000..ece87fa
--- /dev/null
+++ b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/ListIAMGroupsCmd.java
@@ -0,0 +1,88 @@
+// 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.api.command.iam;
+
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.iam.IAMApiService;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiCommandJobType;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseListDomainResourcesCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.iam.IAMGroupResponse;
+
+
+@APICommand(name = "listIAMGroups", description = "Lists iam groups", responseObject = IAMGroupResponse.class)
+public class ListIAMGroupsCmd extends BaseListDomainResourcesCmd {
+ public static final Logger s_logger = Logger.getLogger(ListIAMGroupsCmd.class.getName());
+
+ private static final String s_name = "listiamgroupsresponse";
+
+ @Inject
+ public IAMApiService _iamApiSrv;
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "lists iam groups by name")
+ private String iamGroupName;
+
+ @Parameter(name = ApiConstants.ID, type = CommandType.UUID, description = "list the iam group by the id provided", entityType = IAMGroupResponse.class)
+ private Long id;
+
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+ public String getIAMGroupName() {
+ return iamGroupName;
+ }
+
+
+ public Long getId(){
+ return id;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public void execute(){
+
+ ListResponse<IAMGroupResponse> response = _iamApiSrv.listIAMGroups(id, iamGroupName, getDomainId(),
+ getStartIndex(), getPageSizeVal());
+ response.setResponseName(getCommandName());
+ setResponseObject(response);
+
+ }
+
+ @Override
+ public ApiCommandJobType getInstanceType() {
+ return ApiCommandJobType.IAMGroup;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/ListIAMPoliciesCmd.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/ListIAMPoliciesCmd.java b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/ListIAMPoliciesCmd.java
new file mode 100644
index 0000000..096cc3b
--- /dev/null
+++ b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/ListIAMPoliciesCmd.java
@@ -0,0 +1,88 @@
+// 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.api.command.iam;
+
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.iam.IAMApiService;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiCommandJobType;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseListDomainResourcesCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.iam.IAMPolicyResponse;
+
+
+@APICommand(name = "listIAMPolicies", description = "Lists IAM policies", responseObject = IAMPolicyResponse.class)
+public class ListIAMPoliciesCmd extends BaseListDomainResourcesCmd {
+ public static final Logger s_logger = Logger.getLogger(ListIAMPoliciesCmd.class.getName());
+
+ private static final String s_name = "listiampoliciesresponse";
+
+ @Inject
+ public IAMApiService _iamApiSrv;
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "lists iam policies by name")
+ private String iamPolicyName;
+
+ @Parameter(name = ApiConstants.ID, type = CommandType.UUID, description = "list the iam policy by the id provided", entityType = IAMPolicyResponse.class)
+ private Long id;
+
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+ public String getIAMPolicyName() {
+ return iamPolicyName;
+ }
+
+
+ public Long getId(){
+ return id;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public void execute(){
+
+ ListResponse<IAMPolicyResponse> response = _iamApiSrv.listIAMPolicies(id, iamPolicyName, getDomainId(),
+ getStartIndex(), getPageSizeVal());
+ response.setResponseName(getCommandName());
+ setResponseObject(response);
+
+ }
+
+ @Override
+ public ApiCommandJobType getInstanceType() {
+ return ApiCommandJobType.IAMPolicy;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/RemoveAccountFromIAMGroupCmd.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/RemoveAccountFromIAMGroupCmd.java b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/RemoveAccountFromIAMGroupCmd.java
new file mode 100644
index 0000000..5ff5039
--- /dev/null
+++ b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/RemoveAccountFromIAMGroupCmd.java
@@ -0,0 +1,127 @@
+// 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.api.command.iam;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.iam.IAMApiService;
+import org.apache.cloudstack.api.ACL;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiCommandJobType;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.AccountResponse;
+import org.apache.cloudstack.api.response.iam.IAMGroupResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.iam.api.IAMGroup;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.user.Account;
+
+
+@APICommand(name = "removeAccountFromIAMGroup", description = "remove accounts from an iam group", responseObject = IAMGroupResponse.class)
+public class RemoveAccountFromIAMGroupCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(RemoveAccountFromIAMGroupCmd.class.getName());
+ private static final String s_name = "removeaccountfromiamgroupresponse";
+
+ @Inject
+ public IAMApiService _iamApiSrv;
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+
+ @ACL
+ @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = IAMGroupResponse.class,
+ required = true, description = "The ID of the iam group")
+ private Long id;
+
+ @ACL
+ @Parameter(name = ApiConstants.ACCOUNTS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = AccountResponse.class, description = "comma separated list of account id that are going to be assigned to the iam group.")
+ private List<Long> accountIdList;
+
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+
+ public Long getId() {
+ return id;
+ }
+
+
+ public List<Long> getAccountIdList() {
+ return accountIdList;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+ }
+
+ @Override
+ public void execute() throws ResourceUnavailableException,
+ InsufficientCapacityException, ServerApiException {
+ CallContext.current().setEventDetails("IAM group Id: " + getId());
+ IAMGroup result = _iamApiSrv.removeAccountsFromGroup(accountIdList, id);
+ if (result != null){
+ IAMGroupResponse response = _iamApiSrv.createIAMGroupResponse(result);
+ response.setResponseName(getCommandName());
+ setResponseObject(response);
+ } else {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove accounts from iam group");
+ }
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_IAM_GROUP_UPDATE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "removing accounts from iam group";
+ }
+
+ @Override
+ public ApiCommandJobType getInstanceType() {
+ return ApiCommandJobType.IAMGroup;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/RemoveIAMPermissionFromIAMPolicyCmd.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/RemoveIAMPermissionFromIAMPolicyCmd.java b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/RemoveIAMPermissionFromIAMPolicyCmd.java
new file mode 100644
index 0000000..bf065a0
--- /dev/null
+++ b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/RemoveIAMPermissionFromIAMPolicyCmd.java
@@ -0,0 +1,148 @@
+// 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.api.command.iam;
+
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.acl.PermissionScope;
+import org.apache.cloudstack.api.ACL;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiCommandJobType;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.iam.IAMPolicyResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.iam.IAMApiService;
+import org.apache.cloudstack.iam.api.IAMPolicy;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.user.Account;
+
+
+@APICommand(name = "removeIAMPermissionFromIAMPolicy", description = "Remove iam permission from an iam policy", responseObject = IAMPolicyResponse.class)
+public class RemoveIAMPermissionFromIAMPolicyCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(RemoveIAMPermissionFromIAMPolicyCmd.class.getName());
+ private static final String s_name = "removeiampermissionfromiampolicyresponse";
+
+ @Inject
+ public IAMApiService _iamApiSrv;
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+
+ @ACL
+ @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = IAMPolicyResponse.class,
+ required = true, description = "The ID of the iam policy")
+ private Long id;
+
+ @Parameter(name = ApiConstants.IAM_ACTION, type = CommandType.STRING, required = true, description = "action api name.")
+ private String action;
+
+ @Parameter(name = ApiConstants.ENTITY_TYPE, type = CommandType.STRING, required = false, description = "entity class simple name.")
+ private String entityType;
+
+ @Parameter(name = ApiConstants.IAM_SCOPE, type = CommandType.STRING,
+ required = false, description = "iam permission scope")
+ private String scope;
+
+ @Parameter(name = ApiConstants.IAM_SCOPE_ID, type = CommandType.STRING, required = false, description = "The ID of the permission scope id")
+ private String scopeId;
+
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+
+ public Long getId() {
+ return id;
+ }
+
+
+ public String getAction() {
+ return action;
+ }
+
+ public String getEntityType() {
+ return entityType;
+ }
+
+ public String getScope() {
+ return scope;
+ }
+
+ public Long getScopeId() {
+ // here we will convert the passed String UUID to Long ID since internally we store it as entity internal ID.
+ return _iamApiSrv.getPermissionScopeId(scope, entityType, scopeId);
+ }
+
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+ }
+
+ @Override
+ public void execute() throws ResourceUnavailableException,
+ InsufficientCapacityException, ServerApiException {
+ CallContext.current().setEventDetails("IAM policy Id: " + getId());
+ IAMPolicy result = _iamApiSrv.removeIAMPermissionFromIAMPolicy(id, entityType, PermissionScope.valueOf(scope), getScopeId(), action);
+ if (result != null) {
+ IAMPolicyResponse response = _iamApiSrv.createIAMPolicyResponse(result);
+ response.setResponseName(getCommandName());
+ setResponseObject(response);
+ } else {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove permission from iam policy " + getId());
+ }
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_IAM_POLICY_REVOKE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "removing permission from iam policy";
+ }
+
+ @Override
+ public ApiCommandJobType getInstanceType() {
+ return ApiCommandJobType.IAMPolicy;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/RemoveIAMPolicyFromAccountCmd.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/RemoveIAMPolicyFromAccountCmd.java b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/RemoveIAMPolicyFromAccountCmd.java
new file mode 100644
index 0000000..48c2a73
--- /dev/null
+++ b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/RemoveIAMPolicyFromAccountCmd.java
@@ -0,0 +1,122 @@
+// 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.api.command.iam;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ACL;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiCommandJobType;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.AccountResponse;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.api.response.iam.IAMPolicyResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.iam.IAMApiService;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.user.Account;
+
+
+@APICommand(name = "removeIAMPolicyFromAccount", description = "remove iam policy from accounts", responseObject = SuccessResponse.class)
+public class RemoveIAMPolicyFromAccountCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(RemoveIAMPolicyFromAccountCmd.class.getName());
+ private static final String s_name = "removeiampolicyfromaccountresponse";
+
+ @Inject
+ public IAMApiService _iamApiSrv;
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+
+ @ACL
+ @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = IAMPolicyResponse.class,
+ required = true, description = "The ID of the iam group")
+ private Long id;
+
+ @ACL
+ @Parameter(name = ApiConstants.ACCOUNTS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = AccountResponse.class, description = "comma separated list of iam policy id that are going to be applied to the iam group.")
+ private List<Long> accountIdList;
+
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+
+ public Long getId() {
+ return id;
+ }
+
+
+ public List<Long> getAccountIdList() {
+ return accountIdList;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+ }
+
+ @Override
+ public void execute() throws ResourceUnavailableException,
+ InsufficientCapacityException, ServerApiException {
+ CallContext.current().setEventDetails("IAM policy Id: " + getId());
+ _iamApiSrv.removeIAMPolicyFromAccounts(id, accountIdList);
+ SuccessResponse response = new SuccessResponse();
+ response.setResponseName(getCommandName());
+ setResponseObject(response);
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_IAM_ACCOUNT_POLICY_UPDATE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "removing iam policy from accounts";
+ }
+
+ @Override
+ public ApiCommandJobType getInstanceType() {
+ return ApiCommandJobType.Account;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/RemoveIAMPolicyFromIAMGroupCmd.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/RemoveIAMPolicyFromIAMGroupCmd.java b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/RemoveIAMPolicyFromIAMGroupCmd.java
new file mode 100644
index 0000000..a99143d
--- /dev/null
+++ b/services/iam/plugin/src/org/apache/cloudstack/api/command/iam/RemoveIAMPolicyFromIAMGroupCmd.java
@@ -0,0 +1,127 @@
+// 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.api.command.iam;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.iam.IAMApiService;
+import org.apache.cloudstack.api.ACL;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiCommandJobType;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.iam.IAMGroupResponse;
+import org.apache.cloudstack.api.response.iam.IAMPolicyResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.iam.api.IAMGroup;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.user.Account;
+
+
+@APICommand(name = "removeIAMPolicyFromIAMGroup", description = "remove iam policy from an iam group", responseObject = IAMGroupResponse.class)
+public class RemoveIAMPolicyFromIAMGroupCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(RemoveIAMPolicyFromIAMGroupCmd.class.getName());
+ private static final String s_name = "removeiampolicyfromiamgroupresponse";
+
+ @Inject
+ public IAMApiService _iamApiSrv;
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+
+ @ACL
+ @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = IAMGroupResponse.class,
+ required = true, description = "The ID of the iam group")
+ private Long id;
+
+ @ACL
+ @Parameter(name = ApiConstants.IAM_POLICIES, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = IAMPolicyResponse.class, description = "comma separated list of iam policy id that are going to be applied to the iam group.")
+ private List<Long> policyIdList;
+
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+
+ public Long getId() {
+ return id;
+ }
+
+
+ public List<Long> getRoleIdList() {
+ return policyIdList;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+ }
+
+ @Override
+ public void execute() throws ResourceUnavailableException,
+ InsufficientCapacityException, ServerApiException {
+ CallContext.current().setEventDetails("IAM group Id: " + getId());
+ IAMGroup result = _iamApiSrv.removeIAMPoliciesFromGroup(policyIdList, id);
+ if (result != null){
+ IAMGroupResponse response = _iamApiSrv.createIAMGroupResponse(result);
+ response.setResponseName(getCommandName());
+ setResponseObject(response);
+ } else {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add roles to iam group");
+ }
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_IAM_GROUP_UPDATE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "removing IAM roles from IAM group";
+ }
+
+ @Override
+ public ApiCommandJobType getInstanceType() {
+ return ApiCommandJobType.IAMGroup;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c28450c1/services/iam/plugin/src/org/apache/cloudstack/api/response/iam/IAMGroupResponse.java
----------------------------------------------------------------------
diff --git a/services/iam/plugin/src/org/apache/cloudstack/api/response/iam/IAMGroupResponse.java b/services/iam/plugin/src/org/apache/cloudstack/api/response/iam/IAMGroupResponse.java
new file mode 100644
index 0000000..af28d53
--- /dev/null
+++ b/services/iam/plugin/src/org/apache/cloudstack/api/response/iam/IAMGroupResponse.java
@@ -0,0 +1,193 @@
+// 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.api.response.iam;
+
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import com.google.gson.annotations.SerializedName;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseResponse;
+import org.apache.cloudstack.api.EntityReference;
+import org.apache.cloudstack.api.response.ControlledViewEntityResponse;
+import org.apache.cloudstack.iam.api.IAMGroup;
+
+import com.cloud.serializer.Param;
+
+@SuppressWarnings("unused")
+@EntityReference(value = IAMGroup.class)
+public class IAMGroupResponse extends BaseResponse implements ControlledViewEntityResponse {
+
+ @SerializedName(ApiConstants.ID)
+ @Param(description = "the ID of the iam group")
+ private String id;
+
+ @SerializedName(ApiConstants.NAME)
+ @Param(description = "the name of the iam group")
+ private String name;
+
+ @SerializedName(ApiConstants.DESCRIPTION)
+ @Param(description = "the description of the iam group")
+ private String description;
+
+ @SerializedName(ApiConstants.DOMAIN_ID)
+ @Param(description = "the domain ID of the iam group")
+ private String domainId;
+
+ @SerializedName(ApiConstants.DOMAIN)
+ @Param(description = "the domain name of the iam role")
+ private String domainName;
+
+ @SerializedName(ApiConstants.ACCOUNT)
+ @Param(description = "the account owning the policy")
+ private String accountName;
+
+ @SerializedName(ApiConstants.IAM_MEMBER_ACCOUNTS)
+ @Param(description = "account names assigned to this iam group ")
+ private Set<String> accountNameList;
+
+ @SerializedName(ApiConstants.IAM_POLICIES)
+ @Param(description = "iam policies attached to this iam group ")
+ private Set<String> policyNameList;
+
+ public IAMGroupResponse() {
+ accountNameList = new LinkedHashSet<String>();
+ policyNameList = new LinkedHashSet<String>();
+ }
+
+ @Override
+ public String getObjectId() {
+ return getId();
+ }
+
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ @Override
+ public void setDomainId(String domainId) {
+ this.domainId = domainId;
+ }
+
+ @Override
+ public void setDomainName(String domainName) {
+ this.domainName = domainName;
+ }
+
+ @Override
+ public void setAccountName(String accountName) {
+ this.accountName = accountName;
+
+ }
+
+ @Override
+ public void setProjectId(String projectId) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setProjectName(String projectName) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getDomainId() {
+ return domainId;
+ }
+
+ public String getDomainName() {
+ return domainName;
+ }
+
+ public String getAccountName() {
+ return accountName;
+ }
+
+ public Set<String> getAccountNameList() {
+ return accountNameList;
+ }
+
+ public void setMemberAccounts(Set<String> accts) {
+ accountNameList = accts;
+ }
+
+ public void addMemberAccount(String acct) {
+ accountNameList.add(acct);
+ }
+
+ public void setPolicyList(Set<String> policies) {
+ policyNameList = policies;
+ }
+
+ public void addPolicy(String policy) {
+ policyNameList.add(policy);
+ }
+
+ public Set<String> getPolicyList() {
+ return policyNameList;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ IAMGroupResponse other = (IAMGroupResponse)obj;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ return true;
+ }
+
+}