Package com.trendmicro.codi

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

TOP

Related Classes of com.trendmicro.codi.ZKSessionManager

Copyright © 2018 www.massapicom. 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.