Results 1 to 2 of 2

Thread: AspectJ getting userId

  1. #1
    Join Date
    Jul 2011
    Posts
    11

    Default AspectJ getting userId

    Hi

    For all the domain classes, I want to add created/update datetime and created/update by.

    For date/time I found an addon spring-roo-addon-audit-timestamp.

    This addon adds an AspectJ file where it weaves create and updated timestamp to entity.

    But to add I didn't find any addon - so I added two more fields created/updated by to the same aspectJ file generated by addon spring-roo-addon-audit-timestamp.

    I am using spring security for authentication. I want to get logged-in userid from the httpsession and use it in my aspectJ. I don't know how to get the httpsession object inside the AspectJ.

    Questions:

    1) How do get httpsession object inside AspectJ?
    2) Is there is any better way to add created/updated by fields to domain classes?
    3) Is it possible to create one common AspectJ for auditing timestamp and userid - and use it for all the domain classes/entities?

    Can anybody help?

  2. #2
    Join Date
    Mar 2008
    Location
    Sydney, AU
    Posts
    974

    Default

    1) How do get httpsession object inside AspectJ?
    If your aspect is adding functionality to a MVC controller you can easily get http-related information injected into your method. There is no difference between AspectJ code and Java code. Keep in mind that Roo will delete all your custom code in aj files it manages. For any customization you should write code in .java sources.

    2) Is there is any better way to add created/updated by fields to domain classes?
    3) Is it possible to create one common AspectJ for auditing timestamp and userid - and use it for all the domain classes/entities?
    There are always different ways to skin a cat. If your timestamp code is the same for all entities you can create a application wide aspect with a pointcut expression. See http://www.eclipse.org/aspectj/doc/r...ide/index.html for details.
    Stefan Schmidt
    Software Engineer, Spring Roo
    SpringSource - a division of VMware
    twitter @schmidtstefan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •