【问题标题】:Spring Boot - Angularjs $stateProvider with SecuritySpring Boot - 具有安全性的 Angularjs $stateProvider
【发布时间】:2017-11-10 05:12:01
【问题描述】:

如您所知,我们可以使用 Spring Security 为特定 URL 设置权限。例如

.antmatchers("/assets/**").permitall ()

我的问题是: 我在项目中使用 $stateProvider 和 AngularJS。

所以URL路径Localhost/#/homelocalhost/#/userList

例如,使用Security,我想以"ADMIN"权限登录/#/userList

.antmatchers("/#/userList").hasauthority("ADMIN")

我想这是不可能的。我们如何解决这个问题?

【问题讨论】:

  • 您必须对 Angular 进行用户身份验证和授权,因为这些带有 # 的 URL 是 Angular URL,而不是 Java Spring。您的 java spring 应用程序可以识别 # 之前的部分,而 # 之后的任何内容都与角度相关。
  • 你认为locationprovider html5mode是什么?
  • 看看这里(我在我的应用程序上使用过):stefanoscerra.it/permission-based-auth-system-in-angularjs

标签: angularjs spring spring-boot spring-security


【解决方案1】:

虽然他是一个旧线程,但仍在回复,所以任何谷歌人都会找到这个答案 - 你可以通过这样声明来实现

 .antMatchers("/**/userList").access("hasRole('ADMIN')")

这对我有用。

【讨论】:

    【解决方案2】:

    你不能这样做,因为锚是一个客户端概念,见RFC 1630

    对文档特定部分的引用可能包括 片段标识符,看起来像

       http://www.myu.edu/org/admin/people#andy
    

    在这种情况下,字符串“#andy”不会发送到服务器,而是 由客户保留并在整个对象已被使用时使用 已取回。

    【讨论】:

      猜你喜欢
      • 2014-11-21
      • 2015-09-01
      • 2018-04-28
      • 1970-01-01
      • 2018-02-15
      • 1970-01-01
      • 2021-11-26
      • 1970-01-01
      • 2021-07-14
      相关资源
      最近更新 更多