Azure 为什么客户端ID和客户端机密不注入OAuth2ClientProperties?

Azure 为什么客户端ID和客户端机密不注入OAuth2ClientProperties?,azure,spring-boot,spring-security,active-directory,spring-security-oauth2,Azure,Spring Boot,Spring Security,Active Directory,Spring Security Oauth2,我有一个SpringBoot应用程序,Azure AD作为OAuth2提供程序。这是我的application.yml文件: server: port: 8080 address: localhost security: oauth2: client: registration: azure: client-id: XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX client-secre

我有一个SpringBoot应用程序,Azure AD作为OAuth2提供程序。这是我的
application.yml
文件:

server:
  port: 8080
  address: localhost
security:
  oauth2:
    client:
      registration:
        azure:
          client-id: XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
          client-secret: ?h?_XXXXXXXXXXXXXXXXXXXXXXXX
azure:
  cosmosdb:
    uri: https://myapp.documents.azure.com:443/
    key: ${COSMOSDB_KEY}
    database: Core
  activedirectory:
    tenant-id: ${TENANT_ID}
    user-group:
      allowed-group: user-group
如您所见,我在open中使用客户机id和客户机secret(不是通过环境变量),但它仍然不起作用

这是我的gradle构建文件:

plugins {
    id 'org.springframework.boot' version '2.2.6.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
}

group = 'group'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
    jcenter()
}

ext {
    set('azureVersion', "2.2.0")
}

dependencies {
//    Web
    implementation 'org.modelmapper:modelmapper:2.3.7'
    implementation 'org.springframework.boot:spring-boot-starter-web'

//    Azure
    implementation 'com.microsoft.azure:azure-spring-boot-starter'
    implementation 'com.microsoft.azure:azure-cosmosdb-spring-boot-starter'
    implementation 'com.microsoft.azure:azure-active-directory-spring-boot-starter'

//    OpenAPI
    implementation 'org.springdoc:springdoc-openapi-ui:1.3.7'
    implementation 'org.springdoc:springdoc-openapi-webmvc-core:1.3.7'

//    Security
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'

//    Lombok
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    testCompileOnly 'org.projectlombok:lombok'
    testAnnotationProcessor 'org.projectlombok:lombok'

//    Tests
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    testImplementation 'org.springframework.security:spring-security-test'
}

dependencyManagement {
    imports {
        mavenBom "com.microsoft.azure:azure-spring-boot-bom:${azureVersion}"
    }
}

test {
    useJUnitPlatform()
}
我的安全配置:

@Slf4j
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    public void configure(WebSecurity web) {
        web
                .ignoring()
                .antMatchers("/webjars/**", "/favicon.ico");
    }

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .anyRequest().authenticated()
                .and()
                .formLogin()
                .loginPage("/login")
                .failureUrl("/login-error")
                .permitAll()
                .and()
                .oauth2Client();
    }
}
我在启动过程中遇到以下错误:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration': Unsatisfied dependency expressed through method 'setConfigurers' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.OAuth2ClientConfiguration$OAuth2ClientWebMvcSecurityConfiguration': Unsatisfied dependency expressed through method 'setClientRegistrationRepository' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'clientRegistrationRepository' defined in class path resource [org/springframework/boot/autoconfigure/security/oauth2/client/servlet/OAuth2ClientRegistrationRepositoryConfiguration.class]: Unsatisfied dependency expressed through method 'clientRegistrationRepository' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.security.oauth2.client-org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Client id must not be empty.

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.OAuth2ClientConfiguration$OAuth2ClientWebMvcSecurityConfiguration': Unsatisfied dependency expressed through method 'setClientRegistrationRepository' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'clientRegistrationRepository' defined in class path resource [org/springframework/boot/autoconfigure/security/oauth2/client/servlet/OAuth2ClientRegistrationRepositoryConfiguration.class]: Unsatisfied dependency expressed through method 'clientRegistrationRepository' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.security.oauth2.client-org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Client id must not be empty.

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'clientRegistrationRepository' defined in class path resource [org/springframework/boot/autoconfigure/security/oauth2/client/servlet/OAuth2ClientRegistrationRepositoryConfiguration.class]: Unsatisfied dependency expressed through method 'clientRegistrationRepository' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.security.oauth2.client-org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Client id must not be empty.

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.security.oauth2.client-org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Client id must not be empty.

Caused by: java.lang.IllegalStateException: Client id must not be empty.

我在这里遗漏了什么?

我忘了添加
spring.
前缀到
security
属性。应该是这样的:

security:
  oauth2:
    client:
      registration:
        azure:
          client-id: XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
          client-secret: ?h?_XXXXXXXXXXXXXXXXXXXXXXXX
另外,我的
azure
属性也不正确:我需要使用
允许的组,而不是
允许的组