-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: PathMatcherInterceptor 생성 및 로그인 인터셉터 개선 (#307)
- Loading branch information
1 parent
61af388
commit ca43e47
Showing
14 changed files
with
192 additions
and
201 deletions.
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
43 changes: 0 additions & 43 deletions
43
backend/src/main/java/com/woowacourse/moamoa/auth/config/AuthRequestMatchConfig.java
This file was deleted.
Oops, something went wrong.
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
40 changes: 40 additions & 0 deletions
40
...rc/main/java/com/woowacourse/moamoa/auth/controller/interceptor/PathMatcherContainer.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,40 @@ | ||
package com.woowacourse.moamoa.auth.controller.interceptor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.AntPathMatcher; | ||
import org.springframework.util.PathMatcher; | ||
|
||
@Component | ||
public class PathMatcherContainer { | ||
|
||
private final PathMatcher pathMatcher; | ||
private final List<PathRequestMatcher> includePathPatterns; | ||
private final List<PathRequestMatcher> excludePathPatterns; | ||
|
||
public PathMatcherContainer() { | ||
this.pathMatcher = new AntPathMatcher(); | ||
this.includePathPatterns = new ArrayList<>(); | ||
this.excludePathPatterns = new ArrayList<>(); | ||
} | ||
|
||
public boolean isNotIncludePath(final String targetPath, final String pathMethod) { | ||
final boolean excludePattern = excludePathPatterns.stream() | ||
.anyMatch(requestPath -> requestPath.match(pathMatcher, targetPath, pathMethod)); | ||
|
||
final boolean isNotIncludePattern = includePathPatterns.stream() | ||
.noneMatch(requestPath -> requestPath.match(pathMatcher, targetPath, pathMethod)); | ||
|
||
return excludePattern || isNotIncludePattern; | ||
} | ||
|
||
public void includePathPattern(final String path, final HttpMethod method) { | ||
this.includePathPatterns.add(new PathRequestMatcher(path, method)); | ||
} | ||
|
||
public void excludePathPattern(final String path, final HttpMethod method) { | ||
this.excludePathPatterns.add(new PathRequestMatcher(path, method)); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
.../main/java/com/woowacourse/moamoa/auth/controller/interceptor/PathMatcherInterceptor.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 com.woowacourse.moamoa.auth.controller.interceptor; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
|
||
@Component | ||
@AllArgsConstructor | ||
public class PathMatcherInterceptor implements HandlerInterceptor { | ||
|
||
private final HandlerInterceptor handlerInterceptor; | ||
private final PathMatcherContainer pathMatcherContainer; | ||
|
||
@Override | ||
public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler) | ||
throws Exception { | ||
|
||
if (pathMatcherContainer.isNotIncludePath(request.getRequestURI(), request.getMethod())) { | ||
return true; | ||
} | ||
|
||
return this.handlerInterceptor.preHandle(request, response, handler); | ||
} | ||
|
||
public PathMatcherInterceptor includePathPattern(final String pathPattern, final HttpMethod method) { | ||
this.pathMatcherContainer.includePathPattern(pathPattern, method); | ||
return this; | ||
} | ||
|
||
public PathMatcherInterceptor excludePathPattern(final String pathPattern, final HttpMethod method) { | ||
this.pathMatcherContainer.excludePathPattern(pathPattern, method); | ||
return this; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
.../src/main/java/com/woowacourse/moamoa/auth/controller/interceptor/PathRequestMatcher.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,18 @@ | ||
package com.woowacourse.moamoa.auth.controller.interceptor; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.util.PathMatcher; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public class PathRequestMatcher { | ||
|
||
private final String path; | ||
private final HttpMethod method; | ||
|
||
public boolean match(final PathMatcher pathMatcher, final String targetPath, final String pathMethod) { | ||
return pathMatcher.match(path, targetPath) && this.method.matches(pathMethod); | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
...d/src/main/java/com/woowacourse/moamoa/auth/controller/matcher/AuthenticationRequest.java
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
...ain/java/com/woowacourse/moamoa/auth/controller/matcher/AuthenticationRequestMatcher.java
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
...a/com/woowacourse/moamoa/auth/controller/matcher/AuthenticationRequestMatcherBuilder.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.