Skip to content

Commit 20f7792

Browse files
committed
merging 4.8 -> master
2 parents ecac28b + 744f9d5 commit 20f7792

12 files changed

Lines changed: 701 additions & 16 deletions

File tree

api/src/com/cloud/user/DomainService.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,14 @@ public interface DomainService {
5656
*/
5757
Domain findDomainByPath(String domainPath);
5858

59+
/**
60+
* finds the domain by either id or provided path
61+
*
62+
* @param id the domain id
63+
* @param domainPath the domain path use to lookup a domain
64+
*
65+
* @return domainId the long value of the domain ID, or null if no domain id exists with provided id/path
66+
*/
67+
Domain findDomainByIdOrPath(Long id, String domainPath);
68+
5969
}

debian/control

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ Description: A common package which contains files which are shared by several C
1515

1616
Package: cloudstack-management
1717
Architecture: all
18-
Depends: ${misc:Depends}, ${python:Depends}, cloudstack-common (= ${source:Version}), tomcat6 | tomcat7, sudo, jsvc, python-mysql.connector, libmysql-java, augeas-tools, mysql-client, adduser, bzip2, ipmitool
18+
Depends: ${misc:Depends}, ${python:Depends}, cloudstack-common (= ${source:Version}), tomcat6 | tomcat7, sudo, jsvc, python-mysql.connector, libmysql-java, augeas-tools, mysql-client, adduser, bzip2, ipmitool, lsb-release
1919
Conflicts: cloud-server, cloud-client, cloud-client-ui
2020
Description: CloudStack server library
2121
The CloudStack management server
2222

2323
Package: cloudstack-agent
2424
Architecture: all
25-
Depends: ${misc:Depends}, ${python:Depends}, openjdk-8-jre-headless | openjdk-7-jre-headless, cloudstack-common (= ${source:Version}), lsb-base (>= 4.0), libcommons-daemon-java, openssh-client, qemu-kvm (>= 1.0), libvirt-bin (>= 0.9.8), uuid-runtime, iproute, ebtables, vlan, jsvc, ipset, python-libvirt, ethtool, iptables
25+
Depends: ${misc:Depends}, ${python:Depends}, openjdk-8-jre-headless | openjdk-7-jre-headless, cloudstack-common (= ${source:Version}), lsb-base (>= 4.0), libcommons-daemon-java, openssh-client, qemu-kvm (>= 1.0), libvirt-bin (>= 0.9.8), uuid-runtime, iproute, ebtables, vlan, jsvc, ipset, python-libvirt, ethtool, iptables, lsb-release
2626
Conflicts: cloud-agent, cloud-agent-libs, cloud-agent-deps, cloud-agent-scripts
2727
Description: CloudStack agent
2828
The CloudStack agent is in charge of managing shared computing resources in

