@Override
public void setUp() throws Exception {
super.setUp();
authenticator = new ZooKeeperAuthenticator(conf);
ZooKeeper zk = authenticator.wrapper.getZooKeeper();
JSONJAXBContext context =
new JSONJAXBContext(JSONConfiguration.natural().build(),
UserModel.class);
JSONMarshaller marshaller = context.createJSONMarshaller();
if (zk.exists(ZooKeeperAuthenticator.USERS_ZNODE_ROOT + "/" +
ADMIN_TOKEN, null) == null) {
UserModel model = new UserModel();
model.name = ADMIN_USERNAME;
model.admin = true;
ByteArrayOutputStream os = new ByteArrayOutputStream();
marshaller.marshallToJSON(model, os);
zk.create(ZooKeeperAuthenticator.USERS_ZNODE_ROOT + "/" + ADMIN_TOKEN,
os.toByteArray(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
if (zk.exists(ZooKeeperAuthenticator.USERS_ZNODE_ROOT + "/" +
USER_TOKEN, null) == null) {
UserModel model = new UserModel();
model.name = USER_USERNAME;
ByteArrayOutputStream os = new ByteArrayOutputStream();
marshaller.marshallToJSON(model, os);
zk.create(ZooKeeperAuthenticator.USERS_ZNODE_ROOT + "/" + USER_TOKEN,
os.toByteArray(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
if (zk.exists(ZooKeeperAuthenticator.USERS_ZNODE_ROOT + "/" +
DISABLED_TOKEN, null) == null) {
UserModel model = new UserModel();
model.name = DISABLED_USERNAME;
model.disabled = true;
ByteArrayOutputStream os = new ByteArrayOutputStream();
marshaller.marshallToJSON(model, os);
zk.create(ZooKeeperAuthenticator.USERS_ZNODE_ROOT + "/" +DISABLED_TOKEN,
os.toByteArray(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
}