Skip to content

Commit

Permalink
feat:蓝盾APP Oauth2授权登录实现 #9353
Browse files Browse the repository at this point in the history
  • Loading branch information
fcfang123 committed Nov 9, 2023
1 parent a152f56 commit 3df1aba
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ interface ServiceDeptResource {
fun getUserInfoAndWaterMark(
@HeaderParam(AUTH_HEADER_DEVOPS_USER_ID)
@ApiParam("用户ID", required = true)
userId: String
userId: String,
@ApiParam("项目ID", required = true)
@QueryParam("projectCode")
projectCode: String
): Result<UserAndDeptInfoVo?>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.tencent.devops.auth.pojo.BkUserExtras
import io.swagger.annotations.ApiModel
import io.swagger.annotations.ApiModelProperty

@ApiModel("用户和组织信息返回")
@ApiModel("用户和组织信息返回实体")
data class UserAndDeptInfoVo(
@ApiModelProperty("id")
val id: Int,
Expand All @@ -21,5 +21,7 @@ data class UserAndDeptInfoVo(
@ApiModelProperty("用户额外详细信息")
val extras: BkUserExtras? = null,
@ApiModelProperty("水印信息")
val waterMark: String? = null
val waterMark: String? = null,
@ApiModelProperty("是否是项目成员")
val belongProjectMember: Boolean? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ class ServiceDeptResourceImpl @Autowired constructor(
return Result(deptService.getUserInfo(userId, name))
}

override fun getUserInfoAndWaterMark(userId: String): Result<UserAndDeptInfoVo?> {
return Result(deptService.getUserInfoAndWaterMark(userId))
override fun getUserInfoAndWaterMark(
userId: String,
projectCode: String
): Result<UserAndDeptInfoVo?> {
return Result(deptService.getUserInfoAndWaterMark(userId, projectCode))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import com.tencent.devops.auth.entity.UserDeptTreeInfo
import com.tencent.devops.auth.pojo.vo.BkUserInfoVo
import com.tencent.devops.auth.pojo.vo.DeptInfoVo
import com.tencent.devops.auth.pojo.vo.UserAndDeptInfoVo
import com.tencent.devops.auth.service.iam.PermissionProjectService
import com.tencent.devops.auth.service.secops.SecOpsService
import com.tencent.devops.common.api.exception.ErrorCodeException
import com.tencent.devops.common.api.exception.OperationException
Expand All @@ -68,7 +69,8 @@ import java.util.concurrent.TimeUnit
class AuthDeptServiceImpl @Autowired constructor(
val redisOperation: RedisOperation,
val objectMapper: ObjectMapper,
val secOpsService: SecOpsService
val secOpsService: SecOpsService,
val permissionProjectService: PermissionProjectService
) : DeptService {

@Value("\${esb.code:#{null}}")
Expand Down Expand Up @@ -266,7 +268,10 @@ class AuthDeptServiceImpl @Autowired constructor(
return userInfoCache.getIfPresent(name)?.get() ?: getUserAndPutInCache(userId, name)
}

override fun getUserInfoAndWaterMark(userId: String): UserAndDeptInfoVo? {
override fun getUserInfoAndWaterMark(
userId: String,
projectCode: String
): UserAndDeptInfoVo? {
val userInfo = getUserInfo(
userId = userId,
name = userId
Expand All @@ -275,14 +280,20 @@ class AuthDeptServiceImpl @Autowired constructor(
defaultMessage = "user not exist!$userId"
)
val userWaterMark = secOpsService.getUserWaterMark(userId = userId)
val belongProjectMember = permissionProjectService.isProjectUser(
userId = userId,
projectCode = projectCode,
group = null
)
return UserAndDeptInfoVo(
id = userInfo.id,
name = userInfo.name,
type = userInfo.type,
hasChild = userInfo.hasChild,
deptInfo = userInfo.deptInfo,
extras = userInfo.extras,
waterMark = userWaterMark.data
waterMark = userWaterMark.data,
belongProjectMember = belongProjectMember
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ class DefaultDeptServiceImpl : DeptService {
type = ManagerScopesEnum.USER
)

override fun getUserInfoAndWaterMark(userId: String): UserAndDeptInfoVo? = UserAndDeptInfoVo(
override fun getUserInfoAndWaterMark(
userId: String,
projectCode: String
): UserAndDeptInfoVo? = UserAndDeptInfoVo(
id = 0,
name = userId,
type = ManagerScopesEnum.USER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ interface DeptService {
// 获取单个用户信息
fun getUserInfo(userId: String, name: String): UserAndDeptInfoVo?

fun getUserInfoAndWaterMark(userId: String): UserAndDeptInfoVo?
fun getUserInfoAndWaterMark(userId: String, projectCode: String): UserAndDeptInfoVo?
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import javax.ws.rs.HeaderParam
import javax.ws.rs.Path
import javax.ws.rs.PathParam
import javax.ws.rs.Produces
import javax.ws.rs.QueryParam
import javax.ws.rs.core.MediaType

@Api(tags = ["OPENAPI_USER_MANAGEMENT_V4"], description = "OPENAPI-用户管理")
Expand All @@ -37,6 +38,9 @@ interface ApigwUserManagementResourceV4 {
apigwType: String?,
@ApiParam("用户ID", required = true, defaultValue = AUTH_HEADER_USER_ID_DEFAULT_VALUE)
@HeaderParam(AUTH_HEADER_USER_ID)
userId: String
userId: String,
@ApiParam("项目ID", required = true)
@QueryParam("projectCode")
projectCode: String
): Result<UserAndDeptInfoVo?>
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ class ApigwUserManagementResourceV4Impl @Autowired constructor(
override fun getUserInfo(
appCode: String?,
apigwType: String?,
userId: String
userId: String,
projectCode: String
): Result<UserAndDeptInfoVo?> {
logger.info("OPENAPI_GET_USER_INFO_V4|$appCode|$userId")
return client.get(ServiceDeptResource::class).getUserInfoAndWaterMark(
userId = userId
userId = userId,
projectCode = projectCode
)
}

Expand Down

0 comments on commit 3df1aba

Please sign in to comment.