我正在尝试在Freemarker模板中检查用户角色。我试过这个:
<#assign security=JspTaglibs["http://www.springframework.org/security/tags"] />
并通过以下方式检查角色:
<@security.authorize access="hasRole('ADMIN')">
/*DO SOME STUFF*/
</@security.authorize>
但我得到一个错误:
freemarker.template.TemplateModelException: Error while looking for TLD file for "http://www.springframework.org/security/tags"; see cause exception.
Interned中有很多解决方案,我尝试了一切:在pom.xml中添加了依赖项,尝试将链接更改为taglibs等。
但它没有用,所以我怎么能解决这个问题,或者还有另一种检查用户角色的方法?
最后找到解决方案。
您应该使用access="hasAnyAuthority('ADMIN')
或将您的角色从“ADMIN”更改为“ROLE_ADMIN”coz access="hasRole"
仅适用于名为ROLE的角色