java - 使用 Spring Boot Starter 解决 Azure Active Directory JWT token 算法问题保护 Java Web 应用程序

标签 java spring-boot azure oauth-2.0 azure-active-directory

我使用 spring boot starter 为 azure Active Directory 一步一步创建了 java web 应用程序,如:https://learn.microsoft.com/en-us/azure/developer/java/spring-framework/configure-spring-boot-starter-java-app-with-azure-active-directory 中所述。

当我打开 localhost:8080 时,使用我的 azure 帐户的应用程序工作正常,它会将我重定向到我进行登录的 azure,然后我会重定向回我的应用程序。

问题是当我尝试使用客户的 azure AD 帐户配置此虚拟应用程序时。在这里,当我打开我的应用程序主机应用程序时,我会将我重定向到 azure 登录,登录后我收到了类似屏幕截图 enter image description here 的错误。

这是我的 application.properties

azure.activedirectory.tenant-id=placeholder 

azure.activedirectory.client-id=placeholder 
azure.activedirectory.client-secret=placeholder 
azure.activedirectory.object-id=placeholder 


azure.activedirectory.user-group.allowed-groups=group1 
azure.activedirectory.session-stateless=true


security.oauth2.authorization.token-key-access=permitAll() 
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
application.baseurl.logout.redirect=https://mydomain:8081/

application.groups.for.displaying=
application.groups.for.filtering=
server.port=8081



server.ssl.enabled=true 
server.ssl.trust-store=/apps/tomcat/conf/trusted.jks 
server.ssl.trust-store-password=mykeys 


server.ssl.key-store=/apps/tomcat/conf/.keystore 
server.ssl.key-store-password=f213495a0be855c4ab190a1f84cc18cd 
server.ssl.key-store-type=JKS

server.ssl.key-alias=key-dev-ui 
server.ssl.key-password=f213495a0be855c4ab190a1f84cc18cd

我的配置:

 @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.cors().and().csrf().disable().authorizeRequests().anyRequest().authenticated().and().oauth2Login().and().csrf()
                .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
                .and().oauth2Client();
    }

最佳答案

请检查以下几点:

  1. 当从 token 获取的颁发者值来自与预期不同的端点 (v2) 时,可能会出现此问题。请确保使用最新版本的 Spring Boot api 并检查其是否在依赖项中。
  2. 您需要在门户中将重定向 URL 设置为 http://localhost:8080/login/oauth2/code/azure 或 http://localhost:8080/login/oauth2/code/。您可以配置其他值根据您的应用程序代替 localhost:8080 。必须在您的应用程序属性中配置此重定向 uri。
  3. 确保公开 API 并确保权限也已配置并获得管理员同意。

enter image description here

。提供默认范围(确保在代码中添加范围)或直接提供应用程序中存在的范围( checkin 应用程序代码),例如 User.read 、file.read 或offline_access ,并在门户中提供委托(delegate)权限,如下所示(如果这些存在于代码中)。

enter image description here

(或)

enter image description here

和高级管理员同意 enter image description here

另请参阅springboot starter dev guide | ms docs请检查下面的引用资料。

如果上述情况不属于进一步调查的情况,您可以通过编辑问题来提供其他配置详细信息。

引用文献:

  1. spring-rest-azure-ad-oauth
  2. using-spring-security-with-azure-active-directory-mga

关于java - 使用 Spring Boot Starter 解决 Azure Active Directory JWT token 算法问题保护 Java Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69770894/

相关文章:

java - 使用 Selenium WebDriver 进行搜索可以在 google 上运行,但在 yahoo 上失败

java - 每秒更新通知中的 RemoteViews

spring-boot - 文本字段未针对需要每个文档 : Elasticsearch 的操作进行优化

azure - 通过 ARM 模板配置每日交易量上限警告级别

python - 使用 az cli 或 python sdk 检索 blob 存储连接字符串?

AzureRM 站点到站点连接状态为 "Unknown"

java - 难以理解通配符

java - 上下文初始化失败/创建名为 'org.springframework.security.filterChains' 的 bean 时出错

java - 从 cron 运行 Spring Boot 应用程序

java - Elastic Search for Spring Boot 2.1.3的最新稳定版本