描述:
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
最佳答案
请检查以下解决方法
请检查依赖项: azure-active-directory-spring-boot-starter 和 spring-boot-starter-oauth2-client。
在安全配置中尝试这个
@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/