【发布时间】:2022-01-15 02:09:29
【问题描述】:
我正在尝试使用 Web 服务为我的 Spring Boot 运行 azure Active Directory。问题是当我成功登录时,它会抛出一个错误:
我添加了以下属性(tetant-id、client-id、client-secret、user-group.allowed-group-names)
azure.activedirectory.redirect-uri-template=http://localhost:8080/login/oauth2/code/
我的配置是:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
public class AADSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) {
web.ignoring().antMatchers("/health");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/oauth2/**", "/login/**")
.permitAll()
.anyRequest()
.authenticated()
.and()
.oauth2Login();
}
}
简单的控制器请求是:
@GetMapping("/list")
@PreAuthorize("hasRole('Admin') or hasRole('Users')")
public String getListPage() {
return "list";
}
依赖的版本是:
<spring.security.version>5.6.0</spring.security.version>
<spring.boot.version>2.5.4</spring.boot.version>
<azure.version>3.10.0</azure.version>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>azure-spring-boot-starter-active-directory</artifactId>
<version>${azure.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-jose</artifactId>
<version>5.6.0</version>
</dependency>
你能告诉我这个问题,以便我可以解决吗?
更新: 使用 msal4j 解决。
示例是:
https://github.com/Azure-Samples/ms-identity-java-webapp/tree/master/msal-java-webapp-sample
【问题讨论】:
-
嗨@volkangurbuz,检查令牌使用jwt.io 验证声明:1)确保您选择了正确的签名算法(RS256)2)检查孩子 声明表示用于验证令牌的特定公钥。确保您正在检查用于签署令牌的密钥。3)验证 scp 声明以验证用户已授予调用应用程序调用您的 API 的权限。4)检查与 aud (audience) :标识令牌的预期接收者
-
也可以参考这个帖子:stackoverflow.com/questions/56638408/…
-
您的问题解决了吗?
标签: spring-boot spring-security azure-active-directory spring-security-oauth2