-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add (AOP) BadWordFilter In RequestDTO
- Loading branch information
Showing
8 changed files
with
197 additions
and
5 deletions.
There are no files selected for viewing
148 changes: 148 additions & 0 deletions
148
raisedragon-api/src/main/kotlin/com/whatever/raisedragon/common/BadWords.kt
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...m/whatever/raisedragon/common/aop/Auth.kt → ...tever/raisedragon/common/aop/auth/Auth.kt
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
2 changes: 1 addition & 1 deletion
2
...ver/raisedragon/common/aop/AuthContext.kt → ...aisedragon/common/aop/auth/AuthContext.kt
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
5 changes: 5 additions & 0 deletions
5
...on-api/src/main/kotlin/com/whatever/raisedragon/common/aop/badwordfilter/BadWordFilter.kt
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,5 @@ | ||
package com.whatever.raisedragon.common.aop.badwordfilter | ||
|
||
@Target(AnnotationTarget.FIELD) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
annotation class BadWordFilter |
34 changes: 34 additions & 0 deletions
34
.../src/main/kotlin/com/whatever/raisedragon/common/aop/badwordfilter/BadWordFilterAspect.kt
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,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" | ||
} | ||
} |
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