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

2단계 - 인가(Authorization) 리뷰 요청 드립니다. #22

Open
wants to merge 10 commits into
base: yeongunheo
Choose a base branch
from

Conversation

yeongunheo
Copy link

안녕하세요 이슬님!

Spring Security 2단계 인가 미션 리뷰 요청 드립니다.

애노테이션을 활용한 인가 처리가 잘 이해가 되지 않아, SecuredAuthorizationManager를 만든 뒤 AuthorizationManagerBeforeMethodInterceptor에서 이를 가져다 사용하는 방향으로 구현했는데, 이게 괜찮은 방향인지는 잘 모르겠네요. 이부분에 대한 피드백을 한번 받아보고 싶습니다!

그리도 RequestMatcherRegistry의 역할이 필요한 RequestMatcher을 모두 등록한 뒤 HTTP 요청이 들어왔을 때 적절한 RequestMatcher를 찾아서 반환하는 것으로 이해했는데 올바르게 이해한걸까요?

RequestMatcherRegistry도 한번 직접 구현해보고 싶었는데 첫 리뷰 요청이 너무 길어지는 것 같아 이번 단계에서는 구현하지 못했습니다.

감사합니다.

Copy link

@parkeeseul parkeeseul left a comment

Choose a reason for hiding this comment

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

안녕하세요! 인가 미션을 함께 하게 된 박이슬 입니다.
미션 잘 진행해 주셨네요!
spring security의 구조에 대해 고민하신 노력이 느껴집니다 👍
몇 가지 코멘트 남겨두었으니 한번 확인 부탁드릴게요!
내일 강의도 화이팅 입니다 🔥


private final Set<String> authorities;

public AuthorityAuthorizationManager(Set<String> authorities) {

Choose a reason for hiding this comment

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

가변인자(String... authorities)를 사용하면 여러 권한을 더 쉽게 전달할 수 있을 것 같네요 😄
new AuthorityAuthorizationManager("ROLE_ADMIN", "ROLE_USER")

}

private SecuredAuthorizationManager securedAuthorizationManager() {
return new SecuredAuthorizationManager(new AuthorityAuthorizationManager<>(Set.of("ADMIN")));

Choose a reason for hiding this comment

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

현재는 @Secured 를 사용할 경우 ADMIN 권한 밖에 체크가 불가능 하겠네요 🤔
Spring Security 에서는 AuthoritiesAuthorizationManager 를 사용하여 @Secured("ROLE_ADMIN")와 같은 권한을 체크하고 있는데 이부분에 대해 한번 학습해보고 개선해보면 좋을 것 같아요 😄


@DisplayName("인증된 사용자는 자신의 정보를 조회할 수 있다.")
@Test
void request_success_members_me() throws Exception {

Choose a reason for hiding this comment

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

테스트 코드 👍

import org.springframework.aop.PointcutAdvisor;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;

public class AuthorizationManagerBeforeMethodInterceptor implements MethodInterceptor, PointcutAdvisor {

Choose a reason for hiding this comment

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

Q.애노테이션을 활용한 인가 처리가 잘 이해가 되지 않아, SecuredAuthorizationManager를 만든 뒤 AuthorizationManagerBeforeMethodInterceptor에서 이를 가져다 사용하는 방향으로 구현했는데, 이게 괜찮은 방향인지는 잘 모르겠네요. 이부분에 대한 피드백을 한번 받아보고 싶습니다!

A. 잘 구현해 주셨네요! 👍
AuthorizationManagerBeforeMethodInterceptor 에서 @Secured가 적용된 메서드를 감지하고, AuthorizationManager를 실행하여 사용자의 권한을 확인한 후 인가 여부를 결정하는 구조로 동작하는 방식으로 잘 구현해 주셨습니다.

다만, 다른 코멘트에서 남겼듯이 AuthoritiesAuthorizationManager 에 대해서는 한번 확인해 보시고 개선해 보면 좋을 것 같아요.
혹시 추가적으로 어려우신 부분이 있다면 남겨주시면 답변 드리도록 하겠습니다 😄

@Bean
public SecurityFilterChain securityFilterChain() {
return new DefaultSecurityFilterChain(
List.of(
new SecurityContextHolderFilter(),
new UsernamePasswordAuthenticationFilter(userDetailsService()),
new BasicAuthenticationFilter(userDetailsService()),
new CheckAuthenticationFilter()
new AuthorizationFilter(new RequestMatcherDelegatingAuthorizationManager(List.of(

Choose a reason for hiding this comment

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

질문 주신 부분에 대한 저의 의견 여기에 남기겠습니다.

Q. RequestMatcherRegistry의 역할이 필요한 RequestMatcher을 모두 등록한 뒤 HTTP 요청이 들어왔을 때 적절한 RequestMatcher를 찾아서 반환하는 것으로 이해했는데 올바르게 이해한걸까요?

A.RequestMatcherRegistry는 보안 규칙을 등록하는 역할을 합니다.
요청이 들어오면 Spring Security의 AuthorizationFilter가 RequestMatcherDelegatingAuthorizationManager를 통해
적절한 RequestMatcher를 찾아 인가(Authorization)를 수행합니다.

즉, RequestMatcherRegistry는 보안 설정을 구성하는 단계에서 사용되며,
실제 요청이 들어왔을 때 요청과 매칭되는 RequestMatcher를 찾아 적용하는 것은 RequestMatcherDelegatingAuthorizationManager이고,
이를 실행하여 최종적으로 인가를 결정하는 것은 AuthorizationFilter의 역할일 것 같네요 😄

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