Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 使用Thymeleaf检查特定的Stormpath组成员资格_Spring Boot_Thymeleaf_Stormpath - Fatal编程技术网

Spring boot 使用Thymeleaf检查特定的Stormpath组成员资格

Spring boot 使用Thymeleaf检查特定的Stormpath组成员资格,spring-boot,thymeleaf,stormpath,Spring Boot,Thymeleaf,Stormpath,我正在尝试确定登录用户是否是特定Stormpath组的成员 以下操作有效,但基于错误的属性(groups.href) 看起来推荐的方法是在将帐户组发送到Thymeleaf进行渲染之前,从控制器中确定帐户组访问权限。基本上,您添加了一个与正在检查的内容相关的模型属性,并在填充该属性的控制器中执行该检查。然后在模板中验证属性是否按预期设置 -阅读名为“Spring Security Access Control By Group Membership”的部分通常,您希望让服务器端(控制器)来完成繁重

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

以下操作有效,但基于错误的属性(groups.href)


看起来推荐的方法是在将帐户组发送到Thymeleaf进行渲染之前,从控制器中确定帐户组访问权限。基本上,您添加了一个与正在检查的内容相关的模型属性,并在填充该属性的控制器中执行该检查。然后在模板中验证属性是否按预期设置


-阅读名为“Spring Security Access Control By Group Membership”的部分通常,您希望让服务器端(控制器)来完成繁重的工作

因此,在控制器中,您可能有如下内容:

@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视图中,您可以:

    <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开发人员布道者

@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";
}
    <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>