gpt4 book ai didi

java - 为什么在Azure AD保护的Spring boot应用程序中它被称为 'APPROLE_Admin'而不是 'Admin'

转载 作者:行者123 更新时间:2023-12-02 06:55:27 27 4
gpt4 key购买 nike

我关注了这篇文章,https://learn.microsoft.com/en-us/azure/developer/java/spring-framework/configure-spring-boot-starter-java-app-with-azure-active-directory并创建了一个应用程序角色

enter image description here

并分配用户

enter image description here

在 Spring Boot 应用程序中,我必须使用“APPROLE_Admin”而不是“Admin”?为什么?它应该只是“管理员”,对吗?

@CrossOrigin(origins = "http://localhost:8080")
@RestController
@RequestMapping("/api")
public class TutorialController {

@Autowired
TutorialRepository tutorialRepository;

@PreAuthorize("hasAuthority('APPROLE_Admin')")
@GetMapping("/tutorials")

最佳答案

APPROLE_ 前缀来自 Spring Cloud Azure 的默认属性配置。

spring.cloud.azure.active-directory.resource-server.claim-to-authority-prefix-map

Configure which claim will be used to build GrantedAuthority, and prefix of the GrantedAuthority’s string value. Default value is: "scp" → "SCOPE_", "roles" → "APPROLE_".

Documentation link

您可以使用所需的前缀更新属性:

spring:
cloud:
azure:
active-directory:
resource-server:
claim-to-authority-prefix-map:
roles: "" # no prefix
scp: "MY_SCP_PREFIX_"

关于java - 为什么在Azure AD保护的Spring boot应用程序中它被称为 'APPROLE_Admin'而不是 'Admin',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72340523/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com