Search in sources :

Example 1 with UserInfo

use of org.voltdb.compiler.VoltProjectBuilder.UserInfo in project voltdb by VoltDB.

the class TestUpdateClasses method testRoleControl.

@Test
public void testRoleControl() throws Exception {
    System.out.println("\n\n-----\n testRoleControl \n-----\n\n");
    String pathToCatalog = Configuration.getPathToCatalogForTest("updateclasses.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("updateclasses.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("-- Don't care");
    builder.setUseDDLSchema(true);
    RoleInfo[] groups = new RoleInfo[] { new RoleInfo("adhoc", true, false, false, false, false, false) };
    UserInfo[] users = new UserInfo[] { new UserInfo("adhocuser", "adhocuser", new String[] { "adhoc" }), new UserInfo("sysuser", "sysuser", new String[] { "ADMINISTRATOR" }) };
    builder.addRoles(groups);
    builder.addUsers(users);
    // Test defines its own ADMIN user
    builder.setSecurityEnabled(true, false);
    boolean success = builder.compile(pathToCatalog, 2, 1, 0);
    assertTrue("Schema compilation failed", success);
    MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
    // This is maybe cheating a little bit?
    InMemoryJarfile jarfile = new InMemoryJarfile();
    for (Class<?> clazz : PROC_CLASSES) {
        VoltCompiler comp = new VoltCompiler(false);
        comp.addClassToJar(jarfile, clazz);
    }
    for (Class<?> clazz : EXTRA_CLASSES) {
        VoltCompiler comp = new VoltCompiler(false);
        comp.addClassToJar(jarfile, clazz);
    }
    Client auth_client = null;
    try {
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToCatalog = pathToCatalog;
        config.m_pathToDeployment = pathToDeployment;
        // Default client auth is going to fail, catch and keep chugging
        try {
            startSystem(config);
        } catch (IOException ioe) {
            assertTrue(ioe.getMessage().contains("Authentication rejected"));
        }
        m_client.close();
        // reconnect m_client with auth that will connect but no sysproc powers
        ClientConfig bad_config = new ClientConfig("adhocuser", "adhocuser");
        m_client = ClientFactory.createClient(bad_config);
        m_client.createConnection("localhost");
        // Need a client with the right auth
        ClientConfig auth_config = new ClientConfig("sysuser", "sysuser");
        auth_client = ClientFactory.createClient(auth_config);
        auth_client.createConnection("localhost");
        ClientResponse resp;
        resp = auth_client.callProcedure("@SystemCatalog", "CLASSES");
        System.out.println(resp.getResults()[0]);
        // New cluster, you're like summer vacation...
        assertEquals(0, resp.getResults()[0].getRowCount());
        assertFalse(VoltTableTestHelpers.moveToMatchingRow(resp.getResults()[0], "CLASS_NAME", PROC_CLASSES[0].getCanonicalName()));
        boolean threw = false;
        try {
            resp = auth_client.callProcedure(PROC_CLASSES[0].getSimpleName());
        } catch (ProcCallException pce) {
            assertTrue(pce.getMessage().contains("was not found"));
            threw = true;
        }
        assertTrue(threw);
        threw = false;
        try {
            resp = m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
        } catch (ProcCallException pce) {
            assertTrue(pce.getMessage().contains("does not have admin permission"));
            threw = true;
        }
        assertTrue(threw);
        resp = auth_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
        assertEquals(ClientResponse.SUCCESS, resp.getStatus());
        // Are we still like summer vacation?
        resp = auth_client.callProcedure("@SystemCatalog", "CLASSES");
        VoltTable results = resp.getResults()[0];
        System.out.println(results);
        assertEquals(3, results.getRowCount());
        assertTrue(VoltTableTestHelpers.moveToMatchingRow(results, "CLASS_NAME", PROC_CLASSES[0].getCanonicalName()));
        assertEquals(1L, results.getLong("VOLT_PROCEDURE"));
        assertEquals(0L, results.getLong("ACTIVE_PROC"));
    } finally {
        if (auth_client != null) {
            auth_client.close();
        }
        teardownSystem();
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Configuration(org.voltdb.VoltDB.Configuration) UserInfo(org.voltdb.compiler.VoltProjectBuilder.UserInfo) IOException(java.io.IOException) VoltTable(org.voltdb.VoltTable) VoltDB(org.voltdb.VoltDB) VoltCompiler(org.voltdb.compiler.VoltCompiler) RoleInfo(org.voltdb.compiler.VoltProjectBuilder.RoleInfo) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) Configuration(org.voltdb.VoltDB.Configuration) Client(org.voltdb.client.Client) ClientConfig(org.voltdb.client.ClientConfig) ProcCallException(org.voltdb.client.ProcCallException) Test(org.junit.Test)

Example 2 with UserInfo

use of org.voltdb.compiler.VoltProjectBuilder.UserInfo in project voltdb by VoltDB.

the class TestJSONInterface method testDeploymentSecurityAuthorizationHashed.

public void testDeploymentSecurityAuthorizationHashed() throws Exception {
    try {
        String simpleSchema = "CREATE TABLE foo (\n" + "    bar BIGINT NOT NULL,\n" + "    PRIMARY KEY (bar)\n" + ");";
        File schemaFile = VoltProjectBuilder.writeStringToTempFile(simpleSchema);
        String schemaPath = schemaFile.getPath();
        schemaPath = URLEncoder.encode(schemaPath, "UTF-8");
        VoltProjectBuilder builder = new VoltProjectBuilder();
        builder.addSchema(schemaPath);
        builder.addPartitionInfo("foo", "bar");
        builder.addProcedures(DelayProc.class);
        builder.setHTTPDPort(8095);
        UserInfo[] users = new UserInfo[] { new UserInfo("user1", "admin", new String[] { "user" }), new UserInfo("user2", "admin", new String[] { "administrator" }) };
        builder.addUsers(users);
        // suite defines its own ADMINISTRATOR user
        builder.setSecurityEnabled(true, false);
        boolean success = builder.compile(Configuration.getPathToCatalogForTest("json.jar"));
        assertTrue(success);
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToCatalog = config.setPathToCatalogForTest("json.jar");
        config.m_pathToDeployment = builder.getPathToDeployment();
        server = new ServerThread(config);
        server.start();
        server.waitForInitialization();
        //Get deployment bad user
        String dep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment/", "user1", "admin", "hashed", 401, "application/json");
        assertTrue(dep.contains("Permission denied"));
        //good user
        dep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment/", "user2", "admin", "hashed", 200, "application/json");
        assertTrue(dep.contains("cluster"));
        //Download deployment bad user
        dep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment/download", "user1", "admin", "hashed", 401, "application/json");
        assertTrue(dep.contains("Permission denied"));
        //good user
        dep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment/download", "user2", "admin", "hashed", 200, "text/xml");
        assertTrue(dep.contains("<deployment>"));
        assertTrue(dep.contains("</deployment>"));
        dep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment/download", "user2", "admin", "hashed256", 200, "text/xml");
        assertTrue(dep.contains("<deployment>"));
        assertTrue(dep.contains("</deployment>"));
        //Test back with sha1
        dep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment/download", "user2", "admin", "hashed", 200, "text/xml");
        assertTrue(dep.contains("<deployment>"));
        assertTrue(dep.contains("</deployment>"));
    } finally {
        if (server != null) {
            server.shutdown();
            server.join();
        }
        server = null;
    }
}
Also used : Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) UserInfo(org.voltdb.compiler.VoltProjectBuilder.UserInfo) File(java.io.File)

Example 3 with UserInfo

use of org.voltdb.compiler.VoltProjectBuilder.UserInfo in project voltdb by VoltDB.

the class TestJSONInterface method testDeploymentSecurityAuthorizationBasic.

public void testDeploymentSecurityAuthorizationBasic() throws Exception {
    try {
        String simpleSchema = "CREATE TABLE foo (\n" + "    bar BIGINT NOT NULL,\n" + "    PRIMARY KEY (bar)\n" + ");";
        File schemaFile = VoltProjectBuilder.writeStringToTempFile(simpleSchema);
        String schemaPath = schemaFile.getPath();
        schemaPath = URLEncoder.encode(schemaPath, "UTF-8");
        VoltProjectBuilder builder = new VoltProjectBuilder();
        builder.addSchema(schemaPath);
        builder.addPartitionInfo("foo", "bar");
        builder.addProcedures(DelayProc.class);
        builder.setHTTPDPort(8095);
        UserInfo[] users = new UserInfo[] { new UserInfo("user1", "admin", new String[] { "user" }), new UserInfo("user2", "admin", new String[] { "administrator" }) };
        builder.addUsers(users);
        // suite defines its own ADMINISTRATOR user
        builder.setSecurityEnabled(true, false);
        boolean success = builder.compile(Configuration.getPathToCatalogForTest("json.jar"));
        assertTrue(success);
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToCatalog = config.setPathToCatalogForTest("json.jar");
        config.m_pathToDeployment = builder.getPathToDeployment();
        server = new ServerThread(config);
        server.start();
        server.waitForInitialization();
        //Get deployment bad user
        String dep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment/", "user1", "admin", "basic", 401, "application/json");
        assertTrue(dep.contains("Permission denied"));
        //good user
        dep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment/", "user2", "admin", "basic", 200, "application/json");
        assertTrue(dep.contains("cluster"));
        //Download deployment bad user
        dep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment/download", "user1", "admin", "basic", 401, "application/json");
        assertTrue(dep.contains("Permission denied"));
        //good user
        dep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment/download", "user2", "admin", "basic", 200, "text/xml");
        assertTrue(dep.contains("<deployment>"));
        assertTrue(dep.contains("</deployment>"));
    } finally {
        if (server != null) {
            server.shutdown();
            server.join();
        }
        server = null;
    }
}
Also used : Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) UserInfo(org.voltdb.compiler.VoltProjectBuilder.UserInfo) File(java.io.File)

