【发布时间】:2018-03-24 12:59:58
【问题描述】:
我已经完成了文档中列出的步骤 -
https://developer.okta.com/blog/2017/03/16/spring-boot-saml#run-the-app-and-login-with-okta
一切正常,我看到生成 SAML 响应并从 OKTA 对应用程序进行重新编辑,但是当请求到达应用程序时,我收到此错误 -
类型=禁止,状态=403)。发现无效的 CSRF 令牌“null” 请求参数“_csrf”或标头“X-CSRF-TOKEN”。
我曾尝试禁用 csrf,但随后它会通过 SAML 重定向进入无限循环。
这里是 SecurityConfiguration.java-
package com.example;
import static org.springframework.security.extensions.saml2.config.SAMLConfigurer.saml;
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;
@EnableWebSecurity
@Configuration
@EnableGlobalMethodSecurity(securedEnabled = true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Value("${security.saml2.metadata-url}")
String metadataUrl;
@Value("${server.ssl.key-alias}")
String keyAlias;
@Value("${server.ssl.key-store-password}")
String password;
@Value("${server.port}")
String port;
@Value("${server.ssl.key-store}")
String keyStoreFilePath;
@Override
protected void configure(final HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/saml*").permitAll()
.anyRequest().authenticated()
.and()
.apply(saml())
.serviceProvider()
.keyStore()
.storeFilePath("saml/keystore.jks")
.password(this.password)
.keyname(this.keyAlias)
.keyPassword(this.password)
.and()
.protocol("https")
.hostname(String.format("%s:%s", "10.200.10.10", this.port))
.basePath("/")
.and()
.identityProvider()
.metadataFilePath(this.metadataUrl);
}
}
欢迎提出任何建议。
【问题讨论】: