-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 재학생 인증 API authToken 추가 (#93) * feat: 회원가입 API 권한 추가 (#93) * refactor: JwtTokenProvider 리팩토링 (#93) * refactor: controller 리팩토링 (#93) * feat: AuthVerified 어노테이션 (#93) * feat: AuthVerified 어노테이션 등록 (#93) * feat: 회원가입 API 재학생 인증 권한 설정 (#93)
- Loading branch information
1 parent
0efb94d
commit 294a44b
Showing
14 changed files
with
140 additions
and
28 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
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
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
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
15 changes: 15 additions & 0 deletions
15
src/main/java/com/smunity/server/global/security/annotation/AuthVerified.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,15 @@ | ||
package com.smunity.server.global.security.annotation; | ||
|
||
import io.swagger.v3.oas.annotations.Parameter; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.PARAMETER) | ||
@Parameter(hidden = true) | ||
public @interface AuthVerified { | ||
|
||
} |
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
44 changes: 44 additions & 0 deletions
44
src/main/java/com/smunity/server/global/security/resolver/AuthVerifiedArgumentResolver.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,44 @@ | ||
package com.smunity.server.global.security.resolver; | ||
|
||
import com.smunity.server.global.security.annotation.AuthVerified; | ||
import com.smunity.server.global.security.provider.JwtTokenProvider; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.core.MethodParameter; | ||
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.HandlerMethodArgumentResolver; | ||
import org.springframework.web.method.support.ModelAndViewContainer; | ||
|
||
/** | ||
* 컨트롤러 메서드의 파라미터가 @AuthVerified String 타입일 때 해당 파라미터를 처리하도록 지정하는 클래스 | ||
*/ | ||
@Component | ||
@RequiredArgsConstructor | ||
public class AuthVerifiedArgumentResolver implements HandlerMethodArgumentResolver { | ||
|
||
private final JwtTokenProvider jwtTokenProvider; | ||
|
||
/** | ||
* 파라미터 타입 확인 (@AuthVerified, String) | ||
*/ | ||
@Override | ||
public boolean supportsParameter(MethodParameter parameter) { | ||
boolean hasAuthMemberAnnotation = parameter.hasParameterAnnotation(AuthVerified.class); | ||
boolean isStringType = String.class.isAssignableFrom(parameter.getParameterType()); | ||
return hasAuthMemberAnnotation && isStringType; | ||
} | ||
|
||
/** | ||
* 해당 컨트롤러 메서드의 파라미터 처리 | ||
*/ | ||
@Override | ||
public String resolveArgument(@NonNull MethodParameter parameter, ModelAndViewContainer mavContainer, | ||
@NonNull NativeWebRequest webRequest, WebDataBinderFactory binderFactory) { | ||
HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest(); | ||
String jwt = jwtTokenProvider.resolveToken(request); | ||
return jwtTokenProvider.getUsername(jwt); | ||
} | ||
} |