Announcement Announcement Module
Collapse
No announcement yet.
AspectJ getting userId Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment

    Working...
    X