๐ŸŒธ [SPRING BOOT] | ์‹œํ๋ฆฌํ‹ฐ - ํšŒ์›๊ฐ€์ž… ์ด๋ฉ”์ผ ์ธ์ฆ ์—๋Ÿฌ, ํ”„๋กœํ•„ ์ด๋ฏธ์ง€ ์ €์žฅ ์—๋Ÿฌ , NullPointerException , spring boot security๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•˜๋Š”๋ฐ security login form์ด ๋‚˜์˜ฌ๋•Œ

2808 ๋‹จ์–ด ERR๐Ÿ˜ˆR.zipERR๐Ÿ˜ˆR.zip

๐ŸŸฆ ํšŒ์›๊ฐ€์ž… ์ด๋ฉ”์ผ ์ธ์ฆ ์—๋Ÿฌ

๐Ÿ”น ์—๋Ÿฌ

์„ ์ƒ๋‹˜ ๊ฑฐ ๊ทธ๋Œ€๋กœ zip ๋‹ค์šด, yaml ์ˆ˜์ •, db์—ฐ๊ฒฐ ํ–ˆ๋Š”๋ฐ ์ด๋ฉ”์ผ ์ธ์ฆ์ด ์•ˆ๋๋‹ค.

์›์ธ :

  • DB์— authCd๊ฐ€ null์ด ๋˜์–ด์•ผ ํ•˜๋Š”๋ฐ ๊ทธ๋Œ€๋กœ ๋‚จ์•„์žˆ์–ด์„œ
  • ํšŒ์›๊ฐ€์ž…์ด ๋˜์ง€ ์•Š์•˜๋‹ค.

๐Ÿ”น ํ•ด๊ฒฐ

  • securityํŒจํ‚ค์ง€์˜ SecurityConfig์˜ configure(HttpSecurity http)์˜ http.authorizeRequests().antMatchers()๋ฅผ ์ˆ˜์ •
  • "/user/auth" ๋ฅผ ์ถ”๊ฐ€
        http.authorizeRequests()
                .antMatchers("/user/login", "/user/join").permitAll()
                .anyRequest().authenticated();

๐Ÿ‘‡

        http.authorizeRequests()
                .antMatchers("/user/login", "/user/join", "/user/auth").permitAll()
                .anyRequest().authenticated();

๐ŸŸฆ ํ”„๋กœํ•„ ์ด๋ฏธ์ง€ ์ €์žฅ ์—๋Ÿฌ , NullPointerException

๐Ÿ”น ์—๋Ÿฌ

โ— NullPointerException

  • userService์—์„œ
  • imgArr์ด Null์ด๋ผ์„œ
  • ์ด๋ฏธ์ง€ ์ €์žฅ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ์—๋Ÿฌ๊ฐ€ ๋‚ฌ๋‹ค

๐Ÿ”น ํ•ด๊ฒฐ

  • profile.html์—์„œ <input type="file">ํƒœ๊ทธ์˜ name์„ ๋˜‘๊ฐ™์ด imgArr๋กœ
  • UserService์™€ profile.html์—์„œ์˜ ์ด๋ฆ„์„ ํ†ต์ผํ•ด์ฃผ์—ˆ๋”๋‹ˆ ํ•ด๊ฒฐ๋˜์—ˆ๋‹ค.

๐ŸŸฆ spring boot security๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•˜๋Š”๋ฐ security login form์ด ๋‚˜์˜ฌ๋•Œ

๐Ÿ”น ์—๋Ÿฌ

pom.xml์— security ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์žˆ์—ˆ์ง€๋งŒ ์‚ฌ์šฉํ•˜์ง€ ์•Š์€ ์ƒํƒœ์—์„œ ์‹คํ–‰์„ ํ–ˆ๋Š”๋ฐ security login form์ด ๋‚˜์™”๋‹ค.

  • ๊ทธ๋ž˜์„œ pom.xml์˜ security ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ (org.thymeleaf.extras/thymeleaf-extras-springsecurity5) ์ฃผ์„์ฒ˜๋ฆฌ๋ฅผ ํ–ˆ๋‹ค
  • ๊ทธ๋Ÿฌ๋‚˜ ์—ฌ์ „ํžˆ security login form์ด ๋‚˜์™”๋‹ค.

๐Ÿ”น ์›์ธ

  • org.thymeleaf.extras/thymeleaf-extras-springsecurity5
    ๋ง๊ณ ๋„
  • org.springframework.boot/ spring-boot-starter-security
    ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์žˆ์—ˆ๋‹ค.

๐Ÿ”น ํ•ด๊ฒฐ

  • pom.xml์—
    org.springframework.boot/ spring-boot-starter-security์™€ org.thymeleaf.extras/ thymeleaf-extras-springsecurity5 ๋ฅผ ๋ชจ๋‘ ์ฃผ์„์ฒ˜๋ฆฌ ํ›„
  • Rearoadํ•˜๋‹ˆ security login form์ด ์‚ฌ๋ผ์กŒ๋‹ค.

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