Skip to content

Commit

Permalink
Feat: Security 작업 및 Request Response Logging (#11)
Browse files Browse the repository at this point in the history
* feat: Add Security Config

* feat: Create Request Response Log

* chore: re setting module

* feat: Add BadRequest Exception

* feat: Add BusinessException

* feat: Add Unauthorized

* feat: separate sealed class

* feat: Add Conflict Exception

* feat: Add NotFound Exception

* feat: Add ServiceUnavailable Exception

* feat: Add InternalServerError Exception

* feat: Add NotAcceptable Exception

* feat: Add UnsupportedMediaType Exception

* feat: Add Bad Request Detail Case

* feat: Add Unauthorized Detail Case

* feat: Add Sns Auth Type

* feat: Add SnsType

* feat: Add SnsType attribute convertor

* feat: Add UserEntity

* feat: Add UserEntity

* feat: Add User detail for security

* feat: Add user domain model

* feat: Add user mapper

* style: add comma

* feat: change private id to public

* feat: Create LoadUserInputBoundary

* feat: Create UserGateway

* feat: Add User find feature

* build: Add jwt category bundle

* build: Add springdoc dependency

* feat: Add JwtConfig file

* feat: Add jwt value property in JwtConfig

* style: fix style

* style: fix typo

* build: Add Mockk Dependency

mockito 의존성 제거 및 mockK 의존성 추가

* build: Add JwtConfigContract

* build: Add mockK in version catalog

* feat: Add AuthToken Domain Model

* feat: Add BeIssuedAuthTokenUseCase

* feat: Add BeIssuedAuthTokenUseCase

* feat: Move ZoneId to JwtConfigContract Companion

* feat: Add jwt validate usecase

* feat: Move ZoneId to JwtConfigContract Companion

* test: Add unexpired token verification test

* feat: Add AuthenticationToken

* chore: Fix file name

* test: Add Unauthorized Case Test

* feat: move magic string to companion object

* feat: change magic string to const

* feat: Change Validate Use Case to Extract Token Use Case

* feat: Fix Extract token throw method

* feat: Add Jwt Authentication with Security

* chore: Fix CI action

* chore: Fix CI action

* chore: Fix CI action

* chore: Fix CI action

* chore: Fix CI action test files path
  • Loading branch information
jinsu4755 authored Sep 20, 2023
1 parent f4679cd commit afc5bc9
Show file tree
Hide file tree
Showing 87 changed files with 1,377 additions and 614 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/gradle_task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
on:
workflow_call:
inputs:
tasks:
description: gradle execute option
type: string

jobs:
gradle-task:
strategy:
matrix:
gradle: ${{ fromJSON(inputs.tasks) }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.CI_TOKEN }}
submodules: true

- name: Gradle cache
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: gradle

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

- name: Run Gradle Task
run: ./gradlew ${{matrix.gradle}}
128 changes: 45 additions & 83 deletions .github/workflows/pr_ci_checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,95 +11,57 @@ permissions:
pull-requests: write

jobs:
ktlint:
ci:
uses: ./.github/workflows/gradle_task.yml
with:
tasks: '["ktlintCheck", "build -x test -x ktlintCheck", "test"]'
secrets: inherit

publish-test-result:
needs:
- ci
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
with:
token: ${{ secrets.CI_TOKEN }}
submodules: true
files: |
module-domain/build/test-results/**/*.xml
module-infrastructure/build/test-results/**/*.xml
module-usecase/build/test-results/**/*.xml
- name: Gradle cache
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: gradle

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

- name: ktlintCheck
run: ./gradlew ktlintCheck
build:
result-success:
needs:
- ci
if: success()
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.CI_TOKEN }}
submodules: true

- name: Gradle cache
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: gradle

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

- name: build
run: ./gradlew build -x test -x ktlintCheck

