fixed #17 : Aufschalten von Subdomains

This commit is contained in:
Peter Hormanns 2011-07-14 17:42:33 +00:00
parent 264870dec3
commit bbb8ae1767

View File

@ -94,13 +94,28 @@ public class DomainModuleImpl extends AbstractModuleImpl {
}
EntityManager em = getTransaction().getEntityManager();
UnixUser loginUser = getLoginUser();
if (!loginUser.hasHostmasterRole()) {
// search for domains superior to dom
Query domainQuery = em.createQuery("SELECT d FROM Domains d WHERE d.name = :domainName");
String superior = dom.getName();
String prefix = null;
while (superior.contains(".")) {
prefix = superior.substring(0, superior.indexOf('.'));
superior = superior.substring(superior.indexOf('.') + 1);
if ("hostsharing.net".equals(superior) && admin.getName().equals(prefix)) {
break;
}
domainQuery.setParameter("domainName", superior);
if (domainQuery.getResultList().size() > 0) {
List<?> resultList = domainQuery.getResultList();
if (resultList.size() > 0) {
Domain superDom = (Domain) resultList.get(0);
if (loginUser.hasPacAdminRoleFor(superDom.getUser().getPac())) {
break; // same pac
}
if (loginUser.hasCustomerRoleFor(superDom.getUser().getPac().getCustomer())) {
break; // same customer
}
DNSCheck dnsCheck = new DNSCheck(dom.getDnsMaster());
if (dnsCheck.checkDomain(dom.getName())) {
break;
@ -109,6 +124,7 @@ public class DomainModuleImpl extends AbstractModuleImpl {
}
}
}
}
Query adminQuery = em.createQuery("SELECT u FROM UnixUsers u WHERE u.name = :adminName");
adminQuery.setParameter("adminName", admin.getName());
@ -179,17 +195,19 @@ public class DomainModuleImpl extends AbstractModuleImpl {
}
private void needsWriteAccessOn(AbstractEntity ent, String method) throws AuthorisationException {
UnixUser loginUser = getLoginUser();
if (ent instanceof Domain) {
Domain dom = (Domain) ent;
String aLoginUserName = getLoginUser().getName();
String aLoginUserName = loginUser.getName();
UnixUser domUser = dom.getUser();
Pac domPac = domUser.getPac();
boolean isPacAdmin = aLoginUserName.equals(domPac.getName());
boolean isPacAdmin = loginUser.hasPacAdminRoleFor(domPac);
boolean isCustomer = aLoginUserName.equals(domPac.getCustomer().getName());
if (!isPacAdmin && !isCustomer)
throw new AuthorisationException(getLoginUser(), method, dom);
boolean isHostmaster = loginUser.hasHostmasterRole();
if (!isPacAdmin && !isCustomer && !isHostmaster)
throw new AuthorisationException(loginUser, method, dom);
} else {
throw new AuthorisationException(getLoginUser(), method, ent);
throw new AuthorisationException(loginUser, method, ent);
}
}