Spring Boot集成SpringDoc生成Api文档

以下以 Maven 为例介绍 Spring Boot集成SpringDoc生成Api文档。 添加依赖 1 2 3 4 <dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> </dependency> 配置 annotationProcessor,实现通过 javadoc 生成文档。 每个 maven 模块都需要配置: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 <properties> <therapi-runtime-javadoc.version>0.15.0</therapi-runtime-javadoc.version> <maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version> </properties> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>${maven-compiler-plugin.version}</version> <configuration> <annotationProcessorPaths> <!-- https://springdoc.org/#javadoc-support --> <path> <groupId>com.github.therapi</groupId> <artifactId>therapi-runtime-javadoc-scribe</artifactId> <version>${therapi-runtime-javadoc.version}</version> </path> </annotationProcessorPaths> </configuration> </plugin> 配置 spring boot 插件,生成 build.properties 1 2 3 4 5 6 7 8 9 10 11 12 <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> <goal>build-info</goal> </goals> </execution> </executions> </plugin> 自动装配 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 @Configuration(proxyBeanMethods = false) @ConditionalOnProperty(name = SPRINGDOC_ENABLED, matchIfMissing = true) @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) public class SpringdocConfig { @Value("${server.port}") private String port; @Value("${openapi.prod-url:https://localhost}") private String prodUrl; @Bean public OpenAPI openAPI() { Server devServer = new Server(); devServer.setUrl("http://localhost:" + port); devServer.setDescription("Server URL in Development environment"); Server prodServer = new Server(); prodServer.setUrl(prodUrl); prodServer.setDescription("Server URL in Production environment"); Contact contact = new Contact(); contact.setEmail("[email protected]"); contact.setName("ChenSoul"); contact.setUrl("https://blog.chensoul.cc"); License mitLicense = new License().name("Apache License").url("https://www.apache.org/licenses/LICENSE-2.0.txt"); Info info = new Info() .title("Spring Boot3 Monolith API") .version("1.0") .contact(contact) .description("This API exposes endpoints to manage charging sessions.").termsOfService("https://blog.chensoul.cc/terms") .license(mitLicense); return new OpenAPI().info(info).servers(List.of(devServer, prodServer)); } }

2024-07-10 · 1 min · 298 words · chensoul

All things about OAuth

OAuth 是一种开放协议,允许通过网络、移动和桌面应用程序以简单、标准的方式进行安全授权。 OAuth 2 入门 以下是一些 OAuth 2.0 指南,涵盖了理解和实现客户端和服务器所需的许多主题。 OAuth 2.0 简化版 由 Aaron Parecki 编写的*《OAuth 2.0 Simplified*》是一份专注于编写客户端的 OAuth 2.0 指南,它在入门级别上清晰地概述了规范。 ...

2024-06-06 · 1 min · 453 words · chensoul

JWT

什么是 JWT? JWT(JSON Web Token)是一种开放标准(RFC 7519),用于在网络应用程序之间安全地传输信息。它被设计用于在两方之间传输声明,这些声明可以是身份验证和授权信息,也可以是任何其他类型的信息。 ...

2024-06-06 · 6 min · 2517 words · chensoul

OAuth2和OIDC区别

认证和授权 认证 (Authentication): 认证是验证用户、设备或系统身份的过程。 常见的认证方式包括用户名/密码、生物特征(如指纹、人脸)、单点登录(SSO)等。 认证确保只有被授权的实体才能访问系统或资源。 授权 (Authorization): 授权是确定已认证的实体被允许执行哪些操作或访问哪些资源的过程。 授权通常基于预定义的策略和规则,如角色、权限、访问控制列表(ACL)等。 授权决定了经过身份验证的实体可以执行的操作和访问的资源。 认证和授权的关系: ...

2024-06-06 · 4 min · 1613 words · chensoul

[译][译]OAuth2 with Spring 第5部分:使用PKCE保护您的Spring Boot应用程序以增强安全性

原文地址:https://mainul35.medium.com/oauth2-with-spring-part-5-securing-your-spring-boot-application-with-pkce-for-enhanced-security-d8025cd08769 ...

2024-06-05 · 7 min · 3172 words · chensoul

[译]OAuth2 with Spring 第1部分:了解基本概念

原文地址:https://mainul35.medium.com/oauth2-with-spring-part-1-knowing-the-basic-concepts-5c4aa17884a 在本系列关于 Spring 的 OAuth2的文章中,我将尝试介绍和解释与 OAuth2 相关的每一个问题以及如何在 Spring 框架中实现这些问题。请记住,OAuth2 完全是一个概念性的东西,在不同的框架中,它有自己的实现。此外,许多应用程序开发人员开发自己的 OAuth2 实现,而不使用 Spring 框架提供的 OAuth2 框架支持。因此,我将就这个主题撰写一系列文章。 ...

2024-06-05 · 4 min · 1526 words · chensoul

[译]OAuth2 with Spring 第2部分:授权服务器入门

原文地址:https://mainul35.medium.com/oauth2-with-spring-part-2-getting-started-with-authorization-server-13804910cb2a Spring 团队最近发布了他们的授权服务器。OAuth2 一直是一个热门话题,而构建或理解授权服务器一直是一个谜。在本系列的第 1 部分中,我描述了几乎所有您需要了解的有关 OAuth2 的概念性内容。在本系列的这篇文章中,我将尝试演示如何构建具有client_credential授权类型的授权服务器。我将从使用配置属性进行自动配置开始解释它们,并通过编写 Java 代码自定义配置。让我们开始吧。 ...

2024-06-05 · 2 min · 985 words · chensoul

[译]OAuth2 with Spring 第3部分:使用Spring授权服务器授予authorization_code OIDC客户端

原文地址:https://mainul35.medium.com/oauth2-with-spring-part-3-authorizing-oidc-client-with-via-authorization-code-grant-from-spring-67769f9dd68a ...

2024-06-05 · 5 min · 2282 words · chensoul

[译]OAuth2 with Spring 第4部分:Spring授权客户端与Google授权服务器的社交登录演示

原文地址:https://mainul35.medium.com/oauth2-with-spring-part-4-spring-authorization-client-social-login-demo-with-google-be6097ec18a5 ...

2024-06-05 · 4 min · 1773 words · chensoul

[译]OAuth2.0服务器

背景 前言 作者:Aaron Parecki 我第一次接触 OAuth 是在 2010 年,当时我正在构建一个 API,我知道我希望第三方开发人员能够在其基础上构建应用程序。当时,OAuth 看起来令人生畏。OAuth 1 的实现只有少数几个,而 OAuth 2.0 仍是一个草稿。一天晚上,我决定坐下来,拿着精酿啤酒和最新草案的纸质副本,从头到尾阅读它,直到我理解它。 ...

2024-06-05 · 151 min · 75193 words · chensoul