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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:59:34+00:00 2026-05-31T17:59:34+00:00

I am new to Spring Security. I have been working on creating a custom

  • 0

I am new to Spring Security. I have been working on creating a custom voter that will decide whether to grant permission or not based on the value of an attribute of the object. That is, if object instance A has attribute X with value i, user with ROLE_MGR has access. If object instance B has value j in the X attribute, then ROLE_MGR does not have access. is it possible to do that and if so, what do I need to do? if this is not possible we may decide not to use Spring Security.

  • 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-31T17:59:35+00:00Added an answer on May 31, 2026 at 5:59 pm

    I figured it out. I need to use a custom permission evaluator. The snippets from my code are provided below for anyone that might be trying to do something similar:

    security.xml

    <security:global-method-security
        pre-post-annotations="enabled">
        <security:expression-handler ref="expressionHandler" />
    </security:global-method-security>
    
    <bean id="expressionHandler"
        class="org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler">
        <property name="permissionEvaluator">
            <bean id="permissionEvaluator"
                class="org.krams.tutorial.infrastructure.SomePermissionsEvaluator" />
        </property>
    </bean>
    

    Service Interface
    @PostFilter(“hasPermission(filterObject, ‘READ’)”)
    public List getAll();

    Custom Permissions Evaluator

    @Override
    public boolean hasPermission(Authentication authorities,
            Object targetDomainObject, Object permission) {
    
        boolean Decision = false;
        System.out.println("Initial Decision: " + Decision);
    
        Date cutoffDate = null;
        try {
            cutoffDate = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH)
                    .parse("January 1, 2012");
            System.out.println("Cutoff Date: " + cutoffDate.toString());
        } catch (ParseException e) {
            e.printStackTrace();
        }
    
        System.out.println("Domain Object Date: "
                + Post.class.cast(targetDomainObject).getDate());
    
        if (Post.class.cast(targetDomainObject).getDate().before(cutoffDate)) {
            Decision = false;
            System.out.println("In before");
        } else {
            Decision = true;
            System.out.println("In after");
        }
        System.out.println("Final Decision: " + Decision);
        System.out.println("--------");
        return Decision;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am relatively new to the Spring Framework and Spring security. I have used
I'm new to Spring Security. How do I add an event listener which will
I'm trying to work out whether values that have been hashed (using the code
I currently running into trouble with spring security, I have been following the two
I am new to Spring Security and have configured Spring Security in my Spring
I am new to Spring MVC. But I had certain experience in working with
I'm brand spanking new at Spring and have gotten a majority of the knowledge
I'm pretty new to the Spring Framework, I've been playing around with it and
I am new to working with Spring on regular basis so I had a
I've been struggling with Spring Security LDAP for a while now, and just when

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.