配置spring boot以允许某些文件类型。

时间:2016-08-22 00:20:23

标签: spring-security spring-boot swagger swagger-ui swagger-2.0

我打开了这个question already。我需要知道如何允许spring-boot允许加载.css的{​​{1}}和.js个文件?

这是我的swagger文件

WebSecurityConfig.java

1 个答案:

答案 0 :(得分:0)

只允许对.css.js路径的所有访问权限(正如您已使用/register和其他途径执行此操作)

@Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity
                .csrf().disable()
                .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
                .authorizeRequests()
                .antMatchers("/auth/**").permitAll()
                .antMatchers("/register/**").permitAll()
                .antMatchers("/swagger-ui*").permitAll()
                .antMatchers("/v2/**").permitAll()
                .antMatchers("/webjars/**").permitAll() //swagger ui files
                .antMatchers("/sysadmin/**").hasRole("SYSADMIN")
                .antMatchers("/admin/**").hasRole("ADMIN")
                .antMatchers("/siteadmin/**").hasRole("SITEADMIN")
                .anyRequest().authenticated();

        // Custom JWT based security filter
        httpSecurity
                .addFilterBefore(authenticationTokenFilterBean(), UsernamePasswordAuthenticationFilter.class);

    }