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,18 +94,34 @@ public class DomainModuleImpl extends AbstractModuleImpl {
} }
EntityManager em = getTransaction().getEntityManager(); EntityManager em = getTransaction().getEntityManager();
// search for domains superior to dom UnixUser loginUser = getLoginUser();
Query domainQuery = em.createQuery("SELECT d FROM Domains d WHERE d.name = :domainName"); if (!loginUser.hasHostmasterRole()) {
String superior = dom.getName(); // search for domains superior to dom
while (superior.contains(".")) { Query domainQuery = em.createQuery("SELECT d FROM Domains d WHERE d.name = :domainName");
superior = superior.substring(superior.indexOf('.') + 1); String superior = dom.getName();
domainQuery.setParameter("domainName", superior); String prefix = null;
if (domainQuery.getResultList().size() > 0) { while (superior.contains(".")) {
DNSCheck dnsCheck = new DNSCheck(dom.getDnsMaster()); prefix = superior.substring(0, superior.indexOf('.'));
if (dnsCheck.checkDomain(dom.getName())) { superior = superior.substring(superior.indexOf('.') + 1);
if ("hostsharing.net".equals(superior) && admin.getName().equals(prefix)) {
break; break;
} else { }
throw new HSAdminException("domain " + dom.getName() + " is not delegated to " + dom.getDnsMaster()); domainQuery.setParameter("domainName", superior);
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;
} else {
throw new HSAdminException("domain " + dom.getName() + " is not delegated to " + dom.getDnsMaster());
}
} }
} }
} }
@ -179,17 +195,19 @@ public class DomainModuleImpl extends AbstractModuleImpl {
} }
private void needsWriteAccessOn(AbstractEntity ent, String method) throws AuthorisationException { private void needsWriteAccessOn(AbstractEntity ent, String method) throws AuthorisationException {
UnixUser loginUser = getLoginUser();
if (ent instanceof Domain) { if (ent instanceof Domain) {
Domain dom = (Domain) ent; Domain dom = (Domain) ent;
String aLoginUserName = getLoginUser().getName(); String aLoginUserName = loginUser.getName();
UnixUser domUser = dom.getUser(); UnixUser domUser = dom.getUser();
Pac domPac = domUser.getPac(); Pac domPac = domUser.getPac();
boolean isPacAdmin = aLoginUserName.equals(domPac.getName()); boolean isPacAdmin = loginUser.hasPacAdminRoleFor(domPac);
boolean isCustomer = aLoginUserName.equals(domPac.getCustomer().getName()); boolean isCustomer = aLoginUserName.equals(domPac.getCustomer().getName());
if (!isPacAdmin && !isCustomer) boolean isHostmaster = loginUser.hasHostmasterRole();
throw new AuthorisationException(getLoginUser(), method, dom); if (!isPacAdmin && !isCustomer && !isHostmaster)
throw new AuthorisationException(loginUser, method, dom);
} else { } else {
throw new AuthorisationException(getLoginUser(), method, ent); throw new AuthorisationException(loginUser, method, ent);
} }
} }