Results 1 to 3 of 3

Thread: AuthenticationCredentialsNotFoundException with PreAuthorize hasAnyRole annotation

  1. #1
    Join Date
    Sep 2008
    Posts
    3

    Default AuthenticationCredentialsNotFoundException with PreAuthorize hasAnyRole annotation

    Gentlepeople,

    Using a PreAuthorize tag on a bean, e.g.


    @PreAuthorize("hasAnyRole('Administrator','Supervi sor')")


    I get "An Authentication object was not found in the SecurityContext" exception when not authenticated.

    Would it not make more sense to get a "Access is denied" exception which I get when invoking that method after authentication with a user with none of the required roles

    Am I missing something (obvious)?

    Thanks

    Peter

  2. #2
    Luke Taylor is offline Senior Member Acegi Security System TeamSpring Team
    Join Date
    Aug 2004
    Location
    Glasgow, Scotland
    Posts
    3,449

    Default

    Quote Originally Posted by pgp.coppens View Post

    I get "An Authentication object was not found in the SecurityContext" exception when not authenticated.
    No. The AuthenticationCredentialsNotFoundException is what drives the authentication process. You get an AccessDeniedException if you are authenticated but don't have sufficient rights.

    Note that there is a bug with the use of hasAnyRole(), which will be fixed in 3.0.1 (check Jira), but that isn't what is happening here.
    Spring - by Pivotal
    twitter @tekul

  3. #3
    Join Date
    Sep 2008
    Posts
    3

    Default

    Appreciate your quick reply. So if my manage to setup such that at least anonymous authentication is available the access denied would show up?

    (I am actually struggling configuring anonymous authentication in my env. The app is running outside a webapp. any pointers to example would be appreciated)

    Thanks

    Peter

Posting Permissions

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