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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:01:39+00:00 2026-05-26T15:01:39+00:00

I am using spring mvc3 to build a user-manager system. This system conain the

  • 0

I am using spring mvc3 to build a user-manager system.

This system conain the following models:

Department
User

And the Departments have the hierarchic structure,for example:

Dep1
  SubDep1
  SubDep2
    Sub_sub_dep1
    xxxx

One can add/update/delete departments/users if he is authenciationed,but he can only do these operation within his department and the sub-departmens.

For example,there are three departments(with there users):

Dep01(user1:{id:1}}
  Dep0101(user2:{id:2}
  Dep0102(user3:{id:3}
    Dep010201(user4:{id:4}

So user1 can do the /add/upate/delete all the users(user1,user2,user3,user4)

While user3 can only do the operation for user(user3,user4).

I can control that the user3 can not see the user1 and user2 in the department/list page.

But how about if he enter the url like this:

department/update/1

This has to be avoided since the user1(whose id is 1) does not belong to Dep0102 or Dep010201.

How to controll this?

  • 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-26T15:01:40+00:00Added an answer on May 26, 2026 at 3:01 pm

    One option is to create a custom Spring Security PermissionEvaluator and implement your custom checks in the hasPermission(Authentication authentication, Object targetDomainObject, Object permission) method.

    The signature of the method to protect ends up looking like this:

    @PreAuthorize("hasRole('ROLE_USER') and hasPermission(#_dept, 'deptAndSubs')")
    public String methodToProtect(String _dept)throws Exception    {
            <custom code>;
        }
    

    The first argument to the hasPermission expression is the department that the user wants to modify and the second is the permission. For us the deptAndSubs permission indicates that the user can execute the method only if the department being modified is equal to the users assigned department or any of the sub departments of that department (other permissions are ‘deptOnly’ and ‘subsOnly’).

    In our application we have a custom Spring Security UserDetails object that includes the user department code so we can get the logged in user’s department directly from the Authentication object that Spring passes into the method. Here’s what the custom evaluator finally ends up looking like:

        public class CustomPermissionEvaluator implements PermissionEvaluator {
               @Override
               public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) {
                AppUser appUser = (AppUser)authentication.getPrincipal();
                if(permission instanceof String){
                    if("deptAndSubs".equals(permission)){
                        return isTargetDeptInUserDeptTree((String)targetDomainObject, appUser.getDeptCode());
                    }else if(.... other permission checks){}
                }
                return false;
            }
    

    The method isTargetDeptInUserDeptTree is custom code to extract the user’s department tree and verify that the target department is in it.

    Finally you have to set up your xml configuration:

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

    Good luck!

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

Sidebar

Related Questions

I am using spring mvc 3.0 to build an web application. User can get
Using Spring 2.5 tag library, I have an Integer value in a command form
I'm using Spring.net with NHiberante (HibernateTemplate) to implement my DAO's. I also have some
I have seen this question , and using its method throws up an error
I have a webapp which is built using spring 3 and tiles 2 (not
What is wrong with this configuration? I'm using Spring 3 and Hibernate 3.6 and
I have an MVC3 application using NHibernate. I've created my own membership and role
I am trying to build a sample for myself using MVC3, Razor view engine
I am using MVC3 and I want to have LogIn form and Register form
I'm using Spring MVC 3.0 and can't quite see all the parts to this

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.