Spring boot 第二节:在Spring引导应用程序中使用Thymeleaf授权未按预期工作

Spring boot 第二节:在Spring引导应用程序中使用Thymeleaf授权未按预期工作,spring-boot,spring-security,thymeleaf,Spring Boot,Spring Security,Thymeleaf,我正在尝试向表中的新行添加链接,此链接应仅可由管理员角色访问 弹簧靴:1.4.0.0版本 &thymeleaf-extras-springsecurity4.version:2.1.2.RELEASE <sec:authorize access="hasRole('ROLE_ADMIN')"> <tr> <td>...</td> <td>...</td> </tr>

我正在尝试向表中的新行添加链接,此链接应仅可由管理员角色访问

弹簧靴:1.4.0.0版本 &thymeleaf-extras-springsecurity4.version:2.1.2.RELEASE

 <sec:authorize access="hasRole('ROLE_ADMIN')">
    <tr>
        <td>...</td>
        <td>...</td>
    </tr>
 </sec:authorize>
但是使用此代码,即使没有管理员权限的用户也可以查看表中的行

有人能帮我找到前进的路吗

它应该能起作用。。 我很确定您也在向该用户添加角色_ADMIN。 尝试调试呈现jsp的控制器(在使用标记的位置),然后从身份验证中获取principle对象

  authentication.getPrincipal()

并遍历该对象,直到您找不到授权为止,检查用户是否具有角色\u ADMIN

是否确实要在(AuthenticationProvider.authenticate(…)的实现过程中为用户添加正确的角色?是的,我确定您可以尝试删除对
.access()
的调用并使用
hasRole(“ADMIN”)
方法。您也不应该再需要
角色前缀了。他需要显示/隐藏html元素,甚至删除访问权限()他仍然有同样的必要性。这似乎是多个依赖项之间的版本冲突,这就是为什么它不起作用的原因。现在可以正常工作了,谢谢。
http.authorizeRequests()
        .antMatchers("/api/systemuser/*").access("hasRole('ROLE_ADMIN')")
        //.antMatchers("/*").access("hasRole('ROLE_ADMIN')")
        //.antMatchers("/ui/report/win").access("hasRole('ROLE_USER')")
        //.antMatchers("/userError").access("hasRole('ROLE_ERROR')")
        .antMatchers("/swagger*/**", "/about", "/").authenticated()
        .anyRequest().authenticated()
        .and()
        .httpBasic()
        .authenticationEntryPoint(authenticationEntryPoint)
;
http.csrf().disable();
  authentication.getPrincipal()