【问题标题】:freemarker and spring security taglib looking fo a list of functionsfreemarker 和 spring security taglib 寻找函数列表
【发布时间】:2015-01-26 20:14:03
【问题描述】:

嗨,我正在处理一个 apring mvc 项目,并且我正在使用 freemarker 作为我的模板引擎,我像这样在我的页面中添加了 spring secuirty

<#assign security=JspTaglibs["http://www.springframework.org/security/tags"] />

我把这个标签放在我希望对特定用户可见的内容中

<@security.authorize  ifAnyGranted="ROLE_ADMIN">
  <div><h1>Hello ADMIN</h1></div>
</@security.authorize>

<@security.authorize  ifAnyGranted="ROLE_USER">
  <div><h1>Hello USER</h1></div>
</@security.authorize>

我的问题是我在哪里可以找到像ifAnyGranted 这样的函数列表除了这个之外还有其他函数吗?这个函数是用于freemarker 或spring 安全标签库的吗?因为我正在查看 spring security taglib 文档,但我找不到这个函数,他们使用像 access="hasRole('guest') 这样的函数,如果我在我的页面中尝试它不起作用,我在哪里可以找到像 ifAnyGranted 这样的函数或任何其他类似的函数是我正在使用的这个库的名称,我尝试在 google freemarker 和 spring security 中搜索,但找不到太多信息

【问题讨论】:

标签: java spring-mvc spring-security template-engine freemarker


【解决方案1】:

如果我对文档的解释正确,某些函数/属性没有列出,因为它们是 Spring Security 2.0 的遗留选项,不鼓励使用它们。您可以将它们写为安全表达式。

老办法:

<@security.authorize  ifAnyGranted="ROLE_USER,ROLE_ADMIN">

新方法:

<@security.authorize  access="hasRole('ROLE_USER') or hasRole('ROLE_ADMIN')">

如果您仍想使用旧方式,authz package 为您提供可用属性。

【讨论】:

  • 当我尝试使用 hasRole 时,它​​给了我这个错误`词法错误:在 "\"hasRole(\'ROLE_ADMIN\')>\r\n

    之后遇到 管理员您好

    \r\n @security.authorize>\r\n \r\n@layout.myLayout>".]`
  • @stackUser2000 看起来像 freemarker 语法错误。缺少"
猜你喜欢
  • 1970-01-01
  • 2010-12-15
  • 1970-01-01
  • 2012-02-12
  • 1970-01-01
  • 2019-10-19
  • 2015-07-29
  • 2013-10-19
  • 2011-11-22
相关资源
最近更新 更多