Example 4 with UserInfo

use of org.voltdb.compiler.VoltProjectBuilder.UserInfo in project voltdb by VoltDB.

the class TestCatalogDiffs method testChangeUsersAssignedGroups.

public void testChangeUsersAssignedGroups() throws IOException {
    RoleInfo[] gi = new RoleInfo[2];
    gi[0] = new RoleInfo("group1", true, true, true, true, false, false);
    gi[1] = new RoleInfo("group2", true, true, true, true, false, true);
    UserInfo[] ui = new UserInfo[2];
    ui[0] = new UserInfo("user1", "password", new String[] { "group1" });
    ui[1] = new UserInfo("user2", "password", new String[] { "group2" });
    String original = compileWithGroups(false, null, gi, ui, "base", BASEPROCS);
    Catalog catOriginal = catalogForJar(original);
    // swap the user's group assignments
    ui[0] = new UserInfo("user1", "password", new String[] { "group2" });
    ui[1] = new UserInfo("user2", "password", new String[] { "group1" });
    String updated = compileWithGroups(false, null, gi, ui, "base", BASEPROCS);
    Catalog catUpdated = catalogForJar(updated);
    verifyDiff(catOriginal, catUpdated, false);
}
Also used : RoleInfo(org.voltdb.compiler.VoltProjectBuilder.RoleInfo) UserInfo(org.voltdb.compiler.VoltProjectBuilder.UserInfo)

