Backend Language/Spring boot(Java)

Spring Security ๋ฐ Jwt๋ฅผ ์ด์šฉํ•˜์—ฌ ๋กœ๊ทธ์ธ ๋กœ์ง์„ ๊ตฌํ˜„ํ•˜๋˜ ์ค‘, ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€๋‹ค. org.springframework.security.authentication.BadCredentialsException: ์ž๊ฒฉ ์ฆ๋ช…์— ์‹คํŒจํ•˜์˜€์Šต๋‹ˆ๋‹ค. at org.springframework.security.authentication.dao.DaoAuthenticationProvider.additionalAuthenticationChecks(DaoAuthenticationProvider.java:80) at org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.authenticate(Ab..
์•ฑ ๋Ÿฐ์นญ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋ฉด์„œ, ๋กœ๊ทธ์•„์›ƒ api๋ฅผ ์ƒ์„ฑํ–ˆ๋‹ค. JWT๋กœ User์˜ ์ •๋ณด๋ฅผ ์ ‘๊ทผํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ–ˆ๊ธฐ ๋•Œ๋ฌธ์—, ๋กœ๊ทธ์•„์›ƒ์„ ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” AccessToken์˜ ์‹œ๊ฐ„์„ ๋งŒ๋ฃŒํ•ด์•ผํ–ˆ๋‹ค. ์ƒ์„ฑํ•œ Token์„ ๋งŒ๋ฃŒํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” Redis๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•œ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๊ฒŒ ๋˜์—ˆ๊ณ , ๋ธ”๋กœ๊ทธ์— ์ž‘์„ฑํ•˜๋ฉฐ ๋ณต์Šตํ•ด๋ณด๊ณ ์ž ํ•œ๋‹ค. 1. build.gradle implementation 'org.springframework.boot:spring-boot-starter-data-redis' build.gradle์— ์œ„์™€ ๊ฐ™์€ dependencies ์ถ”๊ฐ€ 2. RedisRepositoryConfig @RequiredArgsConstructor @Configuration @EnableRedisRepositories public c..
spring security๋ฅผ ๊ณต๋ถ€ํ•˜๊ณ ์ž, spring boot file์„ ์ƒ์„ฑํ•˜์˜€๋Š”๋ฐ build ์‹œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜์˜€๋‹ค. ํ”„๋กœ์ ํŠธ ๋ฒ„์ „์ด 17์ด์–ด์„œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€๊ณ , 11๋กœ downgrade๋ฅผ ํ•ด์ฃผ์–ด์„œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜์˜€๋‹ค. # build.gradle file ์ˆ˜์ • group = 'com.example' version = '0.0.1-SNAPSHOT' sourceCompatibility = '17' ----------------------------------------------- group = 'com.example' version = '0.0.1-SNAPSHOT' sourceCompatibility = '11' #๋ณ€๊ฒฝ
์ง€๋‚œ UMC 1๊ธฐ ์•ฑ ๊ฐœ๋ฐœ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋ฉด์„œ ์‚ฌ์šฉํ•œ ๊ตฌ์กฐ์— ๋Œ€ํ•ด์„œ ๊ฐ„๋‹จํ•˜๊ฒŒ ์ •๋ฆฌํ•ด๋ณด๊ณ ์ž ํ•œ๋‹ค. ์ปจํŠธ๋กค๋Ÿฌ: ์›น MVC(Model, View, Controller)์˜ ์ปจํŠธ๋กค๋Ÿฌ ์—ญํ•  ์„œ๋น„์Šค: ํ•ต์‹ฌ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง ๊ตฌํ˜„ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ: ๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค์— ์ ‘๊ทผ, ๋„๋ฉ”์ธ ๊ฐ์ฒด๋ฅผ DB์— ์ €์žฅํ•˜๊ณ  ๊ฐ„๋ฆฌ ๋„๋ฉ”์ธ: ๋น„์ฆˆ๋‹ˆ์Šค ๋„๋ฉ”์ธ ๊ฐ์ฒด ์˜ˆ) ํšŒ์›, ์ฃผ๋ฌธ, ์ฟ ํฐ, ๋“ฑ๋“ฑ ์ฃผ๋กœ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ €์žฅํ•˜๊ณ  ๊ด€๋ฆฌ๋จ
# ํ”„๋กœ์ ํŠธ ํŒŒ์ผ๋กœ ์ด๋™ cd //project file path # ๋นŒ๋“œ ์ œ๊ฑฐ ํ›„ ๋นŒ๋“œ gradlew clean build # ๋นŒ๋“œ # gradlew.bat ํŒŒ์ผ ์‹คํ–‰ ๋ช…๋ น์–ด $gradlew build # ์‹คํ–‰ํ•˜๊ธฐ java -jar (ํ”„๋กœ์ ํŠธ ๋ช…)-0.0.1-SNAPSHOT.jar ํ”„๋กœ์ ํŠธ ์‹คํ–‰ํ•˜๊ธฐ์œ„ํ•œ ํŒŒ์ผ์€ ํ”„๋กœ์ ํŠธํŒŒ์ผ/build/libs์— ๋“ค์–ด์žˆ๋‹ค. path๋กœ ์ด๋™ํ•˜์—ฌ java -jar + ์ด๋ฅผ ๋ณต์‚ฌ, ๋ถ™์—ฌ๋„ฃ๊ธฐ ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.
์œ„ ์‚ฌ์ดํŠธ์—์„œ ์›ํ•˜๋Š” Project, dependencies๋ฅผ ์„ ํƒํ•œ ํ›„, Generate๋ฅผ ํ•˜๊ฒŒ ๋˜๋ฉด zipํŒŒ์ผ์„ ๋‹ค์šด ๋ฐ›๊ฒŒ ๋œ๋‹ค. ์••์ถ•์„ ํ’€๊ณ  ์›ํ•˜๋Š” IDE์—์„œ ํ”„๋กœ๊ทธ๋žจ(build gradle ํŒŒ์ผ)์„ ์—ด๋ฉด ๋œ๋‹ค. ๋‚˜๋Š” Intellj๋ฅผ ์‚ฌ์šฉํ•˜๊ณ ์ž ํ•œ๋‹ค. ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•œ ํ›„, build gradle ํŒŒ์ผ์„ ๋ณด๋ฉด ์„ ํƒํ•œ dependencies๊ฐ€ ๋“ค์–ด์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. ํ”„๋กœ์ ํŠธ๋ฅผ run ํ•˜๊ฒŒ ๋˜๋ฉด localhost:8080์„ ํ†ตํ•ด ์œ„ ํ™”๋ฉด์ด ๋‚˜ํƒ€๋‚˜๊ฒŒ ๋œ๋‹ค. ์ด๋Ÿผ ์„ฑ๊ณต์ด๋‹ค.
์•ฑ ๊ฐœ๋ฐœ ํ”„๋กœ์ ํŠธ๋ฅผ ํ•˜๋ฉด์„œ User๊ฐ€ ์“ด ๊ธ€์„ ๋ถˆ๋Ÿฌ์˜ฌ ๋•Œ, ๋ชจ๋“  ๊ธ€์ด ๋ถˆ๋Ÿฌ์™€์ง€๊ฒŒ ๋˜๊ธฐ ๋•Œ๋ฌธ์— ์ผ์ • ๋ถ€๋ถ„์˜ ๊ธ€๋งŒ ๋ถˆ๋Ÿฌ์™€์ง€๊ฒŒ api๋ฅผ ์ˆ˜์ •ํ•ด๋‹ฌ๋ผ๋Š” ๋ถ€ํƒ์„ ๋ฐ›์•˜๋‹ค. ์ธํ„ฐ๋„ท์— ์ฐพ์•„๋ณด๋‹ˆ, FrontEnd์˜ ์—ญํ• ์ธ ๊ฒƒ ๊ฐ™์•˜์ง€๋งŒ ์ผ๋‹จ ์•Œ๊ฒ ๋‹ค๊ณ  ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ์ตœ๋Œ€ํ•œ api๋ฅผ ์ˆ˜์ •ํ•ด๋ณด๊ณ ์žํ–ˆ๋‹ค. (์•ž์œผ๋กœ๋Š” ์ด๊ฒŒ ์„œ๋ฒ„์˜ ์—ญํ• ์ธ์ง€, ํ”„๋ก ํŠธ์˜ ์—ญํ• ์ธ์ง€ ๋‹ค์‹œ ํ™•์ธํ•œ ํ›„ api๋ฅผ ์ƒ์„ฑํ•ด์•ผ๊ฒ ๋‹ค) Jpa Repository๋ฅผ ํ†ตํ•ด์„œ User๊ฐ€ ์“ด ๊ธ€์˜ ๊ฐ’์„ ๋ถˆ๋Ÿฌ์˜ค๊ฒŒ ๋œ๋‹ค. ์ด๋•Œ, Return variable์ด List๊ฐ€ ๋˜๋ฏ€๋กœ ๊ฐ’์„ ๋ณ€๊ฒฝํ•˜๋Š”๋ฐ for๋ฌธ์„ ์‚ฌ์šฉํ•ด์„œ List์— ์žˆ๋Š” ๊ฐ’์„ ๋˜๋‹ค๋ฅธ List๋กœ ์˜ฎ๊ฒจ์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ณต์žกํ•œ ๋ฐ˜๋ณต๋ฌธ์ด ์‚ฌ์šฉ๋  ๊ฒƒ์œผ๋กœ ์˜ˆ์ƒ๋˜์—ˆ๋‹ค. for๋ฌธ์œผ๋กœ List๋ฅผ ๋˜ ๋‹ค๋ฅธ List๋กœ ์˜ฎ๊ธฐ๋ฉด์„œ ์•ˆ์— ์žˆ๋Š” ๊ฐ’์„ ๋ณ€๊ฒฝํ•˜๋Š”..
๊ทธ ์ „๊นŒ์ง€๋Š” api์—์„œ ์ง์ ‘ userid๋ฅผ ๊ฑด๋‚ด๊ณ  JPA CRUD FindByUserId๋ฅผ ํ†ตํ•ด ์œ ์ €์˜ ์ •๋ณด๋ฅผ ๋ถˆ๋Ÿฌ์™”์—ˆ๋‹ค. ํ•˜์ง€๋งŒ ํšŒ์›๊ฐ€์ž…์„ ํ•˜๊ณ , ๋กœ๊ทธ์ธ์„ ํ•˜๊ฒŒ ๋˜๋ฉด token์„ ์ œ๊ณตํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ UMC APP API๋ฅผ ํŒ€์›๋ถ„๊ป˜์„œ ์ƒ์„ฑํ•ด์ฃผ์…จ๋‹ค. ๊ทธ๋ ‡๋‹ค๋ฉด, token(authorization์— ์žˆ๋Š”)๋ฅผ ๊ณ„์† ์‚ฌ์šฉํ•ด์„œ json์„ ๋ฐ›์•„์™€์•ผํ•˜๋Š” ์ƒํ™ฉ์—์„œ๋Š” userId๋ฅผ ๋ณด๋‚ด์ง€ ์•Š๊ณ  jwt๋ฅผ ํ†ตํ•ด์„œ ์ •๋ณด๋ฅผ ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ์ง€ ์•Š์„๊นŒํ•˜๋Š” ์˜๋ฌธ์ด ๋“ค์—ˆ๋‹ค. ์ด์— ๋ฐœ๊ฒฌํ•˜๊ฒŒ ๋œ 3๊ฐ€์ง€ ๋ฐฉ๋ฒ• ์ค‘, ๐Ÿ’ป๋™์•„๋ฆฌ ์•ฑ ํ”„๋กœ์ ํŠธ์—์„œ๋Š” Principal์„ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค. (@AuthenticationPrincipal ์ด๋‚˜ SecurityContextHolder, Authentication ๋ชจ๋‘ ์‚ฌ์šฉํ–ˆ๋Š”๋ฐ ์—๋Ÿฌ ๋‚จ,, ์ด์œ ๋ฅผ ๋ชจ๋ฅด๊ฒ ์›€,,..
โ€ป ํ•ด๊ฒฐ ๋‚ด์šฉ์€ ๋งจ ๋งˆ์ง€๋ง‰์— ์žˆ์Œ โ€ป ๊ฐ์ฒด์ง€ํ–ฅ์ ์‚ฌ๊ณ ์™€ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ˆ˜์—…์„ ๋“ฃ๋˜ ์ค‘ ์ด์™€ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€๋‹ค. ๊ต์ˆ˜๋‹˜์ด ์„ค๋ช…ํ•ด์ฃผ์‹  ์ฝ”๋“œ๋ฅผ ๋˜‘๊ฐ™์ด ์ž‘์„ฑํ–ˆ๋Š”๋ฐ, ๋‚˜๋งŒ ์ด๋Ÿฐ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒƒ์ด๋‹ค. ํŠนํžˆ @RestController๋ฅผ ์ฃผ์„์ฒ˜๋ฆฌ ํ•ด์ œํ•˜๊ณ  ์ง„ํ–‰ํ–ˆ๋”๋‹ˆ ๋ฐœ์ƒํ•œ ์˜ค๋ฅ˜์˜€๋‹ค,,, ( ๊ทธ ์ „์—๋Š” ์ž˜๋งŒ ๋๋Š”๋ฐ,, ์™œ๊ทธ๋ ค,,) ์˜ค๋ฅ˜๋‚ด์šฉ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2021-12-02 13:15:47.039 ERROR 28612 --- [ main] o.s.boot.SpringApplication : Application ru..
ํ•™๊ต ์ „๊ณต ์ˆ˜์—… ์‹œ๊ฐ„์— Sping boot๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด์„œ, Httpie๋ฅผ ์„ค์น˜๋ฅผ ํ•ด์•ผ๋งŒ ํ–ˆ๋‹ค. Mac OS์—์„œ๋Š” ๋‹ค์šด๋กœ๋“œ๊ฐ€ ์‰ฝ์ง€๋งŒ, Winodw OS์—์„œ๋Š” Python์ด ์„ค์น˜๋˜์–ด ์žˆ์ง€ ์•Š์•„ ์„ค์น˜๊ฐ€ ์šฉ์ดํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— Winodw OS์—์„œ Httpie๋ฅผ ์„ค์น˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ž‘์„ฑํ•˜๊ณ ์ž ํ•œ๋‹ค. https://luji.tistory.com/99 httpie Windows์—์„œ ์„ค์น˜ํ•˜๊ธฐ httpie๋ž€? ํŒŒ์ด์„ ์—์„œ ๊ฐœ๋ฐœ๋œ ์œ ํ‹ธ๋ฆฌํ‹ฐ๋กœ http ๊ฐœ๋ฐœ์ด๋‚˜ ๋””๋ฒ„๊น… ์šฉ๋„๋กœ ์‚ฌ์šฉ๋œ๋‹ค. ์‚ฌ์šฉ์„ฑ์ด ์‰ฌ์šฐ๋ฉด์„œ json์ด ๋‚ด์žฅ๋˜์–ด์žˆ๋‹ค. ๊ฐ€๋…์„ฑ์ด ๋›ฐ์–ด๋‚˜๋ฉฐ ๊ธฐํƒ€ ์žฅ์ ๋“ค์ด ์žˆ์Œ. ๋ณดํ†ต ๋ฆฌ๋ˆ…์Šค๋‚˜ ๋งฅ์—์„  yum, apt, bre luji.tistory.com ์ด ๋ธ”๋กœ๊ทธ๋ฅผ ํ†ตํ•ด์„œ Httpie ์„ค์น˜๋ฅผ ์ง„ํ–‰ํ–ˆ๋‹ค. 1. ๋ฐ‘ ๋งํฌ์— ๋“ค์–ด๊ฐ€์„œ Python์„ ..
chaerlo127
'Backend Language/Spring boot(Java)' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก