关于 Oauth2 Authorization Server
该项目提供基于 Spring Boot 的 OAuth2 Authorization Server,并包含数据库、Redis、可观测性及 AI 相关组件。README 介绍了基于 Docker 的运行和测试,以及 AOT、原生镜像和检查点恢复选项。
主要功能
- 01OAuth2 授权服务器
- 02MariaDB 和 Redis 服务
- 03Docker Compose 配置
- 04AOT 与原生镜像构建方式
- 05CRaC 检查点与恢复
- 06自动依赖更新工作流
适用场景
- 01在本地运行并测试 OAuth2 服务器
- 02通过 Swagger UI 查看 API 端点
- 03构建并运行原生镜像
- 04对应用创建检查点并恢复
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
使用 Spring Boot 4 和 Java 26 构建 OAuth2 授权服务器
前提条件
- 应安装 Java 26 -->
export JAVA_HOME=$(/usr/libexec/java_home -v 26) - 应安装 Maven
- 应安装 Docker
- 可以安装 Postman
如何运行和测试
-
运行以下命令,为 AI 模型 API 密钥设置环境变量
-
export OPENAI_API_KEY=your_api_key_here export DEEPSEEK_API_KEY=your_api_key_here export ANTHROPIC_API_KEY=your_api_key_here # Optional export GOOGLE_GENAI_API_KEY=your_api_key_here # Optional
-
-
cd oauth2-authorization-server # Run tests on the host (requires Docker for Testcontainers) mvn clean verify # Build and start the application together with all infrastructure services docker compose --profile start_application up -d --build # Start only infrastructure services (Redis, MariaDB, LDAP, Ollama, etc.) docker compose up -d # For local development without Docker (requires infrastructure services running via docker compose up -d) ./mvnw spring-boot:run # or: mvn spring-boot:run -
Import the followings to test in Postman
-
Swagger: http://localhost:9000/swagger-ui/index.html
- Click
Authorizeand enter the following credentials client_id:clientclient_secret:secret- Use one of the following default values to log in http://localhost:9000/login
- username:
Developerpassword:password - username:
Adminpassword:password - username:
Userpassword:password
- username:
- Click
-
Actuator: http://localhost:9000/actuator/
-
Database credentials
url:jdbc:mariadb://localhost:3306/oauth2_authorization_serverusername:mb_testpassword:test
-
Redis
host:localhostport:6379
-
Redis Insight: http://localhost:5540/
- Click
Add Redis database Connection URL-->redis://[email protected]:6379- Click
Add Database 
- Click
-
Ollama
- http://localhost:3000/ sign up for an account for local environment
- Search for
mxbai-embed-largeand download it if it does not exist - Search for
mistraland download it if it does not exist - Search for
deepseek-r1:7band download it if it does not exist
-
Grafana UI
- http://localhost:3001/
- username:
admin - password:
admin
Debugging Spring Boot Tests in IntelliJ IDEA
- Run one of the below commands in the terminal
mvn test -Dmaven.surefire.debug- If port 5005 is already in use, you can specify a custom port
mvn test -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"
- Open IntelliJ IDEA
- Go to
Run > Attach to Process(or use shortcut)- Windows/Linux:
Ctrl + Alt + 5 - Mac:
Cmd + Alt + 5
- Windows/Linux:
- Select the Java process running your tests
- The test will pause until you connect your debugger. Once connected, you can use breakpoints and step through your code.
How to Run and Test with CDC (Class Data Sharing)
- Java 26+ should be installed
- Run
./mvnw clean installor./mvnw clean install -Paotor./mvnw -Paot packagecommand to build the application with AOT - Run
docker-compose up -dcommand to run necessary services - Run
docker build -t oauth2-authorization-server -f DockerfileForAOTCache .command to build the image - Run
docker run -d --restart=always -p 9000:9000 oauth2-authorization-server:latestcommand to run the image
How to Run and Test Native Image with GraalVM
- Java 26 GraalVM edition should be installed
- Run
docker-compose up -dcommand to run necessary services - Run
./mvnw -Pnative native:compileor./mvnw -Pnative native:compile -DskipTestscommand to build the native image - Run
./target/oauth2-authorization-servercommand to run the native image - Install Grype (OPTIONAL)
- Run
native-image-inspect ./target/oauth2-authorization-server-0.0.1 | grype -vcommand to scan vulnerabilities
- Run
- Run
native-image-inspect ./target/oauth2-authorization-server-0.0.1 >output.jsoncommand and openoutput.jsonor visit http://localhost:9000/actuator/sbom/native-image to inspect all libraries, methods etc. used in the native image - Run
open ./target/oauth2-authorization-server-build-report.htmlto see build report - Use Swagger UI to test the application
Spring Boot with CRaC (Coordinated Restore at Checkpoint) by Creating Ready to Restore Container Image.
- Warning: for real projects make sure to not leak sensitive data in CRaC files since they contain a snapshot of the memory of the running JVM instance.
- Checkpoint
- Run
on demand checkpoint/restore of a running application
with:
./docs/scripts/checkpoint.sh - Run
an automatic checkpoint/restore at startup
with:
./docs/scripts/checkpointOnRefresh.sh
- Run
on demand checkpoint/restore of a running application
with:
- Restore
- Restore the application with:
./docs/scripts/restore.sh
- Restore the application with:
- Use Swagger UI to test the application
Docker Compose image versions
- Check pinned image tags in
docker-compose.yml:- Linux / macOS / Git Bash:
./docs/scripts/check-compose-image-updates.sh - Windows:
.\docs\scripts\check-compose-image-updates.cmd - Preview upgrades:
./docs/scripts/check-compose-image-updates.sh --dry-run - Apply OUTDATED bumps:
./docs/scripts/check-compose-image-updates.sh --apply
- Linux / macOS / Git Bash:
- CI runs the read-only check on every pipeline; automated Maven + Compose upgrades run via
.github/workflows/dependency-update.yml.
How to Run and Test AI Models Locally with Docker Desktop Model Runner
- Requires: Docker Desktop 4.40 and later
- Run
docker-compose up -dcommand to run necessary services - Run
docker model pull ai/gemma3:4B-Q4_K_Mcommand to pull the model- Run
docker model run ai/gemma3:4B-Q4_K_Mcommand to run the model to test it from the command line (OPTIONAL)
- Run
Docker Desktop-->Settings-->Features in development-->Beta features-->Enable Docker Model Runner-->Enable host-side TCP support-->Apply & Restart- Run
mvn testormvn clean installormvn clean packageor./mvnw clean installcommand to run all the tests - Run
mvn spring-boot:runcommand to run the application - Use Swagger UI to test the application
Dependency Version Management
Dependency versions are managed via
the Maven Versions Plugin and a version-rules.xml filter
that excludes alpha/beta/RC/SNAPSHOT releases.
Local — using the helper script:
./docs/scripts/update-versions.sh check # Show all outdated versions (parent + props + deps + plugins)
./docs/scripts/update-versions.sh update # Auto-update everything and review with: git diff pom.xml
./docs/scripts/update-versions.sh update-props # Update only <properties> versions (safest)
./docs/scripts/update-versions.sh update-parent # Update only spring-boot-starter-parent
./docs/scripts/update-versions.sh revert # Revert pom.xml from backup
CI/CD — 自动创建 PR:
MB 依赖版本更新工作流每周一运行(也可按需运行), 检查更新、验证构建是否成功编译,并自动创建 PR。
参考资料
- Spring Boot 3 教程:使用 Spring Authorization Server 实现 Security OAuth2,并将登录数据保存到数据库
- Spring Boot LDAP 身份验证入门:使用 Spring Security 和 LDAP Server
- BCryptPasswordEncoderTests
- 使用 Spring Boot 3、Java 21 和 CDS 构建高效容器(SpringOne 2024)
- Spring Boot AOT + GraalVM Native Images 入门
- 欢迎使用 GraalVM for JDK 24!🚀
- 容器映像和文件系统漏洞扫描器 Grype
- Project CRaC 简介:提升 Java 和 Spring 开发中的运行时效率
- 模型上下文协议(MCP)
- 使用 Docker Compose 安装 Ollama
- Spring AI Advisors 指南
- 使用 Spring AI Evaluators 测试大模型响应
- 向量数据库
- Java + RAG:使用 Spring AI 打造 AI 金融顾问💡
- 在本地运行 AI 模型:使用 Docker Desktop Model Runner,无需 API 密钥,也无需付费
- Spring AI 2.0 M1 与 Spring Boot 4 集成
- AppMap for Java 安装与使用分步指南
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。




