Oauth2 Authorization Server について
Spring BootベースのOAuth2 Authorization Serverを提供し、データベース、Redis、オブザーバビリティ、AI関連コンポーネントを含みます。READMEではDockerによる実行・テストに加え、AOT、ネイティブイメージ、チェックポイントと復元の方法を説明しています。
主な機能
- 01OAuth2認可サーバー
- 02MariaDBとRedisのサービス
- 03Docker Composeの構成
- 04AOTおよびネイティブイメージのビルド手段
- 05CRaCのチェックポイントと復元
- 06依存関係更新ワークフローの自動化
活用シーン
- 01ローカルでOAuth2サーバーを実行・テスト
- 02Swagger 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 # ホスト上でテストを実行します(Testcontainers 用に Docker が必要です) mvn clean verify # すべてのインフラストラクチャサービスとともにアプリケーションをビルドして起動します docker compose --profile start_application up -d --build # インフラストラクチャサービスのみを起動します(Redis、MariaDB、LDAP、Ollama など) docker compose up -d # Docker を使わずにローカル開発する場合(docker compose up -d でインフラストラクチャサービスを起動しておく必要があります) ./mvnw spring-boot:run # または: 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 Dependency Version Update ワークフローは毎週月曜日(および手動実行時)に実行され、 更新を確認し、ビルドがコンパイルできることを検証して、PR を自動的に作成します。
参考資料
- Spring Boot 3 チュートリアル:Security OAuth2 Spring Authorization Server でログインデータをデータベースに保存する
- Spring Security と LDAP Server を使った Spring Boot LDAP 認証のゼロからの実装
- BCryptPasswordEncoderTests
- Spring Boot 3、Java 21、CDS による効率的なコンテナー(SpringOne 2024)
- Spring Boot AOT と GraalVM Native Images の始め方
- GraalVM for JDK 24 へようこそ!🚀
- コンテナーイメージとファイルシステム向けの脆弱性スキャナー Grype
- Project CRaC 入門:Java と Spring 開発のランタイム効率を高める
- Model Context Protocol(MCP)
- Docker Compose を使った Ollama のインストール
- Spring AI Advisors ガイド
- Spring AI Evaluators を使った LLM 応答のテスト
- ベクトルデータベース
- Java + RAG:Spring AI で AI を活用した金融アドバイザーを作成する 💡
- AI モデルをローカルで実行:Docker Desktop Model Runner で API キーも料金も不要
- Spring Boot 4 と連携する Spring AI 2.0 M1
- AppMap for Java のインストールと使用方法:ステップバイステップガイド
コメント
AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。




