Skip to content

Commit

Permalink
EPMRPP-87605 || Migrate from springfox-swagger to SpringDoc for UAT s…
Browse files Browse the repository at this point in the history
…ervice (#294)
  • Loading branch information
APiankouski authored Jan 8, 2024
1 parent 7b11574 commit 1312c3c
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 136 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ dependencies {
implementation 'com.epam.reportportal:commons-rules'
implementation 'com.epam.reportportal:commons-model'
} else {
implementation 'com.github.reportportal:commons-dao:3d0fd7a8'
implementation 'com.github.reportportal:commons-rules:01ec4d17'
implementation 'com.github.reportportal:commons-model:232e69a5'
implementation 'com.github.reportportal:commons-dao:9941604'
implementation 'com.github.reportportal:commons-rules:837ccf2'
implementation 'com.github.reportportal:commons-model:94c46aa'
}

//Fix CVE-2021-41079, CVE-2022-23181, CVE-2021-33037, CVE-2021-30640, CVE-2022-42252
Expand Down Expand Up @@ -88,7 +88,7 @@ dependencies {
implementation 'org.apache.tika:tika-core'

implementation 'javax.inject:javax.inject:1'
implementation 'io.springfox:springfox-swagger2'
implementation 'org.springdoc:springdoc-openapi-ui:1.7.0'
implementation 'org.apache.commons:commons-compress:1.21'
implementation 'org.cryptacular:cryptacular:1.1.4'
// TODO: snakeyaml 2.0 supported by Spring Boot 3 only
Expand Down
2 changes: 1 addition & 1 deletion project-properties.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project.ext {
publishRepo = "https://maven.pkg.github.com/reportportal/service-authorization"
dependencyRepos = ["commons-dao", "commons-rules", "commons-model", "commons-bom"]
releaseMode = project.hasProperty("releaseMode")
scriptsUrl = commonScriptsUrl + 'java21' //(releaseMode ? '5.10.0' : 'master')
scriptsUrl = commonScriptsUrl + (releaseMode ? '5.10.0' : 'develop')
isDebugMode = System.getProperty("DEBUG", "false") == "true"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright 2023 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.epam.reportportal.auth.config;

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.media.Schema;
import io.swagger.v3.oas.models.servers.Server;
import io.swagger.v3.oas.models.tags.Tag;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;
import javax.servlet.ServletContext;
import org.springdoc.core.customizers.OpenApiCustomiser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
* @author <a href="mailto:andrei_piankouski@epam.com">Andrei Piankouski</a>
*/
@Configuration
@ComponentScan(basePackages = "com.epam.reportportal.auth")
public class SpringDocConfiguration {

@Autowired
private ServletContext servletContext;

@Value("${spring.application.name}")
private String applicationName;

@Value("${info.build.version}")
private String buildVersion;

@Bean
public OpenAPI springShopOpenAPI() {
return new OpenAPI()
.info(new Info().title("Report Portal")
.description("Report Portal UAT documentation")
.version(buildVersion)
.contact(new Contact()
.name("Support")
.email("Support Report Portal <support@reportportal.io>")
)
.license(new License().name("Apache 2.0")
.url("http://www.apache.org/licenses/LICENSE-2.0")))
.addServersItem(new Server().url("/" + applicationName));
}

@Bean
public OpenApiCustomiser sortSchemasAlphabetically() {
return openApi -> {
Map<String, Schema> schemas = openApi.getComponents().getSchemas();
openApi.getComponents().setSchemas(new TreeMap<>(schemas));
};
}

@Bean
public OpenApiCustomiser sortTagsAlphabetically() {
return openApi -> {
List<Tag> sortedTags = openApi.getTags().stream()
.sorted(Comparator.comparing(Tag::getName))
.collect(Collectors.toList());
openApi.setTags(sortedTags);
};
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,29 @@
import com.epam.ta.reportportal.ws.model.OperationCompletionRS;
import com.epam.ta.reportportal.ws.model.integration.auth.AbstractAuthResource;
import com.epam.ta.reportportal.ws.model.integration.auth.UpdateAuthRQ;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.beans.PropertyEditorSupport;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.beans.PropertyEditorSupport;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/settings/auth")
@Tag(name = "auth-configuration-endpoint", description = "Auth Configuration Endpoint")
public class AuthConfigurationEndpoint {

private final CreateAuthIntegrationHandler createAuthIntegrationHandler;
Expand All @@ -63,7 +73,7 @@ public AuthConfigurationEndpoint(CreateAuthIntegrationHandler createAuthIntegrat
@Transactional
@PostMapping(value = "/{authType}")
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Create new auth integration")
@Operation(summary = "Create new auth integration")
public AbstractAuthResource createAuthIntegration(@RequestBody @Valid UpdateAuthRQ request, @AuthenticationPrincipal ReportPortalUser user,
@PathVariable AuthIntegrationType authType) {
return createAuthIntegrationHandler.createAuthIntegration(authType, request, user);
Expand All @@ -78,7 +88,7 @@ public AbstractAuthResource createAuthIntegration(@RequestBody @Valid UpdateAuth
@Transactional
@PutMapping(value = "/{authType}/{integrationId}")
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Update auth integration")
@Operation(summary = "Update auth integration")
public AbstractAuthResource updateAuthIntegration(@RequestBody @Valid UpdateAuthRQ request, @AuthenticationPrincipal ReportPortalUser user,
@PathVariable AuthIntegrationType authType, @PathVariable Long integrationId) {
return createAuthIntegrationHandler.updateAuthIntegration(authType, integrationId, request, user);
Expand All @@ -93,7 +103,7 @@ public AbstractAuthResource updateAuthIntegration(@RequestBody @Valid UpdateAuth
@Transactional(readOnly = true)
@GetMapping(value = "/{authType}")
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Retrieves auth settings")
@Operation(summary = "Retrieves auth settings")
public AbstractAuthResource getSettings(@PathVariable AuthIntegrationType authType) {
return getAuthIntegrationHandler.getIntegrationByType(authType);
}
Expand All @@ -107,7 +117,7 @@ public AbstractAuthResource getSettings(@PathVariable AuthIntegrationType authTy
@Transactional
@DeleteMapping(value = "/{integrationId}")
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Retrieves auth settings")
@Operation(summary = "Retrieves auth settings")
public OperationCompletionRS deleteSettings(@PathVariable Long integrationId) {
return deleteAuthIntegrationHandler.deleteAuthIntegrationById(integrationId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import com.epam.reportportal.auth.integration.handler.GetAuthIntegrationHandler;
import com.epam.ta.reportportal.ws.model.OperationCompletionRS;
import com.epam.ta.reportportal.ws.model.settings.OAuthRegistrationResource;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
Expand All @@ -39,6 +40,7 @@
*/
@Controller
@RequestMapping("/settings/oauth")
@Tag(name = "o-auth-configuration-endpoint", description = "O Auth Configuration Endpoint")
public class OAuthConfigurationEndpoint {

private final CreateAuthIntegrationHandler createAuthIntegrationHandler;
Expand All @@ -65,7 +67,7 @@ public OAuthConfigurationEndpoint(CreateAuthIntegrationHandler createAuthIntegra
@RequestMapping(value = "/{authId}", method = { POST, PUT })
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Creates/Updates OAuth Integration Settings")
@Operation(summary = "Creates/Updates OAuth Integration Settings")
public OAuthRegistrationResource updateOAuthSettings(@PathVariable("authId") String oauthProviderId,
@RequestBody @Validated OAuthRegistrationResource clientRegistrationResource) {
return createAuthIntegrationHandler.createOrUpdateOauthSettings(oauthProviderId, clientRegistrationResource);
Expand All @@ -80,7 +82,7 @@ public OAuthRegistrationResource updateOAuthSettings(@PathVariable("authId") Str
@RequestMapping(value = "/{authId}", method = { DELETE })
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Deletes OAuth Integration Settings")
@Operation(summary = "Deletes OAuth Integration Settings")
public OperationCompletionRS deleteOAuthSetting(@PathVariable("authId") String oauthProviderId) {
return deleteAuthIntegrationHandler.deleteOauthSettingsById(oauthProviderId);
}
Expand All @@ -93,7 +95,7 @@ public OperationCompletionRS deleteOAuthSetting(@PathVariable("authId") String o
@GetMapping
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Returns OAuth Server Settings")
@Operation(summary = "Returns OAuth Server Settings")
public Map<String, OAuthRegistrationResource> getOAuthSettings() {
return getAuthIntegrationHandler.getAllOauthIntegrations();
}
Expand All @@ -107,7 +109,7 @@ public Map<String, OAuthRegistrationResource> getOAuthSettings() {
@RequestMapping(value = "/{authId}", method = { GET })
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Returns OAuth Server Settings")
@Operation(summary = "Returns OAuth Server Settings")
public OAuthRegistrationResource getOAuthSettings(@PathVariable("authId") String oauthProviderId) {
return getAuthIntegrationHandler.getOauthIntegrationById(oauthProviderId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.epam.ta.reportportal.commons.ReportPortalUser;
import com.google.common.collect.ImmutableMap;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -36,6 +37,7 @@
*/
@RestController
@Transactional
@Tag(name = "sso-endpoint", description = "Sso Endpoint")
public class SsoEndpoint {

@RequestMapping(value = { "/sso/me", "/sso/user" }, method = { GET, POST })
Expand Down
Loading

0 comments on commit 1312c3c

Please sign in to comment.