嗨,我试图在springboot应用程序中包含saml身份验证,我面临一个问题。当我尝试在身份验证后提交post方法时,它会重定向到saml auth url并返回到我的应用程序,然后实际的post请求就消失了。我想通过post方法向db添加一些数据,当我尝试提交我的post时,它会重定向到saml第三方身份验证提供程序并授权请求,然后使用默认的重定向url返回到我的应用程序,现在我的post请求不见了,它不会被实际控制器命中。
在下面添加我的代码:
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
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.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.saml.SAMLCredential;
import org.springframework.security.saml.websso.WebSSOProfileOptions;
import static org.springframework.security.extensions.saml2.config.SAMLConfigurer.saml;
@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;
@Value("${server.hostname}")
String hostname;
@Value("${server.protocol}")
String protocol;
@Override
protected void configure(final HttpSecurity http) throws Exception {
http.headers().frameOptions().sameOrigin();
http.authorizeRequests()
.antMatchers("/saml*").permitAll()
.anyRequest().authenticated()
.and()
.apply(saml())
.serviceProvider()
.keyStore()
.storeFilePath(this.keyStoreFilePath)
.password(this.password)
.keyname(this.keyAlias)
.keyPassword(this.password)
.and()
.protocol(this.protocol)
.hostname(String.format("%s:%s", this.hostname, this.port))
.basePath("/")
.and()
.identityProvider()
.metadataFilePath(this.metadataUrl);
}
}
暂无答案!
目前还没有任何答案,快来回答吧!