inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

이야기를 나눠요

173만명의 커뮤니티!! 함께 토론해봐요.

spring-boot 2.7 이상을 사용 하시는 분의 경우

Spring Cloud로 개발하는 마이크로서비스 애플리케이션(MSA)

안녕하세요. 강사님께서는 2.6 버전을 사용 권장 하셨지만 왠지 모를 궁금함에 2.7에서 사용하는 spring security 5.7 이상에서 바뀐 부분으로 한번 적용을 해보고 싶었습니다. 인프런에 올라온 많은 분들의 질문을 정리 하여 만들어 보았습니다. package com.example.userservice.security; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.web.SecurityFilterChain; import com.example.userservice.service.UserService; import lombok.RequiredArgsConstructor; @Configuration @EnableWebSecurity @RequiredArgsConstructor public class WebSecurity { private final UserService userService; private final BCryptPasswordEncoder bCryptPasswordEncoder; private final Environment env; AuthenticationManager authenticationManager; // spring.boot 2.7 부터는 WebSecurityConfigurerAdapter가 아닌 // SecurityFilterChain 을 사용 합니다. @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { AuthenticationManagerBuilder authenticationManagerBuilder = http.getSharedObject(AuthenticationManagerBuilder.class); authenticationManagerBuilder.userDetailsService(userService).passwordEncoder(bCryptPasswordEncoder); authenticationManager = authenticationManagerBuilder.build(); //AuthenticationFilter authenticationFilter = new AuthenticationFilter(); //authenticationFilter.setAuthenticationManager(authenticationManager); AuthenticationFilter authenticationFilter = new AuthenticationFilter(authenticationManager , userService , env); http.csrf().disable(); http.authorizeRequests() //.antMatchers("/error/**").permitAll() // public abstract java.lang.String javax.servlet.ServletRequest.getRemoteAddr() is not supported 보기 싫을때 활성화 .antMatchers("/**") .hasIpAddress("127.0.0.1") .and() .authenticationManager(authenticationManager) .addFilter(authenticationFilter) ; http.headers().frameOptions().disable(); return http.build(); } //ex) 기존의 경우 AuthenticationManagerBuilder 를 오버라이드 하여 사용 하였지만 filterChain 안에서 호출 하여 설정 합니다. /* protected void configure(AuthenticationManagerBuilder auth) throws Exception{ auth.userDetailsService(userService).passwordEncoder(bCryptPasswordEncoder); } */ //ex)filter를 authenticationAmanger에 주입 하던 getAuthenticationFilter역시 filterChain 내부에서 사용 합니다. /* private AuthenticationFilter getAuthenticationFilter() throws Exception { AuthenticationFilter authenticationFilter = new AuthenticationFilter(); authenticationFilter.setAuthenticationManager(authenticationManager); return authenticationFilter; } */ }

  • spring-boot
  • jpa
  • 아키텍처
  • spring-cloud
  • kafka
  • msa
최재영 댓글 0 좋아요 1 조회수 2548

MSA 와 관련하여 질문드립니다.

스프링 MVC 2편 - 백엔드 웹 개발 활용 기술

안녕하세요 완강 후 추가적으로 궁금한 사항이 있어서 글을 올리게 되었습니다. 요즘 대세인 MSA와 관련하여 여쭙고 싶어서 연락드립니다. [문제상황] MSA와 관련하여 아키텍쳐에서는 요청에 맞추어 반응하는 서버를 만들기 위하여 docker container 를 활용한 서버들을 많이 구성하는 걸로 알고 있습니다. 이때, Spring boot은 다양한 기능들을 제공하지만 python의 flask나 Fastapi와 같은 가벼운 프레임워크에 비해서는 안좋은 점들이 있을것이라 생각듭니다. (예를 들어서 컨테이너의 용량이 크고, 콜드 스타트의 시작이 늦다는 점... 이 대표적으로 생각납니다.) [질의사항] 1. Springboot 로 MSA를 구성하였을 경우 앞서 얘기드렸던 문제점이 없는지 여부 2. Springboot 가 MSA에서 갖는 장점 3. 프레임워크의 무겁다와 가볍다의 개념이 무엇인지 궁금합니다. 4. 배민에서는 JAVA를 사용하여 프로젝트를 진행하는데, 우리나라의 경우 JAVA를 사용하는 시니어개발자들이 많아 사용하는 걸로 알고있습니다. 만약 그렇지 않았다면, JAVA Spring boot 가 아닌 다른 프레임워클 사용하여 개발하였을지 궁금합니다. 감사합니다.

  • spring
  • msa
정영호 댓글 1 좋아요 0 조회수 614

인기 태그

인프런 TOP Writers

주간 인기글