spring-boot - 使用 Thymeleaf 检查特定的 Stormpath 组成员

标签 spring-boot thymeleaf stormpath

我正在尝试确定登录用户是否是特定 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>

结果:

enter image description here

全面披露:我是 Stormapth 的 Java 开发布道师

关于spring-boot - 使用 Thymeleaf 检查特定的 Stormpath 组成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38885992/

相关文章:

node.js - (Jade & Stormpath) 仅在特定用户访问页面时显示某些 HTML 元素

node.js - 我可以自定义 Stormpath 登录屏幕的外观吗?

java - 在 Spock 集成测试中模拟 JPA 存储库

java - thymeleaf 的可读性

java - Spring Boot AOP 不适用于 AfterThrow

java - 当我尝试保存数据时 Ajax 不工作

spring-mvc - 如何在 Thymeleaf 中使用 "map.get(key)"- Broadleaf Ecom

angular - 如何在 ionic 2 和 Angular 2 上使用 http post 方法?

java - Avro - java.io.IOException : Not a data file

java - 如何在不使用 XML 文件的情况下为一个类创建多个依赖 bean?