【发布时间】:2021-02-05 13:08:07
【问题描述】:
有人在使用 Spring Boot 资源服务器和 Keycloak 吗?
我将 application.properties 配置为spring.security.oauth2.resourceserver.jwt.issuer-uri = http://localhost:9080/auth/realms/<myrealm>
在我的 WebSecurityConfigurerAdapter 中,我可以使用客户端范围,例如
.antMatchers(HttpMethod.GET, "/user/**").hasAuthority("SCOPE_read")
但我无法使用这些角色!
.antMatchers(HttpMethod.GET, "/user/**").hasRole("ADMIN")
该信息在 jwt 中可用,但 spring 不知何故不使用它。有人知道我在哪里可以找到描述映射的文档吗? 不知何故,我认为我的脑海中有一个节点,但是在哪里,哪一个?
那是我的 jwt:
"exp": 1603373908,
"iat": 1603373608,
"jti": "0b18b386-9f62-4c42-810e-692ccc4ed7d1",
"iss": "http://localhost:9080/auth/realms/jhipster",
"aud": "account",
"sub": "4c973896-5761-41fc-8217-07c5d13a004b",
"typ": "Bearer",
"azp": "web_app",
"session_state": "17411db5-8d50-4f25-b520-9a3e8b19fd67",
"acr": "1",
"allowed-origins": [
"*"
],
"realm_access": {
"roles": [
"test",
"ROLE_USER",
"offline_access",
"ROLE_ADMIN",
"uma_authorization"
]
},
"resource_access": {
"account": {
"roles": [
"manage-account",
"manage-account-links",
"view-profile"
]
}
},
"scope": "email profile",
"email_verified": true,
"roles": [
"test",
"ROLE_USER",
"offline_access",
"ROLE_ADMIN",
"uma_authorization"
],
"name": "Admin Administrator",
"preferred_username": "admin",
"given_name": "Admin",
"family_name": "Administrator",
"email": "admin@localhost"
}```
Thanks a lot
Fredy
【问题讨论】:
标签: spring-boot spring-security keycloak openid-connect spring-oauth2