第一次使用飞碟用户,对Java和Springboot也很新...
情况: 我有一个要转换为PDF的html文件。在我尝试添加授权之前,它一直有效。我想添加授权,以便仅根据loggedUser在数据库中是否具有某些“访问权限”才能看到html的特定部分。想知道我是由于pdf生成器引起错误还是由于其他原因导致的错误...首先以为是由于SpringSecurity4导致将POM.xml中的依赖项更改为SpringSecurity5,但仍然无法正常工作。有没有一种方法可以限制在创建PDF时可以使用的html文件区域中的访问?我在html中添加了sec:authorize,但是出现以下错误...
错误: 2018-10-16 16:09:20.372错误19164-[[p-nio-60-exec-3] org.thymeleaf.TemplateEngine:[THYMELEAF] [http-nio-60-exec-3]异常处理模板“ “ reports / technologyInformation”:执行处理器'org.thymeleaf.extras.springsecurity4.dialect.processor.AuthorizeAttrProcessor'时出错(报告/ technologyInformation:117) org.thymeleaf.exceptions.TemplateProcessingException:处理器'org.thymeleaf.extras.springsecurity4.dialect.processor.AuthorizeAttrProcessor'执行期间出错(报告/ technologyInformation:117)
和 引起原因:org.thymeleaf.exceptions.ConfigurationException:Thymeleaf执行上下文不是Web上下文(org.thymeleaf.context.IWebContext的实现。Spring Security集成只能在Web环境中使用。
HTML:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8"/>
<title>Technology Information Report</title>
<style>
...
</style>
</head>
<body>
<div class="topHeader">
<h1>client name here</h1>
</div>
<div class="row">
<table>
<tbody>
<tr class="addRowColor">
<th rowspan="2" class="col1"><h3>Affiliate Portal</h3></th>
<td class="col2"> <p><strong>URL:</strong> <a href="https://res.com/login">www.res.com</a></p></td>
</tr>
<tr>
<td>
<p><strong>Usernames:</strong></p>
<p th:text="${client.principleName}"></p>
<p th:text="${client.email}"></p>
<div th:each="employee: ${client.employees}">
<p style="display: inline;" th:text="${employee.name} "></p>
<p style="display: inline;">, </p>
<p style="display: inline;" th:text="${employee.email} "></p>
</div>
<p style="height: .5px;"></p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="row" sec:authorize="${loggedUser.client.ams360Affiliate == 'Access – NO AMS'} or hasROle('ROLE_ADMIN')">
<table>
<tbody>
<tr>
<td class="col1"><h3>Training Library</h3></td>
<td class="col3">
<p><strong>Username:</strong> username</p>
<p><strong>Password: </strong><span class="pwd">pwd</span></p>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hig</groupId>
<artifactId>oli</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>OliDb</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
</dependency>
<dependency>
<groupId>com.github.dblock.waffle</groupId>
<artifactId>waffle-spring-security3</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>org.springframework.security.kerberos</groupId>
<artifactId>spring-security-kerberos-web</artifactId>
<version>1.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.4.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version>
</dependency>
<dependency>
<groupId>org.metawidget.modules</groupId>
<artifactId>metawidget-all</artifactId>
<version>2.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<!-- flying saucer pdf -->
<dependency>
<groupId>org.xhtmlrenderer</groupId>
<artifactId>flying-saucer-pdf</artifactId>
<version>9.1.4</version>
</dependency>
<!-- jxls simple excel -->
<dependency>
<groupId>org.jxls</groupId>
<artifactId>jxls</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>org.jxls</groupId>
<artifactId>jxls-poi</artifactId>
<version>1.0.14</version>
</dependency>
<dependency>
<groupId>org.jxls</groupId>
<artifactId>jxls-jexcel</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
<version>3.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>3.2.8.RELEASE</version>
</dependency>
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>-->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
</project>