use of com.cloud.user.UserVO in project cloudstack by apache.
the class VmwareDatacenterApiUnitTest method testSetUp.
@Before
public void testSetUp() {
Mockito.when(_configDao.isPremium()).thenReturn(true);
ComponentContext.initComponentsLifeCycle();
MockitoAnnotations.initMocks(this);
DataCenterVO zone = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24", null, null, NetworkType.Basic, null, null, true, true, null, null);
zoneId = 1L;
HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), zoneId, "192.168.56.1", "192.168.56.0/24", 8, "test");
podId = 1L;
AccountVO acct = new AccountVO(200L);
acct.setType(Account.ACCOUNT_TYPE_ADMIN);
acct.setAccountName("admin");
acct.setDomainId(domainId);
UserVO user1 = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
CallContext.register(user1, acct);
when(_accountDao.findByIdIncludingRemoved(0L)).thenReturn(acct);
dc = new VmwareDatacenterVO(guid, vmwareDcName, vCenterHost, user, password);
vmwareDcs = new ArrayList<VmwareDatacenterVO>();
vmwareDcs.add(dc);
vmwareDcId = dc.getId();
cluster = new ClusterVO(zone.getId(), pod.getId(), "vmwarecluster");
cluster.setHypervisorType(HypervisorType.VMware.toString());
cluster.setClusterType(ClusterType.ExternalManaged);
cluster.setManagedState(ManagedState.Managed);
clusterId = 1L;
clusterList = new ArrayList<ClusterVO>();
clusterList.add(cluster);
clusterDetails = new ClusterDetailsVO(clusterId, "url", url);
dcZoneMap = new VmwareDatacenterZoneMapVO(zoneId, vmwareDcId);
Mockito.when(_dcDao.persist(Matchers.any(DataCenterVO.class))).thenReturn(zone);
Mockito.when(_dcDao.findById(1L)).thenReturn(zone);
Mockito.when(_podDao.persist(Matchers.any(HostPodVO.class))).thenReturn(pod);
Mockito.when(_podDao.findById(1L)).thenReturn(pod);
Mockito.when(_clusterDao.persist(Matchers.any(ClusterVO.class))).thenReturn(cluster);
Mockito.when(_clusterDao.findById(1L)).thenReturn(cluster);
Mockito.when(_clusterDao.listByZoneId(1L)).thenReturn(null);
Mockito.when(_clusterDao.expunge(1L)).thenReturn(true);
Mockito.when(_clusterDetailsDao.persist(Matchers.any(ClusterDetailsVO.class))).thenReturn(clusterDetails);
Mockito.when(_clusterDetailsDao.expunge(1L)).thenReturn(true);
Mockito.when(_vmwareDcDao.persist(Matchers.any(VmwareDatacenterVO.class))).thenReturn(dc);
Mockito.when(_vmwareDcDao.findById(1L)).thenReturn(null);
Mockito.when(_vmwareDcDao.expunge(1L)).thenReturn(true);
Mockito.when(_vmwareDcDao.getVmwareDatacenterByNameAndVcenter(vmwareDcName, vCenterHost)).thenReturn(null);
Mockito.when(_vmwareDcZoneMapDao.persist(Matchers.any(VmwareDatacenterZoneMapVO.class))).thenReturn(dcZoneMap);
Mockito.when(_vmwareDcZoneMapDao.findByZoneId(1L)).thenReturn(null);
Mockito.when(_vmwareDcZoneMapDao.expunge(1L)).thenReturn(true);
Mockito.when(addCmd.getZoneId()).thenReturn(1L);
Mockito.when(addCmd.getVcenter()).thenReturn(vCenterHost);
Mockito.when(addCmd.getUsername()).thenReturn(user);
Mockito.when(addCmd.getPassword()).thenReturn(password);
Mockito.when(addCmd.getName()).thenReturn(vmwareDcName);
Mockito.when(removeCmd.getZoneId()).thenReturn(1L);
}
use of com.cloud.user.UserVO in project cloudstack by apache.
the class ApiDiscoveryTest method setUp.
@BeforeClass
public static void setUp() throws ConfigurationException {
testApiName = testCmdClass.getAnnotation(APICommand.class).name();
testApiDescription = testCmdClass.getAnnotation(APICommand.class).description();
testApiSince = testCmdClass.getAnnotation(APICommand.class).since();
testApiAsync = false;
testUser = new UserVO();
s_discoveryService._apiAccessCheckers = mock(List.class);
s_discoveryService._services = mock(List.class);
when(s_apiChecker.checkAccess(any(User.class), anyString())).thenReturn(true);
when(s_pluggableService.getCommands()).thenReturn(new ArrayList<Class<?>>());
when(s_discoveryService._apiAccessCheckers.iterator()).thenReturn(Arrays.asList(s_apiChecker).iterator());
when(s_discoveryService._services.iterator()).thenReturn(Arrays.asList(s_pluggableService).iterator());
Set<Class<?>> cmdClasses = new HashSet<Class<?>>();
cmdClasses.add(ListApisCmd.class);
s_discoveryService.start();
s_discoveryService.cacheResponseMap(cmdClasses);
}
use of com.cloud.user.UserVO in project cloudstack by apache.
the class ListSamlAuthorizationCmd method execute.
@Override
public void execute() {
List<UserVO> users = new ArrayList<UserVO>();
if (getUserId() != null) {
UserVO user = _userDao.getUser(getUserId());
if (user != null) {
Account account = _accountService.getAccount(user.getAccountId());
_accountService.checkAccess(CallContext.current().getCallingAccount(), SecurityChecker.AccessType.ListEntry, true, account);
users.add(user);
}
} else if (CallContext.current().getCallingAccount().getType() == Account.ACCOUNT_TYPE_ADMIN) {
users = _userDao.listAll();
}
ListResponse<SamlAuthorizationResponse> response = new ListResponse<SamlAuthorizationResponse>();
List<SamlAuthorizationResponse> authorizationResponses = new ArrayList<SamlAuthorizationResponse>();
for (User user : users) {
SamlAuthorizationResponse authorizationResponse = new SamlAuthorizationResponse(user.getUuid(), user.getSource().equals(User.Source.SAML2), user.getExternalEntity());
authorizationResponse.setObjectName("samlauthorization");
authorizationResponses.add(authorizationResponse);
}
response.setResponses(authorizationResponses);
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of com.cloud.user.UserVO in project cloudstack by apache.
the class SAML2AuthManagerImpl method authorizeUser.
@Override
public boolean authorizeUser(Long userId, String entityId, boolean enable) {
UserVO user = _userDao.getUser(userId);
if (user != null) {
if (enable) {
user.setExternalEntity(entityId);
user.setSource(User.Source.SAML2);
} else {
if (user.getSource().equals(User.Source.SAML2)) {
user.setSource(User.Source.SAML2DISABLED);
} else {
return false;
}
}
_userDao.update(user.getId(), user);
return true;
}
return false;
}
use of com.cloud.user.UserVO in project cloudstack by apache.
the class SAML2AuthManagerImplTest method testIsUserAuthorized.
@Test
public void testIsUserAuthorized() {
final String entityID = "some IDP ID";
// Test unauthorized user
UserVO user = new UserVO(200L);
user.setUsername("someuser");
user.setSource(User.Source.UNKNOWN);
user.setExternalEntity(entityID);
Mockito.when(userDao.getUser(Mockito.anyLong())).thenReturn(user);
assertFalse(saml2AuthManager.isUserAuthorized(user.getId(), "someID"));
// Test authorized user with wrong IDP
user.setSource(User.Source.SAML2);
Mockito.when(userDao.getUser(Mockito.anyLong())).thenReturn(user);
assertFalse(saml2AuthManager.isUserAuthorized(user.getId(), "someID"));
// Test authorized user with wrong IDP
user.setSource(User.Source.SAML2);
Mockito.when(userDao.getUser(Mockito.anyLong())).thenReturn(user);
assertTrue(saml2AuthManager.isUserAuthorized(user.getId(), entityID));
}
Aggregations