当前位置: 首页 > 知识库问答 >
问题:

Thymeleaf Sec:Authorize您可以合并角色或不同属性授权吗?

丁承德
2023-03-14

我正在使用Thymeleaf、Spring-boot和java。我为导航栏设置了li项,并希望为其中一个li项设置访问权限,这样,如果LoggedUser.client.PolicyType==特定访问权限,或者它们具有admin角色,则链接会显示以便它们可以访问该页面。我试过th:authorize,sec:authorize,th:if...都没用。你知道怎么把它搞定吗?

<li th:authorize="${loggedUser.client.policyType == 'Access – NO AMS'} or hasRole('ROLE_ADMIN')" th:classappend="${currentPage == 'directBind'} ? 'active'"><a th:href="@{/directBind}"><img class="left"  height="60%" width="auto" src="/images/mail1.png"/> Direct Bind</a></li>

共有1个答案

皇甫树
2023-03-14

你尝试过以下方法吗?

<li th:if="${#authorization.expression('hasRole(''ROLE_ADMIN'') or ${loggedUser.client.policyType == 'Access – NO AMS'}')}">
   <a th:href="@{/directBind}"><img class="left"  height="60%" width="auto" src="/images/mail1.png"/> Direct Bind</a>
</li >

您需要在.pom上添加以下依赖项,才能使用#authorization。可以使用以下代码添加依赖项。

<dependency>
   <groupId>org.thymeleaf.extras</groupId>
   <artifactId>thymeleaf-extras-springsecurity4</artifactId>
</dependency>
 类似资料:
  • Using a delegation key The collaborator can now push to the repository using Docker Content Trust. Docker will automatically choose and pick the right key for the targets/release role. Edit the file o

  • Importing a delegation certificate As a repository owner: Add the delegation key to the repository using the targets/releases path, as this is what Docker searches for when signing an image (first tar

  • Generating a delegation key Make sure you’re using OpenSSL 1.0.2+, otherwise the keys will be signed with SHA1, which Notary will refuse to import (invalid SHA1 signature algorithm): ❯ brew install op

  • 我在API上使用Vertx框架对JWT令牌进行授权。在用户被授权并且令牌被解密之后,我想要访问令牌的内容,尤其是令牌中的“userId”字段。 最初,我是用作为作为以下内容来访问它的:

  • 我正在试图理解一些Spring Security代码。我也是Spring Security的新手,我想我在这里遗漏了一些基本的东西。 谢谢,雷。

  • Delegation roles Delegation roles allows assigning signing privileges to other repository collaborators. This is particularly interesting in organizations that have multiple people working on the same