unfineapp005
@unfineapp0058594
Reviews Written
-
Average Rating
-
Posts
Q&A
์คํ๋ง ์ํ๋ฆฌํฐ ์ต์ ๋ฒ์ ์ฝ๋ ์์๊น์?
์ง๊ธ์ github ์์ค๋ฅผ ์ฐธ๊ณ ํด๋ ์๋๋ค์.springboot 3.3.0, security-core 6.3.0์ ๊ฐ ์ค์ ํ ๋ฐฉ๋ฒ ๊ณต์ ํฉ๋๋ค.ํน์๋ ๋์์ด ๋ ๊น ์ถ์ด ์ฌ๋ ค์.(2024-07-21) AuthenticationFilter ์ถ๊ฐ ์ userService ๊ด๋ จํ์ฌ ์ํ์ฐธ์กฐ ์ค๋ฅ๋ฅผ ํด๊ฒฐํ ์์ค์ ๋๋ค. @Slf4j @Configuration @EnableWebSecurity @RequiredArgsConstructor public class WebSecurity { private final Environment env; @Bean public SecurityFilterChain filterChain(HttpSecurity http, AuthenticationManager authenticationManager, UserService userService) throws Exception { http.csrf(AbstractHttpConfigurer::disable) .authorizeHttpRequests(authorize -> authorize.requestMatchers("/users/**").permitAll() .requestMatchers("/actuator/**").permitAll() .requestMatchers("/health-check/**").permitAll() .requestMatchers("/error/**").permitAll() .requestMatchers("/**").access((authentication, request) -> { String clientIp = request.getRequest().getRemoteAddr(); log.debug("client ip is = {}", clientIp); // ํ์ฉ๋ IP ๋ฆฌ์คํธ String[] allowedIps = {"192.168.35.194", "192.168.35.195", "192.168.35.196"}; // IP๊ฐ ํ์ฉ๋ ๋ฆฌ์คํธ์ ํฌํจ๋์ด ์๋์ง ํ์ธ boolean isAllowed = Arrays.asList(allowedIps).contains(clientIp); return new AuthorizationDecision(isAllowed); }) ) .authenticationManager(authenticationManager) // ์ฌ์ฉ์ ์ธ์ ์ ์ฅํ์ง ์์ .sessionManagement(configurer -> configurer.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) // ์๋ต ํค๋์ X-Frame-Options ์ถ๊ฐ - ํด๋ฆญ์ฌํน ๊ณต๊ฒฉ ๋ฐฉ์ด - ๋์ผ ์ถ์ฒ๋ง ๋ก๋ ๊ฐ๋ฅ. .headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::sameOrigin)) .addFilter(customAuthenticationFilter(authenticationManager, userService)); return http.build(); } /** * authenticationManager bean ์์ฑ * @param http HttpSecurity * @return authenticationManager bean */ @Bean public AuthenticationManager authenticationManager(HttpSecurity http, UserService userService, BCryptPasswordEncoder passwordEncoder) throws Exception { AuthenticationManagerBuilder authenticationManagerBuilder = http.getSharedObject(AuthenticationManagerBuilder.class); authenticationManagerBuilder.userDetailsService(userService).passwordEncoder(passwordEncoder); return authenticationManagerBuilder.build(); } /** * customAuthenticationFilter bean ์์ฑ * @return customAuthenticationFilter bean */ @Bean public CustomAuthenticationFilter customAuthenticationFilter(AuthenticationManager authenticationManager, UserService userService) { return new CustomAuthenticationFilter(authenticationManager, userService, env); } /** * ๋น๋ฐ๋ฒํธ ์ํธํ ๋ชจ๋ * @return ์ํธํ bean */ @Bean public BCryptPasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } }
- 0
- 7
- 2.5K
Q&A
"mvn spring-boot:run"์ ๊ตฌ๋์ ๋ฌธ์ ์๋๋ฐ, ์ต์ ์ ์ฃผ๋ฉด Build Fail ๋๋ ์์ธ์ ์ ์ ์์๊น์?
์๋์ฐ powerShell์์๋ ํ์ดํ(-)์ ์ฌ์ฉํ ๋ ๋ฐฑํฑ(`) ๋๋ ์์ ๋ฐ์ดํ('')๋ฅผ ์ฌ์ฉํ์ฌ escape ์ฒ๋ฆฌ๋ฅผ ํด์ฃผ์ด์ผ ํฉ๋๋ค.์๋ ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ์๋ฉด ํ์์์์๋ ์คํ ๊ฐ๋ฅํฉ๋๋ค.mvn spring-boot:run `-Dspring-boot.run.jvmArguments='-Dserver.port=9003'์์ธํ ๋ณด๋ฉด ์ ๋ก๊ทธ์ -Dspring-boot๊ฐ ์๋ฆฐ ๊ฒ์ ๋ณผ ์ ์๋ค์.
- 0
- 6
- 1.5K




