6
在Spring MVC和Spring Security的Web应用程序中。Spring Security:手动设置setUserPrincipal
有没有办法手动设置UserPrincipal?
我需要通过我的web应用程序的管理员部分切换到另一个用户。在我的控制器中,是否可以在请求中设置UserPrincipal?连接就好像我是别人一样。
就像是:request.setUserPrincipal()的getName()
您可能需要考虑使用Spring内置的SwitchUser过滤器。看到第二个答案在这里:http://stackoverflow.com/questions/2563220/how-to-change-granted-role-temporarily-to-achieve-view-the-site-as-someone-els或相关的JavaDocs在这里:http://static.springsource.org/spring-security/site/docs/3.0.x/apidocs/org/springframework/security/web/authentication/switchuser/SwitchUserFilter.html – BobG