String pathToCatalog = Configuration.getPathToCatalogForTest("adhocddl.jar");
String pathToDeployment = Configuration.getPathToCatalogForTest("adhocddl.xml");
VoltProjectBuilder builder = new VoltProjectBuilder();
// Need to parallel dbuilder as we modify builder
DeploymentBuilder dbuilder = new DeploymentBuilder(2, 1, 0);
builder.addLiteralSchema(
"create table FOO (" +
"ID integer not null," +
"VAL bigint, " +
"constraint PK_TREE primary key (ID)" +
");\n" +
"create table FOO_R (" +
"ID integer not null," +
"VAL bigint, " +
"constraint PK_TREE_R primary key (ID)" +
");\n"
);
builder.addPartitionInfo("FOO", "ID");
dbuilder.setUseDDLSchema(true);
dbuilder.addUsers(new DeploymentBuilder.UserInfo[]
{new DeploymentBuilder.UserInfo("admin", "admin", new String[] {"ADMINISTRATOR"})});
dbuilder.setSecurityEnabled(true);
dbuilder.setEnableCommandLogging(false);
boolean success = builder.compile(pathToCatalog, 2, 1, 0);
assertTrue("Schema compilation failed", success);
dbuilder.writeXML(pathToDeployment);
//MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
VoltDB.Configuration config = new VoltDB.Configuration();
config.m_pathToCatalog = pathToCatalog;
config.m_pathToDeployment = pathToDeployment;
try {
startServer(config);
ClientConfig adminConfig = new ClientConfig("admin", "admin");
Client adminClient = ClientFactory.createClient(adminConfig);
ClientConfig userConfig = new ClientConfig("user", "user");
Client userClient = ClientFactory.createClient(userConfig);
adminClient.createConnection("localhost");
// Can't connect a user which doesn't exist
boolean threw = false;
try {
userClient.createConnection("localhost");
}
catch (IOException ioe) {
threw = true;
assertTrue(ioe.getMessage().contains("Authentication rejected"));
}
assertTrue("Connecting bad user should have failed", threw);
// Try to add a user with a new role to the system
dbuilder.addUsers(new UserInfo[]
{new UserInfo("user", "user", new String[] {"NEWROLE"})});
dbuilder.writeXML(pathToDeployment);
threw = false;
try {
adminClient.updateApplicationCatalog(null, new File(pathToDeployment));
}
catch (ProcCallException pce) {