๐ Spring/Spring Security
2022.12.27
CORS (Cross-Origin Resource Sharing) ์ด๋? A๋ผ๋ ๋๋ฉ์ธ์์ ์ ๊ณต๋๋ FE์์ → B๋ผ๋ ๋๋ฉ์ธ์ผ๋ก ์ ๊ณต๋๋ BE์ HTTP ์์ฒญ์ ํ์ ๊ฒฝ์ฐ, ๋ธ๋ผ์ฐ์ ๋ ์ด๋ฅผ ์๋ก ๋ค๋ฅธ ๋๋ฉ์ธ์์ ๋ฆฌ์์ค๋ฅผ ๊ณต์ ํ๋ ๊ฒ์ด๋ผ ํ๋จํ๊ณ ๊ทธ๊ฒ์ ๋ฐฉ์งํ๊ธฐ ์ํด ํธ์ถ์ ๊ธ์งํ๋ ๊ฒ์ด๋ค. Preflight Request ๋ธ๋ผ์ฐ์ ์์ ์ค์ HTTP ์์ฒญ์ ๋ณด๋ด๊ธฐ ์ ๋ธ๋ผ์ฐ์ ์ค์ค๋ก ์ด ์์ฒญ์ ๋ณด๋ด๋ ๊ฒ์ด ์์ ํ์ง ์๋น ์์ฒญ์ ํ๊ฒ ๋๋๋ฐ ์ด๊ฒ ๋ฐ๋ก Preflight Request๋ผ๊ณ ํฉ๋๋ค. ์ด Preflight Request๋ OPTION ๋ฉ์๋๋ฅผ ์ด์ฉํด ์์ฒญํ๋๋ฐ ์๋ฒ์์ ๋ณด๋ด์ค ์๋ต ํค๋์ Access-Controller-* ํค๋๋ค์ด ์ ๊ตฌ์ฑ๋์ด์๋์ง ํ์ธํฉ๋๋ค. GET, POST, HEAD ์์ฒญ..
๐ Spring/Spring Security
2022.12.09
Spring Boot 2.7 (Spring 5.7.0-M2) ๋ถํฐ WebSecurityConfigurerAdapter๋ Deprecated๊ฐ ๋์๋ค. Spring Security without the WebSecurityConfigurerAdapter In Spring Security 5.7.0-M2 we deprecated the WebSecurityConfigurerAdapter, as we encourage users to move towards a component-based security configuration. authz .anyRequest().authenticated() ) .httpBasic(withDefaults()); } } ์คํ๋ง์ SecurityFilterChain ๋น์ ๋ฑ๋กํ..
๐ Spring
2022.07.04
์คํ ํ๊ฒฝ Spring Boot 2.7.1 Gradle 7.4.1 Maven 3.8.5 ๋น๋ ์์คํ
์ค์ Gradle ๋๋ณด๊ธฐ plugins { id 'org.springframework.boot' version '2.7.1' id 'io.spring.dependency-management' version '1.0.11.RELEASE' id 'java' id 'org.asciidoctor.jvm.convert' version '3.3.2' // (1) } group = 'com.example' version = '0.0.1-SNAPSHOT' sourceCompatibility = '11' configurations { compileOnly { extendsFrom annotationProcessor } }..
๐ Spring
2022.06.29
ํ์ ๋๋ฉ์ธ์์ Username์ด ์ค๋ณต์ด ๋๋ฉด ์๋๋ฏ๋ก ์๋ ๊ฐ์ด ๋ก์ง์ ์ถ๊ฐํ์ต๋๋ค. Optional account = accountRepository.findByUsername(username); if (account.isPresent()) throw new AccountDuplicateException(username); ํ์ง๋ง Optional์ ๋ฐํํ์ง ๋ง๊ณ ifPresent๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฐ๋ก Exception์ ์ฒ๋ฆฌํ ์ ์์ต๋๋ค. accountRepository.findByUsername(username) .ifPresent(a -> { throw new AccountDuplicateException(username) }); ํจ์ฌ ๋ ๊ฐ๊ฒฐํด์ง๊ณ ์์๋ณด๊ธฐ ์ฌ์ด ์ฝ๋๊ฐ ๋์์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค.
๐ Spring/Spring Security
2022.06.21
Spring boot + Security ๋ฅผ ์ฌ์ฉํ๊ณ ์๋๋ฐ ์๋ฌ ์ฝ๋ ๋ง๋ค ํ์ด์ง๋ฅผ ๋ณด์ฌ์ฃผ๊ณ ์ถ์๋ฐ ์ด๋ป๊ฒ ํด์ผํ๋์ง ๋ฐฉ๋ฒ์ ์๊ฐํด๋ณด๋ค๊ฐ ๋๊ฐ์ง ๋ฐฉ๋ฒ์ด ์๊ฐ๋ฌ์ต๋๋ค. 1. EntryPoint, Handler ์ฌ์ฉ authenticationEntryPoint, accessDeniedHandler์์ ์ฌ์ฉ์์๊ฒ ํด๋น ์๋ฌ ํ์ด์ง๋ก ๋ฆฌ๋ค์ด๋ ์
์ ์ํค๋ ๋ฐฉ๋ฒ์
๋๋ค. Security Config /* Security Config */ @Override protected void configure(HttpSecurity http) throws Exception { http // .. .exceptionHandling() .authenticationEntryPoint(new MyAuthenticationEntryP..
๐ Spring
2022.05.01
Mockito๋ก ํ
์คํธ๋ฅผ ์์ฑํด๋ณด์ ํ๋ก์ ํธ ํ๊ฒฝ: Spring-boot, Junit5, Mockito ๋ชจ๋ ์ฝ๋๋ Github์ ์์ต๋๋ค :) Mockito Mockito๋? ํ
์คํธ ํ๋ ์์ํฌ๋ก ํ
์คํธํ ๋ ๋ชจ๋ ๋น์ ์ผ์ผํ ์ฃผ์
์ํค์ง ์๊ณ , Mock ๊ฐ์ฒด(๊ฐ์ง ๊ฐ์ฒด)๋ฅผ ์ฃผ์
์์ผ ํ์๋ฅผ ํ
์คํธํ ์ ์๊ณ , ์์ง ์์ฑ๋์ง ์์ ์ฝ๋๋ค(์์กด์ฑ ๊ฐ์ฒด) ๋๋ ๊ตฌํํ๊ธฐ ์ด๋ ค์ด ์์กด์ฑ ๊ฐ์ฒด๋ค์ Mockingํ์ฌ ํ
์คํธ ํ ์ ์์ต๋๋ค. ์์กด์ฑ (dependency) spring boot๋ฅผ ์ฌ์ฉ์ค์ด๋ผ๋ฉด, spring-boot-starter-test ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ์ด๋ฏธ JUnit5์ Mockito๊ฐ ํฌํจ๋์ด์์ผ๋ฏ๋ก ์์กด์ฑ์ ์ถ๊ฐํด์ฃผ์ง ์์๋ ๋ฉ๋๋ค. Spring.io - 41.Testing Mock ํ
์คํธ ์์ moc..