Spring WebFlux安全性

时间:2017-07-15 09:55:54

标签: spring spring-boot spring-security spring-webflux

我遇到以下问题:

我正在尝试设置一个包含Spring Webflux和Spring Security的基本Spring Boot(2.0.0.M2)项目。

我的pom.xml看起来像这样(通过start.spring.io生成):

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.M2</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<dependencies>
    ...
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>
    ...
</dependencies>

SpringSecurityConfig:

@EnableWebFluxSecurity
public class SecurityConfig extends WebFluxSecurityConfiguration {}

我没有进一步,因为我在启动时遇到异常:

Caused by: java.lang.ClassNotFoundException: org.springframework.security.web.server.context.SecurityContextRepository

所以我认为整个org.springframework.security.web.server包不在类路径上,尽管它应该在那里,因为它包含在API docs中。

好像我做错了什么,但我不知道是什么。

1 个答案:

答案 0 :(得分:3)

目前Spring Boot的spring-boot-starter-security不包括spring-security-webflux

明确地将其添加为项目依赖项。

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-webflux</artifactId>
</dependency>

请参阅此issue : Provide auto-configuration for WebFlux-based security

顺便说一句,检查我的工作代码:https://github.com/hantsy/spring-reactive-sample/tree/master/boot

已更新:在Spring Boot 2.0.0.RELEASE中,spring-boot-starter-security包含webflux支持。