【问题标题】:Azure active directory with spring boot Oaut2UserService Problem带有spring boot Oaut2UserService问题的Azure Active Directory
【发布时间】:2021-12-30 06:24:03
【问题描述】:

说明:

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

注入点有以下注解: - @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

【问题讨论】:

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


    【解决方案1】:

    请检查以下解决方法

    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);
    1. 还要检查是否是 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

    【讨论】:

    • 不幸的是,您的想法不起作用。当我添加 .oidUserService(oidcUserService) 我仍然需要这个 UserService 并且我不知道它应该来自哪里。
    • 我还仔细检查了 application.yml 中的缩进。从我的角度来看,Semms 是正确的。我的 application.yml 不包含的是第二个春天:secturity:oauth2:client:。我真的需要那个吗?我无法在您发布的文档中找到它。
    猜你喜欢
    • 2020-09-24
    • 1970-01-01
    • 2019-02-10
    • 1970-01-01
    • 2022-01-05
    • 2023-03-11
    • 1970-01-01
    • 2017-01-03
    • 2020-03-16
    相关资源
    最近更新 更多