Search in sources :

Example 11 with UserInfo

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

the class TestCatalogDiffs method testModifyUser.

public void testModifyUser() 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);
    RoleInfo[] gi2 = new RoleInfo[1];
    gi2[0] = new RoleInfo("group2", true, true, true, true, true, true);
    // change a user.
    ui[0] = new UserInfo("user1", "drowssap", new String[] { "group2" });
    String updated = compileWithGroups(false, null, gi2, 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 12 with UserInfo

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

the class TestCatalogDiffs method testAddGroupAndUser.

public void testAddGroupAndUser() throws IOException {
    String original = compile("base", BASEPROCS);
    Catalog catOriginal = catalogForJar(original);
    RoleInfo[] gi = new RoleInfo[1];
    gi[0] = new RoleInfo("group1", true, true, true, true, true, false);
    UserInfo[] ui = new UserInfo[1];
    ui[0] = new UserInfo("user1", "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 13 with UserInfo

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

the class TestCatalogDiffs method testChangeSecurityEnabled.

public void testChangeSecurityEnabled() throws IOException {
    RoleInfo[] gi = new RoleInfo[2];
    gi[0] = new RoleInfo("group1", true, true, true, true, false, true);
    gi[1] = new RoleInfo("group2", true, true, true, true, false, false);
    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);
    // just turn on security
    String updated = compileWithGroups(true, "hash", 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 14 with UserInfo

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

the class TestJSONInterface method testJSONAuth.

public void testJSONAuth() throws Exception {
    try {
        String simpleSchema = "CREATE TABLE HELLOWORLD (\n" + "    HELLO VARCHAR(15),\n" + "    WORLD VARCHAR(20),\n" + "    DIALECT VARCHAR(15) NOT NULL,\n" + "    PRIMARY KEY (DIALECT)\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("HELLOWORLD", "DIALECT");
        RoleInfo gi = new RoleInfo("foo", true, false, true, true, false, false);
        builder.addRoles(new RoleInfo[] { gi });
        // create 20 users, only the first one has an interesting user/pass
        UserInfo[] ui = new UserInfo[15];
        ui[0] = new UserInfo("ry@nlikesthe", "y@nkees", new String[] { "foo" });
        for (int i = 1; i < ui.length; i++) {
            ui[i] = new UserInfo("USER" + String.valueOf(i), "PASS" + String.valueOf(i), new String[] { "foo" });
        }
        builder.addUsers(ui);
        builder.setSecurityEnabled(true, true);
        ProcedureInfo[] pi = new ProcedureInfo[2];
        pi[0] = new ProcedureInfo(new String[] { "foo" }, "Insert", "insert into HELLOWORLD values (?,?,?);", null);
        pi[1] = new ProcedureInfo(new String[] { "foo" }, "Select", "select * from HELLOWORLD;", null);
        builder.addProcedures(pi);
        builder.setHTTPDPort(8095);
        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();
        ParameterSet pset;
        // test good auths
        for (UserInfo u : ui) {
            pset = ParameterSet.fromArrayNoCopy(u.name, u.password, u.name);
            String response = callProcOverJSON("Insert", pset, u.name, u.password, true);
            Response r = responseFromJSON(response);
            assertEquals(ClientResponse.SUCCESS, r.status);
        }
        // test re-using auths
        for (UserInfo u : ui) {
            pset = ParameterSet.fromArrayNoCopy(u.name + "-X", u.password + "-X", u.name + "-X");
            String response = callProcOverJSON("Insert", pset, u.name, u.password, false);
            Response r = responseFromJSON(response);
            assertEquals(ClientResponse.SUCCESS, r.status);
        }
        // test bad auth
        UserInfo u = ui[0];
        pset = ParameterSet.fromArrayNoCopy(u.name + "-X1", u.password + "-X1", u.name + "-X1");
        String response = callProcOverJSON("Insert", pset, u.name, "ick", true, false, 401, ClientAuthScheme.HASH_SHA256);
        Response r = responseFromJSON(response);
        assertEquals(ClientResponse.UNEXPECTED_FAILURE, r.status);
        response = callProcOverJSON("Insert", pset, u.name, "ick", false, false, 401, ClientAuthScheme.HASH_SHA256);
        r = responseFromJSON(response);
        assertEquals(ClientResponse.UNEXPECTED_FAILURE, r.status);
        // test malformed auth (too short hash)
        pset = ParameterSet.fromArrayNoCopy(u.name + "-X2", u.password + "-X2", u.name + "-X2");
        String paramsInJSON = pset.toJSONString();
        HashMap<String, String> params = new HashMap<>();
        params.put("Procedure", "Insert");
        params.put("Parameters", paramsInJSON);
        params.put("User", u.name);
        params.put("Password", Encoder.hexEncode(new byte[] { 1, 2, 3 }));
        response = callProcOverJSONRaw(params, 401);
        r = responseFromJSON(response);
        assertEquals(ClientResponse.UNEXPECTED_FAILURE, r.status);
        // test malformed auth (gibberish password, but good length)
        pset = ParameterSet.fromArrayNoCopy(u.name + "-X3", u.password + "-X3", u.name + "-X3");
        paramsInJSON = pset.toJSONString();
        params = new HashMap<>();
        params.put("Procedure", "Insert");
        params.put("Parameters", paramsInJSON);
        params.put("User", u.name);
        params.put("Password", "abcdefghiabcdefghiabcdefghiabcdefghi");
        response = callProcOverJSONRaw(params, 401);
        r = responseFromJSON(response);
        assertEquals(ClientResponse.UNEXPECTED_FAILURE, r.status);
        // the update catalog test below is for enterprise only
        if (VoltDB.instance().getConfig().m_isEnterprise == false) {
            return;
        }
        // ENG-963 below here
        // do enough to get a new deployment file
        VoltProjectBuilder builder2 = new VoltProjectBuilder();
        builder2.addSchema(schemaPath);
        builder2.addPartitionInfo("HELLOWORLD", "DIALECT");
        // Same groups
        builder2.addRoles(new RoleInfo[] { gi });
        // create same 15 users, hack the last 14 passwords
        ui = new UserInfo[15];
        ui[0] = new UserInfo("ry@nlikesthe", "y@nkees", new String[] { "foo" });
        for (int i = 1; i < ui.length; i++) {
            ui[i] = new UserInfo("USER" + String.valueOf(i), "welcomehackers" + String.valueOf(i), new String[] { "foo" });
        }
        builder2.addUsers(ui);
        builder2.setSecurityEnabled(true, true);
        builder2.addProcedures(pi);
        builder2.setHTTPDPort(8095);
        success = builder2.compile(Configuration.getPathToCatalogForTest("json-update.jar"));
        assertTrue(success);
        pset = ParameterSet.fromArrayNoCopy(Encoder.hexEncode(MiscUtils.fileToBytes(new File(config.m_pathToCatalog))), new String(MiscUtils.fileToBytes(new File(builder2.getPathToDeployment())), "UTF-8"));
        response = callProcOverJSON("@UpdateApplicationCatalog", pset, ui[0].name, ui[0].password, true);
        r = responseFromJSON(response);
        assertEquals(ClientResponse.SUCCESS, r.status);
        // retest the good auths above
        for (UserInfo user : ui) {
            ParameterSet ps = ParameterSet.fromArrayNoCopy(user.name + "-X3", user.password + "-X3", user.name + "-X3");
            String respstr = callProcOverJSON("Insert", ps, user.name, user.password, false);
            Response resp = responseFromJSON(respstr);
            assertEquals(ClientResponse.SUCCESS, resp.status);
        }
        VoltProjectBuilder builder3 = new VoltProjectBuilder();
        builder3.addSchema(schemaPath);
        builder3.addPartitionInfo("HELLOWORLD", "DIALECT");
        // Same groups
        builder3.addRoles(new RoleInfo[] { gi });
        ui = new UserInfo[1];
        ui[0] = new UserInfo("ry@nlikesthe", "D033E22AE348AEB5660FC2140AEC35850C4DA9978C6976E5B5410415BDE908BD4DEE15DFB167A9C873FC4BB8A81F6F2AB448A918", new String[] { "foo" }, false);
        builder3.addUsers(ui);
        builder3.setSecurityEnabled(true, true);
        builder3.addProcedures(pi);
        builder3.setHTTPDPort(8095);
        success = builder3.compile(Configuration.getPathToCatalogForTest("json-update.jar"));
        assertTrue(success);
        pset = ParameterSet.fromArrayNoCopy(Encoder.hexEncode(MiscUtils.fileToBytes(new File(config.m_pathToCatalog))), new String(MiscUtils.fileToBytes(new File(builder3.getPathToDeployment())), "UTF-8"));
        response = callProcOverJSON("@UpdateApplicationCatalog", pset, "ry@nlikesthe", "y@nkees", true);
        r = responseFromJSON(response);
        assertEquals(ClientResponse.SUCCESS, r.status);
        // retest the good auths above
        ParameterSet ps = ParameterSet.fromArrayNoCopy(ui[0].name + "-X4", "admin-X4", ui[0].name + "-X4");
        String respstr = callProcOverJSON("Insert", ps, ui[0].name, "admin", false);
        Response resp = responseFromJSON(respstr);
        assertEquals(ClientResponse.SUCCESS, resp.status);
    } finally {
        if (server != null) {
            server.shutdown();
            server.join();
        }
        server = null;
    }
}
Also used : Configuration(org.voltdb.VoltDB.Configuration) HashMap(java.util.HashMap) ProcedureInfo(org.voltdb.compiler.VoltProjectBuilder.ProcedureInfo) UserInfo(org.voltdb.compiler.VoltProjectBuilder.UserInfo) ClientResponse(org.voltdb.client.ClientResponse) HttpResponse(org.apache.http.HttpResponse) RoleInfo(org.voltdb.compiler.VoltProjectBuilder.RoleInfo) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) File(java.io.File)

Example 15 with UserInfo

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

the class TestJSONInterface method testDeploymentSecurity.

public void testDeploymentSecurity() 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" }), //user3 used for both hash testing.
        new UserInfo("user3", "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 with diff hashed password
        //20E3AAE7FC23385295505A6B703FD1FBA66760D5 FD19534FBF9B75DF7CD046DE3EAF93DB77367CA7C1CC017FFA6CED2F14D32E7D
        //D033E22AE348AEB5660FC2140AEC35850C4DA997 8C6976E5B5410415BDE908BD4DEE15DFB167A9C873FC4BB8A81F6F2AB448A918
        //sha-256
        String dep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment/?User=" + "user3&" + "Hashedpassword=8C6976E5B5410415BDE908BD4DEE15DFB167A9C873FC4BB8A81F6F2AB448A918", null, null, null, 200, "application/json");
        assertTrue(dep.contains("cluster"));
        //sha-1
        dep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment/?User=" + "user3&" + "Hashedpassword=D033E22AE348AEB5660FC2140AEC35850C4DA997", null, null, null, 200, "application/json");
        assertTrue(dep.contains("cluster"));
        //Get deployment invalid user
        dep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment/?User=" + "invaliduser&" + "Hashedpassword=d033e22ae348aeb5660fc2140aec35850c4da997", null, null, null, 401, "application/json");
        assertTrue(dep.contains("failed to authenticate"));
        //Get deployment unauthorized user
        dep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment/?User=" + "user1&" + "Hashedpassword=d033e22ae348aeb5660fc2140aec35850c4da997", null, null, null, 401, "application/json");
        assertTrue(dep.contains("Permission denied"));
        //good user
        dep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment/?User=" + "user2&" + "Hashedpassword=d033e22ae348aeb5660fc2140aec35850c4da997", null, null, null, 200, "application/json");
        assertTrue(dep.contains("cluster"));
        //Download deployment unauthorized user
        dep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment/download?User=" + "user1&" + "Hashedpassword=d033e22ae348aeb5660fc2140aec35850c4da997", null, null, null, 401, "application/json");
        assertTrue(dep.contains("Permission denied"));
        //good user
        dep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment/download?User=" + "user2&" + "Hashedpassword=d033e22ae348aeb5660fc2140aec35850c4da997", null, null, null, 200, "text/xml");
        assertTrue(dep.contains("<deployment>"));
        assertTrue(dep.contains("</deployment>"));
        //get with jsonp
        dep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment/?User=" + "user2&" + "Hashedpassword=d033e22ae348aeb5660fc2140aec35850c4da997&jsonp=jackson5", null, null, null, 200, "application/json");
        assertTrue(dep.contains("cluster"));
        assertTrue(dep.contains("jackson5"));
        assertTrue(dep.matches("^jackson5(.*)"));
    } 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)

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