-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: member, auth, common 패키지 생성 및 의존성 수정
- Loading branch information
1 parent
065f2b5
commit 09a7764
Showing
215 changed files
with
1,059 additions
and
981 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
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
48 changes: 48 additions & 0 deletions
48
backend/kirikiri/src/main/java/co/kirikiri/auth/interceptor/AuthInterceptorImpl.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,48 @@ | ||
package co.kirikiri.auth.interceptor; | ||
|
||
import co.kirikiri.auth.service.AuthService; | ||
import co.kirikiri.common.exception.AuthenticationException; | ||
import co.kirikiri.common.interceptor.AuthInterceptor; | ||
import co.kirikiri.common.interceptor.Authenticated; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.method.HandlerMethod; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class AuthInterceptorImpl implements AuthInterceptor { | ||
|
||
private static final String BEARER = "Bearer "; | ||
|
||
private final AuthService authService; | ||
|
||
@Override | ||
public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, | ||
final Object handler) { | ||
if (!(handler instanceof final HandlerMethod handlerMethod)) { | ||
return true; | ||
} | ||
if (handlerMethod.hasMethodAnnotation(Authenticated.class)) { | ||
final String authorizationHeader = request.getHeader(HttpHeaders.AUTHORIZATION); | ||
checkHeader(authorizationHeader); | ||
final String token = authorizationHeader.substring(BEARER.length()); | ||
checkTokenCertify(token); | ||
} | ||
return true; | ||
} | ||
|
||
private void checkHeader(final String authorizationHeader) { | ||
if (authorizationHeader == null || !authorizationHeader.startsWith(BEARER)) { | ||
throw new AuthenticationException("인증 헤더가 적절하지 않습니다."); | ||
} | ||
} | ||
|
||
private void checkTokenCertify(final String token) { | ||
if (!authService.isCertified(token)) { | ||
throw new AuthenticationException("토큰이 유효하지 않습니다."); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...sistence/auth/RefreshTokenRepository.java → ...h/persistence/RefreshTokenRepository.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package co.kirikiri.persistence.auth; | ||
package co.kirikiri.auth.persistence; | ||
|
||
import java.util.Optional; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...ence/auth/RefreshTokenRepositoryImpl.java → ...rsistence/RefreshTokenRepositoryImpl.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
48 changes: 48 additions & 0 deletions
48
...irikiri/src/main/java/co/kirikiri/auth/resolver/MemberIdentifierArgumentResolverImpl.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,48 @@ | ||
package co.kirikiri.auth.resolver; | ||
|
||
import co.kirikiri.auth.service.AuthService; | ||
import co.kirikiri.common.exception.AuthenticationException; | ||
import co.kirikiri.common.exception.ServerException; | ||
import co.kirikiri.common.interceptor.Authenticated; | ||
import co.kirikiri.common.resolver.MemberIdentifier; | ||
import co.kirikiri.common.resolver.MemberIdentifierArgumentResolver; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.core.MethodParameter; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.bind.support.WebDataBinderFactory; | ||
import org.springframework.web.context.request.NativeWebRequest; | ||
import org.springframework.web.method.support.ModelAndViewContainer; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class MemberIdentifierArgumentResolverImpl implements MemberIdentifierArgumentResolver { | ||
|
||
private static final String BEARER = "Bearer "; | ||
|
||
private final AuthService authService; | ||
|
||
@Override | ||
public boolean supportsParameter(final MethodParameter parameter) { | ||
if (!parameter.hasMethodAnnotation(Authenticated.class)) { | ||
throw new ServerException("MemberIdentifier는 인증된 사용자만 사용 가능합니다. (@Authenticated)"); | ||
} | ||
return parameter.getParameterType().equals(String.class) | ||
&& parameter.hasParameterAnnotation(MemberIdentifier.class); | ||
} | ||
|
||
@Override | ||
public String resolveArgument(final MethodParameter parameter, final ModelAndViewContainer mavContainer, | ||
final NativeWebRequest webRequest, final WebDataBinderFactory binderFactory) { | ||
final String authorizationHeader = webRequest.getHeader(HttpHeaders.AUTHORIZATION); | ||
checkHeader(authorizationHeader); | ||
final String token = authorizationHeader.substring(BEARER.length()); | ||
return authService.findIdentifierByToken(token); | ||
} | ||
|
||
private void checkHeader(final String authorizationHeader) { | ||
if (authorizationHeader == null || !authorizationHeader.startsWith(BEARER)) { | ||
throw new AuthenticationException("인증 헤더가 적절하지 않습니다."); | ||
} | ||
} | ||
} |
26 changes: 13 additions & 13 deletions
26
...co/kirikiri/service/auth/AuthService.java → ...co/kirikiri/auth/service/AuthService.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
4 changes: 2 additions & 2 deletions
4
...rikiri/service/auth/JwtTokenProvider.java → ...rikiri/auth/service/JwtTokenProvider.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
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
4 changes: 2 additions & 2 deletions
4
...kirikiri/service/OauthNetworkService.java → ...iri/auth/service/OauthNetworkService.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
2 changes: 1 addition & 1 deletion
2
.../kirikiri/service/auth/TokenProvider.java → .../kirikiri/auth/service/TokenProvider.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
11 changes: 11 additions & 0 deletions
11
backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/LoginDto.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 co.kirikiri.auth.service.dto; | ||
|
||
import co.kirikiri.member.domain.vo.Identifier; | ||
import co.kirikiri.member.domain.vo.Password; | ||
|
||
public record LoginDto( | ||
Identifier identifier, | ||
Password password | ||
) { | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...rvice/dto/auth/NaverMemberProfileDto.java → ...th/service/dto/NaverMemberProfileDto.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
2 changes: 1 addition & 1 deletion
2
...o/auth/NaverMemberProfileResponseDto.java → ...ce/dto/NaverMemberProfileResponseDto.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
2 changes: 1 addition & 1 deletion
2
.../service/dto/auth/NaverOauthTokenDto.java → .../auth/service/dto/NaverOauthTokenDto.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
2 changes: 1 addition & 1 deletion
2
...rvice/dto/auth/OauthRedirectResponse.java → ...th/service/dto/OauthRedirectResponse.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
2 changes: 1 addition & 1 deletion
2
...ervice/dto/auth/request/LoginRequest.java → ...uth/service/dto/request/LoginRequest.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
2 changes: 1 addition & 1 deletion
2
...dto/auth/request/ReissueTokenRequest.java → ...vice/dto/request/ReissueTokenRequest.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
2 changes: 1 addition & 1 deletion
2
...auth/response/AuthenticationResponse.java → .../dto/response/AuthenticationResponse.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
12 changes: 6 additions & 6 deletions
12
...o/kirikiri/service/mapper/AuthMapper.java → ...ikiri/auth/service/mapper/AuthMapper.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
4 changes: 2 additions & 2 deletions
4
.../kirikiri/service/mapper/OauthMapper.java → ...kiri/auth/service/mapper/OauthMapper.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
2 changes: 1 addition & 1 deletion
2
...irikiri/service/aop/ExceptionConvert.java → ...kirikiri/common/aop/ExceptionConvert.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
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
Oops, something went wrong.