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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:21:59+00:00 2026-05-25T21:21:59+00:00

In Spring 3, is there a method that accepts a comma-separated list of permissions

  • 0

In Spring 3, is there a method that accepts a comma-separated list of permissions and returns a Boolean of whether the logged in user has any of those permissions? I envision doing something like:

if(loggedInUserHasAnyOfThesePermissions("PERMISSION_READ,PERMISSION_EDIT")){
    //do stuff
}

Currently, since don’t know of any such built-in method, I’m doing this:

Set<String> permissions = new HashSet();
for (GrantedAuthority auth : SecurityContextHolder.getContext().getAuthentication().getAuthorities()) {
    permissions.add(auth.getAuthority());
}

if (permissions.contains("PERMISSION_READ") || permissions.contains("PERMISSION_EDIT")) {
    //do stuff
}

I’ve searched for hours and haven’t found a more concise and elegant way of doing this, but one must exist. Thanks for your help!

P.S. I’m already familiar with how to handle permissions in JSP like this: ( how to conditionally show jsp content to logged in users with Spring security ) But what I need now is a way to check within the controller.

  • 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-25T21:22:00+00:00Added an answer on May 25, 2026 at 9:22 pm

    I ended up coding my own class: MyUserDetails class has various methods including one that iterates over roles and permissions to see all the permissions that a user has, such as:

    for (Permission permission : role.getPermissions()) {
              permissions.add(new GrantedAuthorityImpl(permission.getName()));
            }
    

    It’s pretty ugly, but I don’t have a better way yet.

    I use it by doing something like:

    MyUser loggedInUser = myUserDAO.getByUsername(principal.getName());
    MyUserDetails loggedInUserUD = new MyUserDetails(loggedInUser);
    if (loggedInUserUD.hasAnyPermission("perm1, perm2")){
    //do stuff
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a standard library method that converts a string that has duration in
Write a method called wordCount that accepts a String as its parameter and returns
Is there a method that could tell for a string like foo bar Foo
Is there a built-in function/method that can check if a given string is a
I have a method that effectively takes a string. However, there is a very
Is there a method built in to NSString that tokenizes the string and searches
I just started playing in scala. I got a method that accepts string array
I have a method that accepts a parameter obj of type System.Object Now I
Is it possible to create a dbus method that accepts multiple arguments? I wish
Here's the situation. I have a base class which implements a method that accepts

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.