You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2014/07/08 16:28:41 UTC
Using EL expressions in JMX operations (e.g. expireSession)
All,
In order to help me with a few sundry operations, I've written some
crude command-line tools that use JMXProxyServlet to do my bidding.
Here's a gem:
for sessionid in `wget -qO -
'http://localhost/manager/jmxproxy?invoke=Catalina:type=Manager,context=/myapp,host=localhost&op=listSessionIds'
| sed -e "s/ /\n/g" | grep '^[0-9A-Z]\+\(\..*\)\?$' | grep -v "^OK$"` ;
do wget -qO -
"http://localhost/manager/jmxproxy?invoke=Catalina:type=Manager,context=/myapp,host=localhost&op=getSessionAttribute&ps=$sessionid,user"
; done
That dumps out all the users currently logged-in, plus a bunch of "OK -
Operation getSessionAttribute without return value" outputs.
Tweaking the above command, I can get Tomcat to give me the list of
sessions for which there is no user, for example.
Now, let's say that I want to expire all the sessions for which there is
no user. I can run the above command (with obvious modifications) and
get a list of session ids for which there are are no users, and then I
can execute /another/ call to JMXProxyServlet calling expireSession with
the id of the session.
While that sounds like fun, I wonder if there isn't a better way. I also
think this idea could be useful for other operations as well: allow the
use of an EL expression that can be used to match sessions.
For instance, one could write an EL expression that would be executed on
each session and return a true/false (or maybe just true/not-true), and
then expireSessions (plural, to distinguish it from the existing
single-session expiration operation). Something like this:
${!empty session.user && ((now - session.lastAccessedTime) > 120000)}
Asking JMXProxyServlet to expire all sessions matching the above
expression would then kill any session that had no user attribute (might
have to use session.getAttribute('user')... I'm no EL expert) and was
also left unattended for 2-minutes or more.
Is there any interest in this kind of thing? Parsing (specifically) and
executing EL expressions on the fly might be a bit expensive for
administrative operations, but of course one does not need to use such
features if one does not want to.
I haven't really thought about it too much, but I suspect there would be
other situations where being able to filter objects using an EL-based
predicate might be useful.
-chris
Re: Using EL expressions in JMX operations (e.g. expireSession)
Posted by Christopher Schultz <ch...@christopherschultz.net>.
Mark,
On 7/8/14, 4:16 PM, Mark Thomas wrote:
> On 08/07/2014 15:28, Christopher Schultz wrote:
>> All,
>>
>> In order to help me with a few sundry operations, I've written
>> some crude command-line tools that use JMXProxyServlet to do my
>> bidding.
>>
>> Here's a gem:
>>
>> for sessionid in `wget -qO -
>> 'http://localhost/manager/jmxproxy?invoke=Catalina:type=Manager,context=/myapp,host=localhost&op=listSessionIds'
>>
>>
> | sed -e "s/ /\n/g" | grep '^[0-9A-Z]\+\(\..*\)\?$' | grep -v "^OK$"` ;
>> do wget -qO -
>> "http://localhost/manager/jmxproxy?invoke=Catalina:type=Manager,context=/myapp,host=localhost&op=getSessionAttribute&ps=$sessionid,user"
>>
>>
> ; done
>>
>> That dumps out all the users currently logged-in, plus a bunch of
>> "OK - Operation getSessionAttribute without return value" outputs.
>>
>> Tweaking the above command, I can get Tomcat to give me the list
>> of sessions for which there is no user, for example.
>>
>> Now, let's say that I want to expire all the sessions for which
>> there is no user. I can run the above command (with obvious
>> modifications) and get a list of session ids for which there are
>> are no users, and then I can execute /another/ call to
>> JMXProxyServlet calling expireSession with the id of the session.
>>
>> While that sounds like fun, I wonder if there isn't a better way. I
>> also think this idea could be useful for other operations as well:
>> allow the use of an EL expression that can be used to match
>> sessions.
>>
>> For instance, one could write an EL expression that would be
>> executed on each session and return a true/false (or maybe just
>> true/not-true), and then expireSessions (plural, to distinguish it
>> from the existing single-session expiration operation). Something
>> like this:
>>
>> ${!empty session.user && ((now - session.lastAccessedTime) >
>> 120000)}
>>
>> Asking JMXProxyServlet to expire all sessions matching the above
>> expression would then kill any session that had no user attribute
>> (might have to use session.getAttribute('user')... I'm no EL
>> expert) and was also left unattended for 2-minutes or more.
>>
>> Is there any interest in this kind of thing? Parsing (specifically)
>> and executing EL expressions on the fly might be a bit expensive
>> for administrative operations, but of course one does not need to
>> use such features if one does not want to.
>>
>> I haven't really thought about it too much, but I suspect there
>> would be other situations where being able to filter objects using
>> an EL-based predicate might be useful.
>
> Executing arbitrary user provided EL expressions often creates all
> sorts of security problems.
I agree in general, but the policy about the manager webapp has always
been that if one has access to it, then one already has the keys to the
kingdom. We could introduce (yet) another role to the manager for this
kind of thing.
> My concern is that the complexity of implementing this securely may
> outweigh the benefit it brings.
A fair argument.
This use case is fairly rare and, honestly, could be handled with a
small amount of custom code on my part. I just thought something like
this might have some utility to others, so I figured I'd present the idea.
If there's additional interest, we can re-visit it.
-chris
Re: Using EL expressions in JMX operations (e.g. expireSession)
Posted by Mark Thomas <ma...@apache.org>.
On 08/07/2014 15:28, Christopher Schultz wrote:
> All,
>
> In order to help me with a few sundry operations, I've written
> some crude command-line tools that use JMXProxyServlet to do my
> bidding.
>
> Here's a gem:
>
> for sessionid in `wget -qO -
> 'http://localhost/manager/jmxproxy?invoke=Catalina:type=Manager,context=/myapp,host=localhost&op=listSessionIds'
>
>
| sed -e "s/ /\n/g" | grep '^[0-9A-Z]\+\(\..*\)\?$' | grep -v "^OK$"` ;
> do wget -qO -
> "http://localhost/manager/jmxproxy?invoke=Catalina:type=Manager,context=/myapp,host=localhost&op=getSessionAttribute&ps=$sessionid,user"
>
>
; done
>
> That dumps out all the users currently logged-in, plus a bunch of
> "OK - Operation getSessionAttribute without return value" outputs.
>
> Tweaking the above command, I can get Tomcat to give me the list
> of sessions for which there is no user, for example.
>
> Now, let's say that I want to expire all the sessions for which
> there is no user. I can run the above command (with obvious
> modifications) and get a list of session ids for which there are
> are no users, and then I can execute /another/ call to
> JMXProxyServlet calling expireSession with the id of the session.
>
> While that sounds like fun, I wonder if there isn't a better way. I
> also think this idea could be useful for other operations as well:
> allow the use of an EL expression that can be used to match
> sessions.
>
> For instance, one could write an EL expression that would be
> executed on each session and return a true/false (or maybe just
> true/not-true), and then expireSessions (plural, to distinguish it
> from the existing single-session expiration operation). Something
> like this:
>
> ${!empty session.user && ((now - session.lastAccessedTime) >
> 120000)}
>
> Asking JMXProxyServlet to expire all sessions matching the above
> expression would then kill any session that had no user attribute
> (might have to use session.getAttribute('user')... I'm no EL
> expert) and was also left unattended for 2-minutes or more.
>
> Is there any interest in this kind of thing? Parsing (specifically)
> and executing EL expressions on the fly might be a bit expensive
> for administrative operations, but of course one does not need to
> use such features if one does not want to.
>
> I haven't really thought about it too much, but I suspect there
> would be other situations where being able to filter objects using
> an EL-based predicate might be useful.
Executing arbitrary user provided EL expressions often creates all
sorts of security problems.
My concern is that the complexity of implementing this securely may
outweigh the benefit it brings.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: Using EL expressions in JMX operations (e.g. expireSession)
Posted by Konstantin Kolinko <kn...@gmail.com>.
2014-07-08 18:28 GMT+04:00 Christopher Schultz <ch...@christopherschultz.net>:
>
> (...)
>
> For instance, one could write an EL expression that would be executed on
> each session and return a true/false (or maybe just true/not-true), and
> then expireSessions (plural, to distinguish it from the existing
> single-session expiration operation). Something like this:
>
> ${!empty session.user && ((now - session.lastAccessedTime) > 120000)}
>
> Asking JMXProxyServlet to expire all sessions matching the above
> expression would then kill any session that had no user attribute (might
> have to use session.getAttribute('user')... I'm no EL expert) and was
> also left unattended for 2-minutes or more.
>
> Is there any interest in this kind of thing? Parsing (specifically) and
> executing EL expressions on the fly might be a bit expensive for
> administrative operations, but of course one does not need to use such
> features if one does not want to.
>
> I haven't really thought about it too much, but I suspect there would be
> other situations where being able to filter objects using an EL-based
> predicate might be useful.
>
1. This example is not self-contained. It does not define "now". It
does not define where "session" comes from.
2. Do you expect evaluation of EL to turn into series of JMX calls? I
think those session properties are not available directly. You need to
ask for them.
3. Error processing = ? Thread safety = ?
I think this needs three or more use case examples to better
understand the problem.
If it is just a single use case, a custom JSP page may do better.
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org