본문 바로가기
오류를 개발새발

JWT String argument cannot be null or empty

by 휴일이 2023. 1. 18.

어느 페이지를 가던 JWT 토큰이 널이면 안 된다는 오류가 발생했다

 

jwt 관련 설정을 다 만들어놓고나니

index페이지에서도 jwt토큰을 요구하는 것이어따...

 

 

해답은 좀 간단했다ㅎㅎ;

 

원래 addFilter로 걍 모든 작업에 해당 jwt 검증 필터가 등록하게 만들어버렷엇던것...

 

@Override
protected void configure(final HttpSecurity http) throws Exception {
    http.csrf().disable()
            .sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.STATELESS)

            .and()
            .httpBasic()
            .disable()
            .addFilter(new JwtAuthorizationFilter())
            .addFilter(new JwtAuthorizationFilter())

이런 식으로 ㅎㅎ;

 

 

UsernamePasswordAuthenticationFilter 필터가 동작하기 전에

내가 만든 필터를 동작하도록 바꿔주니

잘 돌아갓다 

 

.and()
        .addFilterBefore(jwtAuthenticationFilter(authenticationManager()), UsernamePasswordAuthenticationFilter.class)
;

 

 

내가 시큐리티를 이해 못햇을 적에

어떤 스프링 시큐리티 강의를 봣는데

걍 addFilter 로 넣어줫길래 그렇게 해도 되는 줄 알았는데

 

로그인 요청이 와서

UsernamePasswordAuthenticationFilter 가 올 때만

내 필터를 동작시켜야하는 거라서

이렇ㄱ ㅔ설정해야하는 것이엇다~

 

 

오늘도 이렇게 하나 배워갑니다...

 

 

728x90