java - 具有 Spring Boot Oaut2UserService 问题的 Azure Active Directory

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

描述:

com.azure.spring.aad.webapp.AADWebSecurityConfigurerAdapter 中的 oidcUserService 字段需要类型为“org.springframework.security.oauth2.client.userinfo.OAuth2UserService”的 bean,但无法找到。

注入(inject)点有以下注解: - @org.springframework.beans.factory.annotation.Autowired(required=true)

行动: 考虑在配置中定义“org.springframework.security.oauth2.client.userinfo.OAuth2UserService”类型的 bean。

SecurityConfig.java

   @EnableWebSecurity
    @EnableGlobalMethodSecurity(prePostEnabled = true)
    @Profile("azure")
    public class SecurityConfig extends AADWebSecurityConfigurerAdapter {
        @Value( "${app.protect.authenticated}")
        private String[] protectedRoutes;

@Override
public void configure(HttpSecurity http) throws Exception {
    super.configure(http);
    http.authorizeRequests()
        .anyRequest().authenticated();

}

}

如果我将我的 SecurtiyConfig.java 与其他几个教程进行比较,它非常相似。或者至少他们在 SecurityConfig 中没有 OAuth2UserService Bean。这就是我不明白的地方。 有人可以帮忙吗? https://code-premium.exaas.bosch.com/ps.go/msal-search-users/-/tree/main/1-Authentication/sign-in

最佳答案

请检查以下解决方法

  1. 请检查依赖项: azure-active-directory-spring-boot-starter 和 spring-boot-starter-oauth2-client。

  2. 在安全配置中尝试这个

@Override
    protected void configure(HttpSecurity http) throws Exception {
        http
              .authorizeRequests()
                .anyRequest().authenticated()
                .and()
                .oauth2Login()
                .userInfoEndpoint()
                .oidcUserService(oidcUserService);

  • 另请检查 application.yml 文件或 application.properties 中是否存在缩进问题。 security 属性必须位于 spring 属性之下,依此类推
  •  azure:
          activedirectory:
            tenant-id: <tenant-id>
        //other

    spring:
      security:
        oauth2:
          client:
           //other

    请引用此Spring Boot Starter for Azure Active Directory developer's guide | Microsoft Docs

    关于java - 具有 Spring Boot Oaut2UserService 问题的 Azure Active Directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70035497/

    相关文章:

    java - 任务 ':compileGroovy'的执行失败。 org.springframework.security.authentication.encoding.PasswordEncoder

    asp.net - Windows Azure Web 角色日志文件

    python - 为什么 list_blobs 也返回虚拟目录?

    java - spring security认证添加子域

    Java类构造函数

    java - PriorityQueue的顺序错误

    java - Spring Boot 中的配置文件位于 jar 文件之外

    java - 性能问题 - JSF 中 AjaxStateHolder 中的 LRUMap()?

    spring-boot - 使用 Jersey 2 和 Spring Boot 向 Annotation-driven swagger.json 添加授权

    azure - 在应用服务环境中安装 ASP.NET CORE 3.0 扩展?