1 /*
2  * @(#) $Id: JSTKShellAuthRMIServerImpl.java,v 1.2 2003/07/08 08:13:53 pankaj Exp $
3  *
4  * Copyright (c) 2002-03 by Pankaj Kumar (http://www.pankaj-k.net). 
5  * All rights reserved.
6  *
7  * The license governing the use of this file can be found in the 
8  * root directory of the containing software.
9  */
10package org.jstk.jstksh;
11
12import java.rmi.Remote;
13import java.rmi.Naming;
14import java.rmi.RemoteException;
15import java.rmi.server.*;
16import javax.security.auth.Subject;
17
18public class JSTKShellAuthRMIServerImpl extends JSTKShellRMIServerImpl {
19
20    public JSTKShellAuthRMIServerImpl() throws java.rmi.RemoteException {
21        super(0);
22    }
23
24    public JSTKShellAuthRMIServerImpl(int port) throws java.rmi.RemoteException {
25        super(port);
26    }
27
28    public JSTKShellAuthRMIServerImpl(int port, RMIClientSocketFactory clientFactory,
29            RMIServerSocketFactory serverFactory) throws java.rmi.RemoteException {
30        super(port, clientFactory, serverFactory);
31        shell = new JSTKShellServer();
32    }
33
34    public String execCommand(String[] cmdargs) throws RemoteException {
35        try {
36            JSTKShellActions.ExecCommandAction action = new JSTKShellActions.ExecCommandAction(shell, cmdargs);
37            return (String)Subject.doAs(sub, action);
38        } catch (Exception e){
39            throw new RemoteException("Exception at RMI Server", e);
40        }
41    }
42
43    public String createSession() throws RemoteException {
44        try {
45            JSTKShellActions.CreateSessionAction action = new JSTKShellActions.CreateSessionAction(shell);
46            return (String)Subject.doAs(sub, action);
47        } catch (Exception e){
48            throw new RemoteException("Exception at RMI Server", e);
49        }
50    }
51
52    public void destroySession(String sessId) throws RemoteException {
53        try {
54            JSTKShellActions.DestroySessionAction action = new JSTKShellActions.DestroySessionAction(shell, sessId);
55            Subject.doAs(sub, action);
56        } catch (Exception e){
57            throw new RemoteException("Exception at RMI Server", e);
58        }
59    }
60
61    public static void main(String[] args) throws Exception{
62        JSTKShellAuthRMIServerImpl impl = new JSTKShellAuthRMIServerImpl();
63        impl.initialize(args, "JSTKShellAuthRMIServer");
64    }
65}
66