Sponsored by Deepsite.site

Oauth2 Authorization Server

Created By
musabbozkurt8 months ago
OAuth2 Authorization Server with Spring Boot 3 and Java 24
Content

OAuth2 Authorization Server with Spring Boot 3 and Java 24

Prerequisites

  • Java 24 should be installed --> export JAVA_HOME=$(/usr/libexec/java_home -v 24)
  • Maven should be installed
  • Docker should be installed
  • Postman can be installed

How to Run and Test

  • Run export DEEPSEEK_API_KEY=your_api_key_here command to set DeepSeek API key
  • Run docker-compose up -d command to run necessary services
  • Run mvn test or mvn clean install or mvn clean package or ./mvnw clean install command to run all the tests
  • Run mvn spring-boot:run command to run the application
  • Import the followings to test in Postman
  • Swagger: http://localhost:9000/swagger-ui/index.html
    • Click Authorize and enter the following credentials
    • client_id: client
    • client_secret: secret
    • Use one of the following default values to log in http://localhost:9000/login
      • username: Developer password: password
      • username: Admin password: password
      • username: User password: password
  • Actuator: http://localhost:9000/actuator/
  • Database credentials
    • url: jdbc:mariadb://localhost:3306/oauth2_authorization_server
    • username: mb_test
    • password: test
  • Redis
    • host: localhost
    • port: 6379
  • Redis Insight: http://localhost:5540/
    • Click Add Redis database
    • Connection URL --> redis://default@host.docker.internal:6379
    • Click Add Database
    • img.png
  • Ollama
    • http://localhost:3000/ sign up for an account for local environment
    • Search for mxbai-embed-large and download it if it does not exist
    • Search for deepseek-r1:7b and download it if it does not exist

Debugging Spring Boot Tests in IntelliJ IDEA

  1. 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"
  2. Open IntelliJ IDEA
  3. Go to Run > Attach to Process (or use shortcut)
    • Windows/Linux: Ctrl + Alt + 5
    • Mac: Cmd + Alt + 5
  4. Select the Java process running your tests
  5. 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 Native Image with GraalVM

  • Java 24 GraalVM edition should be installed
  • Run docker-compose up -d command to run necessary services
  • Run ./mvnw -Pnative native:compile or ./mvnw -Pnative native:compile -DskipTests command to build the native image
  • Run ./target/oauth2-authorization-server command to run the native image
  • Install Grype (OPTIONAL)
    • Run native-image-inspect ./target/oauth2-authorization-server-0.0.1 | grype -v command to scan vulnerabilities
  • Run native-image-inspect ./target/oauth2-authorization-server-0.0.1 >output.json command and open output.json or 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.html to 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
  • Restore
    • Restore the application with: ./docs/scripts/restore.sh
  • Use Swagger UI to test the application

How to Run and Test AI Models Locally with Docker Desktop Model Runner

  • Requires: Docker Desktop 4.40 and later
  • Run docker-compose up -d command to run necessary services
  • Run docker model pull ai/gemma3:4B-Q4_K_M command to pull the model
    • Run docker model run ai/gemma3:4B-Q4_K_M command to run the model to test it from the command line (OPTIONAL)
  • Docker Desktop --> Settings --> Features in development --> Beta features --> Enable Docker Model Runner --> Enable host-side TCP support --> Apply & Restart
    • Docker_Desktop_Enable_Host_Side_TCP_Support.png
  • Run mvn test or mvn clean install or mvn clean package or ./mvnw clean install command to run all the tests
  • Run mvn spring-boot:run command to run the application
  • Use Swagger UI to test the application

References

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
ChatWiseThe second fastest AI chatbot™
Playwright McpPlaywright MCP server
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
WindsurfThe new purpose-built IDE to harness magic
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Serper MCP ServerA Serper MCP Server
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Tavily Mcp
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Amap Maps高德地图官方 MCP Server
DeepChatYour AI Partner on Desktop
CursorThe AI Code Editor
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.