diff --git a/src/backend/ci/core/auth/biz-auth/src/main/kotlin/com/tencent/devops/auth/resources/UserAuthAuthorizationResourceImpl.kt b/src/backend/ci/core/auth/biz-auth/src/main/kotlin/com/tencent/devops/auth/resources/UserAuthAuthorizationResourceImpl.kt index 59d2aabdf43..f70eb7f8d18 100644 --- a/src/backend/ci/core/auth/biz-auth/src/main/kotlin/com/tencent/devops/auth/resources/UserAuthAuthorizationResourceImpl.kt +++ b/src/backend/ci/core/auth/biz-auth/src/main/kotlin/com/tencent/devops/auth/resources/UserAuthAuthorizationResourceImpl.kt @@ -1,24 +1,37 @@ package com.tencent.devops.auth.resources import com.tencent.devops.auth.api.user.UserAuthAuthorizationResource +import com.tencent.devops.auth.constant.AuthMessageCode import com.tencent.devops.common.auth.api.pojo.ResourceAuthorizationConditionDTO import com.tencent.devops.common.auth.api.pojo.ResourceAuthorizationDTO import com.tencent.devops.auth.service.PermissionAuthorizationService +import com.tencent.devops.auth.service.iam.PermissionProjectService import com.tencent.devops.auth.service.iam.PermissionResourceService +import com.tencent.devops.common.api.exception.PermissionForbiddenException import com.tencent.devops.common.api.pojo.Result import com.tencent.devops.common.auth.api.AuthResourceType import com.tencent.devops.common.web.RestResource +import com.tencent.devops.common.web.utils.I18nUtil @RestResource class UserAuthAuthorizationResourceImpl( val permissionAuthorizationService: PermissionAuthorizationService, + val permissionProjectService: PermissionProjectService ) : UserAuthAuthorizationResource { override fun listResourceAuthorization( userId: String, projectId: String, condition: ResourceAuthorizationConditionDTO ): Result> { - // todo 管理员校验 + val hasProjectManagePermission = permissionProjectService.checkProjectManager( + userId = userId, + projectCode = condition.projectCode + ) + if (!hasProjectManagePermission) { + throw PermissionForbiddenException( + message = I18nUtil.getCodeLanMessage(AuthMessageCode.ERROR_AUTH_NO_MANAGE_PERMISSION) + ) + } return Result( permissionAuthorizationService.listResourceAuthorizations( condition = condition diff --git a/src/backend/ci/core/auth/biz-auth/src/main/kotlin/com/tencent/devops/auth/service/PermissionAuthorizationServiceImpl.kt b/src/backend/ci/core/auth/biz-auth/src/main/kotlin/com/tencent/devops/auth/service/PermissionAuthorizationServiceImpl.kt index 5fb688c225c..5d30c980f82 100644 --- a/src/backend/ci/core/auth/biz-auth/src/main/kotlin/com/tencent/devops/auth/service/PermissionAuthorizationServiceImpl.kt +++ b/src/backend/ci/core/auth/biz-auth/src/main/kotlin/com/tencent/devops/auth/service/PermissionAuthorizationServiceImpl.kt @@ -1,16 +1,18 @@ package com.tencent.devops.auth.service +import com.tencent.devops.auth.constant.AuthMessageCode import com.tencent.devops.auth.dao.AuthAuthorizationDao +import com.tencent.devops.auth.service.iam.PermissionProjectService +import com.tencent.devops.common.api.exception.ErrorCodeException +import com.tencent.devops.common.api.exception.PermissionForbiddenException import com.tencent.devops.common.auth.api.pojo.ResourceAuthorizationConditionDTO import com.tencent.devops.common.auth.api.pojo.ResourceAuthorizationDTO import com.tencent.devops.common.auth.api.pojo.ResourceAuthorizationHandoverConditionDTO import com.tencent.devops.common.auth.api.pojo.ResourceAuthorizationHandoverDTO -import com.tencent.devops.common.auth.enums.HandoverChannelCode -import com.tencent.devops.auth.service.iam.PermissionResourceService -import com.tencent.devops.common.api.exception.ErrorCodeException -import com.tencent.devops.common.auth.api.AuthResourceType import com.tencent.devops.common.auth.api.pojo.ResourceAuthorizationHandoverResult +import com.tencent.devops.common.auth.enums.HandoverChannelCode import com.tencent.devops.common.auth.enums.ResourceAuthorizationHandoverStatus +import com.tencent.devops.common.web.utils.I18nUtil import org.jooq.DSLContext import org.springframework.stereotype.Service @@ -18,7 +20,7 @@ import org.springframework.stereotype.Service class PermissionAuthorizationServiceImpl constructor( private val dslContext: DSLContext, private val authAuthorizationDao: AuthAuthorizationDao, - private val permissionResourceService: PermissionResourceService + private val permissionProjectService: PermissionProjectService ) : PermissionAuthorizationService { override fun addResourceAuthorization(resourceAuthorizationList: List): Boolean { authAuthorizationDao.batchAddOrUpdate( @@ -112,12 +114,15 @@ class PermissionAuthorizationServiceImpl constructor( ) { // 若是在授权管理界面操作,则只要校验操作人是否为管理员即可 if (condition.handoverChannel == HandoverChannelCode.MANAGER) { - permissionResourceService.hasManagerPermission( + val hasProjectManagePermission = permissionProjectService.checkProjectManager( userId = operator, - projectId = condition.projectCode, - resourceType = AuthResourceType.PROJECT.value, - resourceCode = condition.projectCode + projectCode = condition.projectCode ) + if (!hasProjectManagePermission){ + throw PermissionForbiddenException( + message = I18nUtil.getCodeLanMessage(AuthMessageCode.ERROR_AUTH_NO_MANAGE_PERMISSION) + ) + } } else { val record = condition.resourceAuthorizationHandoverList.first() validateSingleResourcePermission?.invoke(