HSAdmin Backend Domains, E-Mail, Datenbanken
Peter Hormanns
2013-06-19 e7998979a0321687b33f9a3fb63f1ab88a8cbae9
fix #130
1 files added
4 files modified
122 ■■■■ changed files
hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java 27 ●●●● patch | view | raw | blame | history
hsarback/test/de/hsadmin/remote/ContinuousIntegrationTest.java 1 ●●●● patch | view | raw | blame | history
hsarback/test/de/hsadmin/remote/DomainDeleteTest.java 72 ●●●●● patch | view | raw | blame | history
hsarback/test/de/hsadmin/remote/DomainTest.java 21 ●●●●● patch | view | raw | blame | history
hsarback/test/de/hsadmin/remote/RemoteTest.java 1 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java
@@ -115,32 +115,31 @@
        // Standard domainoptions setzen. TODO: Alle defaults ├╝ber eigene Klasse aus der Datenbank holen. 
        UnixUser loginUser = getTransaction().getLoginUser();
        if (!loginUser.hasHostmasterRole()) {
            boolean usersDomain = false;
            boolean otherUserDomain = false;
            // search for domains superior to dom
            Query domainQuery = em.createQuery("SELECT d FROM Domains d WHERE d.name = :domainName");
            String superior = dom.getName();
            while (superior.contains(".")) {
                if (dom.isPacDomain()) {
                    break;
                }
            while (superior.contains(".") && !usersDomain) {
                superior = superior.substring(superior.indexOf('.') + 1);
                domainQuery.setParameter("domainName", superior);
                List<?> resultList = domainQuery.getResultList();
                if (resultList.size() > 0) {
                    Domain superDom = (Domain) resultList.get(0);
                    if (superDom.isPacDomain()) {
                        throw new HSAdminException("subdomains to pacdomain " + superDom.getName() + " are not allowed");
                    }
                    if (loginUser.hasPacAdminRoleFor(superDom.getUser().getPac())) {
                        break;    // same pac
                    }
                    if (loginUser.hasCustomerRoleFor(superDom.getUser().getPac().getCustomer())) {
                        break;    // same customer
                        usersDomain = true;        // same pac
                    } else{
                        if (loginUser.hasCustomerRoleFor(superDom.getUser().getPac().getCustomer())) {
                            usersDomain = true;        // same customer
                        } else {
                            otherUserDomain = true;
                        }
                    }
                }
            }
            // TODO war es ein break, dann weitermachen, sonst Exception !
            if (!usersDomain && otherUserDomain) {
                throw new AuthorisationException(loginUser, "create", dom);
            }
        }
        Query adminQuery = em.createQuery("SELECT u FROM UnixUsers u WHERE u.name = :adminName");
        adminQuery.setParameter("adminName", admin.getName());
hsarback/test/de/hsadmin/remote/ContinuousIntegrationTest.java
@@ -15,6 +15,7 @@
    UnixUserTest.class,
    EMailAliasTest.class,
    DomainTest.class,
    DomainDeleteTest.class,
    EMailAddressTest.class,
    SSLCertDomainTest.class,
    DatabaseCleanTest.class,
hsarback/test/de/hsadmin/remote/DomainDeleteTest.java
New file
@@ -0,0 +1,72 @@
package de.hsadmin.remote;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import java.util.HashMap;
import java.util.Map;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class DomainDeleteTest {
    private static final String MODULE = "domain";
    private XmlRpcClient client;
    private RemoteCASHelper cas;
    @Before
    public void setUp() throws Exception {
        client = RemoteTestHelper.getClient();
        cas = new RemoteCASHelper();
    }
    @After
    public void tearDown() throws Exception {
        client = null;
        cas = null;
    }
    @Test
    public void testDelete() {
        int count = getDomsCount();
        String user = "aaa00";
        String grantingTicketURL = cas.getGrantingTicketURL(user);
        Map<String, String> whereParams = new HashMap<String, String>();
        whereParams.put("name", "f6n.de");
        Object[] params = new Object[] { user,
                cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
                whereParams };
        try {
            Object execute = client.execute(MODULE + ".delete", params);
            assertNull(execute);
        } catch (XmlRpcException e) {
            fail(e.getMessage());
        }
        assertEquals(count - 1, getDomsCount());
    }
    private int getDomsCount() {
        int count = 0;
        String user = "aaa00";
        String grantingTicketURL = cas.getGrantingTicketURL(user);
        Map<String, String> whereParams = new HashMap<String, String>();
        Object[] params = new Object[] { user,
                cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
                whereParams };
        try {
            Object execute = client.execute(MODULE + ".search", params);
            Object[] result = (Object[]) execute;
            count = result.length;
        } catch (XmlRpcException e) {
            fail(e.getMessage());
        }
        return count;
    }
}
hsarback/test/de/hsadmin/remote/DomainTest.java
@@ -54,7 +54,7 @@
        try {
            Object execute = client.execute(MODULE + ".search", params);
            Object[] result = (Object[]) execute;
            assertEquals(2, result.length);
            assertEquals(3, result.length);
            for (Object o : result) {
                if (o instanceof Map<?, ?>) {
                    Map<?, ?> row = (Map<?, ?>) o;
@@ -133,25 +133,6 @@
        } catch (XmlRpcException e) {
            assertEquals(count, getDomsCount());
        }
    }
    @Test
    public void testDelete() {
        int count = getDomsCount();
        String user = "aaa00";
        String grantingTicketURL = cas.getGrantingTicketURL(user);
        Map<String, String> whereParams = new HashMap<String, String>();
        whereParams.put("name", "f6n.de");
        Object[] params = new Object[] { user,
                cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
                whereParams };
        try {
            Object execute = client.execute(MODULE + ".delete", params);
            assertNull(execute);
        } catch (XmlRpcException e) {
            fail(e.getMessage());
        }
        assertEquals(count - 1, getDomsCount());
    }
    @Test
hsarback/test/de/hsadmin/remote/RemoteTest.java
@@ -15,6 +15,7 @@
    UnixUserTest.class,
    EMailAliasTest.class,
    DomainTest.class,
    DomainDeleteTest.class,
    EMailAddressTest.class,
    DatabaseCleanTest.class,
    PacMigrationTest.class,