如何在org.springframework.security.core.Authentication对象值中更改用户名

如何在org.springframework.security.core.Authentication对象值中更改用户名,spring,authentication,spring-security,Spring,Authentication,Spring Security,我想在org.springframework.security.core.Authentication对象中设置用户名,该对象是从authenticationManager(即从authenticationManager.authenticate()获得的)。我想将用户名改为大写或小写。可能吗 我在身份验证对象中看不到任何设置器。请帮帮我。也许是这样的: UsernamePasswordAuthenticationToken authentication = new UsernamePasswo

我想在org.springframework.security.core.Authentication对象中设置用户名,该对象是从authenticationManager(即从authenticationManager.authenticate()获得的)。我想将用户名改为大写或小写。可能吗


我在身份验证对象中看不到任何设置器。请帮帮我。

也许是这样的:

UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken("whatever username you want", null);
SecurityContextHolder.getContext().setAuthentication(authentication);

你能分享你的webSecurityConfig代码,让你的实现更清晰吗!!!