Как веб-страница с Spring Boot может загружать изображения из imgur? - PullRequest
0 голосов
/ 01 октября 2018

Моя веб-страница будет ajax (GET) и получать данные блога из бэкэнда RESTFul.

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

Данные, которые я получилсодержал тег HTML, например:

<p>Hello</p>
<img src="https://i.imgur.com/xxxxxx.jpg">

Но после обновления моей веб-страницы появилась ошибка 403, так как изображения не могут быть получены из imgur.

Моя веб-страница была обновлена ​​успешно, кромеизображения не загружались.

Это мой WebSecurityConfigurerAdapter:

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private CustomUserDetailService customUserDetailService;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .cors()
                    .and()
                .csrf()
                    .disable()
                .authorizeRequests()
                    .antMatchers("/", "/*.*", "/getPost/**", "/css/**", "/js/**", "/tinymce/**").permitAll()
                    .anyRequest().authenticated()
                    .and()

                .formLogin()
                    //.loginPage("/Login")
                    .permitAll()
                    .and()

                .logout()
                    .permitAll();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(this.customUserDetailService)
        .passwordEncoder(this.getPasswordEncoder());
    }

    @Bean
    CorsConfigurationSource corsConfigurationSource() {
        CorsConfiguration configuration = new CorsConfiguration();
        configuration.setAllowedOrigins(Arrays.asList("*", "https://i.imgur.com"));
        configuration.setAllowCredentials(true);
        configuration.setAllowedHeaders(Arrays.asList("Access-Control-Allow-Headers","Access-Control-Allow-Origin","Access-Control-Request-Method", "Access-Control-Request-Headers","Origin","Cache-Control", "Content-Type", "Authorization"));
        configuration.setAllowedMethods(Arrays.asList("DELETE", "GET", "POST", "PATCH", "PUT"));
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", configuration);

        return source;
    }
}

Как я могу решить эту проблему?

Спасибо!

1 Ответ

0 голосов
/ 03 октября 2018

Я думал, что решил это ...

Если бы я использовал http://127.0.0.1,, изображения из imgur не могли быть получены.

Но я был бы успешным, если бы использовал реальный IPподключить мой сайт.

...