gpt4 book ai didi

java - 如何在 WebSSOProfileConsumerImpl 中设置 maxAuthenticationAge?

转载 作者:行者123 更新时间:2023-11-30 07:51:57 25 4
gpt4 key购买 nike

我是 Spring 的新手,刚刚获得了 Spring Security 和 Okta 的 SAML 身份验证,工作遵循 this tutorial .但是,Spring 拒绝超过 7200 秒的 SAML 身份验证,我想延长该时间。

docs说要在 WebSSOProfileConsumerImpl bean 上设置 maxAuthenticationAge,但是...我不知道该怎么做。

有人能给我举个例子或给我指明正确的方向吗?

最佳答案

通常,如果您创建了所有设置,则在@Configuration 类中使用@Been

// can put this been in any related config class, no need to create new one
@Configuration
public class Config {
@Bean
public WebSSOProfileConsumer getWebSSOProfileConsumerImpl(){
WebSSOProfileConsumerImpl consumer = new WebSSOProfileConsumerImpl();
consumer.setMaxAuthenticationAge(5000);
return consumer;
}
}

或者Xml(真实项目xml demo)

<bean  class="org.springframework.security.saml.websso.WebSSOProfileConsumerImpl"
id="myWebSSOProfileConsumer">
<property name="maxAuthenticationAge" value="5000"/>
</bean>

但在您的案例中,演示示例使用 import static org.springframework.security.extensions.saml2.config.SAMLConfigurer.saml 并且您需要在其中注入(inject) WebSSOProfileConsumerImpl 并且根据 this pull request及其 source code你可能会这样做:

@Override
protected void configure(final HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/saml*").permitAll()
.anyRequest().authenticated()
.and()
.apply(saml())
.webSSOProfileConsumer(getWebSSOProfileConsumerImpl())// <= here
// ... rest of the setup

}


public WebSSOProfileConsumerImpl getWebSSOProfileConsumerImpl() {
WebSSOProfileConsumerImpl profileConsumer = new WebSSOProfileConsumerImpl();
profileConsumer.setMaxAuthenticationAge(5000);
return profileConsumer;
}

可悲的是它还没有发布,你可能不得不重写你的SAMLConfigurer版本。或者只是从 git repo 复制粘贴新版本并使用它。

关于java - 如何在 WebSSOProfileConsumerImpl 中设置 maxAuthenticationAge?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46354521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com