簡體   English   中英

如何在您的Spring配置文件中設置WebSSOProfileConsumerImpl

[英]How to set WebSSOProfileConsumerImpl in your Spring Configuration file

我面臨在我的Spring配置文件中指定WebSSOProfileConsumerImpl的問題。 我正在嘗試在此bean中修改responseSkew,但是在為WebSSOProfileConsumerImpl添加配置后,我遇到了MetadataManager問題


申請開始失敗


描述:

org.springframework.security.saml.websso.AbstractProfileBase中的setMetadata方法的參數0需要一個類型為'org.springframework.security.saml.metadata.MetadataManager'的bean。

行動:

考慮定義類型為“ org.springframework.security.saml.metadata.MetadataManager”的bean

誰能幫助我解決這個問題?

我已經瀏覽了以下鏈接: http : //docs.spring.io/spring-security-saml/docs/current/reference/html/configuration-advanced.html,但是它沒有指定如何在配置中進行設置。

我的密碼

    import static org.springframework.security.extensions.saml2.config.SAMLConfigurer.saml;

import org.springframework.beans.factory.annotation.Qualifier;
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.saml.websso.WebSSOProfileConsumer;
import org.springframework.security.saml.websso.WebSSOProfileConsumerImpl;

@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("${security.saml2.responseSkew}")
    int responseSkew = 0;


    @Override
    protected void configure(final HttpSecurity http) throws Exception {

        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("https")
                    .hostname(String.format("%s:%s", "localhost", this.port))
                    .basePath("/")
                    .and()
                .identityProvider()
                .metadataFilePath(this.metadataUrl).and();

       /* Map<? extends Object, Object> sharedObjects = new Map<? extends Object>, Object>(http.getSharedObjects());
        sharedObjects.put(WebSSOProfileConsumer.class, webSSOprofileConsumerImpl());*/

    }

    @Bean
    @Qualifier("webSSOprofileConsumer")
    public WebSSOProfileConsumer webSSOprofileConsumerImpl() {
        WebSSOProfileConsumerImpl consumerImpl = new WebSSOProfileConsumerImpl();
        consumerImpl.setResponseSkew(this.responseSkew);
        return consumerImpl;
    } 

}

如果不需要將WebSSOProfileConsumer作為Bean來訪問應用程序的其余部分,則可以在configure方法內創建它,如下所示:

@Override
protected void configure(final HttpSecurity http) throws Exception {
    WebSSOProfileConsumerImpl consumerImpl = new WebSSOProfileConsumerImpl();
    consumerImpl.setResponseSkew(this.responseSkew);

    http
        .authorizeRequests()
            .antMatchers("/saml*").permitAll()
            .anyRequest().authenticated()
            .and()
        .apply(saml())
            .serviceProvider()
                .ssoProfileConsumer(consumerImpl)  // <-- added here
                .keyStore()
                // Your method continues as before

我不記得您的情況下常規接線失敗的確切原因,但是要點是configure設置了一個構建器對象而不是常規bean。 通常,ServiceProviderBuilder在其構建步驟中會提供WebSSOProfileConsumer所需的MetadataManager,但是如果自動裝配配置文件使用者,則不會為您提供MetadataManager,因為假定您的自動裝配對象已經完成。

(我在尋找一種配置最大身份驗證年齡的方法時學到了這一點,因為在某些情況下spring-security-saml中的兩個小時默認值低於身份提供商使用的默認值。這有效地將用戶鎖定在應用程序之外,直到身份提供商的最大身份驗證年齡已過。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM