Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat/#1] 아키텍처 설계 & 도메인 작성 #2

Merged
merged 13 commits into from
Jul 8, 2023
8 changes: 4 additions & 4 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<!-- 제목양식을 지켜주세요! [Feat/#{이슈번호}] {제목~~} -->
### Issue
<!-- #{이슈 번호} -->
-
- #

### 내용
<!-- what! -->
-
- [x]

### 핵심 구현 방법
<!-- how! -->
-
- 없음

### 전달 사항
<!-- 팀원과 함께 논의하고 싶은 내용 -->
-
- 없음
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,24 @@ jobs:
with:
java-version: '11'
distribution: 'temurin'

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew clean build -x test

- name: Check Code Formatting
run: ./gradlew spotlessJavaCheck
- name: Build with Gradle
run: ./gradlew clean build
- name: Check Test Results

- name: Test with Gradle
run: |
TEST_RESULT=$(./gradlew test --quiet)
TEST_RESULT=$(./gradlew test)
if [[ $TEST_RESULT == *"FAILURE"* ]]; then
echo "::error::Unit tests failed. Please check the code and try again."
exit 1
fi

- name: Notify Slack
if: always()
uses: 8398a7/[email protected]
Expand All @@ -53,6 +58,13 @@ jobs:
Commit: ${{ github.sha }}
Event: ${{ github.event_name }}
Branch: ${{ github.ref }}

- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
if: ${{ always() }}
with:
files: build/test-results/**/*.xml

- name: Prevent merge on failure
if: ${{ failure() }}
run: echo "::set-output name=mergeable::false"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ cmake-build-*/
*/out/production/*
*/out/test/*
out/production
out/test

# mpeltonen/sbt-idea plugin
.idea_modules/
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

53 changes: 42 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,25 @@ repositories {
}

dependencies {
implementation project(':api-module')
implementation project(':core-module')

implementation project(':member-module')
implementation project(':member-module:member-web-adapter')
implementation project(':member-module:member-application')
implementation project(':member-module:member-persistence-adapter')

implementation project(':teacher-module')
implementation project(':teacher-module:teacher-web-adapter')
implementation project(':teacher-module:teacher-application')
implementation project(':teacher-module:teacher-persistence-adapter')

implementation project(':wronganswernote-module')
implementation project(':wronganswernote-module:wronganswernote-web-adapter')
implementation project(':wronganswernote-module:wronganswernote-application')
implementation project(':wronganswernote-module:wronganswernote-persistence-adapter')

implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'com.h2database:h2'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

Expand All @@ -47,6 +62,10 @@ subprojects {
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java-library'

jar {
enabled = true
}

repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
Expand All @@ -60,6 +79,7 @@ subprojects {
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
Expand All @@ -75,24 +95,35 @@ tasks.named('test') {
useJUnitPlatform()
}

project(':api-module') {
project(':member-module') {
dependencies {
implementation project(':core-module')
implementation project(':member-module:member-web-adapter')
implementation project(':member-module:member-application')
implementation project(':member-module:member-persistence-adapter')
}
}

implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.3.1'
runtimeOnly 'com.h2database:h2'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter-test:2.3.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
project(':teacher-module') {
dependencies {
implementation project(':core-module')
implementation project(':teacher-module:teacher-web-adapter')
implementation project(':teacher-module:teacher-application')
implementation project(':teacher-module:teacher-persistence-adapter')
}
}

project(':wronganswernote-module') {
dependencies {
implementation project(':core-module')
implementation project(':wronganswernote-module:wronganswernote-web-adapter')
implementation project(':wronganswernote-module:wronganswernote-application')
implementation project(':wronganswernote-module:wronganswernote-persistence-adapter')
}
}

project(':core-module') {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation("io.jsonwebtoken:jjwt-api:0.11.5")
runtimeOnly("io.jsonwebtoken:jjwt-impl:0.11.5")
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.11.5")
Expand Down
2 changes: 2 additions & 0 deletions core-module/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ repositories {
}

dependencies {
testImplementation 'com.h2database:h2:2.1.214'

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.miracle.dto;
package com.ohdab.template;

import lombok.Builder;
import lombok.Getter;
Expand All @@ -8,5 +8,5 @@
public class ErrorMessage {

private int errorCode;
private String errorMessage;
private String message;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.ohdab.template;

import lombok.Builder;

@Builder
public class SuccessMessage {

private int code;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.miracle.util.jwt;
package com.ohdab.util.jwt;

import com.ohdab.util.jwt.exception.CustomWeakKeyException;
import io.jsonwebtoken.*;
import io.jsonwebtoken.security.Keys;
import io.jsonwebtoken.security.WeakKeyException;
Expand Down Expand Up @@ -51,12 +52,12 @@ public void afterPropertiesSet() {
byte[] keyBytes = Base64.getDecoder().decode(secretKey);
this.key = Keys.hmacShaKeyFor(keyBytes);
} catch (WeakKeyException e) {
log.error("key 생성 실패", e);
throw new RuntimeException(e);
log.error("제공된 secret key가 256bit를 넘지 않습니다.", e);
throw new CustomWeakKeyException(e);
}
}

public String createToken(Authentication authentication) {
public String createToken(Authentication authentication, Long id) {
String authorities =
authentication.getAuthorities().stream()
.map(GrantedAuthority::getAuthority)
Expand All @@ -68,8 +69,9 @@ public String createToken(Authentication authentication) {
.setIssuer(issuer) // JWT 토큰 발급자
.setIssuedAt(now) // JWT 토큰 발급 시간
.setExpiration(expiration)
.claim("id", id)
.claim(authoritiesKey, authorities)
.signWith(getKey(secretKey), SignatureAlgorithm.HS256)
.signWith(key, SignatureAlgorithm.HS256)
.compact(); // JWT 토큰 생성
}

Expand All @@ -95,16 +97,11 @@ public boolean validateToken(String token) {
} catch (UnsupportedJwtException e) {
log.error("지원하지 않는 JWT 토큰입니다.", e);
} catch (IllegalArgumentException e) {
log.error("JWT 토큰이 잘못되었습니다.", e);
log.error("JWT 토큰이 없거나 잘못되었습니다.", e);
}
return false;
}

private Key getKey(String secretKey) {
String encodedSecretKey = Base64.getEncoder().encodeToString(secretKey.getBytes());
return Keys.hmacShaKeyFor(encodedSecretKey.getBytes());
}

private Claims parseClaims(String token) {
return Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(token).getBody();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.ohdab.util.jwt.exception;

public class CustomWeakKeyException extends RuntimeException {
public CustomWeakKeyException() {}

public CustomWeakKeyException(String message) {
super(message);
}

public CustomWeakKeyException(String message, Throwable cause) {
super(message, cause);
}

public CustomWeakKeyException(Throwable cause) {
super(cause);
}
}
Loading
Loading