【发布时间】:2016-10-26 02:20:14
【问题描述】:
我正在尝试让我的 Web 应用程序再次使用新的 Spring Boot 版本 1.3.5,但百里香方言似乎不再起作用。
我加了
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
</dependency>
到我的 .pom,甚至在我的安全配置中注册了一个 bean:
@Bean
public SpringSecurityDialect springSecurityDialect(){
SpringSecurityDialect dialect = new SpringSecurityDialect();
return dialect;
}
(尽管我认为 Spring Boot 无论如何都会为我做到这一点)。 Wen 使用诸如 e 之类的表达方式。 G。
<li sec:authorize="hasRole('SITE_ADMIN') || hasRole('TENANT_ADMIN')">Admin
</li>
不会渲染表达式,因为角色似乎为空,尽管我可以将自定义用户元素注入控制器:
@RequestMapping(value="/", method=RequestMethod.GET)
public String homePage(@AuthenticationPrincipal VZUser user, Model model){
model.addAttribute("email", user.getEmail());
return "home/index";
}
通过调试,我看到注入的 Principal 对象不为空,但模板似乎无法解析 sec: 对象。我删除了 xmlns 命名空间并重新插入它没有效果。坦率地说,有关此功能的文档非常令人震惊。有什么我想念的吗?
哦,是的。在 Spring Boot 1.3.2 中使用相同的代码(没有新的依赖项和 xhtml 模板中的命名空间声明)...
更新
我认为这与我使用自定义 UserDetailsService 的事实有关。我对内存服务没有任何问题。但是,我的自定义用户实现只有以下内容:
@Override
public Collection<? extends GrantedAuthority> getAuthorities(){
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
for(VZUserRoles role: roles){
authorities.add(new SimpleGrantedAuthority(role.name()));
}
return authorities;
}
我定义了一个基本的 UserDetails 服务并将其放入 AuthenticationMAnagerBuilder。身份验证工作正常,只是似乎没有传递给视图。
【问题讨论】:
-
这个问题的解决方法在:stackoverflow.com/questions/41388332/…
标签: java spring-mvc spring-security spring-boot thymeleaf