-
Notifications
You must be signed in to change notification settings - Fork 36
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
[Step2] 리펙터링 #6
Open
hyunssooo
wants to merge
9
commits into
next-step:hyunssooo
Choose a base branch
from
hyunssooo:step2
base: hyunssooo
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[Step2] 리펙터링 #6
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b350621
feat: add AuthorizeRequestMatcherRegistry
byjo e136e3e
fix: 인가 과정에서 인증 정보 불러오는 방법 수정
hyunssooo facf63b
feat: SecurityFilterChain 하나만 사용하도록 변경
hyunssooo 76a93c2
feat: PreAuthorizationFilter 추가
hyunssooo 3d06e2d
feat: members/me api 추가
hyunssooo 499702f
fix: rename AuthorizationSecurityFilterChain -> DefaultSecurityFilter…
hyunssooo 44ebd16
feat: RoleManager 적용
hyunssooo fc595d1
refactor: 사용하지 않는 코드 제거
hyunssooo 3a4a9a5
feat: 피드백 반영
hyunssooo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/nextstep/app/config/LoginUserArgumentResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package nextstep.app.config; | ||
|
||
import nextstep.app.ui.dto.LoginUser; | ||
import nextstep.security.authentication.Authentication; | ||
import nextstep.security.context.SecurityContextHolder; | ||
import org.springframework.core.MethodParameter; | ||
import org.springframework.web.bind.support.WebDataBinderFactory; | ||
import org.springframework.web.context.request.NativeWebRequest; | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
import org.springframework.web.method.support.ModelAndViewContainer; | ||
|
||
public class LoginUserArgumentResolver implements HandlerMethodArgumentResolver { | ||
|
||
@Override | ||
public boolean supportsParameter(MethodParameter parameter) { | ||
return parameter.getParameterType().equals(LoginUser.class); | ||
} | ||
|
||
@Override | ||
public LoginUser resolveArgument( | ||
MethodParameter parameter, | ||
ModelAndViewContainer mavContainer, | ||
NativeWebRequest webRequest, | ||
WebDataBinderFactory binderFactory | ||
) { | ||
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
final String email = authentication.getPrincipal().toString(); | ||
return new LoginUser(email); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package nextstep.app.ui.dto; | ||
|
||
public class LoginUser { | ||
private final String email; | ||
|
||
public LoginUser(String email) { | ||
this.email = email; | ||
} | ||
|
||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "LoginUser{" + | ||
"email='" + email + '\'' + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/nextstep/security/authorization/PreAuthorizationFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package nextstep.security.authorization; | ||
|
||
import java.io.IOException; | ||
import java.util.Optional; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.http.HttpServletRequest; | ||
import nextstep.security.context.SecurityContext; | ||
import nextstep.security.context.SecurityContextHolder; | ||
import nextstep.security.context.SecurityContextRepository; | ||
import org.springframework.web.filter.GenericFilterBean; | ||
|
||
public class PreAuthorizationFilter extends GenericFilterBean { | ||
|
||
private final SecurityContextRepository securityContextRepository; | ||
|
||
public PreAuthorizationFilter(SecurityContextRepository securityContextRepository) { | ||
this.securityContextRepository = securityContextRepository; | ||
} | ||
|
||
@Override | ||
public void doFilter( | ||
ServletRequest request, | ||
ServletResponse response, | ||
FilterChain chain | ||
) throws IOException, ServletException { | ||
final HttpServletRequest httpServletRequest = (HttpServletRequest) request; | ||
|
||
final Optional<SecurityContext> securityContext = Optional.ofNullable( | ||
securityContextRepository.loadContext(httpServletRequest) | ||
); | ||
securityContext.ifPresent(it -> SecurityContextHolder.setContext(it)); | ||
|
||
chain.doFilter(request, response); | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
src/main/java/nextstep/security/authorization/RoleManager.java
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
src/main/java/nextstep/security/authorization/manager/AuthenticatedAuthorizationManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package nextstep.security.authorization.manager; | ||
|
||
import nextstep.security.authentication.Authentication; | ||
|
||
public class AuthenticatedAuthorizationManager implements AuthorizationManager { | ||
|
||
@Override | ||
public boolean check(Authentication authentication) { | ||
return authentication.isAuthenticated(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/nextstep/security/authorization/manager/AuthorityAuthorizationManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package nextstep.security.authorization.manager; | ||
|
||
import java.util.Set; | ||
import nextstep.security.authentication.Authentication; | ||
|
||
public class AuthorityAuthorizationManager implements AuthorizationManager { | ||
|
||
private final Set<String> authorities; | ||
|
||
public AuthorityAuthorizationManager(Set<String> authorities) { | ||
this.authorities = authorities; | ||
} | ||
|
||
public AuthorityAuthorizationManager(String... authorities) { | ||
this(Set.of(authorities)); | ||
} | ||
|
||
@Override | ||
public boolean check(Authentication authentication) { | ||
return authentication.getAuthorities().stream() | ||
.anyMatch(authorities::contains); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/nextstep/security/authorization/manager/AuthorizationManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package nextstep.security.authorization.manager; | ||
|
||
import nextstep.security.authentication.Authentication; | ||
|
||
public interface AuthorizationManager { | ||
|
||
boolean check(Authentication authentication); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/nextstep/security/authorization/manager/DenyAllAuthorizationManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package nextstep.security.authorization.manager; | ||
|
||
import nextstep.security.authentication.Authentication; | ||
|
||
public class DenyAllAuthorizationManager implements AuthorizationManager { | ||
|
||
@Override | ||
public boolean check(Authentication authentication) { | ||
return false; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/nextstep/security/authorization/manager/PermitAllAuthorizationManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package nextstep.security.authorization.manager; | ||
|
||
import nextstep.security.authentication.Authentication; | ||
|
||
public class PermitAllAuthorizationManager implements AuthorizationManager { | ||
|
||
@Override | ||
public boolean check(Authentication authentication) { | ||
return true; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오오 ArgumentResolver 사용 좋네요! 👏👏