San*_*isy 4 java spring spring-security spring-boot springdoc
我正在使用 swagger 和 springdoc-openapi-ui-1.4.3
@SecurityRequirement(name = "security_auth")
public class ProductController {}
Run Code Online (Sandbox Code Playgroud)
设置安全架构
@SecurityScheme(name = "security_auth", type = SecuritySchemeType.OAUTH2,
flows = @OAuthFlows(authorizationCode = @OAuthFlow(
authorizationUrl = "${springdoc.oAuthFlow.authorizationUrl}"
, tokenUrl = "${springdoc.oAuthFlow.tokenUrl}",scopes = {
@OAuthScope(name = "IdentityPortal.API", description = "IdentityPortal.API")})))
public class OpenApiConfig {}
Run Code Online (Sandbox Code Playgroud)
安全配置
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {// @formatter:off
http
.authorizeRequests()
.antMatchers("/v3/api-docs/**", "/swagger-ui/**", "/swagger-ui.html")
.permitAll()
.antMatchers(HttpMethod.GET, "/user/info", "/api/foos/**")
.hasAuthority("SCOPE_read")
.antMatchers(HttpMethod.POST, "/api/foos")
.hasAuthority("SCOPE_write")
.anyRequest()
.authenticated()
.and()
.oauth2ResourceServer()
.jwt();
}
}
Run Code Online (Sandbox Code Playgroud)
有依赖关系
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
implementation 'org.springdoc:springdoc-openapi-ui:1.4.3'
implementation 'org.springdoc:springdoc-openapi-security:1.4.3'
implementation "org.springframework.boot:spring-boot-starter-security"
Run Code Online (Sandbox Code Playgroud)
配置设置
spring:
profiles:
active: dev
####### resource server configuration properties
security:
oauth2:
resourceserver:
jwt:
issuer-uri: https://localhost:5001
jwk-set-uri: https://localhost:5001/connect/token
springdoc:
swagger-ui:
oauth:
clientId: Local
usepkcewithauthorizationcodegrant: true
oAuthFlow:
authorizationUrl: https://localhost:5001
tokenUrl: https://localhost:5001/connect/token
Run Code Online (Sandbox Code Playgroud)
在 swagger UI 中,clientId 为空并且存在客户端密钥,对于授权码 + PKCE 流客户端密钥不应存在
你的属性语法
使用 pkce 和授权代码授予
是不正确的:
这是 PKCE 的正确属性:
springdoc.swagger-ui.oauth.use-pkce-with-authorization-code-grant=true
Run Code Online (Sandbox Code Playgroud)
要填写客户端 ID,只需使用:
springdoc.swagger-ui.oauth.client-id=yourSPAClientId
Run Code Online (Sandbox Code Playgroud)
对于您对可以隐藏的现有机密文件的评论。这看起来像是 swagger-ui 的增强。
您应该提交 swagger-ui 项目的增强功能:
| 归档时间: |
|
| 查看次数: |
17658 次 |
| 最近记录: |