Search in sources :

Example 1 with CliManagerImpl

use of hudson.cli.CliManagerImpl in project hudson-2.x by hudson.

the class Hudson method doCli.

/**
     * Handles HTTP requests for duplex channels for CLI.
     */
public void doCli(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, InterruptedException {
    if (!"POST".equals(req.getMethod())) {
        // for GET request, serve _cli.jelly, assuming this is a browser
        checkPermission(READ);
        req.getView(this, "_cli.jelly").forward(req, rsp);
        return;
    }
    // do not require any permission to establish a CLI connection
    // the actual authentication for the connecting Channel is done by CLICommand
    UUID uuid = UUID.fromString(req.getHeader("Session"));
    // set the header so that the client would know
    rsp.setHeader("Hudson-Duplex", "");
    FullDuplexHttpChannel server;
    if (req.getHeader("Side").equals("download")) {
        duplexChannels.put(uuid, server = new FullDuplexHttpChannel(uuid, !hasPermission(ADMINISTER)) {

            protected void main(Channel channel) throws IOException, InterruptedException {
                // capture the identity given by the transport, since this can be useful for SecurityRealm.createCliAuthenticator()
                channel.setProperty(CLICommand.TRANSPORT_AUTHENTICATION, getAuthentication());
                channel.setProperty(CliEntryPoint.class.getName(), new CliManagerImpl());
            }
        });
        try {
            server.download(req, rsp);
        } finally {
            duplexChannels.remove(uuid);
        }
    } else {
        duplexChannels.get(uuid).upload(req, rsp);
    }
}
Also used : CliManagerImpl(hudson.cli.CliManagerImpl) LocalChannel(hudson.remoting.LocalChannel) Channel(hudson.remoting.Channel) VirtualChannel(hudson.remoting.VirtualChannel) UUID(java.util.UUID) CliEntryPoint(hudson.cli.CliEntryPoint)

Aggregations

CliEntryPoint (hudson.cli.CliEntryPoint)1 CliManagerImpl (hudson.cli.CliManagerImpl)1 Channel (hudson.remoting.Channel)1 LocalChannel (hudson.remoting.LocalChannel)1 VirtualChannel (hudson.remoting.VirtualChannel)1 UUID (java.util.UUID)1