无法导入 springframework.security.extensions 并找到 saml() 方法
Posted
技术标签:
【中文标题】无法导入 springframework.security.extensions 并找到 saml() 方法【英文标题】:Can't import springframework.security.extensions and find saml() method 【发布时间】:2019-03-04 03:59:13 【问题描述】:org.springframework.security.extensions.saml2.config.SAMLConfigurer 不存在
至少我不能在我的安全配置类中导入 org.springframework.security.extensions.saml2.config.SAMLConfigurer 方法 saml() 还没有已定义。
SecurityConfiguration.java的源代码:
package com.hem.configuration;
import com.hem.properties.ServerProxy;
import com.hem.properties.ServerSsl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.extensions.saml2.config.SAMLConfigurer;
@EnableWebSecurity
@Configuration
@EnableGlobalMethodSecurity(securedEnabled = true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter
private static final String HTTPS = "https";
@Value("$security.saml2.metadata-url")
private String metadataUrl;
@Value("$saml.entity.id")
private String entityId;
@Autowired
private ServerProxy serverProxy;
@Autowired
private ServerSsl serverSsl;
@Autowired
private SAMLUserDetailsServiceImpl samlUserDetailsServiceImpl;
@Override
protected void configure(final HttpSecurity http) throws Exception
http
.authorizeRequests()
.antMatchers("/saml*").permitAll()
.antMatchers("/images/apple-touch-icon.png").permitAll()
.anyRequest().authenticated()
.and()
.apply(saml()) //<-can't find this method
.userDetailsService(samlUserDetailsServiceImpl)
.serviceProvider()
.keyStore()
.storeFilePath(serverSsl.getKeyStore())
.password(serverSsl.getKeyStorePassword())
.keyname(serverSsl.getKeyAlias())
.keyPassword(serverSsl.getKeyStorePassword())
.and()
.protocol(HTTPS)
.hostname(String.format("%s:%s", serverProxy.getHost(), serverProxy.getPort()))
.basePath("/")
.entityId(entityId)
.and()
.identityProvider()
.metadataFilePath(this.metadataUrl);
我的 pom.xml
中的依赖项 <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.extensions</groupId>
<artifactId>spring-security-saml2-core</artifactId>
<version>1.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security.extensions</groupId>
<artifactId>spring-security-saml-dsl</artifactId>
<version>1.0.0.M2</version>
</dependency>
如果您知道如何解决此问题,请分享您的经验。
如果您需要更多信息 - 我会修复请求。
【问题讨论】:
【参考方案1】:在pom.xml
文件中添加以下 Maven 依赖项
<dependencies>
<dependency>
<groupId>org.springframework.security.extensions</groupId>
<artifactId>spring-security-saml-dsl</artifactId>
<version>1.0.0.M3</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone</url>
</repository>
</repositories>
并在上面的类中添加下面的静态导入
import static org.springframework.security.extensions.saml2.config.SAMLConfigurer.saml;
【讨论】:
【参考方案2】:请补充:
import static org.springframework.security.extensions.saml2.config.SAMLConfigurer.saml;
【讨论】:
以上是关于无法导入 springframework.security.extensions 并找到 saml() 方法的主要内容,如果未能解决你的问题,请参考以下文章
我必须安装啥才能解决找不到 GtkSource 的任何类型库,无法导入:GtkSourceView,无法导入名称 GtkSource