Skip to content

Commit

Permalink
Merge pull request #5 from donggukthon/dev
Browse files Browse the repository at this point in the history
✨ [Feat] dev 환경을 prod 환경에 적용한다.
  • Loading branch information
kurtyoon authored Dec 18, 2023
2 parents f98db1c + 4893fc2 commit 218a5fe
Show file tree
Hide file tree
Showing 58 changed files with 1,722 additions and 1 deletion.
Binary file removed .DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ out/

### VS Code ###
.vscode/

.trash/
.DS_Store

application-local.yml
application-dev.yml
application-prod.yml

4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "volunmate_properties"]
path = volunmate_properties
url = https://github.com/kurtyoon/volunmate_properties.git
branch = main
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM gradle:8.2.1-jdk17 AS builder
COPY . /usr/src
WORKDIR /usr/src
RUN gradle wrapper --gradle-version 8.2.1
RUN ./gradlew build

FROM openjdk:17-jdk-alpine
COPY --from=builder /usr/src/build/libs/volunmate-0.0.1-SNAPSHOT.jar /usr/app/app.jar
ENTRYPOINT ["java","-jar","/usr/app/app.jar"]
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# donggukthon_2023_4_B

2023 Donggukthon 4팀 백엔드 레포지토리입니다.

# GitHub Role

해당 Repository는 다음과 같은 Convention을 따릅니다.

## Commit Convention

| 커밋 유형 | 설명 |
| --- | --- |
| Feat | 새로운 기능 추가 |
| Fix | 버그 수정 |
| Docs | 문서 수정 |
| Style | 코드 formatting, 세미콜론 누락, 코드 자체의 변경이 없는 경우 |
| Refactor | 코드 리팩토링 |
| Test | 테스트 코드, 리팩토링 테스트 코드 추가 |
| Chore | 패키지 매니저 수정, 그 외 기타 수정 ex) .gitignore |
| Design | CSS 등 사용자 UI 디자인 변경 |
| Comment | 필요한 주석 추가 및 변경 |
| Rename | 파일 또는 폴더 명을 수정하거나 옮기는 작업만인 경우 |
| Remove | 파일을 삭제하는 작업만 수행한 경우 |
| !BREAKING CHANGE | 커다란 API 변경의 경우 |
| !HOTFIX | 급하게 치명적인 버그를 고쳐야 하는 경우 |

## PR Convention

| 아이콘 | 코드 | 설명 |
| --- | --- | --- |
| 🧑🏻‍🎨 | :art | 코드의 구조/형태 개선 |
| ⚡️ | :zap | 성능 개선 |
| 🔥 | :fire | 코드/파일 삭제 |
| 🐛 | :bug | 버그 수정 |
| 🚑 | :ambulance | 긴급 수정 |
|| :sparkles | 새 기능 |
| 💄 | :lipstick | UI/스타일 파일 추가/수정 |
|| :rewind | 변경 내용 되돌리기 |
| 🔀 | :twisted_rightwards_arrows | 브랜치 합병 |
| 💡 | :bulb | 주석 추가/수정 |
| 🗃 | :card_file_box | 데이터베이스 관련 수정 |
38 changes: 38 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,46 @@ repositories {
}

dependencies {
// spring
implementation 'org.springframework.boot:spring-boot-starter-web'

// mysql
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.mysql:mysql-connector-j'

// security
implementation 'org.springframework.boot:spring-boot-starter-security'

// jwt
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:4.0.0'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'

// swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'

// json
implementation 'com.google.code.gson:gson'

// validation
implementation 'org.springframework.boot:spring-boot-starter-validation'

// lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

// test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
}

task copyGitSubmodule(type: Copy) {
copy {
from './volunmate_properties'
include '*.yml'
into './src/main/resources'
}
}

