[Spring] Spring Security - Method Security

2022. 3. 30. 08:00ใ†Back-End ์ž‘์—…์‹ค/Spring Framework

728x90
๋ฐ˜์‘ํ˜•

 

๐Ÿš€ Spring Security - Method Security

    ๐Ÿ”ฝ  ๊ฐœ์š”

`Spring Seucrity`๋Š” Web ๊ธฐ๋ฐ˜ Security๋„ ์žˆ์ง€๋งŒ, `Method Security`๋ผ๋Š” ๊ธฐ๋Šฅ๋„ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์ด์—์š”.

์ด๊ฒƒ์€ `Service Layer`๋ฅผ ์ง์ ‘ ํ˜ธ์ถœํ•  ๋•Œ, ์ด์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ณด์•ˆ ๊ธฐ๋Šฅ์ธ ๊ฒƒ์ด์—์š”. Web ๊ธฐ๋ฐ˜์˜ Security๋ฅผ ์ ์šฉํ–ˆ์„๋•Œ๋Š” ์–ด์šธ๋ฆฌ์ง€ ์•Š๋Š” ๊ธฐ๋Šฅ์ธ ๊ฒƒ์ด์—์š”.

๋˜ํ•œ, `Web Application` ์™ธ์— `Desktop Application`์—๋„ ์ ์šฉ์ด ๊ฐ€๋Šฅํ•œ ๊ฒƒ์ด์—์š”.

 

 

 

 

    ๐Ÿ”ฝ  EnableGlobalMethodSecurity

`MethodSecurity`๋Š” `SecurityConfig`์„ค์ •์ด ์ ์šฉ๋˜์ง€ ์•Š๋Š” ๊ฒƒ์ด์—์š”.

`MethodSecurity`์šฉ ์„ค์ •์ด ๋”ฐ๋กœ ํ•„์š”ํ•œ๋ฐ ์ด ๋•Œ ์ด์šฉํ•˜๋Š” ๊ฒƒ์ด `@EnableGlobalMethodSecurity`์ธ ๊ฒƒ์ด์—์š”.

 

        ๐Ÿ“ฆ  ์†์„ฑ๋“ค

SecuredEnable prePostEnabled jsr250Enabled
@Secured๋ฅผ ์ด์šฉํ•˜์—ฌ ์ธ๊ฐ€ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉํ•˜๋Š” Option @PreAuthorize, @PostAuthorize๋ฅผ ์ด์šฉํ•˜์—ฌ
์ธ๊ฐ€ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉ ํ•˜๋Š” Option
@RolesAllowed๋ฅผ ์ด์šฉํ•˜์—ฌ ์ธ๊ฐ€ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜๊ณ  ์‹ถ์„ ๋•Œ, ์‚ฌ์šฉํ•˜๋Š” Option
Default Value : false Default Value : false Dafault Value : false

โ–บ @Secured, @RolesAllowd

  โ— ํŠน์ • Method ํ˜ธ์ถœ ์ด์ „ ์ด์šฉ์ž ๊ถŒํ•œ ํ™•์ธ
  โ— Spring EL ๋ฏธ์ง€์›
  โ— `@Secured`๋Š” `Spring`์—์„œ ์ง€์›ํ•˜๋Š” Annotaion์ด๋ฉฐ, `@RolesAllowed`๋Š” Java Standard

 

๋ฐ˜์‘ํ˜•

 

 

โ–บ @PreAuthorize, @PostAuthorize

  โ— ํŠน์ • Method ํ˜ธ์ถœ ์ „, ํ›„ ์ด์šฉ์ž ๊ถŒํ•œ ํ™•์ธ
  โ— Spring EL ์ง€์›
  โ— Spring์—์„œ ์ง€์›ํ•˜๋Š” Annotion
  โ— `PostAuthorize`๋Š” ํ•ด๋‹น Method์˜ ๋ฐ˜ํ™˜(Return)๊ฐ’์„ `returnObject`๋กœ ์ฐธ์กฐํ•˜์—ฌ SpEl์„ ํ†ตํ•ด ์ธ๊ฐ€ ์ฒ˜๋ฆฌ

 

 

 

 

โ–บ @PreAuthorize, @PostAuthorize

  โ— Web ๋ฐฉ์‹์—์„œ๋Š” Role์˜ ๊ณ„์ธต ๊ตฌ์กฐ ์„ค์ •์„ ํ•ด ์ฃผ์ง€๋งŒ, `MethodSecurity`์—์„œ๋Š” ์ ์šฉ๋˜์ง€ ์•Š์Œ
  โ— `MethodSecurity`์šฉ `RoleHieachy` ์„ค์ • ๋ณ„๋„ ํ•„์š”
  โ— `GlobalMethodSecurityConfiguration`Class ์ƒ์† ๋’ค `accessDecisionManager()` Override
        ํ•œ ๋’ค `WebSecurity`์„ค์ •์—์„œ ํ•ด์ค€๊ฒƒ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ `RoleHirearachy`์„ค์ •ํ•˜๊ณ , `accessDicisionVoter`์ถ”๊ฐ€

 

 

 

 

 

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•