shiro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Les Hazlewood <lhazlew...@apache.org>
Subject Re: Daemon Task
Date Thu, 21 Apr 2011 00:36:32 GMT
Hi Dan,

What is your environment like?  How do you initialize the
SecurityManager - via the normal Shiro Filter mechanism?  I'm trying
to discover how you might acquire the SecurityManager instance.

Also, I'm not sure what you mean 'tried variations of
SecurityUtils.setSecurityManager(securityManager)'.  If you call that
method, the SecurityManager instance passed in will be globally
accessible in static memory and always available to the
Subject.Builder instances.  The only way this wouldn't work is if you
have different class loaders and each ClassLoader has its own
SecurityUtils class instance.  This would be very odd however.

You can verify this by looking at the code here:

http://svn.apache.org/repos/asf/shiro/trunk/core/src/main/java/org/apache/shiro/SecurityUtils.java

The getSecurityManager() method will try a ThreadLocal first, and if
not there, try the static member variable.  If you get an exception
from getSecurityManager(), it is definitely not being set in static
memory (e.g. there is a classloader issue involved or when you called
setSecurityManager, it was a null reference).

Finally, once you have constructed your subject via the
Subject.Builder, I'd recommend using the subject.execute* methods
instead of messing with ThreadState mechanisms (unless you're doing
more 'frameworky' kind of stuff that you've left out for brevity).

Anyway, if you can help answer the configuration questions, I'm sure
we'll get it working.

Cheers,

Les

On Wed, Apr 20, 2011 at 5:07 PM, dan <dan@bamlabs.com> wrote:
> Hi --
>
> In my web application, I am trying to run a daemon task.  This task is run
> in the same JVM but
> from outside the normal web/servlet processing.
>
> I am attempting to create a subject and bind it to this task like this:
>
>    Subject subject = new Subject.Builder().buildSubject();
>
>    ThreadState state = new SubjectThreadState(subject);
>    state.bind();
>    try {
>        // run tasks
>    } finally {
>        state.clear();
>    }
>
> but it throws this:
>
> org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager
> accessible to the calling code, either bound to the
> org.apache.shiro.util.ThreadContext or as a vm static singleton.  This is an
> invalid application configuration.
>    at
> org.apache.shiro.SecurityUtils.getSecurityManager(SecurityUtils.java:123)
>
> when it is building the subject.
>
> I believe I would like Shiro to use the exact, same SecurityManager that all
> the standard processing uses, which is DefaultWebSecurityManager, but I
> don't understand how to initialize this "thread" to use it.  I have read
> through the documentation and have I tried variations of
> SecurityUtils.setSecurityManger() with no luck.
>
> Thanks much,
> Dan
>
> --
> View this message in context: http://shiro-user.582556.n2.nabble.com/Daemon-Task-tp6292830p6292830.html
> Sent from the Shiro User mailing list archive at Nabble.com.

Mime
View raw message