【发布时间】:2020-12-10 13:39:14
【问题描述】:
https://docs.microsoft.com/en-us/azure/developer/java/spring-framework/configure-spring-boot-starter-java-app-with-azure-active-directory 上的教程解释了如何在 Microsoft Azure Active Directory 中使用身份验证设置 Spring Security。
忽略两个小差异(此处解释为 OpenID Connect log in in with Office 365 and spring security),这可以正常工作。
在我的 application.properties 中有这个属性:
azure.activedirectory.active-directory-groups=myADUserGroup
(提示:azure.activedirectory.active-directory-groups 似乎是较新的 azure.activedirectory.user-group.allowed-groups 的弃用版本 ...)
我不想限制特定的群体。对于我的用例,每个拥有有效 Microsoft 帐户的用户都可以。 将属性留空甚至删除属性都会导致此异常:
Caused by: java.lang.IllegalStateException: One of the User Group Properties must be populated. Please populate azure.activedirectory.user-group.allowed-groups
at com.microsoft.azure.spring.autoconfigure.aad.AADAuthenticationProperties.validateUserGroupProperties(AADAuthenticationProperties.java:148) ~[azure-spring-boot-2.3.1.jar:na]
一种可能的解决方法是在 application.properties 中为属性输入任意组名:
azure.activedirectory.active-directory-groups=some-arbitrary-group-name-doesnt-matter
不要使用@PreAuthorize("hasRole('[group / role name]')")。
这可行(只要您的应用对角色名称不感兴趣),但感觉不正确。 A)是否有设置通配符活动目录组的“正确”方法? B)org.springframework.security.core.Authentication.getAuthorities() 似乎只提供在该属性中输入的那些组名/角色名,因此解决方法不提供(但 ROLE_USER)。我想阅读用户的所有组/角色。所以我问第二个问题:如何在不知道所有角色的情况下从 org.springframework.security.core.Authentication.getAuthorities() 获取所有角色,尤其是在不将所有角色都输入“azure.activedirectory.active-directory-组”属性?
【问题讨论】:
-
如果以下答案之一对您有帮助,请告诉我们。如果是这样,请记住使用复选标记将其标记为答案,以便社区中其他有类似问题的人可以更轻松地找到解决方案。另外,请花几分钟时间让我们知道我们如何使用此调查链接 - microsoft.qualtrics.com/jfe/form/…
标签: java spring-security azure-active-directory