【问题标题】:Spring security using thymeleaf with "if" condition使用带有“if”条件的百里香叶的弹簧安全性
【发布时间】:2014-05-13 16:31:32
【问题描述】:

我使用 Spring 安全性和使用 thymeleaf 的 HTML 页面。在这种情况下,我无法使用“sec:authorize”属性:

<ul class="nav nav-tabs margin15-bottom">
    <li th:each="criteriaGroup,iterGroups : ${aGroupList}"
        th:class="${iterGroups.index == 0}? 'active'">
        <a th:href="'#' + ${criteriaGroup.id}" data-toggle="tab"
           th:text="${criteriaGroup.groupName}"></a>
    </li>
</ul>

现在我想添加一个 spring 安全属性,例如:如果我有这个特定条件,我需要一个授权 (sec:authorize="hasRole('Criteria')") 虽然我不会看到与这个条件相对应的选项卡:

<ul class="nav nav-tabs margin15-bottom">
    <li th:each="aGroup,iterGroups : ${aGroupList}" th:class="${iterGroups.index == 0}? 'active'"
        th:sec:authorize="$({criteriaGroup.id =='criteriaA'} || ${criteriaGroup.id =='criteriaB'}) ? 'hasRole('Criteria')'">
        <a th:href="'#' + ${criteriaGroup.id}" data-toggle="tab"
           th:text="${criteriaGroup.groupName}"></a>
    </li>
</ul>

但是当我这样做时,出现以下错误:

org.thymeleaf.exceptions.TemplateProcessingException:   Error processing template: dialect prefix "th" is set as non-lenient but attribute "th:sec:authorize" has not been removed during process

如何避免?

【问题讨论】:

    标签: html spring-security thymeleaf


    【解决方案1】:

    去掉 sec:authorize 前面的 th:

    Spring Security 3 集成模块是一种 Thymeleaf 方言。更多信息可以在here找到。

    【讨论】:

      【解决方案2】:

      也许您想使用 #authentication 对象而不是 sec 方言。

      来自文档:

      <div th:text="${#authentication.name}">
          The value of the "name" property of the authentication object should appear here.
      </div>
      

      【讨论】:

      • 默认情况下使用#authentication 表达式似乎不会检查null。
      猜你喜欢
      • 2016-09-17
      • 2018-04-02
      • 2021-12-11
      • 1970-01-01
      • 2018-11-20
      • 2018-04-03
      • 2018-11-24
      • 2017-07-20
      相关资源
      最近更新 更多