Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[신성수] 인가(Authorization) 리뷰 요청 드립니다. #28

Open
wants to merge 20 commits into
base: shinseongsu
Choose a base branch
from

Conversation

shinseongsu
Copy link

늦게 제출해서 죄송합니다. 😢
주말만 시간이 허용되어서 그래도 열심히 PR올리도록 하겠습니다.

요구사항 정리

🚀 1단계 - AuthorizationManager를 활용

  • AuthorizationManager를 활용하여 인가 과정 추상화
    • SecuredAuthorizationManager 구현
    • RequestAuthorizationManager 구현
    • SecuredAuthorizationManager 구현

🚀 2단계 - 요청별 권한 검증 정보 분리

  • 요청별 권한 검증 정보를 별도의 객체로 분리하여 관리
    • RequestMatcher 작성
    • AnyRequestMatcher 구현
    • MvcRequestMatcher 구현
    • RequestMatcherEntry 작성

Copy link

@jinyoungchoi95 jinyoungchoi95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

안녕하세요 성수님 😄

Authorization 미션을 함께하게 된 최진영입니다.

미션 잘 진행해주셨네요 👍 몇가지 코멘트 남겨두었으니 확인부탁드려요 😄

궁금하거나 고민이 되는 부분이 있으시다면 언제든 pr 코멘트 또는 dm으로 요청 부탁드립니다.
감사합니다 🙇‍♂️

Comment on lines +59 to +63
final AuthorizationManager<HttpServletRequest> authorizationManager = new RequestAuthorizationManager(List.of(
createMvcMatcher(GET, "/members", new AuthorityAuthorizationManager<>("ADMIN")),
createMvcMatcher(GET, "/members/me", new AuthenticatedAuthorizationManager<>()),
createMvcMatcher(GET, "/search", new PermitAllAuthorizationManager<>())
), createDefaultMatcher(new DenyAllAuthorizationManager<>()));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

잘 추가해주셨네요 👍

@@ -0,0 +1,5 @@
package nextstep.security.authorization.manager;

public interface AuthorizationResult {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

미션내의 요구사항은 AuthorizationDecision이었으나 최근 버전에서의 추상화를 잘 구현해주셨네요

@@ -0,0 +1,20 @@
package nextstep.security.authorization.manager;

public enum AuthorizationDecision implements AuthorizationResult {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true와 false로 구성되어있어 enum으로 생각해볼 수도 있으나 실제 구현체에서는 AuthorizationDecision을 상속받아 구현하는 새로운 구현체들도 있어 enum으로 사용되지는 않습니다.

일반적으로 enum을 구성하는 것은 몇가지 고정값이 있기 때문에 enum으로 표현하지는 않고 정말 static한 정보들로 표기될때에만 사용되어요. 예를들면 HttpStatus는 400, 401과 같은 코드가 있기 때문에 각각을 표기하는 것처럼요.

그래서 사실은 AuthorizationDecision은 granted가 있다 없다로 생성되는 객체일뿐 enum에 적합하진 않습니다.

Comment on lines +6 to +8
- [x] SecuredAuthorizationManager 구현
- [x] RequestAuthorizationManager 구현
- [x] SecuredAuthorizationManager 구현

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- [x] SecuredAuthorizationManager 구현
- [x] RequestAuthorizationManager 구현
- [x] SecuredAuthorizationManager 구현
- [x] SecuredAuthorizationManager 구현
- [x] RequestAuthorizationManager 구현

중복되어있네요 :)

Comment on lines +20 to +23
return authentication != null
&& authentication.isAuthenticated()
&& authentication.getAuthorities()
.contains(method.getAnnotation(Secured.class).value());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SecuredAuthorizationManager의 구현 내용과 AuthorityAuthorizationManager의 구현 내용을 생각해보면 서로 비슷한 동작이 반복되는 것을 볼 수 있는데요.

AuthorizationManager들의 구현체들은 각각 따로 구성되는 것이 아닌 서로를 사용할 수 있도록 연결할 수 있어요. 그래서 AuthorityAuthorizationManager에서 authority가 있는지를 체크하는 로직을 현재와 같이 전부 몰아넣고, SecuredAuthorizationManager@Secured에 있는 값을 꺼내 AuthorityAuthorizationManager에게 인가여부를 묻는 형태로 구성이 될 수 있습니다.

https://github.com/spring-projects/spring-security/blob/main/core/src/main/java/org/springframework/security/authorization/method/SecuredAuthorizationManager.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants