• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

web ignoring을 설정해도 favicon.ico가 계속 302 redirect 됩니다.

22.06.23 15:21 작성 조회수 1.74k

0

안녕하세요, 강의 잘 보고 있습니다.

 

다만 실전 프로젝트 중 WebIgnoring 을 강사님이 하신 것 처럼 똑같이 따라 했는데도 불구하고

 

계속 favicon.ico가 302 redirect 됩니다. (아직 로그인 인증을 받지 않은 상태에서 루트 경로로 접속 시)

 

인텔리제이도 재시작 해보고, 인텔리제이 메뉴에서 invalidate caches/restart도 봤으나 결과는 계속 localhost:9090/login 으로 302 redirect 입니다.

 

제가 따로 web.ignoring().antMatchers("/favicon.ico", "/**/favicon.ico");와 같이 코드를 추가했어도 계속 302 redirect가 발생되네요.

 

web.ignoring().antMatchers("/favicon.ico", "/**/favicon.ico"); [이 코드를 추가 하나 안 하나 변함 없이 302 redirect가 됩니다]

 

해결 방법이 있을까요?

 

감사합니다. (혹시 제가 이전에 올린 질문 글도 답변 부탁드려도 될까요...?)

 

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        // memory 방식으로 사용자 build

        String password = passwordEncoder().encode("1111");

        auth.inMemoryAuthentication().withUser("user").password(password).roles("USER");
        auth.inMemoryAuthentication().withUser("manager").password(password).roles("MANAGER", "USER");
        auth.inMemoryAuthentication().withUser("admin").password(password).roles("ADMIN", "MANAGER", "USER");
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        ;
        return PasswordEncoderFactories.createDelegatingPasswordEncoder();
    }

    @Override
    public void configure(WebSecurity web) {
        web.ignoring()
                .antMatchers("/favicon.ico", "/**/favicon.ico");

        web.ignoring()
                .requestMatchers(PathRequest.toStaticResources().atCommonLocations());
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .antMatchers("/").permitAll()
                .antMatchers("/mypage/**").hasRole("USER")
                .antMatchers("/messages/**").hasRole("MANAGER")
                .antMatchers("/config/**").hasRole("ADMIN")
                .anyRequest().authenticated()

                .and()
                .formLogin();
    }

}

 

 

감사합니다.

 

답변 1

답변을 작성해보세요.

0

윤영철님의 프로필

윤영철

2022.06.24

resource 폴더밑에 사이즈 0인 favicon.ico파일 하나 만들어놓으시면 됩니다.

runner222님의 프로필

runner222

질문자

2022.06.24

답변 감사드립니다. 윤영철님께서 말씀하신 방법대로도 해결 가능할 것 같지만, 근본적인 문제는 크롬 확장프로그램 AdGuard 때문이었네요... 좋은 하루 되세요!

runner222님의 프로필

runner222

질문자

2022.06.24

제거 오늘 오전에 테스트 해 보았을 때는, AdGuard 를 종료했을 때 302 redirect가 안 됐는데 조금 전에 다시 실행시켜보니 302 redirect 가 돼서 말씀해주신 방법되로 favicon.ico 파일을 직접 추가 했습니다.  더 이상 302가 발생되지 않네요. 답변 정말 감사합니다.