-
Notifications
You must be signed in to change notification settings - Fork 500
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8318 from stubenhuang/issue-token-8317
feat: 通过网关进行的跨服务调用, 必须携带token进行校验 #8317
- Loading branch information
Showing
16 changed files
with
309 additions
and
67 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
.../src/main/kotlin/com/tencent/devops/auth/api/callback/OpenAuthResourceCallBackResource.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,69 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. | ||
* | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. | ||
* | ||
* A copy of the MIT License is included in this file. | ||
* | ||
* | ||
* Terms of the MIT License: | ||
* --------------------------------------------------- | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the | ||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of | ||
* the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | ||
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.tencent.devops.auth.api.callback | ||
|
||
import com.tencent.bk.sdk.iam.dto.callback.request.CallbackRequestDTO | ||
import com.tencent.bk.sdk.iam.dto.callback.response.CallbackBaseResponseDTO | ||
import io.swagger.annotations.Api | ||
import io.swagger.annotations.ApiOperation | ||
import io.swagger.annotations.ApiParam | ||
import javax.ws.rs.Consumes | ||
import javax.ws.rs.POST | ||
import javax.ws.rs.Path | ||
import javax.ws.rs.Produces | ||
import javax.ws.rs.HeaderParam | ||
import javax.ws.rs.core.MediaType | ||
|
||
@Api(tags = ["AUTH_RESOURCE_CALLBACK"], description = "权限-资源-回调接口") | ||
@Path("/open/auth/resource") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
interface OpenAuthResourceCallBackResource { | ||
|
||
@POST | ||
@Path("/projects") | ||
@ApiOperation("项目列表") | ||
fun projectInfo( | ||
@ApiParam(value = "回调信息") | ||
callBackInfo: CallbackRequestDTO, | ||
@HeaderParam("Authorization") | ||
@ApiParam("token") | ||
token: String | ||
): CallbackBaseResponseDTO? | ||
|
||
@POST | ||
@Path("/instances/list") | ||
@ApiOperation("特定资源列表") | ||
fun resourceList( | ||
@ApiParam(value = "回调信息") | ||
callBackInfo: CallbackRequestDTO, | ||
@HeaderParam("Authorization") | ||
@ApiParam("token") | ||
token: String | ||
): CallbackBaseResponseDTO? | ||
} |
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
76 changes: 76 additions & 0 deletions
76
...src/main/kotlin/com/tencent/devops/auth/resources/OpenAuthResourceCallBackResourceImpl.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,76 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. | ||
* | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. | ||
* | ||
* A copy of the MIT License is included in this file. | ||
* | ||
* | ||
* Terms of the MIT License: | ||
* --------------------------------------------------- | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the | ||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of | ||
* the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | ||
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
package com.tencent.devops.auth.resources | ||
|
||
import com.tencent.bk.sdk.iam.dto.callback.request.CallbackRequestDTO | ||
import com.tencent.bk.sdk.iam.dto.callback.response.CallbackBaseResponseDTO | ||
import com.tencent.devops.auth.api.callback.OpenAuthResourceCallBackResource | ||
import com.tencent.devops.auth.service.ResourceService | ||
import com.tencent.devops.common.api.exception.TokenForbiddenException | ||
import com.tencent.devops.common.auth.api.AuthTokenApi | ||
import com.tencent.devops.common.web.RestResource | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.beans.factory.annotation.Autowired | ||
|
||
@RestResource | ||
class OpenAuthResourceCallBackResourceImpl @Autowired constructor( | ||
val resourceService: ResourceService, | ||
val authTokenApi: AuthTokenApi | ||
) : OpenAuthResourceCallBackResource { | ||
|
||
override fun projectInfo( | ||
callBackInfo: CallbackRequestDTO, | ||
token: String | ||
): CallbackBaseResponseDTO { | ||
if (!authTokenApi.checkToken(token)) { | ||
logger.warn("auth token check fail: $token") | ||
throw TokenForbiddenException("auth token check fail") | ||
} | ||
return resourceService.getProject(callBackInfo, token) | ||
} | ||
|
||
override fun resourceList( | ||
callBackInfo: CallbackRequestDTO, | ||
token: String | ||
): CallbackBaseResponseDTO? { | ||
if (!authTokenApi.checkToken(token)) { | ||
logger.warn("auth token check fail: $token") | ||
throw TokenForbiddenException("auth token check fail") | ||
} | ||
logger.info("resourceList: $callBackInfo, token: $token") | ||
return resourceService.getInstanceByResource( | ||
callBackInfo = callBackInfo, | ||
token = token | ||
) | ||
} | ||
|
||
companion object { | ||
private val logger = LoggerFactory.getLogger(OpenAuthResourceCallBackResourceImpl::class.java) | ||
} | ||
} |
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
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
Oops, something went wrong.