【问题标题】:Spring security access roles inside a method方法中的 Spring 安全访问角色
【发布时间】:2018-07-10 10:36:52
【问题描述】:

在 Spring 安全性中,是否可以在方法中获取用户可能与他们的令牌相关联的角色和属性?

@PreAuthorize("hasAuthority(T(ROLES.Admin)")
@Timed
public ResponseEntity<base> save(@RequestBody body) throws URISyntaxException {
    // here i want to get all the data associated whit this user ie. jwt token
    // roles etc .. as i need to pass this on
}

我看到你可以得到本金

【问题讨论】:

    标签: spring spring-security


    【解决方案1】:

    是的,你可以通过Principal获得它。像这样:

    User user = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    user.getAuthorities();
    

    【讨论】:

      猜你喜欢
      • 2011-01-01
      • 2020-02-21
      • 2013-12-15
      • 2014-07-23
      • 2012-04-08
      • 1970-01-01
      • 1970-01-01
      • 2017-11-25
      • 1970-01-01
      相关资源
      最近更新 更多