Skip to content

Commit

Permalink
Add (AOP) BadWordFilter In RequestDTO
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Diger committed Dec 29, 2023
1 parent ebe570a commit ac73d02
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 5 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.whatever.raisedragon.common.aop
package com.whatever.raisedragon.common.aop.auth

@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.whatever.raisedragon.common.aop
package com.whatever.raisedragon.common.aop.auth

import com.whatever.raisedragon.common.exception.BaseException
import com.whatever.raisedragon.common.exception.ExceptionCode
Expand Down Expand Up @@ -51,6 +51,6 @@ class AuthAspect(
companion object {
private const val AUTHORIZATION = "Authorization"
private const val PREFIX_BEARER = "Bearer "
private const val BASE_PACKAGE = "com.whatever.raisedragon.common.aop.Auth"
private const val BASE_PACKAGE = "com.whatever.raisedragon.common.aop.auth.Auth"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.whatever.raisedragon.common.aop
package com.whatever.raisedragon.common.aop.auth

import com.whatever.raisedragon.common.exception.BaseException
import com.whatever.raisedragon.common.exception.ExceptionCode
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.whatever.raisedragon.common.aop.badwordfilter

@Target(AnnotationTarget.FIELD)
@Retention(AnnotationRetention.RUNTIME)
annotation class BadWordFilter
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.whatever.raisedragon.common.aop.badwordfilter

import com.whatever.raisedragon.common.BadWords.containsExplicit
import org.aspectj.lang.ProceedingJoinPoint
import org.aspectj.lang.annotation.Around
import org.aspectj.lang.annotation.Aspect
import org.springframework.stereotype.Component

@Aspect
@Component
class AuthAspect {

@Around("@annotation($BASE_PACKAGE)")
fun filter(pjp: ProceedingJoinPoint): Any {
val args = pjp.args
for (arg in args) {
val fields = arg.javaClass.declaredFields
for (field in fields) {
field.isAccessible = true
if (field.isAnnotationPresent(BadWordFilter::class.java)) {
val value = field.get(arg)
if (value is String && containsExplicit(value)) {
throw IllegalArgumentException("비속어가 포함되어 있습니다.")
}
}
}
}
return pjp.proceed()
}

companion object {
private const val BASE_PACKAGE = "com.whatever.raisedragon.common.aop.badwordfilter.BadWordFilter"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.whatever.raisedragon.controller.goal

import com.whatever.raisedragon.common.aop.badwordfilter.BadWordFilter
import com.whatever.raisedragon.controller.betting.BettingRetrieveResponse
import com.whatever.raisedragon.domain.betting.Betting
import com.whatever.raisedragon.domain.betting.PredictionType
Expand All @@ -18,6 +19,7 @@ data class GoalCreateRequest(
@field:NotNull
val type: BettingType,

@BadWordFilter
@Schema(description = "다짐 내용")
@field:NotNull
val content: String,
Expand All @@ -36,6 +38,7 @@ data class GoalCreateRequest(

@Schema(description = "[Request] 다짐 수정")
data class GoalModifyRequest(
@BadWordFilter
@Schema(description = "다짐 내용")
@field:NotNull
val content: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.whatever.raisedragon.controller.user

import com.whatever.raisedragon.common.aop.badwordfilter.BadWordFilter
import com.whatever.raisedragon.domain.user.Nickname
import io.swagger.v3.oas.annotations.media.Schema

Expand All @@ -14,6 +15,7 @@ data class UserCreateRequest(

@Schema(description = "[Request] 유저 닉네임 수정")
data class UserNicknameUpdateRequest(
@BadWordFilter
@Schema(description = "User Nickname")
val nickname: String
)
Expand Down Expand Up @@ -53,6 +55,6 @@ data class UserNicknameDuplicatedRequest(

@Schema(description = "[Response] 유저 닉네임 중복체크")
data class UserNicknameDuplicatedResponse(
@Schema(description = "닉네임 변경 이력")
@Schema(description = "닉네임 중복 여부")
val nicknameIsDuplicated: Boolean
)

0 comments on commit ac73d02

Please sign in to comment.