Return-Path: X-Original-To: apmail-shiro-user-archive@www.apache.org Delivered-To: apmail-shiro-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 38B531A37 for ; Thu, 21 Apr 2011 00:36:59 +0000 (UTC) Received: (qmail 67962 invoked by uid 500); 21 Apr 2011 00:36:59 -0000 Delivered-To: apmail-shiro-user-archive@shiro.apache.org Received: (qmail 67945 invoked by uid 500); 21 Apr 2011 00:36:59 -0000 Mailing-List: contact user-help@shiro.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@shiro.apache.org Delivered-To: mailing list user@shiro.apache.org Received: (qmail 67937 invoked by uid 99); 21 Apr 2011 00:36:59 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Apr 2011 00:36:59 +0000 X-ASF-Spam-Status: No, hits=1.3 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_NEUTRAL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [209.85.161.45] (HELO mail-fx0-f45.google.com) (209.85.161.45) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Apr 2011 00:36:54 +0000 Received: by fxm2 with SMTP id 2so928370fxm.32 for ; Wed, 20 Apr 2011 17:36:32 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.25.201 with SMTP id a9mr927205fac.141.1303346192778; Wed, 20 Apr 2011 17:36:32 -0700 (PDT) Sender: les.hazlewood@anjinllc.com Received: by 10.223.78.207 with HTTP; Wed, 20 Apr 2011 17:36:32 -0700 (PDT) In-Reply-To: <1303344422441-6292830.post@n2.nabble.com> References: <1303344422441-6292830.post@n2.nabble.com> Date: Wed, 20 Apr 2011 17:36:32 -0700 X-Google-Sender-Auth: lzNCTcmc8W_8lcrm6DTsXtQ_mZs Message-ID: Subject: Re: Daemon Task From: Les Hazlewood To: user@shiro.apache.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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/s= hiro/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 wrote: > Hi -- > > In my web application, I am trying to run a daemon task. =C2=A0This 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: > > =C2=A0 =C2=A0Subject subject =3D new Subject.Builder().buildSubject(); > > =C2=A0 =C2=A0ThreadState state =3D new SubjectThreadState(subject); > =C2=A0 =C2=A0state.bind(); > =C2=A0 =C2=A0try { > =C2=A0 =C2=A0 =C2=A0 =C2=A0// run tasks > =C2=A0 =C2=A0} finally { > =C2=A0 =C2=A0 =C2=A0 =C2=A0state.clear(); > =C2=A0 =C2=A0} > > 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. =C2=A0Th= is is an > invalid application configuration. > =C2=A0 =C2=A0at > 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. =C2=A0I 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/Daem= on-Task-tp6292830p6292830.html > Sent from the Shiro User mailing list archive at Nabble.com.