Skip to content

Commit

Permalink
feat: 支持websocket #2494
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoxuwan committed Nov 15, 2024
1 parent ae04b5b commit ba997a8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ package com.tencent.bkrepo.websocket.config
import com.tencent.bkrepo.common.security.http.jwt.JwtAuthProperties
import com.tencent.bkrepo.common.security.manager.AuthenticationManager
import com.tencent.bkrepo.websocket.constant.APP_ENDPOINT
import com.tencent.bkrepo.websocket.constant.DESKTOP_ENDPOINT
import com.tencent.bkrepo.websocket.constant.USER_ENDPOINT
import com.tencent.bkrepo.websocket.dispatch.push.TransferPush
import com.tencent.bkrepo.websocket.handler.SessionWebSocketHandlerDecoratorFactory
Expand Down Expand Up @@ -68,9 +69,9 @@ class WebsocketConfiguration(
}

override fun registerStompEndpoints(registry: StompEndpointRegistry) {
registry.addEndpoint(USER_ENDPOINT, APP_ENDPOINT)
registry.addEndpoint(USER_ENDPOINT, APP_ENDPOINT, DESKTOP_ENDPOINT)
.setAllowedOriginPatterns("*")
registry.addEndpoint(USER_ENDPOINT, APP_ENDPOINT)
registry.addEndpoint(USER_ENDPOINT, APP_ENDPOINT, DESKTOP_ENDPOINT)
.setAllowedOriginPatterns("*")
.withSockJS()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ package com.tencent.bkrepo.websocket.constant

const val USER_ENDPOINT = "/ws/user"
const val APP_ENDPOINT = "/ws/app"
const val DESKTOP_ENDPOINT = "/ws/desktop"

const val SESSION_ID = "sessionId"
14 changes: 10 additions & 4 deletions src/gateway/lua/auth/auth_web.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ elseif config.auth_mode == "ticket" then
if bk_ticket == nil then
bk_ticket = ngx.var.http_x_devops_bk_ticket
if bk_ticket == nil then
ngx.exit(401)
return
bk_ticket = urlUtil:parseUrl(ngx.var.request_uri)["x-devops-bk-ticket"]
if bk_ticket == nil then
ngx.exit(401)
return
end
end
end
username = oauthUtil:verify_ticket(bk_ticket, "ticket")
Expand All @@ -64,8 +67,11 @@ elseif config.auth_mode == "odc" then
if bk_token == nil then
bk_token = ngx.var.http_x_devops_bk_token
if bk_token == nil then
ngx.exit(401)
return
bk_token = urlUtil:parseUrl(ngx.var.request_uri)["x-devops-bk-token"]
if bk_token == nil then
ngx.exit(401)
return
end
end
end
username = oauthUtil:verify_tai_token(bk_token)
Expand Down
4 changes: 2 additions & 2 deletions src/gateway/vhosts/bkrepo.websocket.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
location ~ /websocket/(ws/user.*) {
location ~ /websocket/(ws/user/.*|ws/desktop/.*) {
header_filter_by_lua_file 'conf/lua/cors_filter.lua';
auth_request /auth/web;
# 设置auth的变量
Expand Down Expand Up @@ -43,4 +43,4 @@ location ~ /websocket/(ws/app.*) {
proxy_set_header Connection "Upgrade";
proxy_http_version 1.1;
proxy_pass http://$target/$path?$args;
}
}

0 comments on commit ba997a8

Please sign in to comment.