Skip to content
This repository has been archived by the owner on May 31, 2022. It is now read-only.

Can not assign new Authority to current access token #1125

Open
pervez8ktt opened this issue Jul 31, 2017 · 2 comments
Open

Can not assign new Authority to current access token #1125

pervez8ktt opened this issue Jul 31, 2017 · 2 comments

Comments

@pervez8ktt
Copy link

pervez8ktt commented Jul 31, 2017

I have a code re assign the authority to existing user

                        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
		        List<GrantedAuthority> updatedAuthorities = new ArrayList<>(auth.getAuthorities());
		        updatedAuthorities.add(new SimpleGrantedAuthority("ROLE_NEW_USER")); 

		        Authentication newAuth = new UsernamePasswordAuthenticationToken(auth.getPrincipal(), auth.getCredentials(), updatedAuthorities);

		        SecurityContextHolder.getContext().setAuthentication(newAuth);

It is working fine with spring security.
But in spring security oauth2 it is not working

What I need is I want to add new role on existing access_token.

@dduliak
Copy link

dduliak commented Nov 10, 2017

you need to update OAuth2AccessToken also,

tokenStore.storeAccessToken(oAuth2AccessToken, newAuth);

@javaProgrammer44
Copy link

I followed the answer of @DenDulyak and it's worked

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

4 participants