-
Notifications
You must be signed in to change notification settings - Fork 0
Add admin authentication for version updates and enhance AppVersionService #44
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package com.moa.common.auth | ||
|
|
||
| @Target(AnnotationTarget.FUNCTION) | ||
| @Retention(AnnotationRetention.RUNTIME) | ||
| annotation class AdminAuth | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.moa.common.auth | ||
|
|
||
| import com.moa.common.exception.UnauthorizedException | ||
| import jakarta.servlet.http.HttpServletRequest | ||
| import jakarta.servlet.http.HttpServletResponse | ||
| import org.springframework.stereotype.Component | ||
| import org.springframework.web.method.HandlerMethod | ||
| import org.springframework.web.servlet.HandlerInterceptor | ||
|
|
||
| @Component | ||
| class AdminAuthInterceptor( | ||
| private val adminProperties: AdminProperties, | ||
| ) : HandlerInterceptor { | ||
|
|
||
| override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean { | ||
| if (handler is HandlerMethod && handler.hasMethodAnnotation(AdminAuth::class.java)) { | ||
| val key = request.getHeader(ADMIN_KEY_HEADER) | ||
| if (key != adminProperties.apiKey) { | ||
| throw UnauthorizedException() | ||
| } | ||
|
Comment on lines
+18
to
+20
|
||
| } | ||
| return true | ||
| } | ||
|
Comment on lines
+15
to
+23
|
||
|
|
||
| companion object { | ||
| private const val ADMIN_KEY_HEADER = "X-Admin-Key" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.moa.common.auth | ||
|
|
||
| import org.springframework.boot.context.properties.ConfigurationProperties | ||
|
|
||
| @ConfigurationProperties(prefix = "admin") | ||
| data class AdminProperties( | ||
| val apiKey: String, | ||
| ) | ||
|
Comment on lines
+5
to
+8
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package com.moa.service.dto | ||
|
|
||
| import com.moa.entity.OsType | ||
|
|
||
| data class AppVersionUpdateRequest( | ||
| val osType: OsType, | ||
| val latestVersion: String, | ||
| val minimumVersion: String, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Limiting
@AdminAuthtoFUNCTIONprevents protecting an entire controller/class with a single annotation. If you want class-level protection, includeAnnotationTarget.CLASSin@Targetand update the interceptor to also check the declaring class (e.g.,handler.beanType) for the annotation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이건 나중에 할게 필요할때...