Как настроить spring mvc с двумя провайдерами аутентификации (saml и jwt)? - PullRequest
0 голосов
/ 09 января 2019

Настройка проекта, который будет использовать jwt в качестве формы входа в систему, а также возможность для пользователя выполнить вход в систему sp saml.

Выдержка из WebSecurityConfig.java

@Autowired
    private CustomUserDetailsService jwtUserDetailsService;

    @Autowired
    TokenHelper tokenHelper;

    @Bean
    public JWTAuthenticationEntryPoint jwtAuthenticationEntryPoint() {
        return new JWTAuthenticationEntryPoint();
    }


    /**
     * Defines the web based security configuration.
     * 
     * @param   http It allows configuring web based security for specific http requests.
     * @throws  Exception 
     */
    @Override  
    protected void configure(HttpSecurity http) throws Exception {     
    http
            .addFilterBefore(metadataGeneratorFilter(), ChannelProcessingFilter.class)
//          .addFilterAfter(samlFilter(), BasicAuthenticationFilter.class)
            .addFilterBefore(samlFilter(), CsrfFilter.class)
            .addFilterAt(new TokenAuthenticationFilter(tokenHelper, jwtUserDetailsService), UsernamePasswordAuthenticationFilter.class);
    http        
        .authorizeRequests()
            .antMatchers("/").permitAll()
            .antMatchers("/saml/**").permitAll()
            .antMatchers("/auth/login").permitAll()
            .antMatchers("/js/**").permitAll()
            .anyRequest().authenticated()
            .and().exceptionHandling()
            .defaultAuthenticationEntryPointFor(samlEntryPoint(), new AntPathRequestMatcher("/saml/login"))
            .defaultAuthenticationEntryPointFor(jwtAuthenticationEntryPoint(), new AntPathRequestMatcher("/auth/login")).;
    http
            .logout()
            .disable();
    }

    /**
     * Sets a custom authentication provider.
     * 
     * @param   auth SecurityBuilder used to create an AuthenticationManager.
     * @throws  Exception 
     */
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(jwtUserDetailsService).passwordEncoder(passwordEncoder());

        auth
            .authenticationProvider(samlAuthenticationProvider());


    }

В настоящее время работает поток входа в систему saml, однако каждый раз, когда я использую форму, я получаю токен jwt, а затем мне все равно требуется вход в систему через saml.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...