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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:47:59+00:00 2026-06-05T08:47:59+00:00

Taking the suggestion provided here , I’ve implemented my own RoleVoter classes that extends

  • 0

Taking the suggestion provided here, I’ve implemented my own RoleVoter classes that extends RoleVoter and the additional check I need to add is that the User, Role, and Organization all line up based on the Organization I have stored in the session.

I have the following UserRole class:

class UserRole implements Serializable {
  User user
  Role role
  Organization organization
  ....
}

And this is my OrganizationRoleVoter class:

class OrganizationRoleVoter extends RoleVoter {

  @Override
  public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) {

    int result = ACCESS_ABSTAIN
    Collection<? extends GrantedAuthority> authorities = extractAuthorities(authentication)

    attributes.each {ConfigAttribute attribute ->
      if (this.supports(attribute)) {
        result = ACCESS_DENIED

        authorities.each {GrantedAuthority authority ->
          //TODO this should also check the chosen organization
          if (attribute.attribute.equals(authority.authority)) {
            return ACCESS_GRANTED
          }
        }
      }
    }
    return result
  }

  Collection<? extends GrantedAuthority> extractAuthorities(Authentication authentication) {
    return authentication.getAuthorities();
  }

}

As you can see in my TODO, this is where I need to also say “is the authority that is being granted here also in line with the organization that I’ve placed in the session. Really at a loss on how to achieve 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-06-05T08:48:01+00:00Added an answer on June 5, 2026 at 8:48 am

    Here is how I’ve solved it thus far. This seems to work but I’m always open for improvements:

    class OrganizationRoleVoter extends RoleVoter {
    
      @Override
      public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) {
    
        int result = ACCESS_ABSTAIN
        Collection<? extends GrantedAuthority> authorities = extractAuthorities(authentication)
        GrailsWebRequest request = RequestContextHolder.currentRequestAttributes()
        Organization selectedOrganization = (Organization) request.session.getAttribute("selectedOrganizationSession")
    
        attributes.each {ConfigAttribute attribute ->
          if (this.supports(attribute)) {
            result = ACCESS_DENIED
            for (GrantedAuthority authority : authorities) {
              if (attribute.attribute.equals(authority.authority)) {
                def user = User.findByUsername(authentication.name)
                def role = Role.findByAuthority(authority.authority)
                if (UserRole.findByUserAndOrganizationAndRole(user, selectedOrganization, role)) {
                  result = ACCESS_GRANTED
                  break
                }
              }
            }
          }
        }
        return result
      }
    
      Collection<? extends GrantedAuthority> extractAuthorities(Authentication authentication) {
        return authentication.getAuthorities();
      }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a suggestion about a scenario. E.g. if a student is taking assessment
Taking a look at my question HERE , I now want to return the
After taking a look at this SO question and doing my own research, it
Edit: Taking dennmat's suggestion into consideration, I have managed to simplify my image acquiring
Update Boilerpipe appears to work really well, but I realized that I don't need
Here's the problem I'm having, I've got a set of logs that can grow
Taking the following code, Resharper tells me that voicesSoFar and voicesNeededMaximum cause access to
I'm building a jQuery plugin that uses CSS styles to add colors and margins
edit 2 : Taking the hint that de Bruijn indices might be easier to
I have a simple photo taking application that has the following design: [Consider the

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.