Results 1 to 10 of 10

Thread: roo security @preAuthorize @postFilter issues

  1. #1
    Join Date
    May 2009
    Posts
    15

    Question roo security @preAuthorize @postFilter issues

    Hi,

    I'm using spring security 3.0.5 with roo. I've been at this for a while now, can't figure it out... so I hope you guys can help.

    In one of my Domain classes I added some find methods to the .java file (in addition to the roo generated ones in the .aj file).

    Trying to secure them as follows doesn't seem to do anything if using mode="aspectj" in the global method security namespace element. Everything works, but I don't think method security is ever actually applied. Don't see anything in logs...

    Code:
    @PreAuthorize("ROLE_USER")
    @PostFilter("hasPermission(filterTarget,role) or hasRole('ROLE_ADMIN')")
    Trying to use aop instead, method security is applied:

    Code:
    org.springframework.security.access.prepost.PrePostAnnotationSecurityMetadataSource - @org.springframework.security.access.prepost.PreAuthorize(value=ROLE_USER) found on specific method: public static java.util.List x.y.DomainObject.findX()
    2011-02-27 10:32:45,728 ["http-bio-8080"-exec-8] DEBUG org.springframework.security.access.prepost.PrePostAnnotationSecurityMetadataSource - @org.springframework.security.access.prepost.PostFilter(value=hasPermission(filterTarget,role) or hasRole('ROLE_ADMIN')) found on specific method: public static java.util.List x.y.DomainObject.findX()
    2011-02-27 10:32:45,737 ["http-bio-8080"-exec-8] DEBUG org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource - Adding security method [CacheKey[x.y.DomainObject; public static java.util.List x.y.DomainObject.findX()]] with attributes [[authorize: 'ROLE_USER', filter: 'null', filterTarget: 'null'], [authorize: 'null', filter: 'hasPermission(filterTarget,role) or hasRole('ROLE_ADMIN')']]
    but results in:

    Code:
    java.lang.IllegalStateException: Post-processor tried to replace bean instance of type [x.y.DomainObject] with (proxy) object of type [$Proxy134] - not supported for aspect-configured classes!
    So my question is:

    Is it even possible to secure methods on the same class in the .aj files as well as the .java files?

    If not what would be the best way to achieve what I want?
    Add my own methods as aspects and only use aspectj mode?

    Thanks!

  2. #2
    Join Date
    Sep 2009
    Posts
    101

    Default

    Did you enable the security aspects in your pom?

    http://forum.springsource.org/showpo...40&postcount=3

    (Look at step #2 - if you don't do that, Spring Security aspects won't be compiled into your code and the annotations won't do anything.)

  3. #3
    Join Date
    May 2009
    Posts
    15

    Default

    Thanks, I was missing that.

    Edit: That did it!!! Thanks a lot!

    Could you still tell me how you knew to do exactly that? I read all the docs, reference guides and so on. I didn't find that info anywhere.
    Last edited by muskatus; Feb 28th, 2011 at 07:01 AM.

  4. #4
    Join Date
    Sep 2009
    Posts
    101

    Default

    I don't remember. It might have been the comments in SEC-1232, or maybe some comments in these here Roo forums. I'd been following this subject for a while....

    (It was some people in these forums that teased out changes to Roo and Spring Security which made some of this work. One cool thing is you can now write your own security aspects that inject @PreAuthorize annotations on Roo-managed methods!)

  5. #5
    Join Date
    May 2009
    Posts
    15

    Default

    Quote Originally Posted by mikej View Post
    One cool thing is you can now write your own security aspects that inject @PreAuthorize annotations on Roo-managed methods!
    Yeah I've seen that. Looks nice indeed.

  6. #6
    Join Date
    Jan 2011
    Posts
    20

    Default

    @mikej and @muskatus

    It worked on tc server developer but it not work with tomcat and jetty. I don't known why?

    Could you test with mvn tomcat:run and mvn jetty:run?
    Last edited by tk1cntt; Mar 6th, 2011 at 04:37 AM.

  7. #7
    Join Date
    Sep 2009
    Posts
    101

    Default

    Sorry, it wouldn't be easy for me to test with mvn tomcat:run (I have an external directory I need on my classpath and I don't see a way to add it to the Maven Tomcat plugin configuration).

    If it helps, I use Tomcat 6 standalone and I start it up via Eclipse.

  8. #8
    Join Date
    May 2009
    Posts
    15

    Default

    Quote Originally Posted by tk1cntt View Post
    @mikej and @muskatus

    It worked on tc server developer but it not work with tomcat and jetty. I don't known why?

    Could you test with mvn tomcat:run and mvn jetty:run?
    I've only used tomcat 7 so far and it works.

  9. #9
    Join Date
    Jan 2011
    Posts
    20

    Default

    Just type

    Code:
    cd /path/to/roo
    
    mvn jetty:run
    and maven will load all plugin depend.

    Please help me test it

    Thanks so much

  10. #10
    Join Date
    Sep 2009
    Posts
    101

    Default

    It's not a plugin dependency, it's an external folder where I keep properties files I don't want to keep inside the war. The tomcat maven plugin doesn't provide a mechanism for adding external folders to the classpath so these properties files can be picked up.

    At any rate, perhaps you could test with Tomcat or Jetty standalone and troubleshoot from there.

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
  •