我正在尝试确定登录用户是否是特定 Stormpath 组的成员。
以下有效,但它基于错误的属性 (groups.href)
<div th:text="${#lists.contains(account.groups.href, 'https://api.stormpath.com/v1/accounts/eXaMpLe12345/groups')}" />
而我正在尝试查找(伪代码)groups.isMemberOf('https://api.stormpath.com/v1/accounts/mYgRrOuP1234/groups')
我知道如何遍历组并打印出它们的所有数据,我可以看到我试图找到的组的 href,但我不知道如何通过它的 href 访问它。
<div th:if="${account.groups != null}">
<ul>
<li th:each="group : ${account.groups}" th:text="${group.href}">group details...</li>
</ul>
</div>
最佳答案
通常,您希望让服务器端( Controller )完成繁重的工作。
所以,在 Controller 中,你可能有这样的东西:
@RequestMapping("/")
public String home(HttpServletRequest request, Model model) {
Account account = AccountResolver.INSTANCE.getAccount(request);
Group group = client.getResource("https://api.stormpath.com/v1/groups/qjWFpHyC5q6NdakGFCfrb", Group.class);
if (account != null) {
model.addAttribute("account", account);
model.addAttribute("group", group);
model.addAttribute("isMemberOfGroup", account.isMemberOfGroup(group.getHref()));
}
return "hello";
}
然后,在您的 thymeleaf View 中,您可以:
<div th:if="${account}">
<h4 th:if="${isMemberOfGroup}" th:text="${account.fullName} + ' is a member of the ' + ${group.name} + ' group.'"></h4>
<h4 th:text="'Account Store: ' + ${account.Directory.Name}"></h4>
<h4 th:text="'Provider: ' + ${account.ProviderData.ProviderId}"></h4>
</div>
结果:
全面披露:我是 Stormapth 的 Java 开发布道师
关于spring-boot - 使用 Thymeleaf 检查特定的 Stormpath 组成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38885992/