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();
}
}
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;
}
}
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;
}
}
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);
}
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);
}
Aggregations