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 8839349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:13:12+00:00 2026-06-14T10:13:12+00:00

I would like to secure my services layer using Spring Security. As explained in

  • 0

I would like to secure my services layer using Spring Security. As explained in the documentation, I need to use a MethodSecurityInterceptor that will check if the method invocation is allowed.

To decide if a service method invocation is allowed for a given user, affecting a required role to the invoked method (using MethodSecurityMetadataSource) is not enough for me since it also depends on the parameters passed to the method. As suggested in the documentation, I can write a custom AccessDecisionVoter and access the arguments though the secured object (MethodInvocation in this case).

But, my authorization logic is different across the methods. For example, the arguments may be different between multiple methods and the authorization logic will also be different.

I see two options:

  • I can use conditional logic in the AccessDecisionVoter to determine the invoked method and the authorization logic to use, but it seems to be an ugly solution.
  • I can define one MethodSecurityInterceptor per method to secure. According to the Spring documentation, a MethodSecurityInterceptor is used to secure many methods, so it makes me thinking there is another way.

The same question exists for access decision after method invocation (using AfterInvocationProvider).

What are the alternatives?

  • 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-06-14T10:13:13+00:00Added an answer on June 14, 2026 at 10:13 am

    You can implement your own method security annotations based on Spring @PreAuthorize("") construction.

    To fetch extra information about the method(beyond method argument values) to SpEL evaluation context you can implement your own MethodSecurityExpressionHandler

    @Service
    public class MySecurityExpressionHandler extends
        DefaultMethodSecurityExpressionHandler {
    
        @Override
        public StandardEvaluationContext createEvaluationContextInternal(
            Authentication auth, MethodInvocation mi) {
    
        StandardEvaluationContext evaluationContext = super
                .createEvaluationContextInternal(auth, mi);
    
        SomeMethodInfoData methodInfoData = mi.getMethod(). ...;
    
        evaluationContext.setVariable("someData", <value computed based on method info data>);
        }
    
        return evaluationContext;
    } 
    

    and register it in your global-method-security declaration

    <security:global-method-security
            pre-post-annotations="enabled">
            <security:expression-handler
                ref="mySecurityExpressionHandler" />
        </security:global-method-security>
    

    Now you can create custom security annotations(and extra process annotation data in MySecurityExpressionHandler if required)

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @PreAuthorize("#<someData>")
    public @interface CustomSecurityAnnotation { ... }
    

    for example you can create a custom annotation to check user roles without messing with strings:

    @MyUserRoleCheck(MyAppRole.Admin)
    public void someMethod()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating some web services which I would like to secure using a
We need to design a secure web application. I would like to propose a
Would like to make anapplication in Java that will not automatically parse parameters used
i'm trying to secure some WCF services. I'd like to use IIS or the
I have a Spring application that publishes some RESTful web services using Apache CXF
I am currently using Spring Security with CAS as the authentication mechanism to secure
I'm building an Azure-hosted WCF service that I'd like to secure with ACS using
Below I explained what I need and in the answer I would like to
Would like a for loop in jquery so that: For every hover_link: show hidden
We are developing a service layer for a new system that will handle all

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.