добавление страницы входа перед swagger-ui. html с использованием тимьянового листа и весенней загрузки - PullRequest
0 голосов
/ 31 марта 2020
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.cors().and().csrf().disable().exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
                .authorizeRequests()
                .antMatchers("/", "/favicon.ico", "/**/*.png", "/**/*.gif", "/**/*.svg", "/**/*.jpg",/**/*.html","/**/*.css", "/**/*.js")
                .permitAll()
                .antMatchers("/v2/api-docs", "/configuration/ui", "/configuration/security","/webjars/**")
                .permitAll().antMatchers("/swagger-resources","/swagger-resources/configuration/ui","/swagger-ui.html").hasRole("SWAG").anyRequest().authenticated()
                .antMatchers("/api/all/**").permitAll().antMatchers("/api/Service/**").permitAll()
                .antMatchers("/api/Service/Package/**").permitAll()


                .antMatchers("api/public/customer/**").hasRole("CUSTOMER1")
                .antMatchers(HttpMethod.OPTIONS).permitAll().anyRequest().authenticated().and()
                .formLogin()
                     .loginPage("/login")
                     .permitAll()
                .and()
                .logout()
                     .invalidateHttpSession(true)
                     .clearAuthentication(true)
                     .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
                     .logoutSuccessUrl("/login?logout")
                     .permitAll()
                .and()
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
                .addFilterBefore(authTokenFilterBean(), UsernamePasswordAuthenticationFilter.class);
    }

@Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
         auth.authenticationProvider(authProvider);

         auth.inMemoryAuthentication()
         .withUser("user").password("{noop}password").roles("USER")
     .and()
         .withUser("manager").password("{noop}password").roles("MANAGER");
    }

@Controller
public class HomeController {

    @GetMapping("/")
    public String root() {
        return "index";
    }

    @GetMapping("/user")
    public String userIndex() {
        return "swagger-ui.html";
    }

    @GetMapping("/login")
    public String login() {
        return "login";
    }

    @GetMapping("/access-denied")
    public String accessDenied() {
        return "/error/access-denied";
    }   

}

поэтому я пытаюсь аутентифицировать / swagger-ui. html как простой всплывающий логин с использованием памяти для доступа к API определенных пользователей

когда я делаю с этим кодом, я получаю следующий вывод прикрепленного изображения

, когда я вхожу в систему, перенаправление для аутентификации отсутствует

> output

...