-
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.
Merge pull request #19 from KUIT-Space/develop
배포 확인 PR
- Loading branch information
Showing
46 changed files
with
1,038 additions
and
99 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 was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
src/main/java/space/space_spring/argument_resolver/jwtLogin/JwtLoginAuth.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 space.space_spring.argument_resolver.jwtLogin; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.PARAMETER) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface JwtLoginAuth { | ||
} |
25 changes: 25 additions & 0 deletions
25
...va/space/space_spring/argument_resolver/jwtLogin/JwtLoginAuthHandlerArgumentResolver.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,25 @@ | ||
package space.space_spring.argument_resolver.jwtLogin; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
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; | ||
|
||
@Component | ||
public class JwtLoginAuthHandlerArgumentResolver implements HandlerMethodArgumentResolver { | ||
|
||
@Override | ||
public boolean supportsParameter(MethodParameter parameter) { | ||
// 일단 parameter의 return value type 을 검사하지는 X | ||
return parameter.hasParameterAnnotation(JwtLoginAuth.class); | ||
} | ||
|
||
@Override | ||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { | ||
HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest(); | ||
return request.getAttribute("userId"); // jwt를 복호화해서 얻은 userId get | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/space/space_spring/argument_resolver/jwtUserSpace/JwtUserSpaceAuth.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 space.space_spring.argument_resolver.jwtUserSpace; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.PARAMETER) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface JwtUserSpaceAuth { | ||
} |
25 changes: 25 additions & 0 deletions
25
.../space_spring/argument_resolver/jwtUserSpace/JwtUserSpaceAuthHandlerArgumentResolver.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,25 @@ | ||
package space.space_spring.argument_resolver.jwtUserSpace; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
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; | ||
|
||
@Component | ||
public class JwtUserSpaceAuthHandlerArgumentResolver implements HandlerMethodArgumentResolver { | ||
|
||
@Override | ||
public boolean supportsParameter(MethodParameter parameter) { | ||
// 일단 parameter의 return value type 을 검사하지는 X | ||
return parameter.hasParameterAnnotation(JwtUserSpaceAuth.class); | ||
} | ||
|
||
@Override | ||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { | ||
HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest(); | ||
return request.getAttribute("jwtPayloadDto"); // jwt를 복호화해서 얻은 userId get | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/space/space_spring/config/SecurityConfig.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,37 @@ | ||
package space.space_spring.config; | ||
|
||
import org.springframework.boot.autoconfigure.security.servlet.PathRequest; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
public class SecurityConfig { | ||
|
||
@Bean | ||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { | ||
http | ||
// csrf 설정을 disable | ||
.csrf((csrfConfig) -> | ||
csrfConfig.disable() | ||
) | ||
// h2 console 화면을 사용하기 위해 해당 옵션들 disable | ||
.headers((headerConfig) -> | ||
headerConfig.frameOptions(frameOptionsConfig -> | ||
frameOptionsConfig.disable() | ||
) | ||
); | ||
// 요청별 권한 설정 | ||
// .authorizeHttpRequests((authorizeRequests) -> | ||
// authorizeRequests | ||
// .requestMatchers(PathRequest.toH2Console()).permitAll() | ||
// .requestMatchers("/", "/user/signup", "/user/login").permitAll() | ||
//// .anyRequest().authenticated() | ||
// ); | ||
|
||
return http.build(); | ||
} | ||
} |
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,41 @@ | ||
package space.space_spring.config; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
import space.space_spring.argument_resolver.jwtLogin.JwtLoginAuthHandlerArgumentResolver; | ||
import space.space_spring.argument_resolver.jwtUserSpace.JwtUserSpaceAuthHandlerArgumentResolver; | ||
import space.space_spring.interceptor.jwtLogin.JwtLoginAuthInterceptor; | ||
import space.space_spring.interceptor.jwtUserSpace.JwtUserSpaceAuthInterceptor; | ||
|
||
import java.util.List; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class WebConfig implements WebMvcConfigurer { | ||
|
||
private final JwtLoginAuthInterceptor jwtLoginAuthInterceptor; | ||
private final JwtUserSpaceAuthInterceptor jwtUserSpaceAuthInterceptor; | ||
|
||
private final JwtLoginAuthHandlerArgumentResolver jwtLoginAuthHandlerArgumentResolver; | ||
private final JwtUserSpaceAuthHandlerArgumentResolver jwtUserSpaceAuthHandlerArgumentResolver; | ||
|
||
@Override | ||
public void addInterceptors(InterceptorRegistry registry) { | ||
registry.addInterceptor(jwtLoginAuthInterceptor) | ||
.order(1) | ||
.addPathPatterns("/space/**", "/test/**"); | ||
|
||
registry.addInterceptor(jwtUserSpaceAuthInterceptor) | ||
.order(2) | ||
.addPathPatterns("/test111/**"); // interceptor 적용되야하는 url enum으로 만들어서 여기에 달면 될듯 | ||
} | ||
|
||
@Override | ||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) { | ||
argumentResolvers.add(jwtLoginAuthHandlerArgumentResolver); | ||
argumentResolvers.add(jwtUserSpaceAuthHandlerArgumentResolver); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/space/space_spring/controller/SpaceController.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,45 @@ | ||
package space.space_spring.controller; | ||
|
||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.validation.BindingResult; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import space.space_spring.argument_resolver.jwtLogin.JwtLoginAuth; | ||
import space.space_spring.argument_resolver.jwtUserSpace.JwtUserSpaceAuth; | ||
import space.space_spring.dto.jwt.JwtPayloadDto; | ||
import space.space_spring.dto.space.PostSpaceCreateRequest; | ||
import space.space_spring.dto.space.PostSpaceCreateResponse; | ||
|
||
import space.space_spring.dto.space.SpaceCreateDto; | ||
import space.space_spring.exception.SpaceException; | ||
import space.space_spring.response.BaseResponse; | ||
import space.space_spring.service.SpaceService; | ||
|
||
import static space.space_spring.response.status.BaseExceptionResponseStatus.INVALID_SPACE_CREATE; | ||
import static space.space_spring.util.BindingResultUtils.getErrorMessage; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/space") | ||
public class SpaceController { | ||
|
||
private final SpaceService spaceService; | ||
|
||
@PostMapping("/create") | ||
public BaseResponse<PostSpaceCreateResponse> createSpace(@JwtLoginAuth Long userId, @Validated @RequestBody PostSpaceCreateRequest postSpaceCreateRequest, BindingResult bindingResult, HttpServletResponse response) { | ||
if (bindingResult.hasErrors()) { | ||
throw new SpaceException(INVALID_SPACE_CREATE, getErrorMessage(bindingResult)); | ||
} | ||
|
||
SpaceCreateDto spaceCreateDto = spaceService.createSpace(userId, postSpaceCreateRequest); | ||
String jwtUserSpace = spaceCreateDto.getJwtUserSpace(); | ||
response.setHeader("Authorization", "Bearer " + jwtUserSpace); | ||
|
||
return new BaseResponse<>(new PostSpaceCreateResponse(spaceCreateDto.getSpaceId())); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/space/space_spring/controller/TestController.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,13 +1,31 @@ | ||
package space.space_spring.controller; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import space.space_spring.argument_resolver.jwtLogin.JwtLoginAuth; | ||
import space.space_spring.argument_resolver.jwtUserSpace.JwtUserSpaceAuth; | ||
import space.space_spring.dto.jwt.JwtPayloadDto; | ||
import space.space_spring.response.BaseResponse; | ||
|
||
@RestController | ||
@Slf4j | ||
public class TestController { | ||
|
||
@GetMapping("/test") | ||
public String test(){ | ||
return "CI/CD 환경 구축 테스트 중. 이 메세지가 보인다면 성공입니다"; | ||
} | ||
|
||
@GetMapping("/test/jwt") | ||
public BaseResponse<String> jwtLoginTest(@JwtLoginAuth Long userId) { | ||
log.info("userId = {}", userId); | ||
return new BaseResponse<>("jwt login test 성공"); | ||
} | ||
|
||
@GetMapping("/test111") | ||
public BaseResponse<String> jwtUserSpaceTest(@JwtUserSpaceAuth JwtPayloadDto jwtPayloadDto) { | ||
log.info("jwtPayloadDto = {}", jwtPayloadDto); | ||
return new BaseResponse<>("jwt user space test 성공"); | ||
} | ||
} |
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.