Example 5 with UserInfo

use of org.voltdb.compiler.VoltProjectBuilder.UserInfo in project voltdb by VoltDB.

the class TestCatalogDiffs method testDeleteUser.

public void testDeleteUser() throws IOException {
    RoleInfo[] gi = new RoleInfo[1];
    gi[0] = new RoleInfo("group1", true, true, true, true, false, false);
    UserInfo[] ui = new UserInfo[1];
    ui[0] = new UserInfo("user1", "password", new String[] { "group1" });
    String original = compileWithGroups(false, null, gi, ui, "base", BASEPROCS);
    Catalog catOriginal = catalogForJar(original);
    // no users this time
    String updated = compileWithGroups(false, null, gi, null, "base", BASEPROCS);
    Catalog catUpdated = catalogForJar(updated);
    verifyDiff(catOriginal, catUpdated, false);
}
Also used : RoleInfo(org.voltdb.compiler.VoltProjectBuilder.RoleInfo) UserInfo(org.voltdb.compiler.VoltProjectBuilder.UserInfo)

Aggregations

UserInfo (org.voltdb.compiler.VoltProjectBuilder.UserInfo)18 RoleInfo (org.voltdb.compiler.VoltProjectBuilder.RoleInfo)14 VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)7 File (java.io.File)6 Configuration (org.voltdb.VoltDB.Configuration)6 TPCCProjectBuilder (org.voltdb.benchmark.tpcc.TPCCProjectBuilder)4 IOException (java.io.IOException)3 ProcedureInfo (org.voltdb.compiler.VoltProjectBuilder.ProcedureInfo)3 Test (org.junit.Test)2 ClientResponse (org.voltdb.client.ClientResponse)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 HttpResponse (org.apache.http.HttpResponse)1 VoltDB (org.voltdb.VoltDB)1 VoltTable (org.voltdb.VoltTable)1 Catalog (org.voltdb.catalog.Catalog)1 Client (org.voltdb.client.Client)1 ClientConfig (org.voltdb.client.ClientConfig)1