Spring Boot 整合 Keycloak
Spring Boot Keycloak 大约 1355 字注意
如果Keycloak
是以Docker
方式启动,注意容器时区问题,创建容器时需指定,否则可能出现403
错误。
-v /etc/localtime:/etc/localtime:ro
Keycloak Clients 配置
Valid Redirect URIs
:*
Web Origins
:*
Maven 依赖
<dependencies>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-boot-starter</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.keycloak.bom</groupId>
<artifactId>keycloak-adapter-bom</artifactId>
<version>18.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Spring Boot 配置
/hello
为不需要权限即可访问(白名单,不设置auth-roles
)。
/*
路径下所有roles
(配置了auth-roles="*"
)都需要验证。
keycloak:
enabled: true
public-client: true
auth-server-url: http://localhost:8080
realm: myrealm
resource: myclient
security-constraints:
- security-collections:
- patterns:
- /*
auth-roles:
- "*"
- security-collections:
- patterns:
- /hello
流程
请求非/hello
接口后会跳转到Keycloak
中定义的登录页面,正确输入Keycloak
中配置的User
即可跳转到请求接口。
参考
https://www.keycloak.org/docs/latest/securing_apps/#java-adapters
阅读 901 · 发布于 2022-09-29
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
Android 仿 iOS 删除时抖动效果阅读 4182
-
Go RWMutex 读写锁阅读 140
-
Go 命令之 go build阅读 1482
-
Spring Boot JSON 将 Long 类型序列化为 String 类型阅读 1541
-
Windows PowerShell 设置命令别名永久生效阅读 1153
-
Spring Boot JPA 关键字自动添加双引号阅读 1415
-
Spring Boot 配置 logback 文件阅读 2897
-
Ubuntu 修改 apt 镜像阅读 4075
-
Android item 填充时最外层布局高度失效解决办法阅读 2028
-
Java 并发编程之自定义线程池阅读 1854