Announcement Announcement Module
Collapse
No announcement yet.
How can we add an authority to GrantedAuthority[] at run time? Page Title Module
Move Remove Collapse
This topic is closed
X
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can we add an authority to GrantedAuthority[] at run time?

    Hi, I am using ACEGI security framework of Spring. Now I am getting all the roles from the database and setting it into the ACEGI user object when the user logs in.I need to add new roles to GrantedAuthority[] array at run time after the user logs in. Is it possible to add/remove roles from GrantedAuthority[] array at run time? I am getting stackOverflowerror while trying to add a new authority. Please help.

  • #2
    How you try to add GrantedAuthority?
    StackOverflowError means that there is recursion in method invocation.

    Comment


    • #3
      Maybe this can help you:
      Code:
      GrantedAuthorityImpl authority	= new GrantedAuthorityImpl("ROLE_NEWROLE");
      SecurityContextHolder.getContext().setAuthentication(
      	new UsernamePasswordAuthenticationToken(
      		SecurityContextHolder.getContext().getAuthentication().getPrincipal(),
      		SecurityContextHolder.getContext().getAuthentication().getCredentials(),
      		new GrantedAuthority[]{authority})
      	);
      This code change the granted Authority dinamicaly, so you can get all the authorities that the principal has and Create a new GrantedAuthority array an put your new(s) authoritie(s) in this array

      Comment

      Working...
      X