使用Thymeleaf检查特定的Stormpath组成员身份

Rob*_*ter 3 thymeleaf spring-boot stormpath

我正在尝试确定登录用户是否是特定Stormpath组的成员.

以下工作,但它基于错误的属性(groups.href)

<div th:text="${#lists.contains(account.groups.href, 'https://api.stormpath.com/v1/accounts/eXaMpLe12345/groups')}" />
Run Code Online (Sandbox Code Playgroud)

而我试图找到(伪代码) 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>
Run Code Online (Sandbox Code Playgroud)

afi*_*erd 5

通常,您可能希望让服务器端(控制器)执行繁重的工作.

所以,在控制器中,你可能有这样的东西:

@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";
}
Run Code Online (Sandbox Code Playgroud)

然后,在您的百里叶视图中,您可以:

    <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>
Run Code Online (Sandbox Code Playgroud)

结果:

在此输入图像描述

完全披露:我是Stormapth的Java Developer Evangelist