Package org.apache.karaf.shell.api.console

Examples of org.apache.karaf.shell.api.console.Session


     * @throws Exception in case of failure.
     */
    private void doVerifyIndex(ManageRealmCommand cmd, int index, Config[] realms) throws Exception {

        // prepare mocks
        Session session = createMock(Session.class);
        BundleContext bundleContext = createMock(BundleContext.class);
        Bundle bundle = createMock(Bundle.class);

        // prepare command
        cmd.index = index;
        cmd.setRealms(Arrays.<JaasRealm> asList(realms));
        cmd.setSession(session);

        for (Config realm : realms)
            realm.setBundleContext(bundleContext);

        Object[] mocks = { session, bundleContext, bundle };

        expect(session.get(ManageRealmCommand.JAAS_REALM)).andReturn(null).anyTimes();
        expect(session.get(ManageRealmCommand.JAAS_ENTRY)).andReturn(null).anyTimes();
        expect(session.get(ManageRealmCommand.JAAS_CMDS)).andReturn(null).anyTimes();
        expect(bundleContext.getBundle()).andReturn(bundle).anyTimes();
        expect(bundle.getBundleId()).andReturn(4711L).anyTimes();

        // verify that the correct realm is returned -- cmd.index is 1-based
        session.put(ManageRealmCommand.JAAS_REALM, realms[index - 1]);
        session.put(eq(ManageRealmCommand.JAAS_ENTRY), anyObject());
        session.put(eq(ManageRealmCommand.JAAS_CMDS), anyObject());

        // start the test
        replay(mocks);
        cmd.execute();
        verify(mocks);
View Full Code Here


        });
        loginContext.login();

        JaasHelper.doAs(subject, new PrivilegedExceptionAction<Object>() {
            public Object run() throws InterruptedException {
                final Session newSession = session.getFactory().create(
                        System.in, System.out, System.err, SuCommand.this.session.getTerminal(), null, null);
                Object oldIgnoreInterrupts = session.get(Session.IGNORE_INTERRUPTS);
                try {
                    session.put(Session.IGNORE_INTERRUPTS, Boolean.TRUE);
                    String name = "Karaf local console user " + ShellUtil.getCurrentUserName();
View Full Code Here

    }

    public void start(final Environment env) throws IOException {
        int exitStatus = 0;
        try {
            final Session session = sessionFactory.create(in, new PrintStream(out), new PrintStream(err));
            for (Map.Entry<String,String> e : env.getEnv().entrySet()) {
                session.put(e.getKey(), e.getValue());
            }
            try {
                Subject subject = this.session != null ? this.session.getAttribute(KarafJaasAuthenticator.SUBJECT_ATTRIBUTE_KEY) : null;
                Object result;
                if (subject != null) {
                    try {
                        String scriptFileName = System.getProperty(SHELL_INIT_SCRIPT);
                        executeScript(scriptFileName, session);
                        result = JaasHelper.doAs(subject, new PrivilegedExceptionAction<Object>() {
                            public Object run() throws Exception {
                                return session.execute(command);
                            }
                        });
                    } catch (PrivilegedActionException e) {
                        throw e.getException();
                    }
                } else {
                    String scriptFileName = System.getProperty(SHELL_INIT_SCRIPT);
                    executeScript(scriptFileName, session);
                    result = session.execute(command);
                }
                if (result != null)
                {
                    // TODO: print the result of the command ?
//                    session.getConsole().println(session.format(result, Converter.INSPECT));
View Full Code Here

TOP

Related Classes of org.apache.karaf.shell.api.console.Session

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.