Changeset 75:57f603ac6d10 in iovar


Ignore:
Timestamp:
Jan 20, 2017, 11:15:01 PM (16 months ago)
Author:
Shawn Wilson <shawn@…>
Branch:
default
Phase:
public
Message:

saw_012017_1 - Working on proper session propagation through local loopback.

Files:
50 edited

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    r74 r75  
    1 Copyright (C) 2016 Virgo Venture, Inc.
     1Copyright (C) 2016-2017 Virgo Venture, Inc.
    22Copyright (C) 2011-2015 Lannocc Technologies
    33@%@~LICENSE~@%@
     4
     5saw_012017_1 - Working on proper session propagation through local loopback.
    46
    57saw_122516_1 - XArgs now supports text/xml input.
  • src/win/iovar/web/Default.java

    r72 r75  
    4242        try
    4343        {
    44             Transport resource = new Resource (CANON_RES, getServletContext ());
     44            Transport resource = new Resource (CANON_RES, getServletContext (), null);
    4545            if (resource.exists ())
    4646            {
     
    137137        else
    138138        {
    139             final Transport resource = Default.getResource (context, req.getRemoteUser (), Utils.getParams (req.getQueryString ()), path);
     139            final Transport resource = Default.getResource (context, req.getSession (), req.getRemoteUser (), Utils.getParams (req.getQueryString ()), path);
    140140            Log.debug ("resource: "+resource);
    141141
     
    161161        else
    162162        {
    163             final Transport resource = Default.getResource (context, req.getRemoteUser (), Utils.getParams (req.getQueryString ()), path);
     163            final Transport resource = Default.getResource (context, req.getSession (), req.getRemoteUser (), Utils.getParams (req.getQueryString ()), path);
    164164            Log.debug ("resource: "+resource);
    165165           
     
    214214        else
    215215        {
    216             final Transport resource = Default.getResource (context, req.getRemoteUser (), Utils.getParams (req.getQueryString ()), path);
     216            final Transport resource = Default.getResource (context, req.getSession (), req.getRemoteUser (), Utils.getParams (req.getQueryString ()), path);
    217217            Log.debug ("resource: "+resource);
    218218
     
    233233        else
    234234        {
    235             final Transport resource = Default.getResource (context, req.getRemoteUser (), Utils.getParams (req.getQueryString ()), path);
     235            final Transport resource = Default.getResource (context, req.getSession (), req.getRemoteUser (), Utils.getParams (req.getQueryString ()), path);
    236236            Log.debug ("resource: "+resource);
    237237
     
    252252        else
    253253        {
    254             final Transport resource = Default.getResource (context, req.getRemoteUser (), Utils.getParams (req.getQueryString ()), path);
     254            final Transport resource = Default.getResource (context, req.getSession (), req.getRemoteUser (), Utils.getParams (req.getQueryString ()), path);
    255255            Log.debug ("resource: "+resource);
    256256
     
    283283        else
    284284        {
    285             final Transport resource = Default.getResource (context, req.getRemoteUser (), Utils.getParams (req.getQueryString ()), path);
     285            final Transport resource = Default.getResource (context, req.getSession (), req.getRemoteUser (), Utils.getParams (req.getQueryString ()), path);
    286286            Log.debug ("resource: "+resource);
    287287            final Map<String,List<String>> params = Utils.getParams (req.getQueryString ());
     
    343343     * Traverse symbolic links and return reference to a given resource.
    344344     */
    345     static Transport getResource (final ServletContext context, final String user, final Map<String,List<String>> params, final String path) throws IOException
     345    static Transport getResource (final ServletContext context, final HttpSession htsession, final String user, final Map<String,List<String>> params, final String path) throws IOException
    346346    {
    347347        final File root = new File (context.getRealPath ("/")).getCanonicalFile ();
    348         return getResource (context, user, params, root, root, path, path.endsWith ("/"));
    349     }
    350    
    351     private static Transport getResource (final ServletContext context, final String user, final Map<String,List<String>> params, final File root, File base, String path, final boolean isDir) throws IOException
     348        return getResource (context, htsession, user, params, root, root, path, path.endsWith ("/"));
     349    }
     350   
     351    private static Transport getResource (final ServletContext context, final HttpSession htsession, final String user, final Map<String,List<String>> params, final File root, File base, String path, final boolean isDir) throws IOException
    352352    {
    353353        Log.debug ("getResource () root: "+root);
     
    370370                else if (sep==0)
    371371                {
    372                     return getResource (context, user, params, root, base, path.substring (1), isDir);
     372                    return getResource (context, htsession, user, params, root, base, path.substring (1), isDir);
    373373                    //path = path.substring (1);
    374374                    //file = new File (base, path).getCanonicalFile ();
     
    411411            if (! target.exists () && (target.getPath ()+File.separator).startsWith (root.getPath ()))
    412412            {
    413                 return new Resource (/*"/"+*/ target.getPath ().substring (root.getPath ().length ()) + (isDir? "/": ""), context, user, params);
     413                return new Resource (/*"/"+*/ target.getPath ().substring (root.getPath ().length ()) + (isDir? "/": ""), context, user, params, htsession);
    414414            }
    415415            else
    416416            {
    417                 if (isDir) return new win.iovar.web.dev.trans.File (target.getPath ()+"/", context, user, params);
    418                 else return new win.iovar.web.dev.trans.File (target.getPath (), context, user, params);
    419             }
    420         }
    421         else
    422         {
    423             return getResource (context, user, params, root, base, path, isDir);
     417                if (isDir) return new win.iovar.web.dev.trans.File (target.getPath ()+"/", context, user, params, htsession);
     418                else return new win.iovar.web.dev.trans.File (target.getPath (), context, user, params, htsession);
     419            }
     420        }
     421        else
     422        {
     423            return getResource (context, htsession, user, params, root, base, path, isDir);
    424424        }
    425425    }
  • src/win/iovar/web/bin/Cat.java

    r57 r75  
    128128            InputStream i2; try
    129129            {
    130                 i2 = Transport.handler (resource, context).get ();
     130                i2 = Transport.handler (resource, context, req.getSession ()).get ();
    131131            }
    132132            catch (final IOException e)
  • src/win/iovar/web/bin/Delete.java

    r57 r75  
    8282        try
    8383        {
    84             Utils.pipe (Transport.handler (resource, params, context).delete (), resp.getOutputStream ());
     84            Utils.pipe (Transport.handler (resource, params, context, req.getSession ()).delete (), resp.getOutputStream ());
    8585        }
    8686        catch (final IOException e)
  • src/win/iovar/web/bin/Exists.java

    r57 r75  
    101101        try
    102102        {
    103             if (Transport.handler (resource, params, context).exists ())
     103            if (Transport.handler (resource, params, context, req.getSession ()).exists ())
    104104            {
    105105                if (output)
  • src/win/iovar/web/bin/Get.java

    r57 r75  
    8282        try
    8383        {
    84             Utils.pipe (Transport.handler (resource, params, context).get (), resp.getOutputStream ());
     84            Utils.pipe (Transport.handler (resource, params, context, req.getSession ()).get (), resp.getOutputStream ());
    8585        }
    8686        catch (final Exception e)
  • src/win/iovar/web/bin/List.java

    r57 r75  
    8181        final Session session = Sessions.get (req);
    8282        final String resource = args.get (0);
    83         final Transport t = Transport.handler (resource, context);
     83        final Transport t = Transport.handler (resource, context, req.getSession ());
    8484        final PrintWriter out = resp.getWriter ();
    8585       
  • src/win/iovar/web/bin/Patch.java

    r57 r75  
    8585            Log.debug ("request data contentType: "+contentType);
    8686           
    87             Utils.pipe (Transport.handler (resource, params, context).patch (req.getInputStream (), contentType), resp.getOutputStream ());
     87            Utils.pipe (Transport.handler (resource, params, context, req.getSession ()).patch (req.getInputStream (), contentType), resp.getOutputStream ());
    8888        }
    8989        catch (final Exception e)
  • src/win/iovar/web/bin/Post.java

    r57 r75  
    8181            Log.debug ("request data contentType: "+contentType);
    8282           
    83             Utils.pipe (Transport.handler (resources.get (0), context).post (req.getInputStream (), contentType).data, resp.getOutputStream ());
     83            Utils.pipe (Transport.handler (resources.get (0), context, req.getSession ()).post (req.getInputStream (), contentType).data, resp.getOutputStream ());
    8484        }
    8585        catch (final Exception e)
  • src/win/iovar/web/bin/Put.java

    r57 r75  
    8282        try
    8383        {
    84             Utils.pipe (Transport.handler (resource, params, context).put (req.getInputStream ()), resp.getOutputStream ());
     84            Utils.pipe (Transport.handler (resource, params, context, req.getSession ()).put (req.getInputStream ()), resp.getOutputStream ());
    8585        }
    8686        catch (final Exception e)
  • src/win/iovar/web/bin/System.java

    r57 r75  
    9292        }
    9393       
    94         final String command = translateResource (resources.remove (0), context, resp);
     94        final String command = translateResource (resources.remove (0), context, resp, req.getSession ());
    9595        if (command==null)
    9696        {
     
    133133                if (arg.charAt (colon-1)!='\\')
    134134                {
    135                     final String resource = translateResource (arg, context, resp);
     135                    final String resource = translateResource (arg, context, resp, req.getSession ());
    136136                    if (resource==null)
    137137                    {
     
    285285     * FIXME: SECURITY! ugly hack, many assumptions here...
    286286     */
    287     String translateResource (final String path, final ServletContext context, final HttpServletResponse resp) throws IOException
    288     {
    289         final Transport resource = Transport.handler (path, context);
     287    String translateResource (final String path, final ServletContext context, final HttpServletResponse resp, final HttpSession htsession) throws IOException
     288    {
     289        final Transport resource = Transport.handler (path, context, htsession);
    290290        Log.info ("resource: "+resource);
    291291       
  • src/win/iovar/web/bin/shell/Export.java

    r53 r75  
    107107            if (val==null) val = s.toString ();
    108108
    109             session.export (context, key, val, master);
     109            session.export (context, req.getSession (), key, val, master);
    110110        }
    111111
    112112        // FIXME: probably shouldn't automatically save here
    113         session.saveUp (context);
     113        session.saveUp (context, req.getSession ());
    114114       
    115115        // FIXME: is this necessary?
  • src/win/iovar/web/bin/shell/Interactive.java

    r53 r75  
    163163            params.put (Shell.EXT_PARAM_SESSION, Arrays.asList (new String[] { shell.getPath () }));
    164164           
    165             final Transport rc = Transport.handler (shrc, params, context);
     165            final Transport rc = Transport.handler (shrc, params, context, req.getSession ());
    166166            if (rc.exists ())
    167167            {
     
    174174            final Map<String,List<String>> params = new HashMap<String,List<String>> ();
    175175            params.put (Shell.EXT_PARAM_SESSION, Arrays.asList (new String[] { shell.getPath () }));
    176             final Transport rc = Transport.handler ("/root/.ioshrc", params, context);
     176            final Transport rc = Transport.handler ("/root/.ioshrc", params, context, req.getSession ());
    177177            if (rc.exists ())
    178178            {
     
    184184            final Map<String,List<String>> params = new HashMap<String,List<String>> ();
    185185            params.put (Shell.EXT_PARAM_SESSION, Arrays.asList (new String[] { shell.getPath () }));
    186             final Transport rc = Transport.handler ("/home/"+user+"/.ioshrc", params, context);
     186            final Transport rc = Transport.handler ("/home/"+user+"/.ioshrc", params, context, req.getSession ());
    187187            if (rc.exists ())
    188188            {
     
    194194        try
    195195        {
    196             final Map<String,String> config = Utils.configMap (Transport.handler (CONFIG_URI, context).get ());
     196            final Map<String,String> config = Utils.configMap (Transport.handler (CONFIG_URI, context, req.getSession ()).get ());
    197197            final String style = config.get (Config.STYLE.toString ());
    198198           
     
    207207                        "</shell>";
    208208               
    209                 XSLT.transform (context, Transport.handler (style, context).get (),
    210                         new ByteArrayInputStream (xml.getBytes ()), resp);
     209                XSLT.transform (context, Transport.handler (style, context, req.getSession ()).get (),
     210                        new ByteArrayInputStream (xml.getBytes ()), resp, req.getSession ());
    211211               
    212212                styled = true;
     
    276276       
    277277        // FIXME: content-disposition, allow-origin not yet utilized here
    278         final Return r = Shell.exec (path, params, new TaskData (shell, context, req.getRemoteUser (), in, req.getContentType (), null, null));
     278        final Return r = Shell.exec (path, params, new TaskData (shell, context, req.getRemoteUser (), req.getSession (), in, req.getContentType (), null, null));
    279279        Log.debug ("output content type: "+r.type);
    280280        resp.setContentType (r.type);
  • src/win/iovar/web/bin/shell/Print.java

    r74 r75  
    11/*
    2  * Copyright (C) 2016 Virgo Venture, Inc.
     2 * Copyright (C) 2016-2017 Virgo Venture, Inc.
    33 * @%@~LICENSE~@%@
    44 */
     
    101101        catch (final Exception e)
    102102        {
     103            Log.fatal (e);
    103104            StackTraceElement[] elems = e.getStackTrace ();
    104105            for (StackTraceElement elem : elems)
  • src/win/iovar/web/bin/shell/Set.java

    r53 r75  
    105105           
    106106            // FIXME: re-evaluate this...
    107             shell.export (1, context, key, val);
     107            shell.export (1, context, req.getSession (), key, val);
    108108        }
    109109       
    110110        // FIXME: re-evaluate this...
    111         shell.saveUp (1, context);
     111        shell.saveUp (1, context, req.getSession ());
    112112       
    113113        Shell.exit (req, context, 0);
  • src/win/iovar/web/bin/shell/Shell.java

    r68 r75  
    141141                    Log.info ("load session: "+path);
    142142
    143                     final InputStream in = Transport.handler (path, context).get (); try
     143                    final InputStream in = Transport.handler (path, context, req.getSession ()).get (); try
    144144                    {
    145145                        if (s==null) s = (Session) Utils.xstream.fromXML (in);
     
    231231                    if (history==null) history = line;
    232232                    else history = line + '\n' + history;
    233                     session.export (context, "HISTORY", history);
    234                     session.saveUp (context);
     233                    session.export (context, req.getSession (), "HISTORY", history);
     234                    session.saveUp (context, req.getSession ());
    235235                   
    236236                    //Script task = new Parser ().parse (line);
     
    266266                            try
    267267                            {
    268                                 forked.save (context);
     268                                forked.save (context, req.getSession ());
    269269                                /*
    270270                                String sessions = context.getInitParameter (SESSIONS_PARAM);
     
    276276                                //task.exec (forked, context, req, resp, out);
    277277
    278                                 final Return r = task.exec (new TaskData (forked, context, user));
     278                                final Return r = task.exec (new TaskData (forked, context, user, req.getSession ()));
    279279                                Log.debug ("cmd returned: "+r);
    280280
     
    288288                            finally
    289289                            {
    290                                 forked.delete (context);
     290                                forked.delete (context, req.getSession ());
    291291                            }
    292292                        }
     
    316316                Log.debug ("script: "+script);
    317317
    318                 final Transport resource = Transport.handler (script, context);
     318                final Transport resource = Transport.handler (script, context, req.getSession ());
    319319                Log.debug("shell script resource: "+resource);
    320320                final InputStream sin = resource.get ();
     
    361361
    362362                        // prepare a localized session for the script
    363                         final Session local = Call.valueOf (script, params).prepare (params, new TaskData (session, context, user));
     363                        final Session local = Call.valueOf (script, params).prepare (params, new TaskData (session, context, user, req.getSession ()));
    364364                        try
    365365                        {
    366                             local.save (context);
     366                            local.save (context, req.getSession ());
    367367
    368368                            //task.exec (session, context, req, resp, out);
    369369                            // FIXME: content-disposition, allow-origin not yet utilized here
    370                             final Return r = task.exec (new TaskData (local, context, user, req.getInputStream (), req.getContentType (), null, null));
     370                            final Return r = task.exec (new TaskData (local, context, user, req.getSession (), req.getInputStream (), req.getContentType (), null, null));
    371371                            Log.debug ("script returned: "+r);
    372372
     
    387387
    388388                            // FIXME: so hacky (propagating exit value up)
    389                             final Session parent = session.getParent (context);
     389                            final Session parent = session.getParent (context, req.getSession ());
    390390                            parent.clearExit ();
    391391                            if (local.getExit () != null)
    392392                            {
    393393                                parent.setExit (local.getExit ());
    394                                 parent.save (context);
     394                                parent.save (context, req.getSession ());
    395395                            }
    396396                            /*
     
    405405                        finally
    406406                        {
    407                             local.delete (context);
     407                            local.delete (context, req.getSession ());
    408408                        }
    409409                    }
     
    461461
    462462                        //task.exec (session, context, req, resp, out);
    463                         final Return r = task.exec (new TaskData (session, context, user));
     463                        final Return r = task.exec (new TaskData (session, context, user, req.getSession ()));
    464464                        Log.debug ("cmd (stdin) returned: "+r);
    465465                       
     
    510510       
    511511        // FIXME: re-evaluate this... we actually store the exit value in the parent session
    512         shell = shell.getParent (context);
     512        shell = shell.getParent (context, req.getSession ());
    513513        if (shell==null)
    514514        {
     
    529529        shell.saveTo ("local:/proc/shell/"+shell.getId (), context);
    530530        */
    531         shell.save (context);
     531        shell.save (context, req.getSession ());
    532532    }
    533533   
  • src/win/iovar/web/bin/shell/Which.java

    r53 r75  
    8989        final String cmd = vals.get (0);
    9090       
    91         final Transport t = reference (session, context, req.getRemoteUser (), cmd, null);
     91        final Transport t = reference (session, context, req.getRemoteUser (), cmd, null, req.getSession ());
    9292       
    9393        if (t!=null)
     
    102102    }
    103103   
    104     public static Transport reference (final Session shell, final ServletContext context, final String user, final String cmd, Map<String,List<String>> params) throws IOException
     104    public static Transport reference (final Session shell, final ServletContext context, final String user, final String cmd, Map<String,List<String>> params, final HttpSession htsession) throws IOException
    105105    {
    106106        // FIXME: SECURITY
     
    112112        {
    113113            Log.debug ("cmd is absolute");
    114             final Transport t = Transport.handler (cmd, params, context);
     114            final Transport t = Transport.handler (cmd, params, context, htsession);
    115115           
    116116            if (t.exists ()) return t;
     
    124124            {
    125125                Log.debug ("checking for: "+path+"/"+cmd);
    126                 final Transport t = Transport.handler (path+"/"+cmd, params, context);
     126                final Transport t = Transport.handler (path+"/"+cmd, params, context, htsession);
    127127               
    128128                if (t.exists ())
  • src/win/iovar/web/bin/shell/task/Call.java

    r55 r75  
    1818import java.util.*;
    1919import javax.servlet.*;
     20import javax.servlet.http.*;
    2021
    2122// 3rd-party imports:
     
    8788     * FIXME: this should be improved (allow named parameters, too?)
    8889     */
    89     void normalize (Session shell, final ServletContext context)
     90    void normalize (Session shell, final ServletContext context, final HttpSession htsession)
    9091    {
    9192        StringBuffer cmd = null;
     
    99100            for (final Text text : segment.items)
    100101            {
    101                 final String str = text.value (shell, context);
     102                final String str = text.value (shell, context, htsession);
    102103                if (str==null)
    103104                {
     
    200201        if (this.data != null && ! this.data.isEmpty ())
    201202        {
    202             normalize (task.shell, task.context);
     203            normalize (task.shell, task.context, task.htsession);
    203204        }
    204205       
     
    207208        for (final Parameter param : this.params)
    208209        {
    209             final String name = param.getName ().value (task.shell, task.context);
     210            final String name = param.getName ().value (task.shell, task.context, task.htsession);
    210211            final CommandText value = param.getValue ();
    211212
     
    217218            }
    218219           
    219             vals.add (value!=null ? value.value (task.shell, task.context) : null );
     220            vals.add (value!=null ? value.value (task.shell, task.context, task.htsession) : null );
    220221        }
    221222       
     
    232233            params.put (Shell.EXT_PARAM_SESSION, Arrays.asList (new String[] { "local:/proc/shell/"+local.getId () }));
    233234           
    234             final Transport t = Which.reference (local, task.context, task.user, cmd, params);
     235            final Transport t = Which.reference (local, task.context, task.user, cmd, params, task.htsession);
    235236            if (t!=null)
    236237            {
     
    239240                {
    240241                    Log.debug ("removing "+Shell.EXT_PARAM_SESSION+" param");
    241                     t.getParams ().remove (Shell.EXT_PARAM_SESSION);
    242                     params.remove (Shell.EXT_PARAM_SESSION);
     242                    List<String> removed = t.getParams ().remove (Shell.EXT_PARAM_SESSION);
     243                    if (removed!=null && !removed.isEmpty ()) Log.warn ("[HTSESSION] removed param ("+removed+"): "+t);
     244                    removed = params.remove (Shell.EXT_PARAM_SESSION);
     245                    if (removed!=null && !removed.isEmpty ()) Log.warn ("[HTSESSION] removed param ("+removed+"): "+this);
    243246                }
    244247               
    245                 return invoke (local, t, task.context, task.in, task.contentType, params);
     248                return invoke (local, t, task.context, task.in, task.contentType, params, task.htsession);
    246249            }
    247250            else
     
    253256        finally
    254257        {
    255             local.delete (task.context);
     258            local.delete (task.context, task.htsession);
    256259        }
    257260    }
     
    261264        // 3. clear previous exit value
    262265        task.shell.clearExit ();
    263         task.shell.save (task.context);
     266        task.shell.save (task.context, task.htsession);
    264267       
    265268        // 4. fork the session
     
    308311    }
    309312   
    310     static Return invoke (final Session shell, final Transport t, final ServletContext context, final InputStream in, final String contentType, final Map<String,List<String>> params) throws IOException
     313    static Return invoke (final Session shell, final Transport t, final ServletContext context, final InputStream in, final String contentType, final Map<String,List<String>> params, final HttpSession htsession) throws IOException
    311314    {
    312315        // re-set command name from more-specific transport path
     
    315318        // FIXME: hardcoded path to shell session storage
    316319        //shell.saveTo ("local:/proc/shell/"+shell.getId (), context);
    317         shell.save (context);
     320        shell.save (context, htsession);
    318321       
    319322/*
     
    335338            Log.info ("redirecting to target: "+target);
    336339           
    337             return invoke (shell, Transport.handler (target, params, context), context, in, contentType, params);
     340            return invoke (shell, Transport.handler (target, params, context, htsession), context, in, contentType, params, htsession);
    338341        }
    339342        else
  • src/win/iovar/web/bin/shell/task/CommandText.java

    r55 r75  
    1414import java.util.*;
    1515import javax.servlet.*;
     16import javax.servlet.http.*;
    1617
    1718// 3rd-party imports:
     
    9596    }
    9697   
    97     public String value (final Session shell, final ServletContext context)
     98    public String value (final Session shell, final ServletContext context, final HttpSession htsession)
    9899    {
    99100        final StringBuffer s = new StringBuffer ();
     
    101102        for (final Text item : items)
    102103        {
    103             final String val = ((Text) item).value (shell, context);
     104            final String val = ((Text) item).value (shell, context, htsession);
    104105            if (val!=null) s.append (val);
    105106        }
  • src/win/iovar/web/bin/shell/task/DoWhile.java

    r55 r75  
    105105            Return r_old = r;
    106106           
    107             r = todo.exec (new TaskData (shell, task.context, task.user, in, task.contentType, task.disposition, task.allowOrigin));
     107            r = todo.exec (new TaskData (shell, task.context, task.user, task.htsession, in, task.contentType, task.disposition, task.allowOrigin));
    108108            Log.debug ("todo exec returned: "+r);
    109109            if (r==null) r = r_old; // may be null if operation was simply variable assignment
     
    113113            // FIXME: re-evaluate
    114114            Log.debug ("reloading session: "+shell);
    115             shell = Sessions.load (task.context, shell.getPath ());
     115            shell = Sessions.load (task.context, task.htsession, shell.getPath ());
    116116           
    117117            in = null;
     
    122122            //out2.flush ();
    123123
    124             r = condition.exec (new TaskData (shell, task.context, task.user, in, task.contentType, task.disposition, task.allowOrigin));
     124            r = condition.exec (new TaskData (shell, task.context, task.user, task.htsession, in, task.contentType, task.disposition, task.allowOrigin));
    125125            Log.debug ("condition exec returned: "+r);
    126126            if (r==null) r = r_old; // may be null if operation was simply variable assignment
     
    130130            // FIXME: re-evaluate
    131131            Log.debug ("reloading session: "+shell);
    132             shell = Sessions.load (task.context, shell.getPath ());
     132            shell = Sessions.load (task.context, task.htsession, shell.getPath ());
    133133           
    134134            //out2.write ("post-condition: "+shell.toString ()+'\n');
  • src/win/iovar/web/bin/shell/task/Escaped.java

    r55 r75  
    1313import java.io.*;
    1414import javax.servlet.*;
     15import javax.servlet.http.*;
    1516
    1617// 3rd-party imports:
     
    5758    }
    5859   
    59     public String value (final Session shell, final ServletContext context)
     60    public String value (final Session shell, final ServletContext context, final HttpSession htsession)
    6061    {
    6162        return String.valueOf(c);
  • src/win/iovar/web/bin/shell/task/Group.java

    r55 r75  
    154154                final Return r_old = r;
    155155                Log.debug ("task exec: "+task);
    156                 r = task.exec (new TaskData (shell, tdata.context, tdata.user, in, tdata.contentType, tdata.disposition, tdata.allowOrigin));
     156                r = task.exec (new TaskData (shell, tdata.context, tdata.user, tdata.htsession, in, tdata.contentType, tdata.disposition, tdata.allowOrigin));
    157157                Log.debug ("task exec returned: "+r);
    158158                if (r==null) r = r_old; // may be null if operation was simply variable assignment
     
    162162                // FIXME: re-evaluate
    163163                Log.debug ("reloading session: "+shell);
    164                 shell = Sessions.load (tdata.context, shell.getPath ());
     164                shell = Sessions.load (tdata.context, tdata.htsession, shell.getPath ());
    165165                // FIXME: hardcoded path to shell session storage
    166166                //shell = (Session) Utils.xstream.fromXML (Transport.handler ("local:/proc/shell/"+shell.getId (), tdata.context).get ());
  • src/win/iovar/web/bin/shell/task/HardQuoted.java

    r55 r75  
    1313import java.io.*;
    1414import javax.servlet.*;
     15import javax.servlet.http.*;
    1516
    1617// 3rd-party imports:
     
    5758    }
    5859   
    59     public String value (final Session shell, final ServletContext context)
     60    public String value (final Session shell, final ServletContext context, final HttpSession htsession)
    6061    {
    6162        return str;
  • src/win/iovar/web/bin/shell/task/HotQuoted.java

    r55 r75  
    1515import java.util.*;
    1616import javax.servlet.*;
     17import javax.servlet.http.*;
    1718
    1819// 3rd-party imports:
     
    9091    }
    9192   
    92     public String value (final Session shell, final ServletContext context)
     93    public String value (final Session shell, final ServletContext context, final HttpSession htsession)
    9394    {
    9495        try
    9596        {
    9697            /* FIXME (user) */
    97             final Return r = exec (new TaskData (shell, context, null));
     98            final Return r = exec (new TaskData (shell, context, null, htsession));
    9899            if (r==null)
    99100            {
     
    139140            if (item instanceof Text)
    140141            {
    141                 value.append (((Text) item).value (task.shell, task.context));
     142                value.append (((Text) item).value (task.shell, task.context, task.htsession));
    142143            }
    143144            else
  • src/win/iovar/web/bin/shell/task/Input.java

    r55 r75  
    1414import java.io.*;
    1515import javax.servlet.*;
     16import javax.servlet.http.*;
    1617
    1718// 3rd-party imports:
     
    3940    }
    4041   
    41     public InputStream read (final Session shell, final ServletContext context) throws IOException
     42    public InputStream read (final Session shell, final ServletContext context, final HttpSession htsession) throws IOException
    4243    {
    43         return Transport.handler (resource.value (shell, context), context).get ();
     44        return Transport.handler (resource.value (shell, context, htsession), context, htsession).get ();
    4445    }
    4546   
  • src/win/iovar/web/bin/shell/task/Literal.java

    r55 r75  
    1313import java.io.*;
    1414import javax.servlet.*;
     15import javax.servlet.http.*;
    1516
    1617// 3rd-party imports:
     
    5253    }
    5354   
    54     public String value (final Session shell, final ServletContext context)
     55    public String value (final Session shell, final ServletContext context, final HttpSession htsession)
    5556    {
    5657        return String.valueOf (c);
  • src/win/iovar/web/bin/shell/task/Operation.java

    r55 r75  
    167167                // FIXME: re-evaluate this...
    168168               
    169                 shell.set (name, val!=null ? val.value (shell, task.context) : null);
     169                shell.set (name, val!=null ? val.value (shell, task.context, task.htsession) : null);
    170170                //shell.export (1, context, name, val!=null ? val.value (shell, context) : null);
    171171               
     
    173173                // FIXME: not sure about saving here
    174174               
    175                 shell.save (task.context);
     175                shell.save (task.context, task.htsession);
    176176                //shell.saveUp (1, context);
    177177            }
     
    182182            else if (cmd instanceof Chain)
    183183            {
    184                 r = call.exec (new TaskData (shell, task.context, task.user, from!=null ? from.read (shell, task.context) : (r!=null ? r.data : task.in),
     184                r = call.exec (new TaskData (shell, task.context, task.user, task.htsession, from!=null ? from.read (shell, task.context, task.htsession) : (r!=null ? r.data : task.in),
    185185                        from!=null ? null : (r!=null ? r.type : task.contentType),
    186186                        from!=null ? null : (r!=null ? r.disposition : task.disposition),
     
    194194                // FIXME: re-evaluate
    195195                Log.debug ("reloading session: "+shell);
    196                 shell = Sessions.load (task.context, shell.getPath ());
     196                shell = Sessions.load (task.context, task.htsession, shell.getPath ());
    197197                // FIXME: hardcoded path to shell session storage
    198198                //shell = (Session) Utils.xstream.fromXML (Transport.handler ("local:/proc/shell/"+shell.getId (), task.context).get ());
     
    228228               
    229229                // FIXME: content-type, disposition, allow-origin not yet utilized here
    230                 final Job job = Job.background (call, new TaskData (shell, task.context, task.user, from!=null ? from.read (shell, task.context) : (r!=null ? r.data : task.in), null, null, null));
     230                final Job job = Job.background (call, new TaskData (shell, task.context, task.user, task.htsession, from!=null ? from.read (shell, task.context, task.htsession) : (r!=null ? r.data : task.in), null, null, null));
    231231                out.write (job.toString ().getBytes ());
    232232                r = new Return (new ByteArrayInputStream (out.toByteArray ()), new Status () {
     
    248248            {
    249249                // FIXME: contentType not fully utilized here
    250                 r = call.exec (new TaskData (shell, task.context, task.user, from!=null ? from.read (shell, task.context) : (r!=null ? r.data : task.in),
     250                r = call.exec (new TaskData (shell, task.context, task.user, task.htsession, from!=null ? from.read (shell, task.context, task.htsession) : (r!=null ? r.data : task.in),
    251251                        from!=null ? null : (r!=null ? r.type : task.contentType),
    252252                        from!=null ? null : (r!=null ? r.disposition : task.disposition),
     
    254254                ));
    255255                Utils.pipe (r.data, out);
    256                 return new Return (to.write (shell, task.context, new ByteArrayInputStream (out.toByteArray ()), r.type), r.status);
     256                return new Return (to.write (shell, task.context, new ByteArrayInputStream (out.toByteArray ()), r.type, task.htsession), r.status);
    257257            }
    258258            else
    259259            {
    260260                // FIXME: contentType not fully utilized here???
    261                 return call.exec (new TaskData (shell, task.context, task.user, from!=null ? from.read (shell, task.context) : (r!=null ? r.data : task.in),
     261                return call.exec (new TaskData (shell, task.context, task.user, task.htsession, from!=null ? from.read (shell, task.context, task.htsession) : (r!=null ? r.data : task.in),
    262262                        from!=null ? null : (r!=null ? r.type : task.contentType),
    263263                        from!=null ? null : (r!=null ? r.disposition : task.disposition),
  • src/win/iovar/web/bin/shell/task/Output.java

    r55 r75  
    1414import java.io.*;
    1515import javax.servlet.*;
     16import javax.servlet.http.*;
    1617
    1718// 3rd-party imports:
     
    4748    }
    4849   
    49     public InputStream write (final Session shell, final ServletContext context, final InputStream data, final String contentType) throws IOException
     50    public InputStream write (final Session shell, final ServletContext context, final InputStream data, final String contentType, final HttpSession htsession) throws IOException
    5051    {
    51         final Transport trans = Transport.handler (resource.value (shell, context), context);
     52        final Transport trans = Transport.handler (resource.value (shell, context, htsession), context, htsession);
    5253        if (append) return trans.patch (data, contentType);
    5354        else return trans.put (data);
  • src/win/iovar/web/bin/shell/task/SoftQuoted.java

    r55 r75  
    1414import java.util.*;
    1515import javax.servlet.*;
     16import javax.servlet.http.*;
    1617
    1718// 3rd-party imports:
     
    9596    }
    9697   
    97     public String value (final Session shell, final ServletContext context)
     98    public String value (final Session shell, final ServletContext context, final HttpSession htsession)
    9899    {
    99100        final StringBuffer s = new StringBuffer ();
     
    103104            if (item instanceof Text)
    104105            {
    105                 final String val = ((Text) item).value (shell, context);
     106                final String val = ((Text) item).value (shell, context, htsession);
    106107                if (val!=null) s.append (val);
    107108            }
  • src/win/iovar/web/bin/shell/task/TaskData.java

    r53 r75  
    1212import java.io.*;
    1313import javax.servlet.*;
     14import javax.servlet.http.*;
    1415
    1516// 3rd-party imports:
     
    2526    public final ServletContext context;
    2627    public final String user;
     28    public final HttpSession htsession;
    2729    public final InputStream in;
    2830    public final String contentType;
     
    3335     * Minimal constructor.
    3436     */
    35     public TaskData (final Session shell, final ServletContext context, final String user)
     37    public TaskData (final Session shell, final ServletContext context, final String user, final HttpSession htsession)
    3638    {
    37         this (shell, context, user, null, null, null, null);
     39        this (shell, context, user, htsession, null, null, null, null);
    3840    }
    3941   
     
    4143     * Maximal constructor.
    4244     */
    43     public TaskData (final Session shell, final ServletContext context, final String user, final InputStream in, final String contentType, final String disposition, final String allowOrigin)
     45    public TaskData (final Session shell, final ServletContext context, final String user, final HttpSession htsession, final InputStream in, final String contentType, final String disposition, final String allowOrigin)
    4446    {
    4547        this.shell = shell;
    4648        this.context = context;
    4749        this.user = user;
     50        this.htsession = htsession;
    4851        this.in = in;
    4952        this.contentType = contentType;
  • src/win/iovar/web/bin/shell/task/Text.java

    r53 r75  
    1111// java imports:
    1212import javax.servlet.*;
     13import javax.servlet.http.*;
    1314
    1415// 3rd-party imports:
     
    2021interface Text
    2122{
    22     public String value (final Session shell, final ServletContext context);
     23    public String value (final Session shell, final ServletContext context, final HttpSession htsession);
    2324}
  • src/win/iovar/web/bin/shell/task/Variable.java

    r55 r75  
    1313import java.io.*;
    1414import javax.servlet.*;
     15import javax.servlet.http.*;
    1516
    1617// 3rd-party imports:
     
    101102    }
    102103
    103     public String value (Session shell, final ServletContext context)
     104    public String value (Session shell, final ServletContext context, final HttpSession htsession)
    104105    {
    105106        if (shell!=null) return shell.get (name);
  • src/win/iovar/web/dev/MySql.java

    r51 r75  
    164164            try
    165165            {
    166                 final Map<String,String> loaded = Utils.configMap (Transport.handler (CONFIG_URI, context).get ());
     166                final Map<String,String> loaded = Utils.configMap (Transport.handler (CONFIG_URI, context, null).get ());
    167167                final Map<Config,String> config = new HashMap<Config,String> ();
    168168               
  • src/win/iovar/web/dev/PostgreSQL.java

    r51 r75  
    289289    Connection getConnection () throws IOException, SQLException
    290290    {
    291         final Map<String,String> config = Utils.configMap (Transport.handler (CONFIG_URI, getServletContext ()).get ());
     291        final Map<String,String> config = Utils.configMap (Transport.handler (CONFIG_URI, getServletContext (), null).get ());
    292292       
    293293        final String host = config.get (Config.HOST.key);
  • src/win/iovar/web/dev/Transport.java

    r57 r75  
    11/*
    2  * Copyright (C) 2016 Virgo Venture, Inc.
     2 * Copyright (C) 2016-2017 Virgo Venture, Inc.
    33 * Copyright (C) 2011-2015 Lannocc Technologies
    44 * @%@~LICENSE~@%@
     
    3131    protected String path;
    3232    protected Map<String,List<String>> params;
     33    protected HttpSession htsession; // FIXME: this is to track the user's session for loopback; find a better way...
    3334    //int status = 0; // NOT HTTP status! Use <=0 for success or >0 for failure
    3435   
     
    9697    }
    9798   
     99    protected void setSession (final HttpSession htsession)
     100    {
     101        this.htsession = htsession;
     102    }
     103   
     104    public HttpSession getSession ()
     105    {
     106        return htsession;
     107    }
     108   
    98109    public abstract InputStream get () throws IOException;
    99110   
     
    135146    }
    136147   
    137     public static Transport handler (final String resource, final ServletContext context) throws IOException
    138     {
    139         return handler (resource, null, context);
    140     }
    141    
    142     public static Transport handler (final String resource, final Map<String,List<String>> params, final ServletContext context) throws IOException
     148    public static Transport handler (final String resource, final ServletContext context, final HttpSession htsession) throws IOException
     149    {
     150        return handler (resource, null, context, htsession);
     151    }
     152   
     153    public static Transport handler (final String resource, final Map<String,List<String>> params, final ServletContext context, final HttpSession htsession) throws IOException
    143154    {
    144155        Log.debug ("params passed to handler (): "+params);
     
    150161        {
    151162            // FIXME: hardcoded reference to /dev/trans
    152             final Local handler = new Local ("/dev/trans/"+resource.substring (0, colon), context, params);
     163            final Local handler = new Local ("/dev/trans/"+resource.substring (0, colon), context, params, htsession);
    153164           
    154165            if (! handler.exists ())
     
    195206                t.setPath (resource.substring (colon+1));
    196207                t.setParams (params);
     208                t.setSession (htsession);
    197209                Log.debug ("transport reference instantiated: "+t);
    198210                return t;
     
    210222        {
    211223            Log.debug ("(default) returning Local handler for: "+resource);
    212             final Local local = new Local (resource, context, params);
     224            final Local local = new Local (resource, context, params, htsession);
    213225            ((Transport) local).method = "local";
    214226            Log.debug ("transport reference instantiated: "+local);
     
    220232     * Use this handler when the resource string is more like an href and should be parsed for parameters
    221233     */
    222     public static Transport handlerHref (final String href, final ServletContext context) throws IOException
     234    public static Transport handlerHref (final String href, final ServletContext context, final HttpSession htsession) throws IOException
    223235    {
    224236        Log.debug ("href: " + href);
     
    240252       
    241253        Log.debug ("href resource: " + resource);
    242         return handler (resource, params, context);
     254        return handler (resource, params, context, htsession);
    243255    }
    244256}
  • src/win/iovar/web/dev/trans/File.java

    r57 r75  
    1717import java.util.*;
    1818import javax.servlet.*;
     19import javax.servlet.http.*;
    1920
    2021// 3rd-party imports:
     
    3940    }
    4041   
    41     public File (final String path, final ServletContext context)
    42     {
    43         this (path, context, null, new HashMap<String,List<String>> ());
    44     }
    45    
    46     public File (final String path, final ServletContext context, final String user, final Map<String,List<String>> params)
     42    public File (final String path, final ServletContext context, final HttpSession htsession)
     43    {
     44        this (path, context, null, new HashMap<String,List<String>> (), htsession);
     45    }
     46   
     47    public File (final String path, final ServletContext context, final String user, final Map<String,List<String>> params, final HttpSession htsession)
    4748    {
    4849        setContext (context);
    4950        setPath (path);
    5051        setParams (params);
     52        setSession (htsession);
    5153       
    5254        this.user = user;
     
    338340                anon.add (0, "file:"+path);
    339341               
    340                 final Session shell = Sessions.load (context, session);
     342                final Session shell = Sessions.load (context, htsession, session);
    341343                Log.debug ("shell session: "+shell);
    342344               
     
    346348               
    347349                    // FIXME: presently only local interpreters are supported
    348                     return Shell.exec (interpreter, params, new TaskData (shell, context, user, data, contentType, null, null));
     350                    return Shell.exec (interpreter, params, new TaskData (shell, context, user, htsession, data, contentType, null, null));
    349351                }
    350352                catch (final ServletException e)
  • src/win/iovar/web/dev/trans/Http.java

    r57 r75  
    88// local imports:
    99import win.iovar.web.*;
     10import win.iovar.web.bin.shell.*;
    1011import win.iovar.web.bin.shell.task.Return;
    1112import win.iovar.web.dev.*;
    1213import win.iovar.web.lib.*;
     14import win.iovar.web.proc.*;
    1315
    1416// java imports:
     
    4042    }
    4143   
     44    /*
    4245    public Http (final String path)
    4346    {
     
    5053        setParams (params);
    5154    }
     55    */
    5256   
    5357    public Http (final Local local)
     
    6064        setPath ("//"+root+"/"+context.getContextPath ()+"/"+local.getPath ());
    6165        setParams (local.getParams ());
     66        setSession (local.getSession ());
     67       
     68        // SECURITY: for local loopback we use the user's session
     69        if (htsession!=null)
     70        {
     71            if (params==null) params = new HashMap<String,List<String>> ();
     72            List<String> sessparam = params.get (Shell.EXT_PARAM_SESSION);
     73            if (sessparam==null)
     74            {
     75                sessparam = new ArrayList<String> ();
     76                final String id = Sessions.getIdFromSession (htsession);
     77
     78                if (id!=null)
     79                {
     80                    sessparam.add (id);
     81                    Log.info ("[HTSESSION] added session parameter ("+ sessparam + "): "+local);
     82                    params.put (Shell.EXT_PARAM_SESSION, sessparam);
     83                }
     84                else
     85                {
     86                    Log.warn ("[HTSESSION] have htsession but no existing shell session: "+local);
     87                }
     88            }
     89            else
     90            {
     91                Log.info ("[HTSESSION] already have a session parameter, keeping it (" + sessparam + "): "+local);
     92            }
     93        }
     94        else
     95        {
     96            Log.warn ("[HTSESSION] no htsession for loopback: "+local);
     97        }
    6298    }
    6399   
     
    71107        final String query = params!=null ? ("?"+Utils.buildQuery (params)) : "";
    72108        return new URL (new URL ("http", "", ""), path+query);
     109    }
     110   
     111    protected CookieStore getCookies ()
     112    {
     113        if (htsession == null)
     114        {
     115            Log.warn ("SECURITY: no http session");
     116        }
     117        final String key = Http.class.getName () + (htsession!=null ? htsession.getId () : "");
     118       
     119        CookieStore cookies = (CookieStore) context.getAttribute (key);
     120        if (cookies==null)
     121        {
     122            Log.debug ("creating new cookie store");
     123            cookies = new BasicCookieStore ();
     124            context.setAttribute (key, cookies);
     125        }
     126       
     127        Log.debug ("cookie store: "+cookies);
     128        return cookies;
    73129    }
    74130   
     
    89145        final ByteArrayOutputStream out = new ByteArrayOutputStream (); // FIXME: #11
    90146        final HttpClientBuilder htbuild = HttpClientBuilder.create ();
    91        
    92         // cookie support
    93         final String key = Http.class.getName ();
    94         CookieStore cookies = (CookieStore) context.getAttribute (key);
    95         if (cookies==null)
    96         {
    97             Log.debug ("creating new cookie store");
    98             cookies = new BasicCookieStore ();
    99             context.setAttribute (key, cookies);
    100         }
    101         Log.debug ("cookie store: "+cookies);
    102         htbuild.setDefaultCookieStore (cookies);
     147        htbuild.setDefaultCookieStore (getCookies ());
    103148       
    104149        final CloseableHttpClient http = htbuild.build (); try
     
    193238        final ByteArrayOutputStream out = new ByteArrayOutputStream (); // FIXME: #11
    194239        final HttpClientBuilder htbuild = HttpClientBuilder.create ();
    195        
    196         // cookie support
    197         final String key = Http.class.getName ();
    198         CookieStore cookies = (CookieStore) context.getAttribute (key);
    199         if (cookies==null)
    200         {
    201             Log.debug ("creating new cookie store");
    202             cookies = new BasicCookieStore ();
    203             context.setAttribute (key, cookies);
    204         }
    205         Log.debug ("cookie store: "+cookies);
    206         htbuild.setDefaultCookieStore (cookies);
     240        htbuild.setDefaultCookieStore (getCookies ());
    207241       
    208242        final CloseableHttpClient http = htbuild.build (); try
     
    248282        final ByteArrayOutputStream bytes = new ByteArrayOutputStream (); // FIXME: #11
    249283        final HttpClientBuilder htbuild = HttpClientBuilder.create ();
    250        
    251         // cookie support
    252         final String key = Http.class.getName ();
    253         CookieStore cookies = (CookieStore) context.getAttribute (key);
    254         if (cookies==null)
    255         {
    256             Log.debug ("creating new cookie store");
    257             cookies = new BasicCookieStore ();
    258             context.setAttribute (key, cookies);
    259         }
    260         Log.debug ("cookie store: "+cookies);
    261         htbuild.setDefaultCookieStore (cookies);
     284        htbuild.setDefaultCookieStore (getCookies ());
    262285       
    263286        final CloseableHttpClient http = htbuild.build ();
     
    312335        final ByteArrayOutputStream bytes = new ByteArrayOutputStream (); // FIXME: #11
    313336        final HttpClientBuilder htbuild = HttpClientBuilder.create ();
    314        
    315         // cookie support
    316         final String key = Http.class.getName ();
    317         CookieStore cookies = (CookieStore) context.getAttribute (key);
    318         if (cookies==null)
    319         {
    320             Log.debug ("creating new cookie store");
    321             cookies = new BasicCookieStore ();
    322             context.setAttribute (key, cookies);
    323         }
    324         Log.debug ("cookie store: "+cookies);
    325         htbuild.setDefaultCookieStore (cookies);
     337        htbuild.setDefaultCookieStore (getCookies ());
    326338       
    327339        final CloseableHttpClient http = htbuild.build ();
     
    412424        final ByteArrayOutputStream out = new ByteArrayOutputStream (); // FIXME: #11
    413425        final HttpClientBuilder htbuild = HttpClientBuilder.create ();
    414        
    415         // cookie support
    416         final String key = Http.class.getName ();
    417         CookieStore cookies = (CookieStore) context.getAttribute (key);
    418         if (cookies==null)
    419         {
    420             Log.debug ("creating new cookie store");
    421             cookies = new BasicCookieStore ();
    422             context.setAttribute (key, cookies);
    423         }
    424         Log.debug ("cookie store: "+cookies);
    425         htbuild.setDefaultCookieStore (cookies);
     426        htbuild.setDefaultCookieStore (getCookies ());
    426427       
    427428        final CloseableHttpClient http = htbuild.build (); try
     
    530531       
    531532        final HttpClientBuilder htbuild = HttpClientBuilder.create ();
    532        
    533         // FIXME: #12
    534         htbuild.setRedirectStrategy (new DefaultRedirectStrategy ());
    535        
    536         // cookie support
    537         final String key = Http.class.getName ();
    538         CookieStore cookies = (CookieStore) context.getAttribute (key);
    539         if (cookies==null)
    540         {
    541             Log.debug ("creating new cookie store");
    542             cookies = new BasicCookieStore ();
    543             context.setAttribute (key, cookies);
    544         }
    545         Log.debug ("cookie store: "+cookies);
    546         htbuild.setDefaultCookieStore (cookies);
     533        htbuild.setRedirectStrategy (new DefaultRedirectStrategy ()); // FIXME: #12
     534        htbuild.setDefaultCookieStore (getCookies ());
    547535       
    548536        final CloseableHttpClient http = htbuild.build ();
  • src/win/iovar/web/dev/trans/Https.java

    r51 r75  
    2828    }
    2929   
     30    /*
    3031    public Https (final String path)
    3132    {
     
    3738        super (path, params);
    3839    }
     40    */
    3941   
    4042    public Https (final Local local)
  • src/win/iovar/web/dev/trans/Local.java

    r71 r75  
    1515import java.util.*;
    1616import javax.servlet.*;
     17import javax.servlet.http.*;
    1718
    1819// 3rd-party imports:
     
    3435    }
    3536   
    36     public Local (final String path, final ServletContext context)
     37    public Local (final String path, final ServletContext context, final HttpSession htsession)
    3738    {
    38         this (path, context, new HashMap<String,List<String>> ());
     39        this (path, context, new HashMap<String,List<String>> (), htsession);
    3940    }
    4041   
    41     public Local (final String path, final ServletContext context, Map<String,List<String>> params)
     42    public Local (final String path, final ServletContext context, final Map<String,List<String>> params, final HttpSession htsession)
    4243    {
    4344        setContext (context);
    4445        setPath (path);
    4546        setParams (params);
     47        setSession (htsession);
    4648    }
    4749   
  • src/win/iovar/web/dev/trans/Resource.java

    r57 r75  
    1919import java.util.*;
    2020import javax.servlet.*;
     21import javax.servlet.http.*;
    2122
    2223// 3rd-party imports:
     
    4243    }
    4344   
    44     public Resource (final String path, final ServletContext context)
    45     {
    46         this (path, context, null, new HashMap<String,List<String>> ());
    47     }
    48    
    49     public Resource (final String path, final ServletContext context, final String user, final Map<String,List<String>> params)
     45    public Resource (final String path, final ServletContext context, final HttpSession htsession)
     46    {
     47        this (path, context, null, new HashMap<String,List<String>> (), htsession);
     48    }
     49   
     50    public Resource (final String path, final ServletContext context, final String user, final Map<String,List<String>> params, final HttpSession htsession)
    5051    {
    5152//        super (path, params);
     
    5354        setPath (path);
    5455        setParams (params);
     56        setSession (htsession);
    5557       
    5658        this.user = user;
     
    317319                anon.add (0, "res:"+path);
    318320               
    319                 final Session shell = Sessions.load (context, session);
     321                final Session shell = Sessions.load (context, htsession, session);
    320322                Log.debug ("shell session: "+shell);
    321323               
     
    325327               
    326328                    // FIXME: presently only local interpreters are supported
    327                     return Shell.exec (interpreter, params, new TaskData (shell, context, user, data, contentType, null, null));
     329                    return Shell.exec (interpreter, params, new TaskData (shell, context, user, htsession, data, contentType, null, null));
    328330                }
    329331                catch (final ServletException e)
  • src/win/iovar/web/lib/Session.java

    r57 r75  
    1717import java.util.Set;
    1818import javax.servlet.*;
     19import javax.servlet.http.*;
    1920
    2021// 3rd-party imports:
     
    114115    }
    115116
    116     public Session getParent (final ServletContext context) throws IOException
     117    public Session getParent (final ServletContext context, final HttpSession htsession) throws IOException
    117118    {
    118119        if (this.parentPath==null) return null;
    119120
    120         return Sessions.load (context, parentPath);
     121        return Sessions.load (context, htsession, parentPath);
    121122    }
    122123   
     
    200201    }
    201202
    202     public String export (final ServletContext context, final String key, final String val) throws IOException
    203     {
    204         return export (context, key, val, false);
    205     }
    206 
    207     public String export (final ServletContext context, final String key, final String val, final boolean master) throws IOException
     203    public String export (final ServletContext context, final HttpSession htsession, final String key, final String val) throws IOException
     204    {
     205        return export (context, htsession, key, val, false);
     206    }
     207
     208    public String export (final ServletContext context, final HttpSession htsession, final String key, final String val, final boolean master) throws IOException
    208209    {
    209210        if (master)
    210211        {
    211             return export (-2, context, key, val);
     212            return export (-2, context, htsession, key, val);
    212213        }
    213214        else
    214215        {
    215216            // FIXME: this probably shouldn't go all the way up
    216             return export (-1, context, key, val);
     217            return export (-1, context, htsession, key, val);
    217218        }
    218219    }
     
    222223     *                  Use -2 to go up to the master session.
    223224     */
    224     public String export (final int count, final ServletContext context, final String key, final String val) throws IOException
    225     {
    226         final Session parent = getParent (context);
     225    public String export (final int count, final ServletContext context, final HttpSession htsession, final String key, final String val) throws IOException
     226    {
     227        final Session parent = getParent (context, htsession);
    227228
    228229        if (count>0)
    229230        {
    230             if (parent!=null) parent.export (count-1, context, key, val);
     231            if (parent!=null) parent.export (count-1, context, htsession, key, val);
    231232        }
    232233        else if (count<0)
    233234        {
    234             if (parent!=null) parent.export (count, context, key, val);
     235            if (parent!=null) parent.export (count, context, htsession, key, val);
    235236        }
    236237
     
    248249     * Sets the given user object in the top user shell (one down from master session).
    249250     */
    250     public void setUser (final ServletContext context, final Object user) throws IOException
    251     {
    252         final Session parent = getParent (context);
     251    public void setUser (final ServletContext context, final HttpSession htsession, final Object user) throws IOException
     252    {
     253        final Session parent = getParent (context, htsession);
    253254
    254255        if (parent != null)
     
    260261            else
    261262            {
    262                 parent.setUser (context, user);
     263                parent.setUser (context, htsession, user);
    263264            }
    264265        }
    265266    }
    266267
    267     public Object getUser (final ServletContext context) throws IOException
    268     {
    269         final Session parent = getParent (context);
     268    public Object getUser (final ServletContext context, final HttpSession htsession) throws IOException
     269    {
     270        final Session parent = getParent (context, htsession);
    270271
    271272        if (parent != null)
     
    277278            else
    278279            {
    279                 return parent.getUser (context);
     280                return parent.getUser (context, htsession);
    280281            }
    281282        }
     
    322323    */
    323324
    324     public InputStream save (final ServletContext context) throws IOException
    325     {
    326         Transport handler = Transport.handler (path, context);
     325    public InputStream save (final ServletContext context, final HttpSession htsession) throws IOException
     326    {
     327        Transport handler = Transport.handler (path, context, htsession);
    327328
    328329        if (handler instanceof Local || handler instanceof Resource)
     
    353354     * FIXME: a quick hack; not sure this should even exist (SECURITY)
    354355     */
    355     public void saveUp (final ServletContext context) throws IOException
    356     {
    357         saveUp (-1, context);
     356    public void saveUp (final ServletContext context, final HttpSession htsession) throws IOException
     357    {
     358        saveUp (-1, context, htsession);
    358359    }
    359360
     
    363364     * @param   count   How far up to go. Use -1 to go all the way.
    364365     */
    365     public void saveUp (final int count, final ServletContext context) throws IOException
    366     {
    367         save (context);
     366    public void saveUp (final int count, final ServletContext context, final HttpSession htsession) throws IOException
     367    {
     368        save (context, htsession);
    368369
    369370        if (count!=0)
    370371        {
    371             final Session parent = getParent (context);
    372             if (parent!=null) parent.saveUp (count-1, context);
     372            final Session parent = getParent (context, htsession);
     373            if (parent!=null) parent.saveUp (count-1, context, htsession);
    373374        }
    374375    }
     
    396397     * Delete this shell and its children.
    397398     */
    398     public void delete (final ServletContext context) throws IOException
     399    public void delete (final ServletContext context, final HttpSession htsession) throws IOException
    399400    {
    400401        for (final String child : children)
    401402        {
    402             Sessions.delete (context, child);
    403         }
    404 
    405         Sessions.delete (context, path);
     403            Sessions.delete (context, htsession, child);
     404        }
     405
     406        Sessions.delete (context, htsession, path);
    406407    }
    407408
  • src/win/iovar/web/proc/Sessions.java

    r53 r75  
    9090        if (shell!=null)
    9191        {
    92             shell.delete (context);
     92            shell.delete (context, req.getSession ());
    9393            Log.debug ("instance "+id+" deleted");
    9494        }
     
    203203   
    204204    /**
     205     * Retrieve the local user instance id from existing http session.
     206     * Does not create a new shell session.
     207     */
     208    public static String getIdFromSession (final HttpSession htsession)
     209    {
     210        // NOTE: this should match get(HttpServletRequest) below
     211        final String user = /* FIXME SECURITY: req.getRemoteUser () */ "XXX";
     212        final String key = Session.class.getName ()+":"+user;
     213        final String id = (String) htsession.getAttribute (key);
     214        return id;
     215    }
     216   
     217    /**
    205218     * Retrieve the local user instance.
    206219     * If the request contains the "iosession" parameter, that shell is retrieved.
     
    212225        final HttpSession session = req.getSession ();
    213226        final ServletContext context = session.getServletContext ();
    214         final String user = req.getRemoteUser ();
     227        final String user = /* FIXME SECURITY: req.getRemoteUser () */ "XXX";
    215228        final String path = req.getParameter (Shell.EXT_PARAM_SESSION);
    216229       
     
    218231        {
    219232            Log.debug ("request for shell from request, path supplied: "+path);
    220             return load (context, path);
     233            return load (context, req.getSession (), path);
    221234        }
    222235        else
     
    234247                // we could get a ClassCastException because user sessions may
    235248                // be persisted across restarts. Just remove the bogus entry.
    236                 Log.warn ("bad data getting user session", e);
     249                Log.warn ("LEGACY: bad data getting user session", e);
    237250                session.removeAttribute (key);
    238251            }
     
    264277     * Load a local or remote shell instance.
    265278     */
    266     public static Session load (final ServletContext context, final String path) throws IOException
     279    public static Session load (final ServletContext context, final HttpSession htsession, final String path) throws IOException
    267280    {
    268281        Log.debug ("request to load shell at: "+path);
    269         final Transport handler = Transport.handler (path, context);
     282        final Transport handler = Transport.handler (path, context, htsession);
    270283       
    271284        if (handler instanceof Local || handler instanceof Resource)
     
    299312     * Delete a local or remote shell instance.
    300313     */
    301     public static void delete (final ServletContext context, final String path) throws IOException
     314    public static void delete (final ServletContext context, final HttpSession htsession, final String path) throws IOException
    302315    {
    303316        Log.debug ("request to delete shell at: "+path);
    304         final Transport handler = Transport.handler (path, context);
     317        final Transport handler = Transport.handler (path, context, htsession);
    305318       
    306319        if (handler instanceof Local || handler instanceof Resource)
     
    324337                    Log.debug ("shell instance removed: "+shell);
    325338                   
    326                     final Session parent = shell.getParent (context);
     339                    final Session parent = shell.getParent (context, htsession);
    327340                    if (parent!=null)
    328341                    {
     
    376389                    {
    377390                        final Session shell = get (context, id);
    378                         shell.delete (context);
     391                        shell.delete (context, null /* FIXME check this */);
    379392                    }
    380393                    catch (final IOException e)
  • src/win/iovar/web/sbin/Init.java

    r53 r75  
    103103                    final Session shell = Sessions.master (context);
    104104       
    105                     final Transport config = Transport.handler (init, context);
     105                    final Transport config = Transport.handler (init, context, null);
    106106                    Log.debug ("init config resource: "+config);
    107107                   
     
    127127                           
    128128                            // FIXME (user)
    129                             Shell.exec (bootwait.getNodeValue (), null, new TaskData (shell, context, null));
     129                            Shell.exec (bootwait.getNodeValue (), null, new TaskData (shell, context, null, null));
    130130//shell.saveTo ("local:/proc/shell/"+shell.getId (), context);
    131131                        }
  • src/win/iovar/web/usr/bin/FormFile.java

    r74 r75  
    381381                    Log.info ("image will be saved to: "+finalpath);
    382382                   
    383                     final Transport resource = Transport.handler (finalpath, context);
     383                    final Transport resource = Transport.handler (finalpath, context, req.getSession ());
    384384                   
    385385                    // FIXME: not ideal
     
    493493                        Log.debug ("setting filename to variable: "+set);
    494494                        // FIXME: re-evaluate this...
    495                         session.export (1, context, set, setname);
     495                        session.export (1, context, req.getSession (), set, setname);
    496496                    }
    497497
    498498                    // FIXME: re-evaluate this...
    499                     session.saveUp (1, context);
     499                    session.saveUp (1, context, req.getSession ());
    500500       
    501501                    // FIXME: is this necessary?
  • src/win/iovar/web/usr/bin/Head.java

    r51 r75  
    9898        if (resources!=null) for (final String resource : resources)
    9999        {
    100             head (new BufferedReader (new InputStreamReader (Transport.handler (resource, context).get ())), out, count);
     100            head (new BufferedReader (new InputStreamReader (Transport.handler (resource, context, req.getSession ()).get ())), out, count);
    101101        }
    102102       
  • src/win/iovar/web/usr/bin/Tail.java

    r51 r75  
    9898        if (resources!=null) for (final String resource : resources)
    9999        {
    100             tail (new BufferedReader (new InputStreamReader (Transport.handler (resource, context).get ())), out, count);
     100            tail (new BufferedReader (new InputStreamReader (Transport.handler (resource, context, req.getSession ()).get ())), out, count);
    101101        }
    102102    }
  • src/win/iovar/web/usr/bin/XArgs.java

    r74 r75  
    291291        }
    292292
    293         final Return r = Shell.exec (resource, callParams, new TaskData (session, context, req.getRemoteUser ()));
     293        final Return r = Shell.exec (resource, callParams, new TaskData (session, context, req.getRemoteUser (), req.getSession ()));
    294294        resp.setContentType (r.type);
    295295        Utils.pipe (r.data, resp.getOutputStream ());
  • src/win/iovar/web/usr/bin/XLink.java

    r51 r75  
    105105        else
    106106        {
    107             in = new InputSource (Transport.handlerHref (resource, context).get ());
     107            in = new InputSource (Transport.handlerHref (resource, context, req.getSession ()).get ());
    108108        }
    109109       
     
    114114            final SAXParser parser = factory.newSAXParser ();
    115115            final XMLReader xml = parser.getXMLReader ();
    116             xml.setContentHandler (new Handler (factory, context, resp.getWriter (), params.containsKey ("quiet")));
     116            xml.setContentHandler (new Handler (factory, context, req.getSession (), resp.getWriter (), params.containsKey ("quiet")));
    117117            xml.parse (in);
    118118           
     
    137137        final SAXParserFactory factory;
    138138        final ServletContext context;
     139        final HttpSession htsession;
    139140        final boolean quiet;
    140141       
    141142        int linkNest = 0;
    142143       
    143         Handler (final SAXParserFactory factory, final ServletContext context, final Writer out, final boolean quiet)
     144        Handler (final SAXParserFactory factory, final ServletContext context, final HttpSession htsession, final Writer out, final boolean quiet)
    144145        {
    145146            super (out);
    146147            this.factory = factory;
    147148            this.context = context;
     149            this.htsession = htsession;
    148150            this.quiet = quiet;
    149151        }
     
    199201                    try
    200202                    {
    201                         xml.parse (new InputSource (Transport.handlerHref (href, context).get ()));
     203                        xml.parse (new InputSource (Transport.handlerHref (href, context, htsession).get ()));
    202204                    }
    203205                    catch (final SAXParseException e)
     
    218220                        }
    219221                        out.append (">");
    220                         Utils.pipe (Transport.handler (href, context).get (), out);
     222                        Utils.pipe (Transport.handler (href, context, htsession).get (), out);
    221223                        out.append ("</"+qname+">");
    222224                    }
  • src/win/iovar/web/usr/bin/XSLT.java

    r53 r75  
    152152        {
    153153            final TransformerFactory tf = TransformerFactory.newInstance();
    154             tf.setURIResolver (new TransportResolver (context));
     154            tf.setURIResolver (new TransportResolver (context, req.getSession ()));
    155155
    156156            final ByteArrayOutputStream bytes; // FIXME: #11
    157157            if (prestyle!=null)
    158158            {
    159                 final StreamSource xsl = new StreamSource (Transport.handler (prestyle, context).get ());
     159                final StreamSource xsl = new StreamSource (Transport.handler (prestyle, context, req.getSession ()).get ());
    160160                final Transformer trx = tf.newTransformer (xsl);
    161161                trx.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
    162162
    163                 final StreamSource xml = new StreamSource (Transport.handler (stylesheet, context).get ());
     163                final StreamSource xml = new StreamSource (Transport.handler (stylesheet, context, req.getSession ()).get ());
    164164                bytes = new ByteArrayOutputStream ();
    165165                trx.transform (xml, new StreamResult (bytes));
     
    173173            {
    174174                if (bytes!=null) xsl = new StreamSource (new ByteArrayInputStream (bytes.toByteArray ()));
    175                 else xsl = new StreamSource (Transport.handler (stylesheet, context).get ());
     175                else xsl = new StreamSource (Transport.handler (stylesheet, context, req.getSession ()).get ());
    176176            }
    177177
    178178            final StreamSource xml;
    179179            {
    180                 if (resource!=null) xml = new StreamSource (Transport.handler (resource, context).get ());
     180                if (resource!=null) xml = new StreamSource (Transport.handler (resource, context, req.getSession ()).get ());
    181181                else xml = new StreamSource (req.getInputStream ());
    182182            }
     
    212212     */
    213213    public static void transform (final ServletContext context, final InputStream xsl,
    214             final InputStream xml, final HttpServletResponse resp)
     214            final InputStream xml, final HttpServletResponse resp, final HttpSession htsession)
    215215           
    216216            throws IOException, TransformerConfigurationException, TransformerException
    217217    {
    218218        final TransformerFactory tf = TransformerFactory.newInstance();
    219         tf.setURIResolver (new TransportResolver (context));
     219        tf.setURIResolver (new TransportResolver (context, htsession));
    220220       
    221221        transform (tf, context, new StreamSource (xsl), new StreamSource (xml), null, null, resp);
     
    277277    {
    278278        final ServletContext context;
    279        
    280         TransportResolver (final ServletContext context)
     279        final HttpSession htsession;
     280       
     281        TransportResolver (final ServletContext context, final HttpSession htsession)
    281282        {
    282283            this.context = context;
     284            this.htsession = htsession;
    283285        }
    284286       
     
    294296                else
    295297                {
    296                     return new StreamSource (Transport.handlerHref (href, context).get ());
     298                    return new StreamSource (Transport.handlerHref (href, context, htsession).get ());
    297299                }
    298300            }
  • src/win/iovar/web/usr/sbin/Cron.java

    r53 r75  
    144144                if ("daily".equals (freq))
    145145                {
    146                     job = new DailyJob (cmd, args, new TaskData (shell, context, user), null);
     146                    job = new DailyJob (cmd, args, new TaskData (shell, context, user, req.getSession ()), null);
    147147                }
    148148                else try
    149149                {
    150                     job = new HertzJob (Integer.parseInt (freq), cmd, args, new TaskData (shell, context, user));
     150                    job = new HertzJob (Integer.parseInt (freq), cmd, args, new TaskData (shell, context, user, req.getSession ()));
    151151                }
    152152                catch (final NumberFormatException e)
     
    158158                        cal.setTime (time);
    159159                       
    160                         job = new DailyJob (cmd, args, new TaskData (shell, context, user), cal);
     160                        job = new DailyJob (cmd, args, new TaskData (shell, context, user, req.getSession ()), cal);
    161161                    }
    162162                    catch (final ParseException ee)
Note: See TracChangeset for help on using the changeset viewer.