-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[ISSUE #15476] Add plugin-owned AI visibility grant API #15513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Zhengcy05
wants to merge
7
commits into
alibaba:develop
Choose a base branch
from
Zhengcy05:feat/ai-visibility-grant-api
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a8d5684
feat: ai-visibility grant api
Zhengcy05 24d8535
fix: add User existence verification and fix test
Zhengcy05 d2fcd51
Merge branch 'develop' into feat/ai-visibility-grant-api
Zhengcy05 eddf511
fix: Modify naming to remove AI semantics
Zhengcy05 2df3d4f
feat: retain at most one visibility role
Zhengcy05 4671420
feat: keep the authorization chain as identity -> role -> permission
Zhengcy05 0210581
feat: expand 'resource' to 512
Zhengcy05 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
ai/src/main/java/com/alibaba/nacos/ai/service/visibility/AiVisibilityResourceLocator.java
This file contains hidden or 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,54 @@ | ||
| /* | ||
| * Copyright 1999-2026 Alibaba Group Holding Ltd. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.alibaba.nacos.ai.service.visibility; | ||
|
|
||
| import com.alibaba.nacos.ai.model.AiResource; | ||
| import com.alibaba.nacos.ai.service.repository.AiResourcePersistService; | ||
| import com.alibaba.nacos.common.utils.StringUtils; | ||
| import com.alibaba.nacos.plugin.visibility.model.VisibilityResource; | ||
| import com.alibaba.nacos.plugin.visibility.spi.VisibilityResourceLocator; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| import static com.alibaba.nacos.api.common.Constants.DEFAULT_NAMESPACE_ID; | ||
|
|
||
| /** | ||
| * AI implementation of {@link VisibilityResourceLocator}. | ||
| * | ||
| * @author Zhengcy05 | ||
| */ | ||
| @Service | ||
| public class AiVisibilityResourceLocator implements VisibilityResourceLocator { | ||
|
|
||
| private final AiResourcePersistService aiResourcePersistService; | ||
|
|
||
| public AiVisibilityResourceLocator(AiResourcePersistService aiResourcePersistService) { | ||
| this.aiResourcePersistService = aiResourcePersistService; | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<VisibilityResource> findResource(String namespaceId, String resourceType, | ||
| String resourceName) { | ||
| String resolvedNamespaceId = | ||
| StringUtils.isBlank(namespaceId) ? DEFAULT_NAMESPACE_ID : namespaceId; | ||
| // The auth plugin resolves resources by the same identity tuple used by AI persistence. | ||
| AiResource resource = | ||
| aiResourcePersistService.find(resolvedNamespaceId, resourceName, resourceType); | ||
| return Optional.ofNullable(resource).map(each -> (VisibilityResource) each); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
115 changes: 115 additions & 0 deletions
115
...in/java/com/alibaba/nacos/plugin/auth/impl/controller/v3/VisibilityGrantControllerV3.java
This file contains hidden or 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,115 @@ | ||
| /* | ||
| * Copyright 1999-2026 Alibaba Group Holding Ltd. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.alibaba.nacos.plugin.auth.impl.controller.v3; | ||
|
|
||
| import com.alibaba.nacos.api.annotation.Since; | ||
| import com.alibaba.nacos.api.exception.NacosException; | ||
| import com.alibaba.nacos.api.model.v2.Result; | ||
| import com.alibaba.nacos.auth.annotation.Secured; | ||
| import com.alibaba.nacos.plugin.auth.constant.ActionTypes; | ||
| import com.alibaba.nacos.plugin.auth.constant.Constants; | ||
| import com.alibaba.nacos.plugin.auth.impl.constant.AuthConstants; | ||
| import com.alibaba.nacos.plugin.auth.impl.visibility.VisibilityGrantInfo; | ||
| import com.alibaba.nacos.plugin.auth.impl.visibility.VisibilityGrantService; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Plugin-owned visibility grant API. | ||
| * | ||
| * @author Zhengcy05 | ||
| */ | ||
| @RestController | ||
| @RequestMapping(AuthConstants.VISIBILITY_PATH) | ||
| public class VisibilityGrantControllerV3 { | ||
|
|
||
| private final VisibilityGrantService visibilityGrantService; | ||
|
|
||
| public VisibilityGrantControllerV3(VisibilityGrantService visibilityGrantService) { | ||
| this.visibilityGrantService = visibilityGrantService; | ||
| } | ||
|
|
||
| /** | ||
| * Grant one visibility action to a user for a resource. | ||
| * | ||
| * @param namespaceId namespace ID, blank for the default namespace | ||
| * @param resourceType resource type | ||
| * @param resourceName resource name | ||
| * @param username grantee username | ||
| * @param action grant action | ||
| * @return success result | ||
| * @throws NacosException if validation or grant management fails | ||
| */ | ||
| @Since("3.3.0") | ||
| @PostMapping | ||
| @Secured(resource = AuthConstants.VISIBILITY_RESOURCE, action = ActionTypes.WRITE, | ||
| tags = Constants.Tag.ONLY_IDENTITY) | ||
| public Result<String> grant(@RequestParam(required = false) String namespaceId, | ||
| @RequestParam String resourceType, @RequestParam String resourceName, | ||
| @RequestParam String username, @RequestParam String action) throws NacosException { | ||
| visibilityGrantService.grant(namespaceId, resourceType, resourceName, username, action); | ||
| return Result.success("grant visibility permission ok!"); | ||
| } | ||
|
|
||
| /** | ||
| * Revoke one visibility action from a user for a resource. | ||
| * | ||
| * @param namespaceId namespace ID, blank for the default namespace | ||
| * @param resourceType resource type | ||
| * @param resourceName resource name | ||
| * @param username grantee username | ||
| * @param action grant action | ||
| * @return success result | ||
| * @throws NacosException if validation or grant management fails | ||
| */ | ||
| @Since("3.3.0") | ||
| @DeleteMapping | ||
| @Secured(resource = AuthConstants.VISIBILITY_RESOURCE, action = ActionTypes.WRITE, | ||
| tags = Constants.Tag.ONLY_IDENTITY) | ||
| public Result<String> revoke(@RequestParam(required = false) String namespaceId, | ||
| @RequestParam String resourceType, @RequestParam String resourceName, | ||
| @RequestParam String username, @RequestParam String action) throws NacosException { | ||
| visibilityGrantService.revoke(namespaceId, resourceType, resourceName, username, action); | ||
| return Result.success("revoke visibility permission ok!"); | ||
| } | ||
|
|
||
| /** | ||
| * List grants attached to one resource. | ||
| * | ||
| * @param namespaceId namespace ID, blank for the default namespace | ||
| * @param resourceType resource type | ||
| * @param resourceName resource name | ||
| * @return current grants | ||
| * @throws NacosException if validation or grant management fails | ||
| */ | ||
| @Since("3.3.0") | ||
| @GetMapping("/list") | ||
| @Secured(resource = AuthConstants.VISIBILITY_RESOURCE, action = ActionTypes.READ, | ||
| tags = Constants.Tag.ONLY_IDENTITY) | ||
| public Result<List<VisibilityGrantInfo>> list( | ||
| @RequestParam(required = false) String namespaceId, | ||
| @RequestParam String resourceType, @RequestParam String resourceName) | ||
| throws NacosException { | ||
| return Result.success(visibilityGrantService.list(namespaceId, resourceType, resourceName)); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.