Examples of ZkSessionManager


Examples of com.trendmicro.codi.ZKSessionManager

   
    private static final String ACL_NODE = "/global/acl/console_admins";

    private static boolean authenticateLock() throws Exception {
        ZKSessionManager.initialize(Daemon.propMIST.getProperty("mistd.zookeeper") + Daemon.propMIST.getProperty("mistd.zookeeper.tmeroot"), Integer.valueOf(Daemon.propMIST.getProperty("mistd.zookeeper.timeout")));
        ZKSessionManager zksm = ZKSessionManager.instance();
        zksm.waitConnected();

        ZNode authNode = new ZNode(ACL_NODE);
        if(authNode.exists()) {
            LoginContext lc = new LoginContext("ldaploginmodule", new CallbackHandler() {

                @Override
                public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
                    for(Callback cb : callbacks) {
                        if(cb instanceof NameCallback) {
                            System.out.print("Enter username: ");
                            ((NameCallback) cb).setName(System.console().readLine());
                        }
                        else if(cb instanceof PasswordCallback) {
                            System.out.print("Enter password: ");
                            ((PasswordCallback) cb).setPassword(System.console().readPassword());
                        }
                    }
                }
            });
            lc.login();

            boolean authorized = false;
            for(String admin : authNode.getContentString().split(",")) {
                for(Principal p : lc.getSubject().getPrincipals()) {
                    if(p instanceof UserPrincipal) {
                        if(p.getName().equals(admin.trim())) {
                            authorized = true;
                        }
                    }
                }
            }
            if(!authorized)
                throw new Exception("You are not authorized to console, please contact with operation");
        }
        else
            myConsole.logResponseNL("Warning: Can't get authorization information, running under unprotected mode!\n");

        zksm.setDefaultPerms(Id.ANYONE, EnumSet.allOf(Perms.class));

        String lockPath = "/global/tme-console.lock";
        consoleLock = new ZLock(lockPath);

        if(consoleLock.tryAcquire(LockType.WRITE_LOCK, 3000) == false)
View Full Code Here

Examples of org.menagerie.ZkSessionManager

                    If the read lock never acquires, then this method will block until the timeout
                    kills everything
                    */
                    ZooKeeper zooKeeper = TestUtils.newZooKeeper(hostString, timeout);
                    try{
                        ZkSessionManager zksm = new BaseZkSessionManager(zooKeeper);
                        ReadWriteLock rwLock = new ReentrantZkReadWriteLock2(baseLockPath,zksm);
                        Lock readLock = rwLock.readLock();
                        readLock.lock();
                        try{
                            return null;
View Full Code Here

Examples of org.menagerie.ZkSessionManager

                    If the read lock never acquires, then this method will block until the timeout
                    kills everything
                    */
                    ZooKeeper zooKeeper = TestUtils.newZooKeeper(hostString, timeout);
                    try{
                        ZkSessionManager zksm = new BaseZkSessionManager(zooKeeper);
                        ReadWriteLock rwLock = new ReentrantZkReadWriteLock2(baseLockPath,zksm);
                        Lock readLock = rwLock.readLock();
                        readLock.lock();
                        try{
                            return null;
View Full Code Here

Examples of org.menagerie.ZkSessionManager

                    } catch (BrokenBarrierException e) {
                        fail(String.format("%d - %s",Thread.currentThread().getId(),e.getMessage()));
                    }
                    ZooKeeper zk = newZooKeeper();
                    try{
                        ZkSessionManager zksm = new BaseZkSessionManager(zk);
                        Lock guard = new ReentrantZkLock2(baseLockPath,zksm);
                        long totalStart = System.currentTimeMillis();
                        for(int i=0;i<MAX_LOCK_ATTEMPTS;i++){
                            timer.addTiming(guardedWork(guard,operator));
                        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.