Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7022773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:37:30+00:00 2026-05-27T23:37:30+00:00

In my spring config file I have <global-method-security pre-post-annotations=enabled/> In my spring @Controller I

  • 0

In my spring config file I have <global-method-security pre-post-annotations="enabled"/>

In my spring @Controller I have a @RequestMapping that has an @PreAuthorize on it as follows:

@PreAuthorize("true == false")
@RequestMapping(value="/image", method=RequestMethod.GET )
@ResponseBody
public ResponseEntity<byte[]> getImage(
        @RequestParam(value="imageSet", required=false) Long imageSetKey
        , @RequestParam(required=false, defaultValue="70") Integer size
        , @RequestParam(required=false) Unit unit
        , @RequestHeader( value="if-none-match", required=false ) String etag 
)
{
    // use the latest and greatest for the unit if they specify the unit, otherwise use the imageSetKey they pass in.
    if ( unit != null )
    {
        return getUnitImage( unit, size, etag );
    }
    // more code to do other stuff
}

Now this @PreAuthorize is evaluated and working correctly. If I put a PreAuthorize on the getUnitImage method, then it is not evaluated and I get into the method just fine. Here is the method on which the @PreAuthorize is NOT evaluated.

@PreAuthorize("true == false")
public ResponseEntity<byte[]> getUnitImage( Unit unit, int size, String etag )
{
    // do stuff, I get into breakpoints here.
}

Thoughts on why the PreAuthorize would be invoked on one method with the RequestMapping, but not on others in the same class?

Spring 3.0.5, Spring Security 3.0.3

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:37:31+00:00Added an answer on May 27, 2026 at 11:37 pm

    This is caused by the way Spring AOP & CGLIB work. Specifically, a proxy class is created that extends your actual class, and that is what provides the implementation of the @PreAuthorize behavior. When you call a method from the same class, it doesn’t go through the proxied class, and thus the desired behavior isn’t executed.

    One way to deal with this is to use AspectJ instead, by adding mode=”aspectj” to your global-method-security element in your Spring config.

    This also happens with @Transactional, and another question specifically about @Transactional has some more details regarding this issue:

    Spring @Transaction method call by the method within the same class, does not work?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my applications web.config file I have a connection string stored. I encrypted it
I have this Spring config: <bean id=boo class=com.x.TheClass/> The class TheClass implements TheInterface .
Spring security has a nice feature, it remembers the url of request resource and
I have a function that searches for a string inside a text file. I
I'm trying to configure an instance of JBossCache using a Spring config file (for
I have a web app that uses Spring's Log4jConfigurer class to initialize my Log4J
I'm trying to reference another object I've defined in a Spring config file from
In my global.asax.vb file, I have code to re-write the URL if there is
i have bean that contain method [void return] and want access to this bean
Here is my situation: I have my mvc-config.xml file for my web service set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.