-
Notifications
You must be signed in to change notification settings - Fork 843
OpenAPI document endpoints #3689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
joemahady-comm
wants to merge
13
commits into
cloudfoundry:develop
Choose a base branch
from
joemahady-comm:TNZ-70080
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+235
−1
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d2d9fc2
[TNZ-70080]: Testing OpenAPI document endpoints
joemahady-comm f0b28f0
[TNZ-70080]: refactored openapi spec generation
joemahady-comm 910bf1b
[TNZ-70080]: refactored openapi spec generation
joemahady-comm 59bc5ea
[TNZ-70080]: refactored openapi spec generation
joemahady-comm 7fbdb1b
[TNZ-70080]: refactored openapi spec generation
joemahady-comm 64f2087
[TNZ-70080]: refactored openapi spec generation
joemahady-comm e128cdc
[TNZ-70080]: utilise buildInfo to populate version and url
joemahady-comm 3393886
Merge branch 'develop' into TNZ-70080
duanemay 8251163
OpenAPI document endpoints, update yaml files
joemahady-comm ad91f90
Merge remote-tracking branch 'fork/TNZ-70080' into TNZ-70080
joemahady-comm 4c4f79c
OpenAPI document endpoints, added tests
joemahady-comm 2fe2a5b
Merge branch 'cloudfoundry:develop' into TNZ-70080
joemahady-comm 5f2c73f
Merge branch 'cloudfoundry:develop' into TNZ-70080
joemahady-comm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
uaa/src/main/java/org/cloudfoundry/identity/uaa/OpenApiConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package org.cloudfoundry.identity.uaa; | ||
|
|
||
| import io.swagger.v3.oas.models.Components; | ||
| import io.swagger.v3.oas.models.OpenAPI; | ||
| import io.swagger.v3.oas.models.info.Contact; | ||
| import io.swagger.v3.oas.models.info.Info; | ||
| import io.swagger.v3.oas.models.info.License; | ||
| import io.swagger.v3.oas.models.security.SecurityRequirement; | ||
| import io.swagger.v3.oas.models.security.SecurityScheme; | ||
| import io.swagger.v3.oas.models.servers.Server; | ||
| import org.cloudfoundry.identity.uaa.home.BuildInfo; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * OpenAPI 3.0 configuration for UAA API documentation. | ||
| * | ||
| * This configuration provides interactive API documentation for all UAA endpoints, | ||
| * including users, groups, clients, identity zones, and identity providers. | ||
| */ | ||
| @Configuration | ||
| public class OpenApiConfiguration { | ||
|
|
||
| private final BuildInfo buildInfo; | ||
|
|
||
| public OpenApiConfiguration(BuildInfo buildInfo) { | ||
| this.buildInfo = buildInfo; | ||
| } | ||
|
|
||
| @Bean | ||
| public OpenAPI uaaOpenAPI() { | ||
| return new OpenAPI() | ||
| .info(new Info() | ||
| .title("UAA API Reference") | ||
| .description(""" | ||
| UAA (User Account and Authentication) is an OAuth2/OpenID Connect server | ||
| for centralized identity management. This API reference provides endpoints | ||
| for managing users, groups, and client applications. | ||
|
|
||
| Key Features: | ||
| - OAuth2 & OpenID Connect authentication | ||
| - SCIM 2.0 user and group management | ||
| - Identity provider integration (SAML, LDAP, OIDC) | ||
| - Multi-tenancy via identity zones | ||
| - Client application management | ||
| """) | ||
| .version(buildInfo.getVersion()) | ||
| .contact(new Contact() | ||
| .name("Cloud Foundry Foundation") | ||
| .url("https://github.com/cloudfoundry/uaa")) | ||
| .license(new License() | ||
| .name("Apache 2.0") | ||
| .url("https://www.apache.org/licenses/LICENSE-2.0"))) | ||
| .servers(List.of( | ||
| new Server() | ||
| .url(buildInfo.getUaaUrl()) | ||
| .description("UAA Server") | ||
| )) | ||
| .addSecurityItem(new SecurityRequirement().addList("bearerAuth")) | ||
| .components(new Components() | ||
| .addSecuritySchemes("bearerAuth", new SecurityScheme() | ||
| .type(SecurityScheme.Type.HTTP) | ||
| .scheme("bearer") | ||
| .bearerFormat("JWT") | ||
| .description(""" | ||
| OAuth2 Bearer token (JWT format). | ||
|
|
||
| Required scopes vary by endpoint: | ||
| - OAuth/Token: uaa.admin, clients.admin | ||
| - Users/Groups: scim.read, scim.write, groups.update | ||
| - Clients: clients.read, clients.write, clients.admin | ||
| - Identity Zones: zones.read, zones.write, uaa.admin | ||
| - Identity Providers: idps.read, idps.write | ||
|
|
||
| Obtain tokens via /oauth/token endpoint. | ||
| """))); | ||
| } | ||
| } | ||
joemahady-comm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
uaa/src/test/java/org/cloudfoundry/identity/uaa/OpenApiConfigurationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| package org.cloudfoundry.identity.uaa; | ||
|
|
||
| import io.swagger.v3.oas.models.OpenAPI; | ||
| import io.swagger.v3.oas.models.security.SecurityScheme; | ||
| import org.cloudfoundry.identity.uaa.home.BuildInfo; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| class OpenApiConfigurationTest { | ||
|
|
||
| private BuildInfo buildInfo; | ||
| private OpenApiConfiguration openApiConfiguration; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| buildInfo = mock(BuildInfo.class); | ||
| when(buildInfo.getVersion()).thenReturn("1.0.0-test"); | ||
| when(buildInfo.getUaaUrl()).thenReturn("https://uaa.example.com"); | ||
| openApiConfiguration = new OpenApiConfiguration(buildInfo); | ||
| } | ||
|
|
||
| @Test | ||
| void uaaOpenAPIBeanIsCreated() { | ||
| OpenAPI openAPI = openApiConfiguration.uaaOpenAPI(); | ||
|
|
||
| assertThat(openAPI).isNotNull(); | ||
| } | ||
|
|
||
| @Test | ||
| void openAPIHasCorrectTitle() { | ||
| OpenAPI openAPI = openApiConfiguration.uaaOpenAPI(); | ||
|
|
||
| assertThat(openAPI.getInfo().getTitle()).isEqualTo("UAA API Reference"); | ||
| } | ||
|
|
||
| @Test | ||
| void openAPIHasDescriptionWithKeyFeatures() { | ||
| OpenAPI openAPI = openApiConfiguration.uaaOpenAPI(); | ||
|
|
||
| String description = openAPI.getInfo().getDescription(); | ||
| assertThat(description) | ||
| .contains("OAuth2/OpenID Connect") | ||
| .contains("SCIM 2.0") | ||
| .contains("Identity provider integration") | ||
| .contains("Multi-tenancy"); | ||
| } | ||
|
|
||
| @Test | ||
| void openAPIVersionComesFromBuildInfo() { | ||
| OpenAPI openAPI = openApiConfiguration.uaaOpenAPI(); | ||
|
|
||
| assertThat(openAPI.getInfo().getVersion()).isEqualTo("1.0.0-test"); | ||
| } | ||
|
|
||
| @Test | ||
| void openAPIHasCorrectContactInfo() { | ||
| OpenAPI openAPI = openApiConfiguration.uaaOpenAPI(); | ||
|
|
||
| assertThat(openAPI.getInfo().getContact().getName()).isEqualTo("Cloud Foundry Foundation"); | ||
| assertThat(openAPI.getInfo().getContact().getUrl()).isEqualTo("https://github.com/cloudfoundry/uaa"); | ||
| } | ||
|
|
||
| @Test | ||
| void openAPIHasApache2License() { | ||
| OpenAPI openAPI = openApiConfiguration.uaaOpenAPI(); | ||
|
|
||
| assertThat(openAPI.getInfo().getLicense().getName()).isEqualTo("Apache 2.0"); | ||
| assertThat(openAPI.getInfo().getLicense().getUrl()).isEqualTo("https://www.apache.org/licenses/LICENSE-2.0"); | ||
| } | ||
|
|
||
| @Test | ||
| void openAPIServerUrlComesFromBuildInfo() { | ||
| OpenAPI openAPI = openApiConfiguration.uaaOpenAPI(); | ||
|
|
||
| assertThat(openAPI.getServers()).hasSize(1); | ||
| assertThat(openAPI.getServers().get(0).getUrl()).isEqualTo("https://uaa.example.com"); | ||
| assertThat(openAPI.getServers().get(0).getDescription()).isEqualTo("UAA Server"); | ||
| } | ||
|
|
||
| @Test | ||
| void openAPIHasBearerAuthSecurityRequirement() { | ||
| OpenAPI openAPI = openApiConfiguration.uaaOpenAPI(); | ||
|
|
||
| assertThat(openAPI.getSecurity()).hasSize(1); | ||
| assertThat(openAPI.getSecurity().get(0).get("bearerAuth")).isNotNull(); | ||
| } | ||
|
|
||
| @Test | ||
| void openAPIHasBearerAuthSecurityScheme() { | ||
| OpenAPI openAPI = openApiConfiguration.uaaOpenAPI(); | ||
|
|
||
| SecurityScheme securityScheme = openAPI.getComponents().getSecuritySchemes().get("bearerAuth"); | ||
| assertThat(securityScheme).isNotNull(); | ||
| assertThat(securityScheme.getType()).isEqualTo(SecurityScheme.Type.HTTP); | ||
| assertThat(securityScheme.getScheme()).isEqualTo("bearer"); | ||
| assertThat(securityScheme.getBearerFormat()).isEqualTo("JWT"); | ||
| } | ||
|
|
||
| @Test | ||
| void securitySchemeDescriptionDocumentsRequiredScopes() { | ||
| OpenAPI openAPI = openApiConfiguration.uaaOpenAPI(); | ||
|
|
||
| String description = openAPI.getComponents().getSecuritySchemes().get("bearerAuth").getDescription(); | ||
| assertThat(description) | ||
| .contains("uaa.admin") | ||
| .contains("scim.read") | ||
| .contains("scim.write") | ||
| .contains("clients.read") | ||
| .contains("clients.write") | ||
| .contains("zones.read") | ||
| .contains("zones.write") | ||
| .contains("idps.read") | ||
| .contains("idps.write"); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.