AccountManager: Add method to translate account type to role type

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
This commit is contained in:
Rohit Yadav 2013-01-10 15:31:32 -08:00
parent f2ae0ae5ae
commit 1425736c19
3 changed files with 35 additions and 0 deletions

View File

@ -20,6 +20,7 @@ import java.util.List;
import java.util.Map;
import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
@ -193,6 +194,8 @@ public interface AccountService {
UserAccount getUserByApiKey(String apiKey);
RoleType getRoleType(Account account);
void checkAccess(Account account, Domain domain) throws PermissionDeniedException;
void checkAccess(Account account, AccessType accessType, boolean sameOwner, ControlledEntity... entities) throws PermissionDeniedException;

View File

@ -37,6 +37,7 @@ import javax.ejb.Local;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.acl.SecurityChecker;
import org.apache.cloudstack.api.command.admin.account.UpdateAccountCmd;
import org.apache.cloudstack.api.command.admin.user.RegisterCmd;
@ -1542,6 +1543,31 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
}
}
@Override
public RoleType getRoleType(Account account) {
RoleType roleType = RoleType.Unknown;
if (account == null)
return roleType;
short accountType = account.getType();
// Account type to role type translation
switch (accountType) {
case Account.ACCOUNT_TYPE_ADMIN:
roleType = RoleType.Admin;
break;
case Account.ACCOUNT_TYPE_DOMAIN_ADMIN:
roleType = RoleType.DomainAdmin;
break;
case Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN:
roleType = RoleType.ResourceAdmin;
break;
case Account.ACCOUNT_TYPE_NORMAL:
roleType = RoleType.User;
break;
}
return roleType;
}
@Override
public User getActiveUser(long userId) {
return _userDao.findById(userId);

View File

@ -23,6 +23,7 @@ import javax.ejb.Local;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
import com.cloud.api.query.vo.ControlledViewEntity;
@ -344,4 +345,9 @@ public class MockAccountManagerImpl implements Manager, AccountManager, AccountS
return null;
}
@Override
public RoleType getRoleType(Account account) {
return null;
}
}