Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Passing in parameters from runtime code

You may want to store away the Subject object in a ThreadLocal or HttpSession (depending upon if user is authenticated in the same request or the same session as the execution of SQL statements of your interest) object by advising the join points that obtain the authenticated user. Then you can access the object inside advice to SQL statement execution. Something like:

aspect LogSQLWithSubject {
   ThreadLocal currentSubjectHolder = new ThreadLocal();

   after returning(Subject subject)
       : call(method_that_returns_authenticated_subject) {
      currentSubjectHolder.set(subject);
   }

   before(String sqlString)
       : call(sql_statement_execution_method)
         && args(sqlString, ...) {
      Subject currentSubject = (Subject)currentSubjectHolder.get();
      ... log sqlString and currentSubject ...
   }
}

-Ramnivas

===
Ramnivas Laddad,
Author, AspectJ in Action
http://ramnivas.com

Seaman, Sloan wrote:

How do I get a variable from the running code into some Aspect?

What I mean to say is that I have an web app that for each user logged in, there is a javax.security.auth.Subject object for. I'm using AspectJ to record all SQL statements that end up getting executed but how do I tie them to the Subject?

I.E. How do I get the .aj code to have an instance of the Subject object? I can't put it in a static place in memory because since it is a web app, I have to worry about threading issues.

Anyone know how I can pull this off?

Thanks!

--
Sloan



Back to the top