[TIL] 22.12.28

조성현·2022년 12월 28일
1
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
    http.csrf().disable();

    // 기본 설정인 Session 방식은 사용하지 않고 JWT 방식을 사용하기 위한 설정
    http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);

    http.authorizeRequests().antMatchers("/api/user/**").permitAll()
                .antMatchers("/api/search").permitAll()
                .antMatchers("/api/shop").permitAll()
                .anyRequest().authenticated()
                // JWT 인증/인가를 사용하기 위한 설정
                .and().addFilterBefore(new JwtAuthFilter(jwtUtil), UsernamePasswordAuthenticationFilter.class);


    http.formLogin().loginPage("/api/user/login-page").permitAll();

    http.exceptionHandling().accessDeniedPage("/api/user/forbidden");

    return http.build();
  }
}

SecurityContextHolder에 값을 넣어주기만하면,
filterChain.doFilter()를 통해서 넘겨주지 않아도 다음 필터에서 꺼내 쓸 수 있다.
이게 어떻게 가능할까? [관련 Ref 링크]

@PreAuthorize 사용할 때, [Ref]3. 더 간단히.. Method로 권한여부 체크하기!를 참고해서 권한유저가 아닐 시 AuthException을 return 하도록 하면 handling까지 할 수 있지 않을까? -> 내일 한번 튜라이 해보자.

@Transaction 관련 Ref(Transactional 트랜잭션 적용 범위)
[Spring] JPA의 save와 saveAll의 성능 차이, 그리고 원인.
[FetchType.LAZY로 인한 JSON 오류]

profile
맛있는 음식과 여행을 좋아하는 당당한 뚱땡이

0개의 댓글