Skip to content

Commit

Permalink
Spring security @RegisteredOAuth2AuthorizedClient is not handled in t…
Browse files Browse the repository at this point in the history
…he right way. Fixes #2595
  • Loading branch information
bnasslahsen committed Jun 16, 2024
1 parent 4059109 commit 07e2c92
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
5 changes: 5 additions & 0 deletions springdoc-openapi-starter-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
<artifactId>spring-security-oauth2-authorization-server</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-client</artifactId>
<optional>true</optional>
</dependency>
<!-- Kotlin -->
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.client.annotation.RegisteredOAuth2AuthorizedClient;
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
import org.springframework.security.web.FilterChainProxy;
import org.springframework.security.web.SecurityFilterChain;
Expand Down Expand Up @@ -169,6 +170,9 @@ OpenApiCustomizer springSecurityLoginEndpointCustomiser(ApplicationContext appli
}
}

/**
* The type Spring doc security o auth 2 configuration.
*/
@Lazy(false)
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(OAuth2AuthorizationService.class)
Expand All @@ -186,4 +190,19 @@ GlobalOpenApiCustomizer springDocSecurityOAuth2Customizer() {
return new SpringDocSecurityOAuth2Customizer();
}
}

/**
* The type Spring doc security o auth 2 client configuration.
*/
@Lazy(false)
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(RegisteredOAuth2AuthorizedClient.class)
class SpringDocSecurityOAuth2ClientConfiguration {

static {
getConfig()
.addAnnotationsToIgnore(RegisteredOAuth2AuthorizedClient.class);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
<artifactId>spring-security-config</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
import org.springframework.security.oauth2.client.annotation.RegisteredOAuth2AuthorizedClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -38,4 +40,11 @@ public String personsWithUser(@RequestBody() Person person,
return "OK";
}

@PostMapping(value = "/persons-with-oauth2-user")
public String personsWithUser(@RequestBody() Person person,
@RegisteredOAuth2AuthorizedClient OAuth2AuthorizedClient authorizedClient,
@AuthenticationPrincipal User user) {
return "OK";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,36 @@
}
}
}
},
"/persons-with-oauth2-user": {
"post": {
"tags": [
"hello-controller"
],
"operationId": "personsWithUser_1",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Person"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"type": "string"
}
}
}
}
}
}
}
},
"components": {
Expand Down

0 comments on commit 07e2c92

Please sign in to comment.