秒:授权不在 spring-boot 项目上评估 [英] sec:authorize not being evaluated on spring-boot project

查看:38
本文介绍了秒:授权不在 spring-boot 项目上评估的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我当前的 spring-boot 项目中,我有一个带有此 html 代码的视图:

但是当我执行应用程序时,显然标记 sec:authorize 没有被评估,因为两个部分都被显示.

我在 application.properties 文件中这样配置 thymeleaf:

# THYMELEAF (ThymeleafAutoConfiguration)spring.thymeleaf.prefix=classpath:/templates/spring.thymeleaf.suffix=.htmlspring.thymeleaf.mode=HTML5spring.thymeleaf.encoding=UTF-8spring.thymeleaf.content-type=text/htmlspring.thymeleaf.cache=false

我的 thymeleaf 配置类是这样实现的:

@Configuration公共课百里香{@豆公共 SpringTemplateEngine templateEngine() {SpringTemplateEngine engine = new SpringTemplateEngine();最终集<ID方言>方言 = new HashSet();dialects.add(new SpringSecurityDialect());engine.setDialects( 方言);返回引擎;}}

谁能指出我在这里遗漏了什么?

解决方案

确保为 Thymeleaf 添加以下依赖项:

<依赖><groupId>org.thymeleaf.extras</groupId><artifactId>thymeleaf-extras-springsecurity4</artifactId><version>2.1.2.RELEASE</version><scope>编译</scope></依赖>

还要确保将此添加到

xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4"

我也不认为 Set 是必要的(如果我错了,请纠正我),您可以将其写为:

Bean公共 SpringTemplateEngine templateEngine() {SpringTemplateEngine engine = new SpringTemplateEngine();engine.setTemplateResolver(templateResolver());engine.addDialect(new SpringSecurityDialect());返回引擎;}

In my current spring-boot project, I have one view with this html code:

<div id="navbar" class="collapse navbar-collapse">
  <ul class="nav navbar-nav navbar-right" sec:authorize="isAuthenticated()">
     ...
  </ul>
  <ul class="nav navbar-nav navbar-right" sec:authorize="isAnonymous()">
     ...
  </ul>
</div>

but when I execute the application, apparently the tag sec:authorize isn't being evaluated, since both parts are being displayed.

I configure thymeleaf in my application.properties file this way:

# THYMELEAF (ThymeleafAutoConfiguration)
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false

my thymeleaf configuration class is implemented this way:

@Configuration
public class Thymeleaf {
  @Bean
  public SpringTemplateEngine templateEngine() {
    SpringTemplateEngine engine  =  new SpringTemplateEngine();
    final Set<IDialect> dialects = new HashSet<IDialect>();
    dialects.add( new SpringSecurityDialect() );
    engine.setDialects( dialects );

    return engine;
  }
}

anyone can point what i am missing here?

解决方案

Make sure you add the following dependency for Thymeleaf:

<dependency>
    <groupId>org.thymeleaf.extras</groupId>
    <artifactId>thymeleaf-extras-springsecurity4</artifactId>
    <version>2.1.2.RELEASE</version>
    <scope>compile</scope>
</dependency>

Also make sure to add this to the <html>

xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4"

I also dont think that Set<IDialect> is necessary (correct me if I'm wrong), You can just write it as:

Bean
public SpringTemplateEngine templateEngine() {
   SpringTemplateEngine engine = new SpringTemplateEngine();
   engine.setTemplateResolver(templateResolver());
   engine.addDialect(new SpringSecurityDialect());
   return engine;
}

这篇关于秒:授权不在 spring-boot 项目上评估的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