Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [ajdt-dev] AOP question / wormhole

Hi Marco,

I’m assuming your EJB’s are running in the same VM as the Web application,
and that you are authenticating users to the Web application. If that is not
the case, there are other options to consider (*). In this case, you can
indeed use the wormhole pattern. The easiest way is to use a percflow
aspect, where you want the cflow of a request. I’ve done it like this
before:

public abstract aspect ServletAuthenticationContext
percflow(serveltRequest()) {
   public pointcut servletRequest() : execution(execution(*
HttpServlet.do*(..));

   private User user;

   protected abstract pointcut authentication(User user);

   after(User user) returning: authentication(user) {
       this.user = user;
   }

   // you can extend this aspect to define how to authenticate & you can
write advice that uses the user variable
   // there will be one instance of this aspect per Web request
}

An alternative approach is to have a singleton aspect and to use a
ThreadLocal or even an InheritedThreadLocal to manage the state. But I think
a percflow aspect is a good match for what you are trying to do.

Ron

(*) I posted to this mailing list a while ago a way to pass extra context to
distributed EJB’s with an aspect. You might also consider using J2EE
security and getting the user’s principal from that.


________________________________________
From: ajdt-dev-bounces@xxxxxxxxxxx [mailto:ajdt-dev-bounces@xxxxxxxxxxx] On
Behalf Of Marco Mistroni
Sent: Wednesday, February 15, 2006 4:59 AM
To: AspectJ Development Tools developer discussions
Subject: [ajdt-dev] AOP question / wormhole

Hello all,
  sorry for this partially- off-topic question
i have following usecase..
I need to track changes to some database tables  (backed by EJBs), and for
that i need to 
get the user who did it as well as the data which has changed 

My 'changes' are in a context of a webapplication, where the user first logs
in to the application
and then will do all changes needed.

I have no problem in tracking changes (i can intercept hte methods of EJBs
which do the changes), but 
i m stuck in finding out how to get the user,.since the user who logs in is
not passed down to the
EJB layer.

Obviously, i can write a LoginAspect that intercepts the login process,
store locally the user and then make it available 
to other aspects in my application
THis will work fine if the system will be used by only one user (considering
the aspect will have default
association), but i have problems in undestanding
what will happen when there will be multiple users logging in,how to track
them 

I can't use anymore the 'default association'  LoginAspect, because (my
opinion) if user1 logs in to the system,and
after that user2 logs in, the LoginAspect will have user2 'stored' as user.
and if
user1 do changes, the ChangeAspect, invoking LoginAspect.getUser()  will get
as user user2..
.
I have tried to use the wormhole pattern, but it didnt work out.... 

maybe i am missing something about association, but how can i have a 'Per
User' association 
for my LoginAspect?

does anyone have any idea on how to do that?

thanks in advance and regards
  Marco



Back to the top