use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project fabric8 by jboss-fuse.
the class EncryptionMasterPasswordSet method createNewAction.
@Override
public Action createNewAction() {
assertValid();
// this is how we get hold of the curator framework
CuratorFramework curator = CuratorFrameworkLocator.getCuratorFramework();
return new EncryptionMasterPasswordSetAction(curator);
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project fabric8 by jboss-fuse.
the class ZookeeperBackingEngineFactory method build.
@Override
public BackingEngine build(Map options) {
assertValid();
ZookeeperBackingEngine engine = null;
EncryptionSupport encryptionSupport = new BasicEncryptionSupport(options);
String path = (String) options.get("path");
if (path == null) {
path = ZookeeperBackingEngine.USERS_NODE;
}
try {
// build appropriate znodes
if (curator != null) {
CuratorFramework framework = curator.get();
if (framework.checkExists().forPath(path) == null) {
framework.create().creatingParentsIfNeeded().forPath(path);
}
}
ZookeeperProperties users = new ZookeeperProperties(curator.get(), path);
users.load();
engine = new ZookeeperBackingEngine(users, encryptionSupport);
} catch (Exception e) {
LOGGER.warn("Cannot initialize engine", e);
}
return engine;
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project fabric8 by jboss-fuse.
the class ZookeeperLoginModule method login.
@Override
public boolean login() throws LoginException {
boolean result;
String user = null;
try {
Callback[] callbacks = new Callback[2];
callbacks[0] = new NameCallback("Username: ");
callbacks[1] = new PasswordCallback("Password: ", false);
try {
callbackHandler.handle(callbacks);
} catch (IOException ioe) {
throw new LoginException(ioe.getMessage());
} catch (UnsupportedCallbackException uce) {
throw new LoginException(uce.getMessage() + " not available to obtain information from user");
}
user = ((NameCallback) callbacks[0]).getName();
if (user == null)
throw new FailedLoginException("user name is null");
if (user.startsWith(BackingEngine.GROUP_PREFIX)) {
throw new IllegalArgumentException("Prefix not permitted in user names: " + BackingEngine.GROUP_PREFIX);
}
char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword();
if (tmpPassword == null) {
tmpPassword = new char[0];
}
if (debug)
LOG.debug("Login [" + this + "] - user=" + user + ",users=" + users);
if (isContainerLogin(user)) {
String token = containers.getProperty(user);
if (token == null) {
// force reload cache of container tokens
CuratorFramework curator = CuratorFrameworkLocator.getCuratorFramework();
if (curator != null) {
try {
getCachedContainerTokens(curator, true);
token = containers.getProperty(user);
} catch (Exception e) {
LOG.warn(e.getMessage());
}
}
// didn't help
if (token == null) {
throw new FailedLoginException("Container doesn't exist");
}
}
// the password is in the first position
if (!new String(tmpPassword).equals(token)) {
// force reload cache of container tokens
CuratorFramework curator = CuratorFrameworkLocator.getCuratorFramework();
if (curator != null) {
try {
getCachedContainerTokens(curator, true);
token = containers.getProperty(user);
} catch (Exception e) {
LOG.warn(e.getMessage());
}
}
// didn't help
if (!new String(tmpPassword).equals(token)) {
throw new FailedLoginException("Tokens do not match");
}
}
principals = new HashSet<Principal>();
principals.add(new UserPrincipal(user));
principals.add(new RolePrincipal("container"));
principals.add(new RolePrincipal("admin"));
subject.getPrivateCredentials().add(new String(tmpPassword));
result = true;
} else {
String userInfos = users.getProperty(user);
if (userInfos == null) {
// force reload cache of user tokens
CuratorFramework curator = CuratorFrameworkLocator.getCuratorFramework();
if (curator != null) {
try {
getCachedUsers(curator, path, true);
userInfos = users.getProperty(user);
} catch (Exception e) {
LOG.warn(e.getMessage());
}
}
// didn't help
if (userInfos == null) {
throw new FailedLoginException("User doesn't exist");
}
}
// the password is in the first position
String[] infos = userInfos.split(",");
String password = infos[0];
if (!checkPassword(new String(tmpPassword), password)) {
// force reload cache of user tokens
CuratorFramework curator = CuratorFrameworkLocator.getCuratorFramework();
if (curator != null) {
try {
getCachedUsers(curator, path, true);
userInfos = users.getProperty(user);
} catch (Exception e) {
LOG.warn(e.getMessage());
}
}
// didn't help
if (userInfos == null) {
throw new FailedLoginException("User doesn't exist");
}
infos = userInfos.split(",");
password = infos[0];
if (!checkPassword(new String(tmpPassword), password)) {
throw new FailedLoginException("Password does not match");
}
}
principals = new HashSet<Principal>();
principals.add(new UserPrincipal(user));
for (int i = 1; i < infos.length; i++) {
if (infos[i].trim().startsWith(BackingEngine.GROUP_PREFIX)) {
// it's a group reference
principals.add(new GroupPrincipal(infos[i].trim().substring(BackingEngine.GROUP_PREFIX.length())));
String groupInfo = (String) users.get(infos[i].trim());
if (groupInfo != null) {
String[] roles = groupInfo.split(",");
for (int j = 1; j < roles.length; j++) {
principals.add(new RolePrincipal(roles[j].trim()));
}
}
} else {
// it's an user reference
principals.add(new RolePrincipal(infos[i].trim()));
}
}
subject.getPrivateCredentials().add(new String(tmpPassword));
result = true;
}
} catch (LoginException ex) {
if (debug) {
LOG.debug("Login failed {}", user, ex);
}
throw ex;
}
if (debug) {
LOG.debug("Successfully logged in {}", user);
}
return result;
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project fabric8 by jboss-fuse.
the class AutoScaleController method activate.
@Activate
void activate() {
CuratorFramework curator = this.curator.get();
enableMasterZkCache(curator);
group = new ZooKeeperGroup<AutoScalerNode>(curator, ZkPath.AUTO_SCALE_CLUSTER.getPath(), AutoScalerNode.class);
group.add(this);
group.update(createState());
group.start();
activateComponent();
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project fabric8 by jboss-fuse.
the class EncryptedPropertyResolverTest method testResolve.
@Test
public void testResolve() throws Exception {
CuratorFramework curator = createMock(CuratorFramework.class);
GetDataBuilder getDataBuilder = createMock(GetDataBuilder.class);
expect(curator.getData()).andReturn(getDataBuilder).anyTimes();
expect(getDataBuilder.forPath(AUTHENTICATION_CRYPT_ALGORITHM.getPath())).andReturn("PBEWithMD5AndDES".getBytes()).anyTimes();
expect(getDataBuilder.forPath(AUTHENTICATION_CRYPT_PASSWORD.getPath())).andReturn("mypassword".getBytes()).anyTimes();
replay(curator);
replay(getDataBuilder);
FabricService fabricService = createMock(FabricService.class);
expect(fabricService.adapt(CuratorFramework.class)).andReturn(curator).anyTimes();
replay(fabricService);
PlaceholderResolver resolver = getEncryptedPropertyResolver();
assertEquals("encryptedpassword", resolver.resolve(fabricService, null, null, null, "crypt:URdoo9++D3tsoC9ODrTfLNK5WzviknO3Ig6qbI2HuvQ="));
verify(curator);
verify(getDataBuilder);
}
Aggregations