use of com.cloud.legacymodel.domain.Domain in project cosmic by MissionCriticalCloud.
the class AccountManagerImpl method getUserAccount.
private UserAccount getUserAccount(final String username, final String password, final Long domainId, final Map<String, Object[]> requestParameters) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Attempting to log in user: " + username + " in domain " + domainId);
}
UserAccount userAccount = _userAccountDao.getUserAccount(username, domainId);
boolean authenticated = false;
final HashSet<ActionOnFailedAuthentication> actionsOnFailedAuthenticaion = new HashSet<>();
final User.Source userSource = userAccount != null ? userAccount.getSource() : User.Source.UNKNOWN;
for (final UserAuthenticator authenticator : _userAuthenticators) {
if (userSource != User.Source.UNKNOWN) {
if (!authenticator.getName().equalsIgnoreCase(userSource.name())) {
continue;
}
}
final Pair<Boolean, ActionOnFailedAuthentication> result = authenticator.authenticate(username, password, domainId, requestParameters);
if (result.first()) {
authenticated = true;
break;
} else if (result.second() != null) {
actionsOnFailedAuthenticaion.add(result.second());
}
}
final boolean updateIncorrectLoginCount = actionsOnFailedAuthenticaion.contains(ActionOnFailedAuthentication.INCREMENT_INCORRECT_LOGIN_ATTEMPT_COUNT);
if (authenticated) {
final Domain domain = _domainMgr.getDomain(domainId);
String domainName = null;
if (domain != null) {
domainName = domain.getName();
}
userAccount = _userAccountDao.getUserAccount(username, domainId);
if (!userAccount.getState().equalsIgnoreCase(Account.State.enabled.toString()) || !userAccount.getAccountState().equalsIgnoreCase(Account.State.enabled.toString())) {
if (s_logger.isInfoEnabled()) {
s_logger.info("User " + username + " in domain " + domainName + " is disabled/locked (or account is disabled/locked)");
}
throw new CloudAuthenticationException("User " + username + " (or their account) in domain " + domainName + " is disabled/locked. Please contact the " + "administrator.");
}
// Whenever the user is able to log in successfully, reset the login attempts to zero
if (!isInternalAccount(userAccount.getId())) {
updateLoginAttempts(userAccount.getId(), 0, false);
}
return userAccount;
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Unable to authenticate user with username " + username + " in domain " + domainId);
}
if (userAccount == null) {
s_logger.warn("Unable to find an user with username " + username + " in domain " + domainId);
return null;
}
if (userAccount.getState().equalsIgnoreCase(Account.State.enabled.toString())) {
if (!isInternalAccount(userAccount.getId())) {
// Internal accounts are not disabled
final int attemptsMade = userAccount.getLoginAttempts() + 1;
if (updateIncorrectLoginCount) {
if (attemptsMade < _allowedLoginAttempts) {
updateLoginAttempts(userAccount.getId(), attemptsMade, false);
s_logger.warn("Login attempt failed. You have " + (_allowedLoginAttempts - attemptsMade) + " attempt(s) remaining");
} else {
updateLoginAttempts(userAccount.getId(), _allowedLoginAttempts, true);
s_logger.warn("User " + userAccount.getUsername() + " has been disabled due to multiple failed login attempts." + " Please contact admin.");
}
}
}
} else {
s_logger.info("User " + userAccount.getUsername() + " is disabled/locked");
}
return null;
}
}
use of com.cloud.legacymodel.domain.Domain in project cosmic by MissionCriticalCloud.
the class QueryManagerImpl method listWhoHasThisIp.
@Override
public ListResponse<WhoHasThisAddressResponse> listWhoHasThisIp(final ListWhoHasThisIpCmd cmd) {
final ListResponse<WhoHasThisAddressResponse> whoHasThisIpList = new ListResponse<>();
final List<WhoHasThisAddressResponse> responsesList = new ArrayList<>();
final String cleanedIpAddress = StringUtils.deleteWhitespace(cmd.getIpAddress());
final List<IPAddressVO> ipAddresses = _ipAddressDao.listByIpAddress(cleanedIpAddress);
ipAddresses.forEach(ipAddress -> {
final WhoHasThisAddressResponse response = new WhoHasThisAddressResponse();
response.setObjectName("whohasthisip");
response.setIpAddress(ipAddress.getAddress().toString());
response.setUuid(ipAddress.getUuid());
response.setState(ipAddress.getState().toString());
final Domain domain = _domainDao.findById(ipAddress.getDomainId());
if (domain != null) {
response.setDomainName(domain.getName());
response.setDomainUuid(domain.getUuid());
}
final Network network = _networkDao.findById(ipAddress.getNetworkId());
if (network != null) {
response.setNetworkUuid(network.getUuid());
response.setCreated(ipAddress.getAllocatedTime());
response.setMode(network.getMode());
}
if (ipAddress.getVpcId() != null) {
final Vpc vpc = _vpcDao.findById(ipAddress.getVpcId());
if (vpc != null) {
response.setNetworkName(vpc.getName());
response.setVpcName(vpc.getName());
response.setVpcUuid(vpc.getUuid());
}
} else if (network != null && !StringUtils.isEmpty(network.getName())) {
response.setNetworkName(network.getName());
}
final Network associatedNetwork = _networkDao.findById(ipAddress.getAssociatedWithNetworkId());
if (associatedNetwork != null) {
response.setAssociatedNetworkName(associatedNetwork.getName());
response.setAssociatedNetworkUuid(associatedNetwork.getUuid());
}
responsesList.add(response);
});
final List<NicVO> nics = _nicDao.listByIpAddress(cleanedIpAddress);
nics.forEach(nic -> {
final WhoHasThisAddressResponse response = new WhoHasThisAddressResponse();
response.setObjectName("whohasthisip");
queryNicsTableResponse(responsesList, nic, response);
});
final List<NicSecondaryIpVO> nicSecondaryIps = _nicSecondaryIpDao.listByIpAddress(cleanedIpAddress);
nicSecondaryIps.forEach(nicSecondaryIp -> {
final WhoHasThisAddressResponse response = new WhoHasThisAddressResponse();
response.setObjectName("whohasthisip");
response.setIpAddress(nicSecondaryIp.getIp4Address());
response.setUuid(nicSecondaryIp.getUuid());
response.setCreated(nicSecondaryIp.getCreated());
final NicVO nicVO = _nicDao.findById(nicSecondaryIp.getNicId());
if (nicVO != null) {
response.setMode(nicVO.getMode());
response.setBroadcastUri(nicVO.getBroadcastUri());
response.setNetmask(nicVO.getIPv4Netmask());
response.setMacAddress(nicVO.getMacAddress());
response.setState(nicVO.getState().toString());
}
final Network network = _networkDao.findById(nicSecondaryIp.getNetworkId());
if (network != null) {
response.setNetworkUuid(network.getUuid());
if (!StringUtils.isEmpty(network.getName())) {
response.setNetworkName(network.getName());
}
}
final VMInstanceVO vm = _vmInstanceDao.findById(nicSecondaryIp.getVmId());
getVMInfo(response, nicVO, vm);
responsesList.add(response);
});
final Account account = CallContext.current().getCallingAccount();
final Domain domain = _domainDao.findById(account.getDomainId());
final List<WhoHasThisAddressResponse> filteredResponsesList = responsesList.stream().filter(response -> ((account.getDomainId() == Domain.ROOT_DOMAIN || domain.getUuid().equals(response.getDomainUuid())) && (StringUtils.isEmpty(cmd.getUuid()) || (!StringUtils.isEmpty(cmd.getUuid()) && response.getUuid().equals(cmd.getUuid()))))).skip(cmd.getStartIndex()).limit(cmd.getPageSizeVal()).collect(Collectors.toList());
whoHasThisIpList.setResponses(filteredResponsesList);
return whoHasThisIpList;
}
use of com.cloud.legacymodel.domain.Domain in project cosmic by MissionCriticalCloud.
the class QueryManagerImpl method listWhoHasThisMac.
public ListResponse<WhoHasThisAddressResponse> listWhoHasThisMac(final ListWhoHasThisMacCmd cmd) {
final ListResponse<WhoHasThisAddressResponse> whoHasThisIpList = new ListResponse<>();
final List<WhoHasThisAddressResponse> responsesList = new ArrayList<>();
final String cleanedMacAddress = StringUtils.deleteWhitespace(cmd.getMacAddress());
final List<NicVO> nics = _nicDao.listByMacAddress(cleanedMacAddress);
nics.forEach(nic -> {
final WhoHasThisAddressResponse response = new WhoHasThisAddressResponse();
response.setObjectName("whohasthismac");
queryNicsTableResponse(responsesList, nic, response);
});
final Account account = CallContext.current().getCallingAccount();
final Domain domain = _domainDao.findById(account.getDomainId());
final List<WhoHasThisAddressResponse> filteredResponsesList = responsesList.stream().filter(response -> ((account.getDomainId() == Domain.ROOT_DOMAIN || domain.getUuid().equals(response.getDomainUuid())) && (StringUtils.isEmpty(cmd.getUuid()) || (!StringUtils.isEmpty(cmd.getUuid()) && response.getUuid().equals(cmd.getUuid()))))).skip(cmd.getStartIndex()).limit(cmd.getPageSizeVal()).collect(Collectors.toList());
whoHasThisIpList.setResponses(filteredResponsesList);
return whoHasThisIpList;
}
use of com.cloud.legacymodel.domain.Domain in project cosmic by MissionCriticalCloud.
the class LdapManagerImpl method listLinkDomainToLdap.
@Override
public LinkDomainToLdapResponse listLinkDomainToLdap(final Long domainId) {
Validate.notNull(domainId, "domainId cannot be null.");
final LdapTrustMapVO ldapTrustMap = _ldapManager.getDomainLinkedToLdap(domainId);
final Domain domain = _domainManager.getDomain(domainId);
final LinkDomainToLdapResponse response;
if (!_ldapManager.isLdapEnabled()) {
return new LinkDomainToLdapResponse(domain.getUuid());
}
if (ldapTrustMap != null) {
response = new LinkDomainToLdapResponse(domain.getUuid(), ldapTrustMap.getType().toString(), ldapTrustMap.getName(), ldapTrustMap.getAccountType());
} else {
response = new LinkDomainToLdapResponse(domain.getUuid());
}
return response;
}
use of com.cloud.legacymodel.domain.Domain in project cosmic by MissionCriticalCloud.
the class AccountManagerImplTest method deleteUserAccountCleanup.
@Test
public void deleteUserAccountCleanup() {
final AccountVO account = new AccountVO();
account.setId(42l);
final DomainVO domain = new DomainVO();
Mockito.when(_accountDao.findById(42l)).thenReturn(account);
Mockito.when(securityChecker.checkAccess(Mockito.any(Account.class), Mockito.any(ControlledEntity.class), Mockito.any(AccessType.class), Mockito.anyString())).thenReturn(true);
Mockito.when(_accountDao.remove(42l)).thenReturn(true);
Mockito.when(_configMgr.releaseAccountSpecificVirtualRanges(42l)).thenReturn(true);
Mockito.when(_userVmDao.listByAccountId(42l)).thenReturn(Arrays.asList(Mockito.mock(UserVmVO.class)));
Mockito.when(_vmMgr.expunge(Mockito.any(UserVmVO.class), Mockito.anyLong(), Mockito.any(Account.class))).thenReturn(false);
Mockito.when(_domainMgr.getDomain(Mockito.anyLong())).thenReturn(domain);
Mockito.when(securityChecker.checkAccess(Mockito.any(Account.class), Mockito.any(Domain.class))).thenReturn(true);
Assert.assertTrue(accountManager.deleteUserAccount(42));
// assert that this was NOT a clean delete
Mockito.verify(_accountDao, Mockito.atLeastOnce()).markForCleanup(Mockito.eq(42l));
}
Aggregations