Ah. In 'standalone' mode, you have to tell SecurityUtils where the SecurityManager is by calling SecurityUtils.setSecurityManager(securityManager);
This is because in a web or Spring/EJB environment, SecurityUtils assumes some framework code elsewhere first executes to set up thread-bound Subject instances: in the web environment, a Servlet Filter will intercept requests, create a Subject based on the request, and bind it to the thread. In RMI environments, AOP proxies will do the same thing based on the incoming invocation. In a standalone environment, where there might not be any Filters intercepting web requests or AOP proxies intercepting remote method invocations, SecurityUtils can't rely on a thread-bound instance. So it has to ask the SecurityManager directly. SecurityUtils.setSecurityManager sets the instance in static memory, shared across the VM. This however is NOT recommended for any environment other than standalone applications - it is sort of a 'last resort' when you can't rely on a container to manage dependency graphs for you... HTH, Les On Tue, Mar 31, 2009 at 9:21 AM, Maciej Pigulski <[email protected]>wrote: > > > On Tue, Mar 31, 2009 at 2:37 AM, Maciej Pigulski > <[email protected]>wrote: > > > > > I had problems with getting to Subjects session to store the > authorization > > info - SecurityUtils.getSubject() was returning a null value. I guess the > > issue is that this object does not exist in this stage, but I couldn't > get > > any other idea how to get into the Session object. > > > That is extremely odd. There should _always_ be a Subject for any thread's > execution. If one does not exist at the time getSubject() is called, it > should have been created automatically. > > Are you running in a webapp or a standalone application? > > Regards, > > Les > > > > I was testing it in a standalone application running outside any containter > (snippet of this class is in my first post in this thread). My target > application is a web application. > > Take notice that I'm trying to SecurityUtils.getSubject() inside overriding > class that extends ActiveDirectoryRealm in queryForAuthenticationInfo(...) > method. Then it returns null. > > > Regards, > Maciej > > -- > View this message in context: > http://n2.nabble.com/Reading-user-roles-from-Active-Directory-tp2503002p2562906.html > Sent from the JSecurity User mailing list archive at Nabble.com. > >
