Results 1 to 3 of 3

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

  1. #1

    Default 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. #2
    Join Date
    Jun 2007
    Location
    Minsk, Belarus
    Posts
    215

    Default

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

  3. #3

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •