我在我的Spring Boot
MVC
应用程序中扩展了MVC
。我还创建了以下方法
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/")
.permitAll()
.antMatchers("/login")
.permitAll()
.antMatchers("/registration")
.permitAll()
.antMatchers("/dashboard")
.hasAuthority("ADMIN")
.anyRequest()
.authenticated()
.and()
.csrf()
.disable()
.formLogin()
.loginPage("/login")
.failureUrl("/login?error=true")
.defaultSuccessUrl("/dashboard")
.usernameParameter("email")
.passwordParameter("password")
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/home")
.and()
.exceptionHandling()
.accessDeniedPage("/access-denied");
}
用户登录后,我需要一些信息,如用户名,角色,电子邮件等,在我的/dashboard
控制器。我怎样才能做到这一点?
我试着在谷歌上搜索,但没有找到任何有关这方面的具体信息。
发布于 2017-12-16 14:02:38
嗯,你没有什么选择:
SecurityContextHolder.getContext().getAuthentication()
(通过这种方式,您可以在整个应用程序中获取凭证)Principle
作为参数来获取信息。Authentication
作为参数。请注意,您必须有某种机制来对用户进行身份验证(例如,使用活动目录的openid),并让您的服务器使用它。
有关更多信息,请参见http://www.baeldung.com/get-user-in-spring-security
https://stackoverflow.com/questions/47846269
复制相似问题