test:
- name: On Success!! Congratulations
uses: rtCamp/action-slack-notify@v2
env:
SLACK_COLOR: '#53A551'
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_TITLE: 'Uni/PR Check S.U.C.C.E.S.S 🎉🎉🎉'
SLACK_ICON: ${{ github.event.org.avatar_url }}
MSG_MINIMAL: event,actions url, commit
SLACK_USERNAME: Uni-server
SLACK_MESSAGE: '${{ github.server_url }}/${{ github.repository }}/pull/${{ github.event.number}}'

result-failure:
needs:
- ci
if: failure()
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.CI_TOKEN }}
submodules: true

- name: Gradle cache
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: gradle

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

- name: test
run: ./gradlew test
- name: On Failed, Notify in Slack
if: ${{ failure() }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_COLOR: '#ff0000'
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_TITLE: 'Uni/Server Debug build Fail❌ 에러를 확인해주세요'
SLACK_ICON: ${{ github.event.org.avatar_url }}
MSG_MINIMAL: event,actions url, commit
SLACK_USERNAME: Uni-server
SLACK_MESSAGE: '${{ github.server_url }}/${{ github.repository }}/pull/${{ github.event.number}}'
7 changes: 7 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ springdoc = "2.1.0"
jjwt = "0.11.5"
kotlin = "1.8.22"
ktlint = "11.0.0"
mockk = "1.13.7"

service = "0.0.1-SNAPSHOT"

Expand Down Expand Up @@ -47,6 +48,7 @@ test-spring-boot-starter = { module = "org.springframework.boot:spring-boot-star
test-spring-security = { module = "org.springframework.security:spring-security-test" }
test-junit5-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit5" }
test-junit5-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit5" }
test-mockk = { module = "io.mockk:mockk", version.ref = "mockk" }

[plugins]
# common
Expand All @@ -62,3 +64,8 @@ ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }
# kotlin

[bundles]
jjwt = [
"jjwt-api",
"jjwt-impl",
"jjwt-jackson"
]

This file was deleted.

This file was deleted.

This file was deleted.

55 changes: 0 additions & 55 deletions module-data/build.gradle

This file was deleted.

9 changes: 0 additions & 9 deletions module-data/settings.gradle

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion module-data/src/main/resources/application.properties

This file was deleted.

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package universe.sparkle.domain

import java.time.ZoneId

interface JwtConfigContract {
fun getSecret(): String
fun getAccessExpiryPeriodDay(): Long
fun getRefreshExpiryPeriodDay(): Long

companion object {
val zoneIdKST = ZoneId.of("Asia/Seoul")
}
}
12 changes: 12 additions & 0 deletions module-domain/src/main/kotlin/universe/sparkle/domain/SnsType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package universe.sparkle.domain

enum class SnsType {
KAKAO, GOOGLE, APPLE;

companion object {
fun findSnsTypeBy(snsTypeName: String): SnsType {
return values().find { it.name == snsTypeName }
?: throw IllegalArgumentException("Unsupported social login type: $snsTypeName")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package universe.sparkle.domain.exception

sealed class BadRequest(
code: Int,
message: String,
) : BusinessException(code, message) {
data class InvalidRequestMethod(
override val message: String = "잘못된 방식의 요청입니다.",
) : BadRequest(1001, message)

data class AlreadyGameCreated(
override val message: String = "이미 승부가 생성되었습니다.",
) : BadRequest(1002, message)

data class UserNotExistent(
override val message: String = "존재하지 않는 유저의 요청입니다.",
) : BadRequest(1003, message)

data class AlreadyGameDone(
override val message: String = "이미 게임이 종료 되었습니다.",
) : BadRequest(1004, message)

data class CoupleNotExistent(
override val message: String = "존재하지 않는 커플의 요청입니다.",
) : BadRequest(1005, message)

data class InvalidInviteCode(
override val message: String = "올바르지 않은 초대 코드입니다.",
) : BadRequest(1006, message)

data class PartnerResultNotEntered(
override val message: String = "상대방이 아직 결과를 입력하지 않았습니다.",
) : BadRequest(1007, message)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package universe.sparkle.domain.exception

sealed class BusinessException(
open val code: Int,
override val message: String,
) : RuntimeException(message)
Loading

0 comments on commit afc5bc9

Please sign in to comment.