Search in sources :

Example 66 with CuratorFramework

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);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework)

Example 67 with CuratorFramework

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;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) EncryptionSupport(org.apache.karaf.jaas.modules.encryption.EncryptionSupport)

Example 68 with CuratorFramework

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;
}
Also used : IOException(java.io.IOException) LoginException(javax.security.auth.login.LoginException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) FailedLoginException(javax.security.auth.login.FailedLoginException) IOException(java.io.IOException) UserPrincipal(org.apache.karaf.jaas.boot.principal.UserPrincipal) CuratorFramework(org.apache.curator.framework.CuratorFramework) PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) FailedLoginException(javax.security.auth.login.FailedLoginException) PasswordCallback(javax.security.auth.callback.PasswordCallback) LoginException(javax.security.auth.login.LoginException) FailedLoginException(javax.security.auth.login.FailedLoginException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) RolePrincipal(org.apache.karaf.jaas.boot.principal.RolePrincipal) UserPrincipal(org.apache.karaf.jaas.boot.principal.UserPrincipal) RolePrincipal(org.apache.karaf.jaas.boot.principal.RolePrincipal) Principal(java.security.Principal)

Example 69 with CuratorFramework

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();
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) Activate(org.apache.felix.scr.annotations.Activate)

Example 70 with CuratorFramework

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);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) FabricService(io.fabric8.api.FabricService) GetDataBuilder(org.apache.curator.framework.api.GetDataBuilder) PlaceholderResolver(io.fabric8.api.PlaceholderResolver) Test(org.junit.Test)

Aggregations

CuratorFramework (org.apache.curator.framework.CuratorFramework)924 Test (org.testng.annotations.Test)290 RetryOneTime (org.apache.curator.retry.RetryOneTime)271 Test (org.junit.Test)199 Timing (org.apache.curator.test.Timing)147 CountDownLatch (java.util.concurrent.CountDownLatch)124 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)114 KeeperException (org.apache.zookeeper.KeeperException)93 IOException (java.io.IOException)79 ConnectionState (org.apache.curator.framework.state.ConnectionState)71 CuratorEvent (org.apache.curator.framework.api.CuratorEvent)58 ExecutorService (java.util.concurrent.ExecutorService)55 ConnectionStateListener (org.apache.curator.framework.state.ConnectionStateListener)53 ArrayList (java.util.ArrayList)51 RetryNTimes (org.apache.curator.retry.RetryNTimes)51 RetryPolicy (org.apache.curator.RetryPolicy)41 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)38 Cleanup (lombok.Cleanup)37 BackgroundCallback (org.apache.curator.framework.api.BackgroundCallback)37 Stat (org.apache.zookeeper.data.Stat)36