Проблема безопасности Spring с настройкой единого входа - PullRequest
0 голосов
/ 15 марта 2019

Я пытаюсь настроить SAML аутентификацию и добавлять роли своим пользователям.

Я использую spring security & spring boot version 2.1.3

Ниже приведены конфигурации, которые я имеюзаписано:

@Configuration
@EnableGlobalMethodSecurity(securedEnabled = true)
@Order(1)
public class SAMLConfiguration 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(this.keyStoreFilePath)
                .password(this.password)
                .keyname(this.keyAlias)
                .keyPassword(this.password)
                .and()
                .protocol("http")
                .hostname(String.format("%s:%s", "localhost", this.port))
                .basePath("/")
                .and()
                .identityProvider()
                .metadataFilePath(this.metadataUrl);
    }
}

Вторые конфигурации, определяющие роли:

@Configuration
@Order(2)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .antMatchers("/internal").hasRole(INTERNAL_ACCESS)
                .antMatchers("/admin/**").hasRole(ADMIN_ACCESS)
                .antMatchers("/guest/**").hasRole(GUEST_ACCESS)
                .and()
                .httpBasic()
                .and()
                .addFilterBefore(new AuthenticationFilter(), BasicAuthenticationFilter.class)
                .csrf().disable().headers();
    }
}

Проблема, с которой я сталкиваюсь, заключается в том, что код компилируется, и обе конфигурации выполняются, но фильтр, который я добавилне вступает в игру.

Похоже, в данный момент работает только одна конфигурация.

Пожалуйста, предложите.

Спасибо

...