server/src/com/cloud/api/ApiServer.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,17 +1003,11 @@ public ResponseObject loginUser(final HttpSession session, final String username
10031003
final Map<String, Object[]> requestParameters) throws CloudAuthenticationException {
10041004
// We will always use domainId first. If that does not exist, we will use domain name. If THAT doesn't exist
10051005
// we will default to ROOT
1006-
if (domainId == null) {
1007-
if (domainPath == null || domainPath.trim().length() == 0) {
1008-
domainId = Domain.ROOT_DOMAIN;
1009-
} else {
1010-
final Domain domainObj = domainMgr.findDomainByPath(domainPath);
1011-
if (domainObj != null) {
1012-
domainId = domainObj.getId();
1013-
} else { // if an unknown path is passed in, fail the login call
1014-
throw new CloudAuthenticationException("Unable to find the domain from the path " + domainPath);
1015-
}
1016-
}
1006+
final Domain userDomain = _domainMgr.findDomainByIdOrPath(domainId, domainPath);
1007+
if (userDomain == null || userDomain.getId() < 1L) {
1008+
throw new CloudAuthenticationException("Unable to find the domain from the path " + domainPath);
1009+
} else {
1010+
domainId = userDomain.getId();
10171011
}
10181012

10191013
final UserAccount userAcct = accountMgr.authenticateUser(username, password, domainId, loginIpAddress, requestParameters);

server/src/com/cloud/api/auth/DefaultLoginAPIAuthenticatorCmd.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
// under the License.
1717
package com.cloud.api.auth;
1818

19+
import com.cloud.domain.Domain;
20+
import com.cloud.user.User;
21+
import com.cloud.user.UserAccount;
1922
import org.apache.cloudstack.api.ApiServerService;
2023
import com.cloud.api.response.ApiResponseSerializer;
2124
import com.cloud.exception.CloudAuthenticationException;
@@ -156,6 +159,16 @@ public String authenticate(String command, Map<String, Object[]> params, HttpSes
156159
if (username != null) {
157160
final String pwd = ((password == null) ? null : password[0]);
158161
try {
162+
final Domain userDomain = _domainService.findDomainByIdOrPath(domainId, domain);
163+
if (userDomain != null) {
164+
domainId = userDomain.getId();
165+
} else {
166+
throw new CloudAuthenticationException("Unable to find the domain from the path " + domain);
167+
}
168+
final UserAccount userAccount = _accountService.getActiveUserAccount(username[0], domainId);
169+
if (userAccount == null || !(User.Source.UNKNOWN.equals(userAccount.getSource()) || User.Source.LDAP.equals(userAccount.getSource()))) {
170+
throw new CloudAuthenticationException("User is not allowed CloudStack login");
171+
}
159172
return ApiResponseSerializer.toSerializedString(_apiServer.loginUser(session, username[0], pwd, domainId, domain, remoteAddress, params),
160173
responseType);
161174
} catch (final CloudAuthenticationException ex) {

server/src/com/cloud/api/query/QueryManagerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3070,9 +3070,9 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(ListTempl
30703070

30713071
boolean listAll = false;
30723072
if (templateFilter != null && templateFilter == TemplateFilter.all) {
3073-
if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {
3073+
if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
30743074
throw new InvalidParameterValueException("Filter " + TemplateFilter.all
3075-
+ " can be specified by admin only");
3075+
+ " can be specified by root admin only");
30763076
}
30773077
listAll = true;
30783078
}

server/src/com/cloud/template/HypervisorTemplateAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ public boolean delete(TemplateProfile profile) {
394394
// publish zone-wide usage event
395395
Long sZoneId = ((ImageStoreEntity)imageStore).getDataCenterId();
396396
if (sZoneId != null) {
397-
UsageEventUtils.publishUsageEvent(eventType, template.getAccountId(), sZoneId, template.getId(), null, null, null);
397+
UsageEventUtils.publishUsageEvent(eventType, template.getAccountId(), sZoneId, template.getId(), null, VirtualMachineTemplate.class.getName(), template.getUuid());
398398
}
399399

400400
s_logger.info("Delete template from image store: " + imageStore.getName());

server/src/com/cloud/user/DomainManagerImpl.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import com.cloud.utils.net.NetUtils;
7474
import com.cloud.vm.ReservationContext;
7575
import com.cloud.vm.ReservationContextImpl;
76+
import com.google.common.base.Strings;
7677

7778
@Component
7879
public class DomainManagerImpl extends ManagerBase implements DomainManager, DomainService {
@@ -218,6 +219,25 @@ public DomainVO findDomainByPath(String domainPath) {
218219
return _domainDao.findDomainByPath(domainPath);
219220
}
220221

222+
@Override
223+
public Domain findDomainByIdOrPath(final Long id, final String domainPath) {
224+
Long domainId = id;
225+
if (domainId == null || domainId < 1L) {
226+
if (Strings.isNullOrEmpty(domainPath) || domainPath.trim().isEmpty()) {
227+
domainId = Domain.ROOT_DOMAIN;
228+
} else {
229+
final Domain domainVO = findDomainByPath(domainPath.trim());
230+
if (domainVO != null) {
231+
return domainVO;
232+
}
233+
}
234+
}
235+
if (domainId != null && domainId > 0L) {
236+
return _domainDao.findById(domainId);
237+
}
238+
return null;
239+
}
240+
221241
@Override
222242
public Set<Long> getDomainParentIds(long domainId) {
223243
return _domainDao.getDomainParentIds(domainId);

0 commit comments

Comments
 (0)