首页 > 解决方案 > 无法在 Spring Security 中解析符号“SamlServerConfiguration”

问题描述

我有一个 spring-boot 项目,我正在尝试使用spring-boot-starter-security(v2.1.4.RELEASE) 和spring-security-saml2-core(v1.0.9.RELEASE) 包创建 SAML2 身份提供者 (IdP)。我基本上是在尝试自定义和构建https://github.com/fhanik/springone2018/blob/master/demo/saml-idp中的代码。但是,当我构建代码时,出现以下错误:

包 org.springframework.security.saml.provider 不存在

找不到符号符号:类 SamlServerConfiguration

我相信我已经包含了参考实现中提到的所有必需的包,所以我不确定为什么会出现这个错误。

以下是我项目中的文件。

AppConfig.java(包含错误的文件):

package com.example.saml.identityprovider;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.saml.provider.SamlServerConfiguration; // error: package does not exist

@ConfigurationProperties(prefix = "spring.security.saml2")
@Configuration
public class AppConfig extends SamlServerConfiguration {  // error: symbol not found
}

Application.java(包含main的文件):

package com.example.saml.identityprovider;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class Application {
    private static final Logger logger = LoggerFactory.getLogger(Application.class);

    /**
     * Returns the homepage message.
     *
     * @return String message
     */
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String getHome() {
        logger.info("Received request for '/' endpoint");
        return "This is a SAML identity provider.";
    }

    /**
     * Provides SPs to select from.
     *
     * @return String
     */
    @RequestMapping("/selectsp")
    public String selectProvider() {
        logger.info("Sample IdP application - Select an SP");
        return "redirect:/saml/idp/select";
    }

    /**
     * Main method.
     *
     * @param args Command-line args
     */
    public static void main(String[] args) {
        SpringApplication.run(Application.class);
    }
}

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>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.1.RELEASE</version>
        <relativePath/>
    </parent>

    <groupId>com.example.saml</groupId>
    <artifactId>identityprovider</artifactId>
    <version>0.1-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <!-- Spring boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.0.1.RELEASE</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
            <version>2.1.4.RELEASE</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.security.extensions/spring-security-saml2-core -->
        <dependency>
            <groupId>org.springframework.security.extensions</groupId>
            <artifactId>spring-security-saml2-core</artifactId>
            <version>1.0.9.RELEASE</version>
        </dependency>
    </dependencies>
</project>

如果有人能指出我可能会错过什么,我将不胜感激。提前致谢!

标签: javaspring-bootspring-securitysaml-2.0

解决方案


推荐阅读