tasks.named('test') {
Expand Down
Binary file removed src/.DS_Store
Binary file not shown.
Binary file removed src/main/.DS_Store
Binary file not shown.
Binary file removed src/main/java/.DS_Store
Binary file not shown.
Binary file removed src/main/java/donggukthon/.DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions src/main/java/donggukthon/volunmate/VolunmateApplication.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package donggukthon.volunmate;

import jakarta.annotation.PostConstruct;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.TimeZone;

@SpringBootApplication
public class VolunmateApplication {

@PostConstruct
public void init() {
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"));
}

public static void main(String[] args) {
SpringApplication.run(VolunmateApplication.class, args);
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/donggukthon/volunmate/annotation/SocialId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package donggukthon.volunmate.annotation;

import java.lang.annotation.*;

@Documented
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface SocialId {
}
24 changes: 24 additions & 0 deletions src/main/java/donggukthon/volunmate/config/CorsConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package donggukthon.volunmate.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

@Configuration
public class CorsConfig {
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration configuration = new CorsConfiguration();

configuration.setAllowCredentials(true);
configuration.addAllowedOriginPattern("*");
configuration.addAllowedHeader("*");
configuration.addAllowedMethod("*");

source.registerCorsConfiguration("/**", configuration);
return new CorsFilter(source);
}
}
50 changes: 50 additions & 0 deletions src/main/java/donggukthon/volunmate/config/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package donggukthon.volunmate.config;

import donggukthon.volunmate.constant.Constants;
import donggukthon.volunmate.security.filter.JwtAuthenticationFilter;
import donggukthon.volunmate.security.filter.JwtExceptionFilter;
import donggukthon.volunmate.security.handler.JwtAccessDeniedHandler;
import donggukthon.volunmate.security.handler.JwtEntryPoint;
import donggukthon.volunmate.security.service.CustomUserDetailsService;
import donggukthon.volunmate.utils.JwtUtil;
import lombok.RequiredArgsConstructor;
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.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
public class SecurityConfig {

private final CustomUserDetailsService customUserDetailsService;
private final JwtEntryPoint jwtEntryPoint;
private final JwtAccessDeniedHandler jwtAccessDeniedHandler;
private final JwtUtil jwtUtil;

@Bean
protected SecurityFilterChain securityFilterChain(final HttpSecurity httpSecurity) throws Exception {
return httpSecurity
.csrf(AbstractHttpConfigurer::disable)
.httpBasic(AbstractHttpConfigurer::disable)
.sessionManagement((sessionManagement) ->
sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(requestMatcherRegistry -> requestMatcherRegistry
.requestMatchers(Constants.NO_AUTH_WHITE_LABEL.toArray(String[]::new)).permitAll()
.anyRequest().authenticated()
)
.exceptionHandling(exceptionHandling -> exceptionHandling
.authenticationEntryPoint(jwtEntryPoint)
.accessDeniedHandler(jwtAccessDeniedHandler))
.addFilterBefore(new JwtAuthenticationFilter(
jwtUtil, customUserDetailsService
), UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(new JwtExceptionFilter(), JwtAuthenticationFilter.class)
.getOrBuild();
}
}
28 changes: 28 additions & 0 deletions src/main/java/donggukthon/volunmate/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package donggukthon.volunmate.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {
@Bean
public GroupedOpenApi publicApi() {
return GroupedOpenApi.builder()
.group("public-api")
.pathsToMatch("/**")
.build();
}

@Bean
public OpenAPI openAPI() {
return new OpenAPI()
.info(new Info()
.title("Volunmate API")
.description("Volunmate API Docs")
.version("0.0.1")
);
}
}
32 changes: 32 additions & 0 deletions src/main/java/donggukthon/volunmate/config/WebMvcConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package donggukthon.volunmate.config;

import donggukthon.volunmate.interceptor.SocialIdArgumentResolver;
import donggukthon.volunmate.interceptor.SocialIdInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
@EnableWebMvc
@RequiredArgsConstructor
public class WebMvcConfig implements WebMvcConfigurer {
private final SocialIdArgumentResolver socialIdArgumentResolver;

@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
WebMvcConfigurer.super.addArgumentResolvers(resolvers);
resolvers.add(socialIdArgumentResolver);
}

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new SocialIdInterceptor())
.addPathPatterns("/api/**")
.excludePathPatterns("/api/health");
}
}
25 changes: 25 additions & 0 deletions src/main/java/donggukthon/volunmate/constant/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package donggukthon.volunmate.constant;

import java.util.List;

public class Constants {
public static String SOCIAL_ID_CLAIM_NAME = "socialId";
public static String USER_TYPE_CLAIM_NAME = "userType";
public static String BEARER_PREFIX = "Bearer ";
public static String AUTHORIZATION = "Authorization";
public static String REAUTHORIZATION = "Reauthorization";

public static List<String> NO_AUTH_WHITE_LABEL = List.of(
"/swagger-ui/index.html",
"/swagger-ui/swagger-ui.css",
"/swagger-ui/swagger-initializer.js",
"/swagger-ui/swagger-ui-standalone-preset.js",
"/swagger-ui/index.css",
"/swagger-ui/swagger-ui-bundle.js",
"/v3/api-docs/swagger-config",
"/v3/api-docs/public-api",
"/swagger-ui/favicon-32x32.png",
"/api/auth/google",
"/api/auth/google/callback"
);
}
52 changes: 52 additions & 0 deletions src/main/java/donggukthon/volunmate/controller/AuthController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package donggukthon.volunmate.controller;


import donggukthon.volunmate.annotation.SocialId;
import donggukthon.volunmate.dto.auth.AuthSignupDto;
import donggukthon.volunmate.dto.exception.ResponseDto;
import donggukthon.volunmate.dto.jwt.JwtTokenDto;
import donggukthon.volunmate.service.OAuth2Service;
import donggukthon.volunmate.type.ELoginProvider;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/auth")
@RequiredArgsConstructor
public class AuthController {
private final OAuth2Service oAuth2Service;

@GetMapping("/google")
public ResponseDto<Map<String, String>> getGoogleRedirectUrl() {
Map<String, String> map = new HashMap<>();
map.put("url", oAuth2Service.getRedirectUrl(ELoginProvider.GOOGLE));
return ResponseDto.ok(map);
}

@GetMapping("/google/callback")
public void getGoogleAccessToken(String code, HttpServletResponse response) throws IOException {
String accessToken = oAuth2Service.getAccessToken(code, ELoginProvider.GOOGLE);
oAuth2Service.login(response, accessToken, ELoginProvider.GOOGLE);
}

@PostMapping("/enroll")
public ResponseDto<Boolean> enroll(@SocialId String socialId, @RequestBody AuthSignupDto authSignupDto) {
return ResponseDto.ok(oAuth2Service.enroll(socialId, authSignupDto));
}

@GetMapping("/logout")
public ResponseDto<Boolean> logout(@SocialId String socialId) {
return ResponseDto.ok(oAuth2Service.logout(socialId));
}

@GetMapping("/refresh")
public ResponseDto<?> updateAccessToken(HttpServletRequest request) {
return ResponseDto.ok(oAuth2Service.reissueAccessToken(request));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package donggukthon.volunmate.controller;

import donggukthon.volunmate.dto.exception.ResponseDto;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class HealthController {
@GetMapping("/health")
public ResponseDto<String> health() {
return ResponseDto.ok("OK");
}
}
Loading

0 comments on commit 218a5fe

Please sign in to comment.