-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/issue#61 #62
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
Open
ammerss
wants to merge
3
commits into
TalkingPotatoTeam:dev
Choose a base branch
from
ammerss:feature/issue#61
base: dev
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
Feature/issue#61 #62
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ | |
| import org.springframework.util.StringUtils; | ||
| import org.springframework.web.filter.OncePerRequestFilter; | ||
| import tp.farming_springboot.api.ResultCode; | ||
|
|
||
| import java.util.HashMap; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Component | ||
|
|
@@ -42,12 +42,19 @@ public class AuthTokenFilter extends OncePerRequestFilter { | |
| protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) | ||
| throws IOException { | ||
| try { | ||
| String jwt = parseJwt(request); | ||
| if (jwtUtils.validateJwtToken(jwt)) { | ||
| HashMap<String, String> map = parseJwt(request); | ||
| if(map.containsKey("access")){ | ||
| String jwt = map.get("access"); | ||
| jwtUtils.validateJwtToken(jwt); | ||
| String username = jwtUtils.getUserNameFromJwtToken(jwt); | ||
| jwtUtils.createAuthentication(username); | ||
| } | ||
|
|
||
| else if(map.containsKey("refresh")){ | ||
| String jwt = map.get("refresh"); | ||
| jwtUtils.validateJwtRefresh(jwt); | ||
| String username = jwtUtils.getUserNameFromJwtRefreshToken(jwt); | ||
| jwtUtils.createAuthentication(username); | ||
| } | ||
| filterChain.doFilter(request, response); | ||
|
Comment on lines
44
to
58
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 로직이 access token 검사 후 혹시 refresh token이 있다면 refresh 토큰으로도 인증이 성공하도록 되어있는데요, 프론트쪽에서 access token과 refresh token을 동시에 사용해야할 일이 있을까요? refresh token은 최대한 사용을 자제하면서 노출을 피하고, access token을 재발급하기 위한 용도로만 사용하는 것이 맞지 않나 싶은데 의견부탁해요~~~
|
||
| } | ||
| catch(BadCredentialsException e) { | ||
|
|
@@ -84,14 +91,19 @@ protected boolean shouldNotFilter(HttpServletRequest request) { | |
| return EXCLUDE_URL.stream().anyMatch(exclude -> exclude.equalsIgnoreCase(request.getServletPath())); | ||
| } | ||
|
|
||
| private String parseJwt(HttpServletRequest request) { | ||
| private HashMap<String, String> parseJwt(HttpServletRequest request) { | ||
| String headerAuth = request.getHeader("Authorization"); | ||
|
|
||
| HashMap<String, String> map = new HashMap<>(); | ||
| if (StringUtils.hasText(headerAuth) && headerAuth.startsWith("Bearer ")) { | ||
| return headerAuth.substring(7); | ||
| } else { | ||
| map.put("access",headerAuth.substring(7)); | ||
| } | ||
| else if(StringUtils.hasText(headerAuth) && headerAuth.startsWith("Refresh ")){ | ||
| map.put("refresh",headerAuth.substring(8)); | ||
| } | ||
| else { | ||
| throw new BadCredentialsException("토큰 정보가 헤더에 없습니다."); | ||
| } | ||
|
|
||
| return map; | ||
| } | ||
|
|
||
| } | ||
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.
authentication.getName()이 user.get().getPhone()과 같은 데이터인데 불필요한 유저 조회가 한번 더 들어가는 것 같습니다~
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.
또, 귀찮겠지만 ResponseEntity는 더이상 사용하지 않고 ApiReponse만 반환하도록 했습니다 ㅎ ProductController 참고하시고
이유는 데이터 -> (감싸기) -> ApiReponse -> (또 감싸기) -> ResponseEntity 이렇게 두번씩 감쌀 필요가 없다는 생각때문입니다