-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: connection closed dev resource
- Loading branch information
1 parent
40b8e56
commit 161424a
Showing
8 changed files
with
89 additions
and
6 deletions.
There are no files selected for viewing
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
37 changes: 37 additions & 0 deletions
37
src/main/kotlin/com/hero/alignlab/config/dev/DevResourceCheckConfig.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,37 @@ | ||
package com.hero.alignlab.config.dev | ||
|
||
import com.hero.alignlab.exception.ErrorCode | ||
import com.hero.alignlab.exception.NoAuthorityException | ||
import jakarta.validation.constraints.NotBlank | ||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
@EnableConfigurationProperties(DevResourceCheckConfig.DevResourceCheckProperties::class) | ||
class DevResourceCheckConfig( | ||
_devResourceCheckProperties: DevResourceCheckProperties | ||
) { | ||
@ConfigurationProperties(prefix = "hero-alignlab.dev.resource") | ||
data class DevResourceCheckProperties( | ||
@field:NotBlank | ||
var key: String = "", | ||
) | ||
|
||
init { | ||
devResourceCheckProperties = _devResourceCheckProperties | ||
} | ||
|
||
companion object { | ||
const val DEV_AUTH_TOKEN_KEY = "X-HERO-DEV-AUTH-TOKEN" | ||
|
||
private lateinit var devResourceCheckProperties: DevResourceCheckProperties | ||
|
||
suspend fun <T> devResource(key: String, function: suspend () -> T): T { | ||
if (devResourceCheckProperties.key == key) { | ||
return function.invoke() | ||
} | ||
throw NoAuthorityException(ErrorCode.NO_AUTHORITY_ERROR) | ||
} | ||
} | ||
} |
File renamed without changes.
1 change: 1 addition & 0 deletions
1
src/main/kotlin/com/hero/alignlab/config/swagger/SpringDocConfig.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
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
27 changes: 27 additions & 0 deletions
27
src/main/kotlin/com/hero/alignlab/domain/dev/resource/DevWebsocketResource.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,27 @@ | ||
package com.hero.alignlab.domain.dev.resource | ||
|
||
import com.hero.alignlab.config.dev.DevResourceCheckConfig.Companion.devResource | ||
import com.hero.alignlab.config.swagger.SwaggerTag.DEV_TAG | ||
import com.hero.alignlab.config.web.ReactiveConcurrentUserWebSocketHandler | ||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import org.springframework.http.MediaType | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestHeader | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@Tag(name = DEV_TAG) | ||
@RestController | ||
@RequestMapping(produces = [MediaType.APPLICATION_JSON_VALUE]) | ||
class DevWebsocketResource( | ||
private val reactiveConcurrentUserWebSocketHandler: ReactiveConcurrentUserWebSocketHandler | ||
) { | ||
@Operation(summary = "websocket connection closed") | ||
@PostMapping("/api/dev/v1/websocket/connection-closed") | ||
suspend fun closedConnection( | ||
@RequestHeader("X-HERO-DEV-TOKEN") token: String | ||
) = devResource(token) { | ||
reactiveConcurrentUserWebSocketHandler.forceCloseAllSessions() | ||
} | ||
} |
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 |
---|---|---|
|
@@ -50,3 +50,8 @@ auth: | |
encrypt: | ||
key: | ||
algorithm: | ||
|
||
hero-alignlab: | ||
dev: | ||
resource: | ||
key: |