【问题标题】:JWT How should I protected endpoints for user and admin?JWT 我应该如何保护用户和管理员的端点?
【发布时间】:2020-04-07 14:19:45
【问题描述】:

我想询问关于良好 JWT 身份验证实践的问题。我需要在我的 spring 后端保护我的一半端点,只有管理员可以从我的其余 Vue api 调用它们,其余的只能从用户将登录的 vue 本机应用程序调用。我应该怎么做? 最好的问候!

【问题讨论】:

标签: spring spring-boot vue.js authentication jwt


【解决方案1】:

这可以通过在您的 userdetails 中使用 spring 安全权限来实现,因此管理员用户将拥有管理员角色,而普通用户将拥有用户角色。

然后可以根据角色保护端点

@PreAuthorize("hasRole('ROLE_ADMIN')")
public List<Foo> findAll() { ... }
...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-09
    • 2022-09-30
    • 1970-01-01
    • 2020-02-22
    • 2017-07-25
    • 1970-01-01
    相关资源
    最近更新 更多