【问题标题】:spring security intercept url pattern is not working when url contains #当 url 包含 # 时,spring security 拦截 url 模式不起作用
【发布时间】:2016-04-11 11:19:09
【问题描述】:

我的网址是

//localhost:8080/server/#/view/3

//localhost:8080/server/#/create

(默认情况下,# 出现在 url 中,因为我使用的是来自 angularjs 的路由)

我想为下面的 url 分配一些权限,所以我使用了下面的 URL 模式

security:intercept-url pattern="/#/create" access="admin"  

security:intercept-url pattern="/#/view/**" access="admin" 

当尝试以不同于管理员(例如用户)的角色访问 url //localhost:8080/server/#/create 时,我仍然能够访问此页面,而当我相应地更改 url 模式时,任何像 //localhost:8080/server/abc/create 这样的 URL 都显示为 Access Denied

URL 中的# 会被忽略吗?有没有其他方法可以解决这个问题?

【问题讨论】:

  • 符合预期以及 http 的工作原理。 # 之后的所有内容都不会提交给服务器。 # 基本上是一个锚点,仅适用于客户端。这就是网络的运作方式。

标签: xml spring url spring-boot


【解决方案1】:

有两种方法可以做到这一点,在前端(angularjs)或后端(spring security)实现安全层。

对于 Angular js,您可以使用插件在成功验证后通过检查后端提供的用户权限来为每个路由提供安全性。这样的插件可以很容易地定制,比如这个博客解释的 angular-role-base-auth

或者这里是另一个

angular-permission

但我建议仍然在后端实现安全层,因为 javascript 代码很容易通过浏览器控制台被黑客入侵。在 Spring Security 中,您可以对这些页面调用的 Web 服务添加权限检查并返回拒绝访问。然后在前端,一旦遇到拒绝访问响应,将页面重定向到显示禁止消息模板的自定义页面。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-11
    • 2012-08-15
    • 2013-06-04
    • 2017-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-27
    相关资源
    最近更新 更多