我已经通过文件中列出的步骤 -
https://developer.okta.com/blog/2017/03/16/spring-boot-saml#run-the-app-and-login-with-okta
一切正常,我看到SAML响应生成并从OKTA发送到应用程序,但当请求到达应用程序时,我得到此错误 -
type = Forbidden,status = 403) . 在请求参数'_csrf'或 Headers 'X-CSRF-TOKEN'上找到无效的CSRF令牌'null' .
我已经尝试禁用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);
}
}
任何建议表示赞赏 .
2 回答
我在您的代码与我的博客文章中看到的唯一区别是以下行:
如果将其更改为以下内容,是否可以正常工作?
这个问题已经解决了..我做了几件事 -
在OKTA中添加目标网址与URL上的单点登录相同_11701069_
另外,在Spring方面,我在SecurityConfiguration中禁用了CSRF保护 -
http.csrf()禁用();
但真正的问题是错误的目标网址 .