From 114c1a2b88826c0d19e8e1ca38282793f2503864 Mon Sep 17 00:00:00 2001 From: Gaurav Mishra Date: Thu, 14 Nov 2024 18:42:47 +0530 Subject: [PATCH 1/4] fix(openapi)!: add health endpoint to openapi Rearrange the application.yml in test to look more like source. BREAKING CHANGE: Move the health endpoint from `/resource/health` to `/resource/api/health` for OpenAPI documentations to be easy to use. Signed-off-by: Gaurav Mishra --- .../resourceserver/Sw360ResourceServer.java | 44 +++++++++++++++++-- .../security/ResourceServerConfiguration.java | 8 ++-- .../src/main/resources/application.yml | 10 ++++- .../SW360RestHealthIndicatorTest.java | 2 +- ...Sw360AuthorizationServerConfiguration.java | 4 +- .../restdocs/HealthSpecTest.java | 4 +- .../src/test/resources/application.yml | 41 ++++++++++------- 7 files changed, 85 insertions(+), 28 deletions(-) diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/Sw360ResourceServer.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/Sw360ResourceServer.java index c4634e0c81..051443da05 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/Sw360ResourceServer.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/Sw360ResourceServer.java @@ -10,10 +10,17 @@ package org.eclipse.sw360.rest.resourceserver; +import io.swagger.v3.oas.models.Operation; +import io.swagger.v3.oas.models.PathItem; import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.License; +import io.swagger.v3.oas.models.media.Content; +import io.swagger.v3.oas.models.media.MediaType; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.responses.ApiResponse; +import io.swagger.v3.oas.models.responses.ApiResponses; import io.swagger.v3.oas.models.security.SecurityScheme; import io.swagger.v3.oas.models.servers.Server; import org.eclipse.sw360.datahandler.common.CommonUtils; @@ -25,6 +32,7 @@ import org.eclipse.sw360.rest.resourceserver.security.apiToken.ApiTokenAuthenticationFilter; import org.springdoc.core.utils.SpringDocUtils; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.actuate.health.Health; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.FilterRegistrationBean; @@ -45,7 +53,7 @@ @Import(Sw360CORSFilter.class) public class Sw360ResourceServer extends SpringBootServletInitializer { - private static final String REST_BASE_PATH = "/api"; + public static final String REST_BASE_PATH = "/api"; @Value("${spring.data.rest.default-page-size:10}") private int defaultPageSize; @@ -168,6 +176,36 @@ public OpenAPI customOpenAPI() { .info(new Info().title("SW360 API").license(new License().name("EPL-2.0") .url("https://github.com/eclipse-sw360/sw360/blob/main/LICENSE")) .version(restVersionString)) - .servers(List.of(server)); + .servers(List.of(server)) + .path("/health", new PathItem().get( + new Operation().tags(Collections.singletonList("Health")) + .summary("Health endpoint").operationId("health") + .responses(new ApiResponses().addApiResponse("200", + new ApiResponse().description("OK") + .content(new Content() + .addMediaType("application/json", new MediaType() + .example(""" + { + "status": "UP", + "components": { + "SW360Rest": { + "status": "UP", + "details": { + "Rest State": { + "isDbReachable": true, + "isThriftReachable": true + } + } + }, + "ping": { + "status": "UP" + } + } + } + """) + .schema(new Schema()) + )) + )) + )); } -} \ No newline at end of file +} diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/security/ResourceServerConfiguration.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/security/ResourceServerConfiguration.java index 7263178062..b9ac930ad0 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/security/ResourceServerConfiguration.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/security/ResourceServerConfiguration.java @@ -60,7 +60,9 @@ public class ResourceServerConfiguration { @Bean public WebSecurityCustomizer webSecurityCustomizer() { - return (web) -> web.ignoring().requestMatchers("/", "/*/*.html", "/*/*.css", "/*/*.js", "/*.js", "/*.json", "/*/*.json", "/*/*.png", "/*/*.gif", "/*/*.ico", "/*/*.woff/*", "/*/*.ttf", "/*/*.html", "/*/*/*.html", "/*/*.yaml", "/v3/api-docs/**"); + return (web) -> web.ignoring().requestMatchers("/", "/*/*.html", "/*/*.css", "/*/*.js", "/*.js", "/*.json", + "/*/*.json", "/*/*.png", "/*/*.gif", "/*/*.ico", "/*/*.woff/*", "/*/*.ttf", "/*/*.html", "/*/*/*.html", + "/*/*.yaml", "/v3/api-docs/**", "/api/health", "/api/info"); } @Bean @@ -80,8 +82,8 @@ public SecurityFilterChain securityFilterChainRS1(HttpSecurity http) throws Exce public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { SimpleAuthenticationEntryPoint saep = new SimpleAuthenticationEntryPoint(); return http.addFilterBefore(filter, BasicAuthenticationFilter.class).authorizeHttpRequests(auth -> { - auth.requestMatchers(HttpMethod.GET, "/health").permitAll(); - auth.requestMatchers(HttpMethod.GET, "/info").hasAuthority("WRITE"); + auth.requestMatchers(HttpMethod.GET, "/api/health").permitAll(); + auth.requestMatchers(HttpMethod.GET, "/api/info").hasAuthority("WRITE"); auth.requestMatchers(HttpMethod.GET, "/api").permitAll(); auth.requestMatchers(HttpMethod.GET, "/api/reports/download").permitAll(); auth.requestMatchers(HttpMethod.GET, "/api/**").hasAuthority("READ"); diff --git a/rest/resource-server/src/main/resources/application.yml b/rest/resource-server/src/main/resources/application.yml index 0b3ed316b3..02d3c90f62 100644 --- a/rest/resource-server/src/main/resources/application.yml +++ b/rest/resource-server/src/main/resources/application.yml @@ -20,6 +20,9 @@ management: base-path: / exposure: include: health,info + path-mapping: + health: /api/health + info: /api/info endpoint: health: show-details: always @@ -28,6 +31,11 @@ management: enabled: true security: enabled: true + health: + diskspace: + enabled: true # Disable to hide sensitive system information + ping: + enabled: true spring: application: @@ -83,4 +91,4 @@ springdoc: enabled: true default-consumes-media-type: application/json default-produces-media-type: application/hal+json - paths-to-exclude: /api/** \ No newline at end of file + paths-to-exclude: /api/** diff --git a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/SW360RestHealthIndicatorTest.java b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/SW360RestHealthIndicatorTest.java index 1d755df974..ed2db2ebb5 100644 --- a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/SW360RestHealthIndicatorTest.java +++ b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/SW360RestHealthIndicatorTest.java @@ -71,7 +71,7 @@ public class SW360RestHealthIndicatorTest { */ private ResponseEntity getMapResponseEntityForHealthEndpointRequest(String endpoint) { return this.testRestTemplate.getForEntity( - "http://localhost:" + this.port + endpoint, Map.class); + "http://localhost:" + this.port + Sw360ResourceServer.REST_BASE_PATH + endpoint, Map.class); } @Test diff --git a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/configuration/security/Sw360AuthorizationServerConfiguration.java b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/configuration/security/Sw360AuthorizationServerConfiguration.java index dc9a244ae0..21b51000f7 100644 --- a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/configuration/security/Sw360AuthorizationServerConfiguration.java +++ b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/configuration/security/Sw360AuthorizationServerConfiguration.java @@ -40,8 +40,8 @@ public SecurityFilterChain appSecurtiy(HttpSecurity httpSecurity) throws Excepti SimpleAuthenticationEntryPoint saep = new SimpleAuthenticationEntryPoint(); httpSecurity.authorizeHttpRequests( authz -> authz - .requestMatchers(HttpMethod.GET, "/health").permitAll() - .requestMatchers(HttpMethod.GET, "/info").permitAll() + .requestMatchers(HttpMethod.GET, "/api/health").permitAll() + .requestMatchers(HttpMethod.GET, "/api/info").permitAll() .anyRequest().authenticated() ).httpBasic(Customizer.withDefaults()).formLogin(Customizer.withDefaults()) .exceptionHandling(x -> x.authenticationEntryPoint(saep)); diff --git a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/HealthSpecTest.java b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/HealthSpecTest.java index 670382cd66..87a4b538d7 100644 --- a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/HealthSpecTest.java +++ b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/HealthSpecTest.java @@ -43,7 +43,7 @@ public void should_document_get_health() throws Exception { given(this.restHealthIndicatorMock.health()).willReturn(spring_health); - mockMvc.perform(get("/health") + mockMvc.perform(get("/api/health") .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andDo(this.documentationHandler.document( @@ -72,7 +72,7 @@ public void should_document_get_health_unhealthy() throws Exception { .build(); given(this.restHealthIndicatorMock.health()).willReturn(spring_health_down); - mockMvc.perform(get("/health") + mockMvc.perform(get("/api/health") .accept(MediaType.APPLICATION_JSON)) .andExpect(status().is2xxSuccessful()) .andDo(this.documentationHandler.document( diff --git a/rest/resource-server/src/test/resources/application.yml b/rest/resource-server/src/test/resources/application.yml index c703ceea7d..3db9ecabe9 100644 --- a/rest/resource-server/src/test/resources/application.yml +++ b/rest/resource-server/src/test/resources/application.yml @@ -1,21 +1,9 @@ #SPDX-FileCopyrightText: © 2024 Siemens AG #SPDX-License-Identifier: EPL-2.0 -spring: - profiles: - active: SECURITY_MOCK - security: - oauth2: - resourceserver: - jwt: - issuer-uri: http://localhost:8080/authorization/oauth2/jwks - jwk-set-uri: http://localhost:8080/authorization/oauth2/jwks - application: - name: resource +server: servlet: - multipart: - max-file-size: 500MB - max-request-size: 600MB + context-path: / management: endpoints: @@ -23,6 +11,9 @@ management: base-path: / exposure: include: health,info + path-mapping: + health: /api/health + info: /api/info endpoint: health: show-details: always @@ -31,9 +22,27 @@ management: enabled: true security: enabled: true -server: + health: + diskspace: + enabled: true # Disable to hide sensitive system information + ping: + enabled: true + +spring: + profiles: + active: SECURITY_MOCK + application: + name: resource servlet: - context-path: / + multipart: + max-file-size: 500MB + max-request-size: 600MB + security: + oauth2: + resourceserver: + jwt: + issuer-uri: http://localhost:8080/authorization/oauth2/jwks + jwk-set-uri: http://localhost:8080/authorization/oauth2/jwks #logging: # level: From c8eccccf36c32e2c42a32e772542832d95c867b6 Mon Sep 17 00:00:00 2001 From: Gaurav Mishra Date: Mon, 2 Dec 2024 15:46:57 +0530 Subject: [PATCH 2/4] chore(properties): unify property locations Unify all `sw360.properties` files to a single file in datahandler library. Also, move all loaders for the property file to SW360Constants class and datahandler.common package. Signed-off-by: Gaurav Mishra --- .../sw360/common/utils/BackendUtils.java | 37 -- .../sw360/cyclonedx/CycloneDxBOMExporter.java | 3 +- .../sw360/datahandler/db/BulkDeleteUtil.java | 153 +++++---- .../db/ComponentDatabaseHandler.java | 8 +- .../datahandler/db/DatabaseHandlerUtil.java | 49 +-- .../db/ProjectDatabaseHandler.java | 6 +- .../datahandler/db/ProjectRepository.java | 7 +- .../sw360/datahandler/db/SvmConnector.java | 34 +- .../org/eclipse/sw360/mail/MailConstants.java | 2 - .../java/org/eclipse/sw360/mail/MailUtil.java | 48 +-- .../src/main/resources/sw360.properties | 136 -------- .../db/ProjectDatabaseHandlerTest.java | 12 +- .../components/db/BulkDeleteUtilTest.java | 301 ++++++++-------- .../db/ComponentDatabaseHandlerTest.java | 21 +- .../db/ComponentSearchHandlerTest.java | 4 +- .../datasource/heuristics/SearchLevels.java | 26 +- .../src/main/resources/cvesearch.properties | 11 - .../src/main/resources/sw360.properties | 12 - .../sw360/fossology/FossologyHandler.java | 10 +- .../outputGenerators/DocxGenerator.java | 5 +- .../outputGenerators/JsonGenerator.java | 5 - .../parsers/CombinedCLIParser.java | 8 +- .../licenseinfo/parsers/SPDXParserTools.java | 14 +- .../src/main/resources/sw360.properties | 13 - .../schedule/service/ScheduleHandler.java | 3 +- .../schedule/service/ScheduleServlet.java | 2 +- .../sw360/schedule/timer/Scheduler.java | 1 + .../src/main/resources/sw360.properties | 27 -- .../vmcomponents/VMComponentHandler.java | 8 +- .../vmcomponents/common/SVMConstants.java | 31 -- .../vmcomponents/handler/SVMSyncHandler.java | 3 +- .../vmcomponents/process/VMProcessor.java | 10 +- .../resources/sw360.properties | 13 - .../datahandler/common/DatabaseConstants.java | 41 +++ .../datahandler/common/SW360Constants.java | 180 +++++++++- .../common}/ScheduleConstants.java | 8 +- .../datahandler/common/ThriftConstants.java | 45 +++ .../permissions/ComponentPermissions.java | 10 +- .../permissions/PermissionUtils.java | 15 - .../permissions/ProjectPermissions.java | 3 +- .../datahandler/thrift/ThriftClients.java | 89 ++--- .../src/main/resources/sw360.properties | 324 +++++++++++++++++- .../ComponentPermissionsVisibilityTest.java | 14 +- .../ProjectPermissionsVisibilityTest.java | 5 +- .../authserver/Sw360AuthorizationServer.java | 22 +- .../Sw360GrantedAuthoritiesCalculator.java | 11 +- .../resourceserver/Sw360ResourceServer.java | 38 +- .../SW360RestHealthIndicator.java | 2 +- .../component/Sw360ComponentService.java | 8 +- .../project/ProjectController.java | 5 +- .../project/Sw360ProjectService.java | 7 +- .../release/Sw360ReleaseService.java | 12 +- .../report/SW360ReportService.java | 9 +- .../ApiTokenAuthenticationFilter.java | 4 +- .../ApiTokenAuthenticationProvider.java | 20 +- .../Sw360GrantedAuthoritiesCalculator.java | 6 +- .../resourceserver/user/Sw360UserService.java | 10 +- .../resourceserver/user/UserController.java | 4 +- .../SW360RestHealthIndicatorTest.java | 3 +- .../restdocs/HealthSpecTest.java | 2 +- .../restdocs/ProjectSpecTest.java | 14 +- 61 files changed, 1019 insertions(+), 915 deletions(-) delete mode 100644 backend/common/src/main/java/org/eclipse/sw360/common/utils/BackendUtils.java delete mode 100644 backend/common/src/main/resources/sw360.properties delete mode 100644 backend/cvesearch/src/main/resources/cvesearch.properties delete mode 100644 backend/cvesearch/src/main/resources/sw360.properties delete mode 100644 backend/licenseinfo/src/main/resources/sw360.properties delete mode 100644 backend/schedule/src/main/resources/sw360.properties delete mode 100644 build-configuration/resources/sw360.properties create mode 100644 libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/DatabaseConstants.java rename {backend/schedule/src/main/java/org/eclipse/sw360/schedule/timer => libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common}/ScheduleConstants.java (97%) create mode 100644 libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/ThriftConstants.java rename rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/{ => actuator}/SW360RestHealthIndicator.java (98%) rename rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/{ => actuator}/SW360RestHealthIndicatorTest.java (98%) diff --git a/backend/common/src/main/java/org/eclipse/sw360/common/utils/BackendUtils.java b/backend/common/src/main/java/org/eclipse/sw360/common/utils/BackendUtils.java deleted file mode 100644 index 317ff26144..0000000000 --- a/backend/common/src/main/java/org/eclipse/sw360/common/utils/BackendUtils.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright Siemens AG, 2019. Part of the SW360 Portal Project. - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.sw360.common.utils; - -import java.util.Properties; - -import org.eclipse.sw360.datahandler.common.CommonUtils; - -public class BackendUtils { - - private static final String PROPERTIES_FILE_PATH = "/sw360.properties"; - protected static final Properties loadedProperties; - public static final Boolean MAINLINE_STATE_ENABLED_FOR_USER; - public static final Boolean IS_BULK_RELEASE_DELETING_ENABLED; - public static final Boolean IS_FORCE_UPDATE_ENABLED; - public static final Boolean DISABLE_CLEARING_FOSSOLOGY_REPORT_DOWNLOAD; - - static { - loadedProperties = CommonUtils.loadProperties(BackendUtils.class, PROPERTIES_FILE_PATH); - MAINLINE_STATE_ENABLED_FOR_USER = Boolean.parseBoolean(loadedProperties.getProperty("mainline.state.enabled.for.user", "false")); - IS_BULK_RELEASE_DELETING_ENABLED = Boolean.parseBoolean(System.getProperty("RunBulkReleaseDeletingTest", loadedProperties.getProperty("bulk.release.deleting.enabled", "false"))); - IS_FORCE_UPDATE_ENABLED = Boolean.parseBoolean( - System.getProperty("RunRestForceUpdateTest", loadedProperties.getProperty("rest.force.update.enabled", "false"))); - DISABLE_CLEARING_FOSSOLOGY_REPORT_DOWNLOAD = Boolean.parseBoolean(loadedProperties.getProperty("disable.clearing.fossology.report.download", "false")); - } - - protected BackendUtils() { - // Utility class with only static functions - } -} diff --git a/backend/common/src/main/java/org/eclipse/sw360/cyclonedx/CycloneDxBOMExporter.java b/backend/common/src/main/java/org/eclipse/sw360/cyclonedx/CycloneDxBOMExporter.java index c59dbe2de8..53cda5251e 100644 --- a/backend/common/src/main/java/org/eclipse/sw360/cyclonedx/CycloneDxBOMExporter.java +++ b/backend/common/src/main/java/org/eclipse/sw360/cyclonedx/CycloneDxBOMExporter.java @@ -33,7 +33,6 @@ import org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler; import org.eclipse.sw360.datahandler.db.PackageDatabaseHandler; import org.eclipse.sw360.datahandler.db.ProjectDatabaseHandler; -import org.eclipse.sw360.datahandler.permissions.PermissionUtils; import org.eclipse.sw360.datahandler.thrift.CycloneDxComponentType; import org.eclipse.sw360.datahandler.thrift.RequestStatus; import org.eclipse.sw360.datahandler.thrift.RequestSummary; @@ -95,7 +94,7 @@ public RequestSummary exportSbom(String projectId, String bomType, Boolean inclu linkedPackageIds.addAll(idsMap.get(SW360Constants.PACKAGE_IDS)); } - if (PermissionUtils.IS_COMPONENT_VISIBILITY_RESTRICTION_ENABLED) { + if (SW360Constants.IS_COMPONENT_VISIBILITY_RESTRICTION_ENABLED) { List releaseList = componentDatabaseHandler.getAccessibleReleaseSummary(user); Set releaseListIds = releaseList.stream().map(Release::getId).collect(Collectors.toSet()); linkedReleaseIds = CollectionUtils.intersection(releaseListIds, linkedReleaseIds).stream().collect(Collectors.toSet()); diff --git a/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/BulkDeleteUtil.java b/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/BulkDeleteUtil.java index 3887813356..93920034b9 100644 --- a/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/BulkDeleteUtil.java +++ b/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/BulkDeleteUtil.java @@ -11,8 +11,9 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.eclipse.sw360.common.utils.BackendUtils; import org.eclipse.sw360.datahandler.common.CommonUtils; +import org.eclipse.sw360.datahandler.common.SW360Constants; +import org.eclipse.sw360.datahandler.common.SW360Constants; import org.eclipse.sw360.datahandler.couchdb.AttachmentConnector; import org.eclipse.sw360.datahandler.entitlement.ComponentModerator; import org.eclipse.sw360.datahandler.entitlement.ReleaseModerator; @@ -47,14 +48,14 @@ /** * Provides a utility for the bulk delete function */ -public class BulkDeleteUtil extends BackendUtils { +public class BulkDeleteUtil { private static final String CONFLICT_ERROR = "conflict"; - + private static final Logger log = LogManager.getLogger(BulkDeleteUtil.class); private static final int LOOP_MAX = 100000; - + private ComponentDatabaseHandler componentDatabaseHandler; private ComponentRepository componentRepository; private ReleaseRepository releaseRepository; @@ -64,10 +65,10 @@ public class BulkDeleteUtil extends BackendUtils { private ReleaseModerator releaseModerator; private AttachmentConnector attachmentConnector; private AttachmentDatabaseHandler attachmentDatabaseHandler; - private DatabaseHandlerUtil dbHandlerUtil; - + private DatabaseHandlerUtil dbHandlerUtil; + private BulkDeleteUtilInspector inspector; - + public interface BulkDeleteUtilInspector { void checkVariables(Map releaseMap, Map componentMap,Map externalLinkMap, Map> referencingReleaseIdsMap); void checkLoopState(int loopCount, Map releaseMap, Map componentMap, Map resultStateMap); @@ -76,10 +77,10 @@ public interface BulkDeleteUtilInspector { void checkUpdatedComponentListInLoop(int loopCount, List updatedComponentList); void checkDeletedReleaseListInLoop(int loopCount, List deletedReleaseList); } - + public BulkDeleteUtil( - ComponentDatabaseHandler componentDatabaseHandler, - ComponentRepository componentRepository, + ComponentDatabaseHandler componentDatabaseHandler, + ComponentRepository componentRepository, ReleaseRepository releaseRepository, ProjectRepository projectRepository, ComponentModerator componentModerator, @@ -94,31 +95,31 @@ public BulkDeleteUtil( this.projectRepository = projectRepository; this.componentModerator = componentModerator; this.releaseModerator = releaseModerator; - this.attachmentConnector = attachmentConnector; + this.attachmentConnector = attachmentConnector; this.attachmentDatabaseHandler = attachmentDatabaseHandler; this.dbHandlerUtil = dbHandlerUtil; this.inspector = null; } public BulkOperationNode deleteBulkRelease(String releaseId, User user, boolean isPreview) throws SW360Exception { - if (!BackendUtils.IS_BULK_RELEASE_DELETING_ENABLED) { + if (!SW360Constants.IS_BULK_RELEASE_DELETING_ENABLED) { throw fail(500, "Bulk release deleting feature is not enabled."); } if (!PermissionUtils.isAdmin(user)) { throw fail(403, "Failed to check the admin privilege."); } - if (!PermissionUtils.IS_ADMIN_PRIVATE_ACCESS_ENABLED) { + if (!SW360Constants.IS_ADMIN_PRIVATE_ACCESS_ENABLED) { throw fail(500, "Admin private access is not enabled."); } - + Release release = releaseRepository.get(releaseId); assertNotNull(release, "No releases found to bulk delete!"); - + //create a result state object Map resultStateMap = new HashMap(); - + //create an all linked release map - Map allLinkedReleaseMap = new HashMap(); + Map allLinkedReleaseMap = new HashMap(); getAllLinkedReleaseMap(release.getId(), allLinkedReleaseMap); Set allLinkedReleaseIds = allLinkedReleaseMap.keySet(); @@ -129,30 +130,30 @@ public BulkOperationNode deleteBulkRelease(String releaseId, User user, boolean Map externalLinkMap = new HashMap(); Map> referencingReleaseIdsMap = new HashMap>(); getExternalLinkMap(allLinkedReleaseMap.keySet(), externalLinkMap, referencingReleaseIdsMap); - + //update result state map for excluded releases for (String externalLinkMapId : externalLinkMap.keySet()) { if (externalLinkMap.get(externalLinkMapId)) { resultStateMap.put(externalLinkMapId, BulkOperationResultState.EXCLUDED); } } - + //create a linked component map Map allComponentMap = getComponenMap(allLinkedReleaseMap); Map workComponentMap = getDuplicatedComponentMap(allComponentMap); - + if (inspector != null) inspector.checkVariables(workReleaseMap, workComponentMap, externalLinkMap, referencingReleaseIdsMap); - + //delete linked releases boolean isCompleted = false; for (int loopCount=0; loopCount leafReleaseIds = getLeafReleaseIds(workReleaseMap); if (inspector != null) inspector.checkLeafReleaseIdsInLoop(loopCount, leafReleaseIds); - + if (CommonUtils.isNullOrEmptyCollection(leafReleaseIds)) { isCompleted = true; break; @@ -164,7 +165,7 @@ public BulkOperationNode deleteBulkRelease(String releaseId, User user, boolean hasExternalLink = true; //remove the release from work tree workReleaseMap.remove(leafReleaseId); - + //remove the release id from ReleaseIdToRelationship of reference releases List referencingReleaseIds = referencingReleaseIdsMap.get(leafReleaseId); for (String referencingReleaseId : referencingReleaseIds) { @@ -183,13 +184,13 @@ public BulkOperationNode deleteBulkRelease(String releaseId, User user, boolean if (hasExternalLink) { continue; } - - //filter releases that failed last time + + //filter releases that failed last time Set targetLeafReleaseIds = leafReleaseIds; Set deletedLeafReleaseIds = new HashSet(); for (String targetLeafReleaseId : targetLeafReleaseIds) { if (resultStateMap.containsKey(targetLeafReleaseId)) { - BulkOperationResultState state = resultStateMap.get(targetLeafReleaseId); + BulkOperationResultState state = resultStateMap.get(targetLeafReleaseId); if (state == BulkOperationResultState.FAILED || state == BulkOperationResultState.CONFLICTED) { log.warn(String.format("Release %s is skipped because the last status was error.", targetLeafReleaseId)); continue; @@ -218,7 +219,7 @@ public BulkOperationNode deleteBulkRelease(String releaseId, User user, boolean } deletedLeafReleaseIds.removeAll(filteredReleaseIds); } - + //update referencing releases Map> previousRelationshipMap = new HashMap>(); Set updatedReferencingReleaseIds = new HashSet(); @@ -256,7 +257,7 @@ public BulkOperationNode deleteBulkRelease(String releaseId, User user, boolean if (deletedLeafReleaseIds.contains(referencedReleaseId)) { deletedLeafReleaseIds.remove(referencedReleaseId); log.error(String.format("Failed to update the referencing release %s, so Release %s is excluded from bulk deletion.", referencingReleaseId, referencedReleaseId)); - + //update the result state of this release resultStateMap.put(referencedReleaseId, BulkOperationResultState.FAILED); } @@ -266,7 +267,7 @@ public BulkOperationNode deleteBulkRelease(String releaseId, User user, boolean referencingRelease.setReleaseIdToRelationship(referencedReleaseMap); } } - + //update components Map> previousComponentReleaseIdsMap = new HashMap>(); Set updatedComponentIds = new HashSet(); @@ -285,7 +286,7 @@ public BulkOperationNode deleteBulkRelease(String releaseId, User user, boolean } List updatedComponentList = updatedComponentIds.stream().map(id -> workComponentMap.get(id)).collect(Collectors.toList()); if (inspector != null) inspector.checkUpdatedComponentListInLoop(loopCount, updatedComponentList); - + if (!isPreview) { resultState = updateBulkComponent(updatedComponentList); } else { @@ -303,9 +304,9 @@ public BulkOperationNode deleteBulkRelease(String releaseId, User user, boolean //exclude from the list of candidates for deletion for (String componentReleaseId : componentReleaseIds) { if (deletedLeafReleaseIds.contains(componentReleaseId)) { - deletedLeafReleaseIds.remove(componentReleaseId); + deletedLeafReleaseIds.remove(componentReleaseId); log.error(String.format("Failed to update the component %s, so Release %s is excluded from bulk deletion.", componentId, componentReleaseId)); - + //update the result state of this release resultStateMap.put(componentReleaseId, BulkOperationResultState.FAILED); //restore referencing releases @@ -323,11 +324,11 @@ public BulkOperationNode deleteBulkRelease(String releaseId, User user, boolean component.setReleaseIds(componentReleaseIds); } } - + //delete releases in bulk List deletedReleaseList = deletedLeafReleaseIds.stream().map(id -> workReleaseMap.get(id)).collect(Collectors.toList()); if (inspector != null) inspector.checkDeletedReleaseListInLoop(loopCount, deletedReleaseList); - + if (!isPreview) { resultState = deleteBulkRelease(deletedReleaseList); } else { @@ -344,7 +345,7 @@ public BulkOperationNode deleteBulkRelease(String releaseId, User user, boolean workReleaseMap.remove(deletedReleaseId); } else { log.error(String.format("Failed to delete the release %s", deletedReleaseId)); - + resultStateMap.put(deletedReleaseId, state); //restore component link Release deletedRelease = workReleaseMap.get(deletedReleaseId); @@ -364,7 +365,7 @@ public BulkOperationNode deleteBulkRelease(String releaseId, User user, boolean } } } - + //update modration request if (!isPreview) { for (String deletedLeafReleaseId : deletedLeafReleaseIds) { @@ -391,7 +392,7 @@ public BulkOperationNode deleteBulkRelease(String releaseId, User user, boolean updatedComponentList.add(component); } } - + Map resultState; if (!isPreview) { List bulkComponentList = new ArrayList(); @@ -424,7 +425,7 @@ public BulkOperationNode deleteBulkRelease(String releaseId, User user, boolean resultStateMap.put(componentId, state); } } - + //update ramained components if (!isPreview) { for (Component updatedComponent : updatedComponentList) { @@ -436,7 +437,7 @@ public BulkOperationNode deleteBulkRelease(String releaseId, User user, boolean resultStateMap.put(componentId, BulkOperationResultState.EXCLUDED); } } - + //update result state for remained releases for (String linkedReleaseId : allLinkedReleaseIds) { if (!resultStateMap.containsKey(linkedReleaseId)) { @@ -447,7 +448,7 @@ public BulkOperationNode deleteBulkRelease(String releaseId, User user, boolean } } } - + //add change log if (!isPreview) { // add release change logs @@ -462,7 +463,7 @@ public BulkOperationNode deleteBulkRelease(String releaseId, User user, boolean Release newRelease = workReleaseMap.get(linkedReleaseId); if (!oldRelease.equals(newRelease)) { //update - dbHandlerUtil.addChangeLogs(newRelease, oldRelease, user.getEmail(), Operation.UPDATE, attachmentConnector, + dbHandlerUtil.addChangeLogs(newRelease, oldRelease, user.getEmail(), Operation.UPDATE, attachmentConnector, Lists.newArrayList(), null, null); } } @@ -479,22 +480,22 @@ public BulkOperationNode deleteBulkRelease(String releaseId, User user, boolean Component newComponent = workComponentMap.get(componentId); if (!oldComponent.equals(newComponent)) { //update - dbHandlerUtil.addChangeLogs(newComponent, oldComponent, user.getEmail(), Operation.UPDATE, attachmentConnector, + dbHandlerUtil.addChangeLogs(newComponent, oldComponent, user.getEmail(), Operation.UPDATE, attachmentConnector, Lists.newArrayList(), null, null); } } } } - + //create result data BulkOperationNode rootNode = createBulkOperationNodeTree( releaseId, BulkOperationNodeType.RELEASE, null, allLinkedReleaseMap, allComponentMap, resultStateMap); - + return rootNode; } - + public Map getDuplicatedReleaseIdToRelationship(Release release) throws SW360Exception { - Map relationship = release.getReleaseIdToRelationship(); + Map relationship = release.getReleaseIdToRelationship(); if (!CommonUtils.isNullOrEmptyMap(relationship)) { Map newReleaseIdToRelationship = new HashMap(); for (String releaseId : relationship.keySet()){ @@ -503,27 +504,27 @@ public Map getDuplicatedReleaseIdToRelationship(Rel } return newReleaseIdToRelationship; } else { - throw fail(500, "Unexpected ReleaseRelationship."); + throw fail(500, "Unexpected ReleaseRelationship."); } } - + public Set getDuplicatedComponentReleaseIds(Component component) throws SW360Exception { - Set releaseIds = component.getReleaseIds(); + Set releaseIds = component.getReleaseIds(); if (!CommonUtils.isNullOrEmptyCollection(releaseIds)) { return new HashSet(releaseIds); } else { - throw fail(500, "Unexpected ReleaseRelationship."); + throw fail(500, "Unexpected ReleaseRelationship."); } } - + public void deleteReleaseAttachments(Release release) throws SW360Exception { attachmentConnector.deleteAttachments(release.getAttachments()); attachmentDatabaseHandler.deleteUsagesBy(Source.releaseId(release.getId())); } - + public Map deleteBulkRelease(List releaseList) { Map resultState = new HashMap(); - + List documentList = new ArrayList(); for(Release release : releaseList) { Document document = new Document(); @@ -566,7 +567,7 @@ public Map updateBulkReleases(Collection deleteBulkComponent(List componentList) { Map resultState = new HashMap(); - + List documentList = new ArrayList(); for(Component component : componentList) { Document document = new Document(); @@ -606,7 +607,7 @@ public Map updateBulkComponent(Collection outMap) throws SW360Exception { if (outMap.containsKey(releaseId)) { return; @@ -631,7 +632,7 @@ public Map getDuplicatedReleaseMap(Map release } return resultMap; } - + public Map getDuplicatedComponentMap(Map componentMap) { Map resultMap = new HashMap(); for (Map.Entry entry : componentMap.entrySet()) { @@ -640,8 +641,8 @@ public Map getDuplicatedComponentMap(Map c resultMap.put(componentId, component); } return resultMap; - } - + } + public void getExternalLinkMap(Set allLinkedReleaseIds, Map outExternalFlagMap, Map> outReferencingReleaseIdsMap) { Map cacheMap = new HashMap(); for (String releaseId : allLinkedReleaseIds) { @@ -649,20 +650,20 @@ public void getExternalLinkMap(Set allLinkedReleaseIds, Map allLinkedReleaseIds, Map> outReferencingReleaseIdsMap, Map cacheMap) { if (cacheMap.containsKey(releaseId)) { return cacheMap.get(releaseId); } List referencingReleaseList = releaseRepository.getReferencingReleases(releaseId); outReferencingReleaseIdsMap.put(releaseId, referencingReleaseList.stream().map(r -> r.getId()).collect(Collectors.toList())); - + Set referencingProjects = projectRepository.searchByReleaseId(releaseId); if (CommonUtils.isNotEmpty(referencingProjects)) { cacheMap.put(releaseId, true); return true; } - + if (CommonUtils.isNotEmpty(referencingReleaseList)) { for (Release referencingRelase : referencingReleaseList) { String referencingRelaseId = referencingRelase.getId(); @@ -680,11 +681,11 @@ public boolean checkReleaseHasExternalLink(String releaseId, Set allLink cacheMap.put(releaseId, false); return false; } - + cacheMap.put(releaseId, false); return false; } - + public Map getComponenMap(Map allLinkedReleaseMap){ Map resultMap = new HashMap(); for (Release release : allLinkedReleaseMap.values()) { @@ -696,7 +697,7 @@ public Map getComponenMap(Map allLinkedRelea } return resultMap; } - + public Set getLeafReleaseIds(Map releaseMap) { Set resultList = new HashSet(); for (Release release : releaseMap.values()) { @@ -706,15 +707,15 @@ public Set getLeafReleaseIds(Map releaseMap) { } return resultList; } - + public BulkOperationNode createBulkOperationNodeTree( - String documentId, + String documentId, BulkOperationNodeType type, String parentId, - Map allLinkedReleaseMap, - Map componentMap, + Map allLinkedReleaseMap, + Map componentMap, Map resultStateMap) throws SW360Exception { - + if (type == BulkOperationNodeType.RELEASE) { //create release node String releaseId = documentId; @@ -737,7 +738,7 @@ public BulkOperationNode createBulkOperationNodeTree( } } releaseNode.setChildList(releaseChildList); - + //create component node String componentId = release.getComponentId(); if (!componentMap.containsKey(componentId)) { @@ -756,18 +757,18 @@ public BulkOperationNode createBulkOperationNodeTree( componentNode.setParentId(parentId); releaseNode.setParentId(componentId); return componentNode; - + } else { throw fail(500, "Unsupported data type " + type.toString()); } } - + public void setInspector(BulkDeleteUtilInspector inspector) { this.inspector = inspector; } - + public void unsetInspector() { this.inspector = null; } - + } diff --git a/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/ComponentDatabaseHandler.java b/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/ComponentDatabaseHandler.java index 50b114e678..994b862098 100644 --- a/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/ComponentDatabaseHandler.java +++ b/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/ComponentDatabaseHandler.java @@ -14,11 +14,11 @@ import com.ibm.cloud.cloudant.v1.model.DocumentResult; import com.google.common.collect.*; -import org.eclipse.sw360.common.utils.BackendUtils; import org.eclipse.sw360.commonIO.AttachmentFrontendUtils; import org.eclipse.sw360.components.summary.SummaryType; import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant; import org.eclipse.sw360.datahandler.common.CommonUtils; +import org.eclipse.sw360.datahandler.common.DatabaseConstants; import org.eclipse.sw360.datahandler.common.DatabaseSettings; import org.eclipse.sw360.datahandler.common.Duration; import org.eclipse.sw360.datahandler.common.SW360Constants; @@ -62,7 +62,6 @@ import org.eclipse.sw360.mail.MailUtil; import org.apache.logging.log4j.Logger; import org.apache.commons.io.IOUtils; -import org.apache.http.HttpStatus; import org.apache.logging.log4j.LogManager; import org.apache.thrift.TException; import org.eclipse.sw360.spdx.SpdxBOMImporter; @@ -76,7 +75,6 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException; -import java.net.URI; import java.net.URL; import java.nio.ByteBuffer; import java.nio.file.*; @@ -1261,7 +1259,7 @@ private Set extractAttachmentNameWithType(Set attachments, C } private void setMainlineState(Release updated, User user, Release current) { - boolean isMainlineStateDisabled = !(BackendUtils.MAINLINE_STATE_ENABLED_FOR_USER + boolean isMainlineStateDisabled = !(SW360Constants.MAINLINE_STATE_ENABLED_FOR_USER || PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user)); if ((null == current || null == current.getMainlineState()) && isMainlineStateDisabled) { @@ -1345,7 +1343,7 @@ private void autosetEccFieldsForReleaseWithDownloadUrl(Release release) { eccInfo.setAl(ECC_AUTOSET_VALUE); eccInfo.setEccn(ECC_AUTOSET_VALUE); eccInfo.setEccComment(ECC_AUTOSET_COMMENT); - if (DatabaseHandlerUtil.AUTO_SET_ECC_STATUS) { + if (DatabaseConstants.AUTO_SET_ECC_STATUS) { eccInfo.setEccStatus(ECCStatus.APPROVED); } eccInfo.setAssessmentDate(SW360Utils.getCreatedOn()); diff --git a/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/DatabaseHandlerUtil.java b/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/DatabaseHandlerUtil.java index 413d97dff1..7099dfccc9 100644 --- a/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/DatabaseHandlerUtil.java +++ b/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/DatabaseHandlerUtil.java @@ -39,7 +39,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Properties; import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -64,6 +63,7 @@ import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant; import org.eclipse.sw360.datahandler.cloudantclient.DatabaseRepositoryCloudantClient; import org.eclipse.sw360.datahandler.common.CommonUtils; +import org.eclipse.sw360.datahandler.common.DatabaseConstants; import org.eclipse.sw360.datahandler.common.DatabaseSettings; import org.eclipse.sw360.datahandler.common.SW360Utils; import org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException; @@ -140,42 +140,14 @@ public class DatabaseHandlerUtil { public static final String SEPARATOR = " -> "; private static ChangeLogsRepository changeLogRepository; private static ObjectMapper mapper = initAndGetObjectMapper(); - public static final String PROPERTIES_FILE_PATH = "/sw360.properties"; - private static final String SVM_JSON_LOG_OUTPUT_LOCATION; private static final String SVM_JSON_FILE_PREFIX = "svm_json_output_"; private static final String SVM_JSON_FILE_SUFFIX = ".json"; private static final String SVM_JSON_LOG_OUTPUT_FILE_PERMISSION = "rw-------"; private static final String ATTACHMENT_ID = "attachmentId_"; private static final String DOCUMENT_ID = "documentId_"; - private static final boolean IS_STORE_ATTACHMENT_TO_FILE_SYSTEM_ENABLED; - private static final String ATTACHMENT_STORE_FILE_SYSTEM_LOCATION; - private static final String ATTACHMENT_STORE_FILE_SYSTEM_PERMISSION; private static ExecutorService ATTACHMENT_FILE_SYSTEM_STORE_THREAD_POOL = Executors.newFixedThreadPool(5); - private static final String ATTACHMENT_DELETE_NO_OF_DAYS; - private static final boolean IS_SW360CHANGELOG_ENABLED; - private static final String CHANGE_LOG_CONFIG_FILE_PATH; - private static final String SW360CHANGELOG_OUTPUT_PATH; private static boolean isChangeLogDisabledMessageLogged = false; private static boolean isLiferayEnvVarNotPresent = true; - public static final boolean AUTO_SET_ECC_STATUS; - - static { - Properties props = CommonUtils.loadProperties(DatabaseSettings.class, PROPERTIES_FILE_PATH); - SVM_JSON_LOG_OUTPUT_LOCATION = props.getProperty("svm.json.log.output.location", "/tmp"); - ATTACHMENT_STORE_FILE_SYSTEM_LOCATION = props.getProperty("attachment.store.file.system.location", - "/opt/sw360tempattachments"); - ATTACHMENT_STORE_FILE_SYSTEM_PERMISSION = props.getProperty("attachment.store.file.system.permission", - "rwx------"); - IS_STORE_ATTACHMENT_TO_FILE_SYSTEM_ENABLED = Boolean.parseBoolean(props.getProperty("enable.attachment.store.to.file.system", "false")); - ATTACHMENT_DELETE_NO_OF_DAYS = props.getProperty("attachemnt.delete.no.of.days", - "30"); - IS_SW360CHANGELOG_ENABLED = Boolean.parseBoolean(props.getProperty("enable.sw360.change.log", "false")); - CHANGE_LOG_CONFIG_FILE_PATH = props.getProperty("sw360changelog.config.file.location", - "/etc/sw360/log4j2.xml"); - SW360CHANGELOG_OUTPUT_PATH = props.getProperty("sw360changelog.output.path", - "sw360changelog/sw360changelog"); - AUTO_SET_ECC_STATUS = Boolean.parseBoolean(props.getProperty("auto.set.ecc.status", "false")); - } public DatabaseHandlerUtil(DatabaseConnectorCloudant db) { changeLogRepository = new ChangeLogsRepository(db); @@ -525,7 +497,7 @@ public static String convertObjectToJson(Object obj) { */ public static void addSelectLogs(T newDocVersion, String userEdited, AttachmentConnector attachmentConnector) { - if (!IS_SW360CHANGELOG_ENABLED) { + if (!DatabaseConstants.IS_SW360CHANGELOG_ENABLED) { if (!isChangeLogDisabledMessageLogged) { log.info("sw360change log is disabled"); isChangeLogDisabledMessageLogged = true; @@ -552,7 +524,7 @@ public static void addSelectLogs(T newDocVersion, String userE }; Thread changeLogsThread = new Thread(changeLogRunnable); - File sw360ChangeLogFileLocation = new File(CHANGE_LOG_CONFIG_FILE_PATH); + File sw360ChangeLogFileLocation = new File(DatabaseConstants.CHANGE_LOG_CONFIG_FILE_PATH); if (sw360ChangeLogFileLocation.exists()) { LoggerContext context = (LoggerContext) LogManager.getContext(false); context.setConfigLocation(sw360ChangeLogFileLocation.toURI()); @@ -564,7 +536,7 @@ public static void addSelectLogs(T newDocVersion, String userE return; } String LIFERAY_HOME = env.get("LIFERAY_INSTALL"); - configureLog4J(SW360CHANGELOG_OUTPUT_PATH, LIFERAY_HOME); + configureLog4J(DatabaseConstants.SW360CHANGELOG_OUTPUT_PATH, LIFERAY_HOME); } changeLogsThread.start(); } @@ -948,7 +920,7 @@ private static Runnable prepareFileHandlerRunnable(String content) { log.info("Preparing to write content to file"); StringBuilder fileNameSb = new StringBuilder(SVM_JSON_FILE_PREFIX) .append(getTimeStamp().replaceAll(" ", "_").replaceAll(":", "-")).append(SVM_JSON_FILE_SUFFIX); - Path outputFile = Paths.get(SVM_JSON_LOG_OUTPUT_LOCATION, fileNameSb.toString()); + Path outputFile = Paths.get(DatabaseConstants.SVM_JSON_LOG_OUTPUT_LOCATION, fileNameSb.toString()); if (!Files.exists(outputFile)) { Set perms = PosixFilePermissions.fromString(SVM_JSON_LOG_OUTPUT_FILE_PERMISSION); FileAttribute> fileAttribute = PosixFilePermissions.asFileAttribute(perms); @@ -988,14 +960,14 @@ private static Runnable prepareFileHandlerRunnable(InputStream content, String u String attachmentId, String fileName) { return () -> { try { - Path outputDir = Paths.get(ATTACHMENT_STORE_FILE_SYSTEM_LOCATION, userEmail, DOCUMENT_ID + documentId, + Path outputDir = Paths.get(DatabaseConstants.ATTACHMENT_STORE_FILE_SYSTEM_LOCATION, userEmail, DOCUMENT_ID + documentId, ATTACHMENT_ID + attachmentId); Path outputFile = Paths.get(fileName); Path outputFilePath = outputDir.resolve(outputFile); log.info("Preparing to store attachment in file system" + outputFilePath); if (!Files.exists(outputFile)) { Set perms = PosixFilePermissions - .fromString(ATTACHMENT_STORE_FILE_SYSTEM_PERMISSION); + .fromString(DatabaseConstants.ATTACHMENT_STORE_FILE_SYSTEM_PERMISSION); FileAttribute> fileAttribute = PosixFilePermissions.asFileAttribute(perms); Files.createDirectories(outputDir, fileAttribute); Files.createFile(outputFilePath, fileAttribute); @@ -1016,7 +988,7 @@ private static Runnable prepareFileHandlerRunnable(InputStream content, String u */ public static void saveAttachmentInFileSystem(AttachmentConnector attachmentConnector, Set before, Set after, String userEmail, String documentId) { - if (!IS_STORE_ATTACHMENT_TO_FILE_SYSTEM_ENABLED) { + if (!DatabaseConstants.IS_STORE_ATTACHMENT_TO_FILE_SYSTEM_ENABLED) { log.debug("Store attachment to file system is disabled"); return; } @@ -1044,13 +1016,13 @@ public static void saveAttachmentInFileSystem(AttachmentConnector attachmentConn } public static RequestStatus deleteOldAttachmentFromFileSystem() { - int noOfDays = Integer.parseInt(ATTACHMENT_DELETE_NO_OF_DAYS); + int noOfDays = Integer.parseInt(DatabaseConstants.ATTACHMENT_DELETE_NO_OF_DAYS); RequestStatus status = null; LocalDate todayDate = LocalDate.now(); LocalDate thresholdDateForAttachmentDelete = todayDate.minusDays(noOfDays); Date thresholdDate = Date.from(thresholdDateForAttachmentDelete.atStartOfDay(ZoneId.systemDefault()).toInstant()); try { - deleteAttachmentAndDirectory(ATTACHMENT_STORE_FILE_SYSTEM_LOCATION, thresholdDate); + deleteAttachmentAndDirectory(DatabaseConstants.ATTACHMENT_STORE_FILE_SYSTEM_LOCATION, thresholdDate); status = RequestStatus.SUCCESS; } catch (IOException e) { log.error("Unable to delete attachment. ", e); @@ -1126,4 +1098,3 @@ public static File saveAsTempFile(InputStream inputStream, String prefix, String return tempFile; } } - diff --git a/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectDatabaseHandler.java b/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectDatabaseHandler.java index 28573e4e1f..7c1d81f339 100644 --- a/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectDatabaseHandler.java +++ b/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectDatabaseHandler.java @@ -12,7 +12,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.ibm.cloud.cloudant.v1.Cloudant; import com.google.common.annotations.VisibleForTesting; @@ -24,7 +23,6 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.apache.thrift.TException; -import org.eclipse.sw360.common.utils.BackendUtils; import org.eclipse.sw360.components.summary.SummaryType; import org.eclipse.sw360.cyclonedx.CycloneDxBOMExporter; import org.eclipse.sw360.cyclonedx.CycloneDxBOMImporter; @@ -685,7 +683,7 @@ private boolean isLinkedReleaseUpdated(Project updated, Project current) { } private void setReleaseRelations(Project updated, User user, Project current) { - boolean isMainlineStateDisabled = !(BackendUtils.MAINLINE_STATE_ENABLED_FOR_USER + boolean isMainlineStateDisabled = !(SW360Constants.MAINLINE_STATE_ENABLED_FOR_USER || PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user)) && updated.getReleaseIdToUsageSize() > 0; @@ -1319,7 +1317,7 @@ public List fillClearingStateSummaryIncludingSubprojects(List return projects; } - + public Project fillClearingStateSummaryIncludingSubprojectsForSingleProject(Project project, User user) { final Map allProjectsIdMap = getRefreshedAllProjectsIdMap(); diff --git a/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectRepository.java b/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectRepository.java index 6167e70f73..200a4ead0f 100644 --- a/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectRepository.java +++ b/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectRepository.java @@ -14,6 +14,7 @@ import org.eclipse.sw360.components.summary.SummaryType; import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant; import org.eclipse.sw360.datahandler.common.CommonUtils; +import org.eclipse.sw360.datahandler.common.SW360Constants; import org.eclipse.sw360.datahandler.common.SW360Utils; import org.eclipse.sw360.datahandler.couchdb.SummaryAwareRepository; import org.eclipse.sw360.datahandler.permissions.PermissionUtils; @@ -424,7 +425,7 @@ public Map> getAccessibleProjectsSummary(User user isUserBelongToBuAndModerator = and(List.of(buAndModorator_visibility_Selector, or(buSelectors))); Map finalSelector; - if (PermissionUtils.IS_ADMIN_PRIVATE_ACCESS_ENABLED && isAdmin) { + if (SW360Constants.IS_ADMIN_PRIVATE_ACCESS_ENABLED && isAdmin) { finalSelector = typeSelector; } else { if (isClearingAdmin) { @@ -556,7 +557,7 @@ public int getMyAccessibleProjectsCount(User user) { } keys[keys.length - 2] = user.getEmail(); keys[keys.length - 1] = "everyone"; - if (PermissionUtils.IS_ADMIN_PRIVATE_ACCESS_ENABLED && isAdmin) { + if (SW360Constants.IS_ADMIN_PRIVATE_ACCESS_ENABLED && isAdmin) { return getConnector().getDocumentCount(Project.class); } if (isClearingAdmin) { @@ -586,7 +587,7 @@ public ProjectData searchByType(String type, User user) { Set accessibleProjects = filterAccessibleProjectsByIds(user, searchIds); return getProjectData(accessibleProjects); } - + private ProjectData getProjectData(Set accessibleProjects) { int totalSize = accessibleProjects.size(); ProjectData projectData = new ProjectData(); diff --git a/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/SvmConnector.java b/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/SvmConnector.java index bd50aaa64a..133e01e263 100644 --- a/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/SvmConnector.java +++ b/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/SvmConnector.java @@ -20,6 +20,7 @@ import org.apache.http.message.BasicHeader; import org.apache.log4j.Logger; import org.eclipse.sw360.datahandler.common.CommonUtils; +import org.eclipse.sw360.datahandler.common.SW360Constants; import org.eclipse.sw360.datahandler.thrift.SW360Exception; import javax.net.ssl.SSLContext; @@ -40,16 +41,10 @@ public class SvmConnector { - private static final String PROPERTIES_FILE_PATH = "/sw360.properties"; - private static final String MONITORING_LIST_API_URL; - private static final String COMPONENT_MAPPINGS_API_URL; - private static final char[] KEY_STORE_PASSPHRASE; - private static final String KEY_STORE_FILENAME; - private static final char[] JAVA_KEYSTORE_PASSWORD; private static final Logger log = Logger.getLogger(SvmConnector.class); public void sendProjectExportForMonitoringLists(String jsonString) throws IOException, SW360Exception { - if(CommonUtils.isNullEmptyOrWhitespace(MONITORING_LIST_API_URL)) { + if(CommonUtils.isNullEmptyOrWhitespace(SW360Constants.SVM_MONITORING_LIST_API_URL)) { return; } try (CloseableHttpClient httpClient = HttpClients @@ -57,7 +52,7 @@ public void sendProjectExportForMonitoringLists(String jsonString) throws IOExce .setSSLSocketFactory(createSslSocketFactoryForSVM()) .build()) { - HttpPut httpPut = new HttpPut(MONITORING_LIST_API_URL); + HttpPut httpPut = new HttpPut(SW360Constants.SVM_MONITORING_LIST_API_URL); httpPut.addHeader(new BasicHeader("Expect", "100-continue")); // prevents error 413 when sending large files MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create(); @@ -85,23 +80,23 @@ private SSLConnectionSocketFactory createSslSocketFactoryForSVM() throws IOExcep String javaKeystoreFilename = System .getProperties() .getProperty("java.home") + File.separator + "lib" + File.separator + "security" + File.separator + "cacerts"; - trustStore.load(new FileInputStream(javaKeystoreFilename), JAVA_KEYSTORE_PASSWORD); + trustStore.load(new FileInputStream(javaKeystoreFilename), SW360Constants.SVM_JAVA_KEYSTORE_PASSWORD); // Loading KeyStore, i.e., PKCS #12 bundle KeyStore keyStore = KeyStore.getInstance("PKCS12"); Optional certStreamOptional = CommonUtils - .loadResource(this.getClass(), KEY_STORE_FILENAME) + .loadResource(this.getClass(), SW360Constants.SVM_KEY_STORE_FILENAME) .map(ByteArrayInputStream::new); if (!certStreamOptional.isPresent()) { throw new IOException("Cannot read SVM client certificate"); } - keyStore.load(certStreamOptional.get(), KEY_STORE_PASSPHRASE); + keyStore.load(certStreamOptional.get(), SW360Constants.SVM_KEY_STORE_PASSPHRASE); SSLContext sslcontext = SSLContexts .custom() .useProtocol("TLSv1.2") .loadTrustMaterial(trustStore) - .loadKeyMaterial(keyStore, KEY_STORE_PASSPHRASE) + .loadKeyMaterial(keyStore, SW360Constants.SVM_KEY_STORE_PASSPHRASE) .build(); return new SSLConnectionSocketFactory(sslcontext, new String[]{"TLSv1.2"}, null, SSLConnectionSocketFactory.STRICT_HOSTNAME_VERIFIER); @@ -112,23 +107,12 @@ private SSLConnectionSocketFactory createSslSocketFactoryForSVM() throws IOExcep } - static { - Properties props = CommonUtils.loadProperties(SvmConnector.class, PROPERTIES_FILE_PATH); - - MONITORING_LIST_API_URL = props.getProperty("svm.sw360.api.url", ""); - COMPONENT_MAPPINGS_API_URL = props.getProperty("svm.sw360.componentmappings.api.url", ""); - KEY_STORE_FILENAME = props.getProperty("svm.sw360.certificate.filename", "not-configured"); - KEY_STORE_PASSPHRASE = props.getProperty("svm.sw360.certificate.passphrase", "").toCharArray(); - JAVA_KEYSTORE_PASSWORD = props.getProperty("svm.sw360.jks.password", "changeit").toCharArray(); - } - - public Map> fetchComponentMappings() throws SW360Exception, IOException { - if(CommonUtils.isNullEmptyOrWhitespace(COMPONENT_MAPPINGS_API_URL)) { + if(CommonUtils.isNullEmptyOrWhitespace(SW360Constants.SVM_COMPONENT_MAPPINGS_API_URL)) { return Collections.emptyMap(); } try (CloseableHttpClient httpClient = HttpClients.createDefault()) { - HttpGet httpGet = new HttpGet(COMPONENT_MAPPINGS_API_URL); + HttpGet httpGet = new HttpGet(SW360Constants.SVM_COMPONENT_MAPPINGS_API_URL); try (CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) { StatusLine statusLine = httpResponse.getStatusLine(); diff --git a/backend/common/src/main/java/org/eclipse/sw360/mail/MailConstants.java b/backend/common/src/main/java/org/eclipse/sw360/mail/MailConstants.java index 67b501b29e..5faf7c70d0 100644 --- a/backend/common/src/main/java/org/eclipse/sw360/mail/MailConstants.java +++ b/backend/common/src/main/java/org/eclipse/sw360/mail/MailConstants.java @@ -16,8 +16,6 @@ */ public class MailConstants { - public static final String MAIL_PROPERTIES_FILE_PATH = "/sw360.properties"; - public static final String DEFAULT_BEGIN = "defaultBegin"; public static final String DEFAULT_END = "defaultEnd"; public static final String UNSUBSCRIBE_NOTICE_BEFORE = "unsubscribeNoticeBefore"; diff --git a/backend/common/src/main/java/org/eclipse/sw360/mail/MailUtil.java b/backend/common/src/main/java/org/eclipse/sw360/mail/MailUtil.java index 5955c43eb3..0071adeb2c 100644 --- a/backend/common/src/main/java/org/eclipse/sw360/mail/MailUtil.java +++ b/backend/common/src/main/java/org/eclipse/sw360/mail/MailUtil.java @@ -13,7 +13,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.thrift.TException; -import org.eclipse.sw360.common.utils.BackendUtils; import org.eclipse.sw360.datahandler.common.CommonUtils; import org.eclipse.sw360.datahandler.common.SW360Constants; import org.eclipse.sw360.datahandler.common.SW360Utils; @@ -35,13 +34,18 @@ import static org.eclipse.sw360.datahandler.common.CommonUtils.isNullEmptyOrWhitespace; import static org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptySet; +import static org.eclipse.sw360.datahandler.common.SW360Constants.props; +import static org.eclipse.sw360.mail.MailConstants.DEFAULT_BEGIN; +import static org.eclipse.sw360.mail.MailConstants.DEFAULT_END; +import static org.eclipse.sw360.mail.MailConstants.UNSUBSCRIBE_NOTICE_AFTER; +import static org.eclipse.sw360.mail.MailConstants.UNSUBSCRIBE_NOTICE_BEFORE; /** * Provides the possibility to send mail from SW360 * * @author birgit.heydenreich@tngtech.com */ -public class MailUtil extends BackendUtils { +public class MailUtil { private static final Logger log = LogManager.getLogger(MailUtil.class); @@ -88,18 +92,18 @@ private static ExecutorService fixedThreadPoolWithQueueSize(int nThreads, int qu } private void setBasicProperties() { - from = loadedProperties.getProperty("MailUtil_from", "__No_Reply__@sw360.org"); - host = loadedProperties.getProperty("MailUtil_host", ""); - port = loadedProperties.getProperty("MailUtil_port", "25"); - enableStarttls = loadedProperties.getProperty("MailUtil_enableStarttls", "false"); - enableSsl = loadedProperties.getProperty("MailUtil_enableSsl", "false"); - isAuthenticationNecessary = loadedProperties.getProperty("MailUtil_isAuthenticationNecessary", "true"); - login = loadedProperties.getProperty("MailUtil_login", ""); - password = loadedProperties.getProperty("MailUtil_password", ""); - enableDebug = loadedProperties.getProperty("MailUtil_enableDebug", "false"); - supportMailAddress = loadedProperties.getProperty("MailUtil_supportMailAddress",""); - smtpSSLProtocol = loadedProperties.getProperty("MailUtil_smtpSSLProtocol", ""); - smtpSSLTrust = loadedProperties.getProperty("MailUtil_smtpSSLTrust", "*"); + from = props.getProperty("MailUtil_from", "__No_Reply__@sw360.org"); + host = props.getProperty("MailUtil_host", ""); + port = props.getProperty("MailUtil_port", "25"); + enableStarttls = props.getProperty("MailUtil_enableStarttls", "false"); + enableSsl = props.getProperty("MailUtil_enableSsl", "false"); + isAuthenticationNecessary = props.getProperty("MailUtil_isAuthenticationNecessary", "true"); + login = props.getProperty("MailUtil_login", ""); + password = props.getProperty("MailUtil_password", ""); + enableDebug = props.getProperty("MailUtil_enableDebug", "false"); + supportMailAddress = props.getProperty("MailUtil_supportMailAddress",""); + smtpSSLProtocol = props.getProperty("MailUtil_smtpSSLProtocol", ""); + smtpSSLTrust = props.getProperty("MailUtil_smtpSSLTrust", "*"); } private void setSession() { @@ -191,7 +195,7 @@ private boolean isMailingEnabledAndValid() { private MimeMessage makeHtmlMessageWithSubjectAndText(ClearingRequestEmailTemplate template, String subjectKeyInPropertiesFile, String ... textParameters) { MimeMessage message = new MimeMessage(session); String mainContentFormat = ""; - String subject = loadedProperties.getProperty(subjectKeyInPropertiesFile, ""); + String subject = props.getProperty(subjectKeyInPropertiesFile, ""); switch (template) { case UPDATED: mainContentFormat = UPDATE_CR_EMAIL_HTML_TEMPLATE; @@ -243,11 +247,11 @@ private MimeMessage makeHtmlMessageWithSubjectAndText(ClearingRequestEmailTempla private MimeMessage makeMessageWithSubjectAndText(String subjectKeyInPropertiesFile, String textKeyInPropertiesFile, String ... textParameters) { MimeMessage message = new MimeMessage(session); - String subject = loadedProperties.getProperty(subjectKeyInPropertiesFile, ""); + String subject = props.getProperty(subjectKeyInPropertiesFile, ""); StringBuilder text = new StringBuilder(); - text.append(loadedProperties.getProperty("defaultBegin", "")); - String mainContentFormat = loadedProperties.getProperty(textKeyInPropertiesFile, ""); + text.append(props.getProperty(DEFAULT_BEGIN, "")); + String mainContentFormat = props.getProperty(textKeyInPropertiesFile, ""); try { String formattedContent = String.format(mainContentFormat, (Object[]) textParameters); @@ -256,12 +260,12 @@ private MimeMessage makeMessageWithSubjectAndText(String subjectKeyInPropertiesF log.error(String.format("Could not format notification email content for keys %s and %s", subjectKeyInPropertiesFile, textKeyInPropertiesFile), e); text.append(mainContentFormat); } - text.append(loadedProperties.getProperty("defaultEnd", "")); - if (!supportMailAddress.equals("")) { - text.append(loadedProperties.getProperty("unsubscribeNoticeBefore", "")); + text.append(props.getProperty(DEFAULT_END, "")); + if (!supportMailAddress.isEmpty()) { + text.append(props.getProperty(UNSUBSCRIBE_NOTICE_BEFORE, "")); text.append(" "); text.append(supportMailAddress); - text.append(loadedProperties.getProperty("unsubscribeNoticeAfter", "")); + text.append(props.getProperty(UNSUBSCRIBE_NOTICE_AFTER, "")); } try { message.setSubject(subject); diff --git a/backend/common/src/main/resources/sw360.properties b/backend/common/src/main/resources/sw360.properties deleted file mode 100644 index d65daa5157..0000000000 --- a/backend/common/src/main/resources/sw360.properties +++ /dev/null @@ -1,136 +0,0 @@ -# Copyright Siemens AG, 2016-2017. Part of the SW360 Portal Project. -# -# This program and the accompanying materials are made -# available under the terms of the Eclipse Public License 2.0 -# which is available at https://www.eclipse.org/legal/epl-2.0/ -# -# SPDX-License-Identifier: EPL-2.0 -# - -# common property file for the backend services -backend.url= http://localhost:8080 - -licenseinfo.spdxparser.use-license-info-from-files=true -mainline.state.enabled.for.user=false - -# settings for the mail utility: -# if host is not set, e-mailing is disabled -MailUtil_host= -MailUtil_from=__No_Reply__@sw360.org -MailUtil_port=25 -MailUtil_enableStarttls= -MailUtil_enableSsl= -MailUtil_isAuthenticationNecessary= -MailUtil_login= -MailUtil_password= -MailUtil_enableDebug= -MailUtil_supportMailAddress= -MailUtil_smtpSSLProtocol= -MailUtil_smtpSSLTrust= - -# text patterns for mail utility -defaultBegin = \ - *** This is an automatically generated email, please do not reply. ***\n\n\ - Dear SW360-user,\n\n -defaultEnd = \ - With best regards,\n\ - SW360-support -unsubscribeNoticeBefore =\n\n*** If you do not wish to receive mails from SW360, please notify: -unsubscribeNoticeAfter =. *** - -subjectForNewModerationRequest= New moderation request -subjectForUpdateModerationRequest= Update on moderation request -subjectForAcceptedModerationRequest= Your moderation request has been accepted -subjectForDeclinedModerationRequest= Your moderation request has been declined -subjectForDeclinedUserModerationRequest= Your request for a SW360 user account has been declined -subjectForNewComponent= New component created -subjectForUpdateComponent= Component updated -subjectForNewRelease= New release created -subjectForUpdateRelease= Release updated -subjectForNewProject= New project created -subjectForUpdateProject= Project updated -subjectForNewClearingRequest= New clearing request <%s> for Project <%s> -subjectForClearingRequestComment= New comment added in clearing request <%s> for Project <%s> -subjectForUpdatedClearingRequest= Your clearing request <%s> has been updated for Project <%s> -subjectForClosedClearingRequest= Your clearing request <%s> has been closed for Project <%s> -subjectForRejectedClearingRequest= Your clearing request <%s> has been rejected for Project <%s> -subjectForUpdatedProjectWithClearingRequest= Project <%s> with clearing request <%s> updated -subjectForSuccessfulExport = Spreadsheet Export Successful - -textForSuccessfulExport = The %s spreadsheet export successfully completed. Please find the download link(%s) here. -textForNewModerationRequest= a new moderation request has been added to your SW360-account.\n\n -textForUpdateModerationRequest= \ - one of the moderation requests previously added to your \ - SW360-account has been updated.\n\n -textForAcceptedModerationRequest= your moderation request to change the %s %s has been accepted by one of the moderators.\n\n -textForDeclinedModerationRequest= your moderation request to change the %s %s has been declined by one of the moderators.\n\n -textForDeclinedUserModerationRequest= your request for a SW360 user account has been declined by one of the administrators.\n\n -textForNewComponent= a new component %s, in which you take part, has been created.\n\n -textForUpdateComponent= the component %s, in which you take part, has been updated.\n\n -textForNewRelease= a new release %s %s, in which you take part, has been created.\n\n -textForUpdateRelease= the release %s %s, in which you take part, has been updated.\n\n -textForNewProject= a new project %s %s, in which you take part, has been created.\n\n -textForUpdateProject= the project %s %s, in which you take part, has been updated.\n\n - -# Vulnerability Monitoring -svm.components.url= -svm.actions.url= -svm.priorities.url= -svm.components.vulnerabilities.url= -svm.vulnerabilities.url= - -# sync="today 00:00:00"+firstOffset, time between sync and now will be skipped -# default is 01:00 am (1*60*60=3600) -schedule.svmsync.firstOffset.seconds=3600 -# default is 24h (24*60*60sec=86400) -schedule.svmsync.interval.seconds=86400 - -# default is 02:00 am (2*60*60=7200) -schedule.svmmatch.firstOffset.seconds=7200 -# default is 24h (24*60*60sec=86400) -schedule.svmmatch.interval.seconds=86400 - -# default is 03:00 am (3*60*60=10800) -schedule.svmlistupdate.firstOffset.seconds=10800 -# default is 24h (24*60*60sec=86400) -schedule.svmlistupdate.interval.seconds=86400 - -# default is 03:00 am (3*60*60=10800) -schedule.trackingfeedback.firstOffset.seconds=10800 -# default is 24h (24*60*60sec=86400) -schedule.trackingfeedback.interval.seconds=86400 - -svm.sw360.api.url= -svm.sw360.certificate.filename= -svm.sw360.certificate.passphrase= -svm.sw360.jks.password=changeit -svm.json.log.output.location=/tmp -svm.component.id= -mainline.component.id= -svm.component.id.key= -svm.short.status= -svm.short.status.key= -svm.scheduler.email= -svm.monitoringlist.id= -textForClosedClearingRequest= your clearing request with id: %s for the project %s has been closed by the clearing team.\n\n -textForRejectedClearingRequest= your clearing request with id: %s for the project %s has been rejected by the clearing team.\n\n -#attachment.store.file.system.location=/opt/sw360tempattachments -#enable.attachment.store.to.file.system=false -#attachment.store.file.system.permission=rwx------ -#attachemnt.delete.no.of.days=30 - -#Uncomment the below file location if the log4j2.xml file is placed inside etc/sw360 folder. -#sw360changelog.config.file.location=/etc/sw360/log4j2.xml -enable.sw360.change.log=false -sw360changelog.output.path=sw360changelog/sw360changelog -auto.set.ecc.status=false - -##This property is used to enable mail request for projects/components report. -#send.project.spreadsheet.export.to.mail.enabled=false -#send.component.spreadsheet.export.to.mail.enabled=false - -## This property is used to enable the bulk release deleting feature. -#bulk.release.deleting.enabled=true - -## This property is used to disable the ISR generation in fossology process -disable.clearing.fossology.report.download=false \ No newline at end of file diff --git a/backend/common/src/test/java/org/eclipse/sw360/datahandler/db/ProjectDatabaseHandlerTest.java b/backend/common/src/test/java/org/eclipse/sw360/datahandler/db/ProjectDatabaseHandlerTest.java index e493d5982a..996260d4bb 100644 --- a/backend/common/src/test/java/org/eclipse/sw360/datahandler/db/ProjectDatabaseHandlerTest.java +++ b/backend/common/src/test/java/org/eclipse/sw360/datahandler/db/ProjectDatabaseHandlerTest.java @@ -13,10 +13,10 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.SetMultimap; -import org.eclipse.sw360.common.utils.BackendUtils; import org.eclipse.sw360.datahandler.TestUtils; import org.eclipse.sw360.datahandler.common.DatabaseSettingsTest; import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant; +import org.eclipse.sw360.datahandler.common.SW360Constants; import org.eclipse.sw360.datahandler.entitlement.ProjectModerator; import org.eclipse.sw360.datahandler.thrift.*; import org.eclipse.sw360.datahandler.thrift.components.Component; @@ -172,10 +172,10 @@ public void testUpdateProject2_1() throws Exception { // Now contributors can also change the project assertEquals(RequestStatus.SUCCESS, status); } - + @Test public void testForceUpdateProject() throws Exception { - if (!BackendUtils.IS_FORCE_UPDATE_ENABLED) { + if (!SW360Constants.IS_FORCE_UPDATE_ENABLED) { return; } Project project1 = handler.getProjectById("P1", user1); @@ -185,7 +185,7 @@ public void testForceUpdateProject() throws Exception { RequestStatus status = handler.updateProject(project1, user2, true); - // if force option is enabled, the project can be changed. + // if force option is enabled, the project can be changed. assertEquals(RequestStatus.SUCCESS, status); } @@ -304,10 +304,10 @@ public void testDeleteProject3_2() throws Exception { boolean deleted = (handler.getProjectById("P3", user3) == null); assertEquals(false, deleted); } - + @Test public void testForceDeleteProject() throws Exception { - if (!BackendUtils.IS_FORCE_UPDATE_ENABLED) { + if (!SW360Constants.IS_FORCE_UPDATE_ENABLED) { return; } int expect = handler.getMyProjectsSummary(user1.getEmail()).size() - 1; diff --git a/backend/components/src/test/java/org/eclipse/sw360/components/db/BulkDeleteUtilTest.java b/backend/components/src/test/java/org/eclipse/sw360/components/db/BulkDeleteUtilTest.java index c35a71357c..714520572d 100644 --- a/backend/components/src/test/java/org/eclipse/sw360/components/db/BulkDeleteUtilTest.java +++ b/backend/components/src/test/java/org/eclipse/sw360/components/db/BulkDeleteUtilTest.java @@ -10,17 +10,16 @@ package org.eclipse.sw360.components.db; -import org.eclipse.sw360.common.utils.BackendUtils; import org.eclipse.sw360.datahandler.TestUtils; import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant; import org.eclipse.sw360.datahandler.common.CommonUtils; import org.eclipse.sw360.datahandler.common.DatabaseSettingsTest; +import org.eclipse.sw360.datahandler.common.SW360Constants; import org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler; import org.eclipse.sw360.datahandler.db.BulkDeleteUtil; import org.eclipse.sw360.datahandler.entitlement.ComponentModerator; import org.eclipse.sw360.datahandler.entitlement.ProjectModerator; import org.eclipse.sw360.datahandler.entitlement.ReleaseModerator; -import org.eclipse.sw360.datahandler.permissions.PermissionUtils; import org.eclipse.sw360.datahandler.thrift.*; import org.eclipse.sw360.datahandler.thrift.components.*; import org.eclipse.sw360.datahandler.thrift.projects.Project; @@ -59,7 +58,7 @@ public class BulkDeleteUtilTest { private static final String category = "Mobile"; //Release IDs - private static final String RELEASE_ID_A1 = "dr_r_a1"; + private static final String RELEASE_ID_A1 = "dr_r_a1"; private static final String RELEASE_ID_B1 = "dr_r_b1"; private static final String RELEASE_ID_C1 = "dr_r_c1"; private static final String RELEASE_ID_C2 = "dr_r_c2"; @@ -68,9 +67,9 @@ public class BulkDeleteUtilTest { private static final String RELEASE_ID_F1 = "dr_r_f1"; private static final String RELEASE_ID_G1 = "dr_r_g1"; private static final String RELEASE_ID_H1 = "dr_r_h1"; - + //Component IDs - private static final String COMPONENT_ID_A = "dr_c_a"; + private static final String COMPONENT_ID_A = "dr_c_a"; private static final String COMPONENT_ID_B = "dr_c_b"; private static final String COMPONENT_ID_C = "dr_c_c"; private static final String COMPONENT_ID_D = "dr_c_d"; @@ -78,10 +77,10 @@ public class BulkDeleteUtilTest { private static final String COMPONENT_ID_F = "dr_c_f"; private static final String COMPONENT_ID_G = "dr_c_g"; private static final String COMPONENT_ID_H= "dr_c_h"; - + //Project IDs private static final String PROJECT_ID_A= "dr_p_a"; - + //Variables for tree data creation private int treeNodeCreateReleaseCounter; private int treeNodeMaxLink; @@ -91,7 +90,7 @@ public class BulkDeleteUtilTest { private DateFormat timeLogDateFormat = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss.SSS"); private BufferedWriter timeLogWriter = null; private long timeLogLastTime = 0; - + @Rule public final ExpectedException exception = ExpectedException.none(); @@ -109,7 +108,7 @@ public class BulkDeleteUtilTest { ReleaseModerator releaseModerator; @Mock ProjectModerator projectModerator; - + @Before public void setUp() throws Exception { assertTestString(dbName); @@ -129,18 +128,18 @@ public void setUp() throws Exception { // Prepare the database databaseConnector = new DatabaseConnectorCloudant(DatabaseSettingsTest.getConfiguredClient(), dbName); changeLogsDatabaseConnector = new DatabaseConnectorCloudant(DatabaseSettingsTest.getConfiguredClient(), changeLogsDbName); - + // Prepare vendors for (Vendor vendor : vendors.values()) { databaseConnector.add(vendor); } - + // Prepare the handler handler = new ComponentDatabaseHandler(DatabaseSettingsTest.getConfiguredClient(), dbName, changeLogsDbName, attachmentsDbName, moderator, releaseModerator, projectModerator); - + // Prepare the utility object bulkDeleteUtil = handler.getBulkDeleteUtil(); - + treeNodeCreateReleaseCounter = 0; } @@ -150,16 +149,16 @@ public void tearDown() throws Exception { TestUtils.deleteDatabase(DatabaseSettingsTest.getConfiguredClient(), dbName); TestUtils.deleteDatabase(DatabaseSettingsTest.getConfiguredClient(), changeLogsDbName); } - + @Test public void testGetAllLinkedReleaseMap() throws Exception { if (!isFeatureEnable()) { System.out.println("BulkReleaseDeletion is disabled. these test is Skipped."); return; } - + createTestRecords001(); - + Map outMap = new HashMap(); bulkDeleteUtil.getAllLinkedReleaseMap(RELEASE_ID_A1, outMap); @@ -170,19 +169,19 @@ public void testGetAllLinkedReleaseMap() throws Exception { assertTrue(outMap.containsKey(RELEASE_ID_D1)); assertTrue(outMap.containsKey(RELEASE_ID_F1)); } - + @Test public void testGetExternalLinkMap() throws Exception { createTestRecords002(); - + Map linkedReleaseMap = new HashMap(); Map outExternalFlagMap = new HashMap(); Map> outReferencingReleaseIdsMap = new HashMap>(); - + bulkDeleteUtil.getAllLinkedReleaseMap(RELEASE_ID_A1, linkedReleaseMap); assertEquals(7, linkedReleaseMap.size()); - + //Check ExternalFlagMap bulkDeleteUtil.getExternalLinkMap(linkedReleaseMap.keySet(), outExternalFlagMap, outReferencingReleaseIdsMap); assertEquals(7, outExternalFlagMap.size()); @@ -194,26 +193,26 @@ public void testGetExternalLinkMap() throws Exception { assertTrue(outExternalFlagMap.get(RELEASE_ID_G1)); assertTrue(outExternalFlagMap.get(RELEASE_ID_H1)); assertFalse(outExternalFlagMap.containsKey(RELEASE_ID_E1)); - + //Check ReferencingReleaseIdsMap assertEquals(7, outReferencingReleaseIdsMap.size()); - List referencingReleaseIdList = null; + List referencingReleaseIdList = null; referencingReleaseIdList = outReferencingReleaseIdsMap.get(RELEASE_ID_A1); assertEquals(0, referencingReleaseIdList.size()); - + referencingReleaseIdList = outReferencingReleaseIdsMap.get(RELEASE_ID_B1); assertEquals(1, referencingReleaseIdList.size()); assertTrue(referencingReleaseIdList.contains(RELEASE_ID_A1)); - + referencingReleaseIdList = outReferencingReleaseIdsMap.get(RELEASE_ID_C1); assertEquals(1, referencingReleaseIdList.size()); assertTrue(referencingReleaseIdList.contains(RELEASE_ID_A1)); - + referencingReleaseIdList = outReferencingReleaseIdsMap.get(RELEASE_ID_D1); assertEquals(2, referencingReleaseIdList.size()); - assertTrue(referencingReleaseIdList.contains(RELEASE_ID_A1)); + assertTrue(referencingReleaseIdList.contains(RELEASE_ID_A1)); assertTrue(referencingReleaseIdList.contains(RELEASE_ID_E1)); - + referencingReleaseIdList = outReferencingReleaseIdsMap.get(RELEASE_ID_F1); assertEquals(1, referencingReleaseIdList.size()); assertTrue(referencingReleaseIdList.contains(RELEASE_ID_B1)); @@ -235,9 +234,9 @@ public void testDeleteBulkRelease001() throws Exception { } createTestRecords001(); - + bulkDeleteUtil.setInspector(new BulkDeleteUtil.BulkDeleteUtilInspector() { - + @Override public void checkVariables(Map releaseMap, Map componentMap, Map externalLinkMap, Map> referencingReleaseIdsMap) {} @@ -245,11 +244,11 @@ public void checkVariables(Map releaseMap, Map releaseMap, Map componentMap, Map resultStateMap) {} - + @Override public void checkLeafReleaseIdsInLoop(int loopCount, Set leafReleaseIds) { switch(loopCount) { - case 0: + case 0: assertTrue(leafReleaseIds.contains(RELEASE_ID_D1)); assertTrue(leafReleaseIds.contains(RELEASE_ID_F1)); assertEquals(2, leafReleaseIds.size()); @@ -258,15 +257,15 @@ public void checkLeafReleaseIdsInLoop(int loopCount, Set leafReleaseIds) assertTrue(leafReleaseIds.contains(RELEASE_ID_C1)); assertTrue(leafReleaseIds.contains(RELEASE_ID_D1)); assertEquals(2, leafReleaseIds.size()); - break; + break; case 2: assertTrue(leafReleaseIds.contains(RELEASE_ID_B1)); assertEquals(1, leafReleaseIds.size()); - break; + break; case 3: assertTrue(leafReleaseIds.contains(RELEASE_ID_A1)); assertEquals(1, leafReleaseIds.size()); - break; + break; } } @@ -290,7 +289,7 @@ public void checkUpdatedReferencingReleaseListInLoop(int loopCount, List updat } } assertEquals(2, updatedComponentList.size()); - break; + break; case 2: for (Component component : updatedComponentList) { if (COMPONENT_ID_B.equals(component.getId())) { @@ -372,7 +371,7 @@ public void checkDeletedReleaseListInLoop(int loopCount, List deletedRe } } assertEquals(2, deletedReleaseList.size()); - break; + break; case 2: for (Release release : deletedReleaseList) { if (RELEASE_ID_B1.equals(release.getId())) { @@ -383,7 +382,7 @@ public void checkDeletedReleaseListInLoop(int loopCount, List deletedRe } } assertEquals(1, deletedReleaseList.size()); - break; + break; case 3: for (Release release : deletedReleaseList) { if (RELEASE_ID_A1.equals(release.getId())) { @@ -394,7 +393,7 @@ public void checkDeletedReleaseListInLoop(int loopCount, List deletedRe } } assertEquals(1, deletedReleaseList.size()); - break; + break; } } }); @@ -413,7 +412,7 @@ public void checkDeletedReleaseListInLoop(int loopCount, List deletedRe assertTrue(componentExists(COMPONENT_ID_D)); assertTrue(componentExists(COMPONENT_ID_E)); assertTrue(componentExists(COMPONENT_ID_F)); - + BulkOperationNode level1Component = bulkDeleteUtil.deleteBulkRelease(RELEASE_ID_A1, user1, false); assertFalse(releaseExists(RELEASE_ID_A1)); @@ -431,7 +430,7 @@ public void checkDeletedReleaseListInLoop(int loopCount, List deletedRe assertTrue(componentExists(COMPONENT_ID_E)); assertTrue(componentExists(COMPONENT_ID_F)); - //Check BulkOperationNodes + //Check BulkOperationNodes //Object[0] : NodeType, Object[1] : ResultState Map expectedResults = new HashMap(); expectedResults.put(RELEASE_ID_A1, new Object[]{BulkOperationNodeType.RELEASE, BulkOperationResultState.SUCCEEDED}); @@ -447,7 +446,7 @@ public void checkDeletedReleaseListInLoop(int loopCount, List deletedRe checkBulkOperationNode(level1Component, expectedResults); } - + private void checkBulkOperationNode(BulkOperationNode node, Map expectedResults ) { String message = String.format("checkBulkOperationNode node id=%s", node.id); Object [] expectedResult = expectedResults.get(node.getId()); @@ -464,37 +463,37 @@ public void testDeleteBulkRelease002() throws Exception { System.out.println("BulkReleaseDeletion is disabled. these test is Skipped."); return; } - + startTimeLog("testDeleteBulkRelease002.log"); try { addTimeLog("test data creation start."); - + List releaseIdList = new ArrayList(); List componentIdList = new ArrayList(); - + createTestRecords002(2, 2, releaseIdList, componentIdList); String rootReleaseId = releaseIdList.get(0); assertEquals(7, releaseIdList.size()); assertEquals(4, componentIdList.size()); - + List otherReleaseIdList = new ArrayList(); List otherComponentIdList = new ArrayList(); for (int i=0; i<10; i++) { - createTestRecords002(2, 2, otherReleaseIdList, otherComponentIdList); + createTestRecords002(2, 2, otherReleaseIdList, otherComponentIdList); } assertEquals(70, otherReleaseIdList.size()); assertEquals(40, otherComponentIdList.size()); - + addTimeLog("test data creation end."); addTimeLog("deleteBulkRelease start."); - + BulkOperationNode level1Component = bulkDeleteUtil.deleteBulkRelease(rootReleaseId, user1, false); assertNotNull(level1Component); - + addTimeLog("deleteBulkRelease end."); - + addTimeLog("check records start."); - + //Records to be deleted for (String releaseId : releaseIdList) { assertFalse(this.releaseExists(releaseId)); @@ -509,25 +508,25 @@ public void testDeleteBulkRelease002() throws Exception { for (String componentId : otherComponentIdList) { assertTrue(this.componentExists(componentId)); } - + addTimeLog("check records end."); - + } finally { stopTimeLog(); } } - + @Test public void testDeleteBulkRelease_ConflictError001() throws Exception { if (!isFeatureEnable()) { System.out.println("BulkReleaseDeletion is disabled. these test is Skipped."); return; } - + createTestRecords001(); - + bulkDeleteUtil.setInspector(new BulkDeleteUtil.BulkDeleteUtilInspector() { - + @Override public void checkVariables(Map releaseMap, Map componentMap, Map externalLinkMap, Map> referencingReleaseIdsMap) {} @@ -535,11 +534,11 @@ public void checkVariables(Map releaseMap, Map releaseMap, Map componentMap, Map resultStateMap) {} - + @Override public void checkLeafReleaseIdsInLoop(int loopCount, Set leafReleaseIds) { switch(loopCount) { - case 0: + case 0: assertTrue(leafReleaseIds.contains(RELEASE_ID_D1)); assertTrue(leafReleaseIds.contains(RELEASE_ID_F1)); assertEquals(2, leafReleaseIds.size()); @@ -548,16 +547,16 @@ public void checkLeafReleaseIdsInLoop(int loopCount, Set leafReleaseIds) assertTrue(leafReleaseIds.contains(RELEASE_ID_C1)); assertTrue(leafReleaseIds.contains(RELEASE_ID_D1)); assertEquals(2, leafReleaseIds.size()); - break; + break; case 2: assertTrue(leafReleaseIds.contains(RELEASE_ID_B1)); assertTrue(leafReleaseIds.contains(RELEASE_ID_C1)); assertEquals(2, leafReleaseIds.size()); - break; + break; case 3: assertTrue(leafReleaseIds.contains(RELEASE_ID_C1)); assertEquals(1, leafReleaseIds.size()); - break; + break; } } @@ -581,7 +580,7 @@ public void checkUpdatedReferencingReleaseListInLoop(int loopCount, List updat } } assertEquals(2, updatedComponentList.size()); - break; + break; case 2: for (Component component : updatedComponentList) { if (COMPONENT_ID_B.equals(component.getId())) { @@ -649,12 +648,12 @@ public void checkDeletedReleaseListInLoop(int loopCount, List deletedRe if (RELEASE_ID_C1.equals(release.getId())) { Map relationMap = release.getReleaseIdToRelationship(); assertTrue(CommonUtils.isNullOrEmptyMap(relationMap)); - + //couse RELEASE_ID_C1 confliction Release conflectedRelease = release.deepCopy(); conflectedRelease.addToLanguages("java"); databaseConnector.update(conflectedRelease); - + } else if (RELEASE_ID_D1.equals(release.getId())) { Map relationMap = release.getReleaseIdToRelationship(); assertTrue(CommonUtils.isNullOrEmptyMap(relationMap)); @@ -663,7 +662,7 @@ public void checkDeletedReleaseListInLoop(int loopCount, List deletedRe } } assertEquals(2, deletedReleaseList.size()); - break; + break; case 2: for (Release release : deletedReleaseList) { if (RELEASE_ID_B1.equals(release.getId())) { @@ -674,10 +673,10 @@ public void checkDeletedReleaseListInLoop(int loopCount, List deletedRe } } assertEquals(1, deletedReleaseList.size()); - break; + break; case 3: fail("unexpected call"); - break; + break; } } }); @@ -696,7 +695,7 @@ public void checkDeletedReleaseListInLoop(int loopCount, List deletedRe assertTrue(componentExists(COMPONENT_ID_D)); assertTrue(componentExists(COMPONENT_ID_E)); assertTrue(componentExists(COMPONENT_ID_F)); - + BulkOperationNode level1Component = bulkDeleteUtil.deleteBulkRelease(RELEASE_ID_A1, user1, false); assertTrue(releaseExists(RELEASE_ID_A1)); //Remained @@ -714,7 +713,7 @@ public void checkDeletedReleaseListInLoop(int loopCount, List deletedRe assertTrue(componentExists(COMPONENT_ID_E)); assertTrue(componentExists(COMPONENT_ID_F)); - //Check BulkOperationNodes + //Check BulkOperationNodes //Object[0] : NodeType, Object[1] : ResultState Map expectedResults = new HashMap(); expectedResults.put(RELEASE_ID_A1, new Object[]{BulkOperationNodeType.RELEASE, BulkOperationResultState.FAILED}); @@ -728,13 +727,13 @@ public void checkDeletedReleaseListInLoop(int loopCount, List deletedRe expectedResults.put(COMPONENT_ID_D, new Object[]{BulkOperationNodeType.COMPONENT, BulkOperationResultState.SUCCEEDED}); expectedResults.put(COMPONENT_ID_F, new Object[]{BulkOperationNodeType.COMPONENT, BulkOperationResultState.EXCLUDED}); checkBulkOperationNode(level1Component, expectedResults); - + //check links of remained releases Release a1= databaseConnector.get(Release.class, RELEASE_ID_A1); Map relationShip_a1 = a1.getReleaseIdToRelationship(); assertTrue(relationShip_a1.containsKey(RELEASE_ID_C1)); assertEquals(1, relationShip_a1.size()); - + Release c1= databaseConnector.get(Release.class, RELEASE_ID_C1); Map relationShip_c1 = c1.getReleaseIdToRelationship(); assertTrue(CommonUtils.isNullOrEmptyMap(relationShip_c1)); @@ -746,11 +745,11 @@ public void testDeleteBulkRelease_ConflictError002() throws Exception { System.out.println("BulkReleaseDeletion is disabled. these test is Skipped."); return; } - + createTestRecords001(); - + bulkDeleteUtil.setInspector(new BulkDeleteUtil.BulkDeleteUtilInspector() { - + @Override public void checkVariables(Map releaseMap, Map componentMap, Map externalLinkMap, Map> referencingReleaseIdsMap) {} @@ -758,11 +757,11 @@ public void checkVariables(Map releaseMap, Map releaseMap, Map componentMap, Map resultStateMap) {} - + @Override public void checkLeafReleaseIdsInLoop(int loopCount, Set leafReleaseIds) { switch(loopCount) { - case 0: + case 0: assertTrue(leafReleaseIds.contains(RELEASE_ID_D1)); assertTrue(leafReleaseIds.contains(RELEASE_ID_F1)); assertEquals(2, leafReleaseIds.size()); @@ -778,7 +777,7 @@ public void checkLeafReleaseIdsInLoop(int loopCount, Set leafReleaseIds) break; default: fail("unexpected call"); - break; + break; } } @@ -802,10 +801,10 @@ public void checkUpdatedReferencingReleaseListInLoop(int loopCount, List updat } else if (COMPONENT_ID_D.equals(component.getId())) { Set releaseIds = component.getReleaseIds(); assertEquals(0, releaseIds.size()); - + //couse COMPONENT_ID_D confliction Component conflectedComponent = component.deepCopy(); conflectedComponent.setDescription("new component"); @@ -834,7 +833,7 @@ public void checkUpdatedComponentListInLoop(int loopCount, List updat } } assertEquals(2, updatedComponentList.size()); - break; + break; default: fail("unexpected call"); break; @@ -857,10 +856,10 @@ public void checkDeletedReleaseListInLoop(int loopCount, List deletedRe } } assertEquals(1, deletedReleaseList.size()); - break; + break; default: fail("unexpected call"); - break; + break; } } }); @@ -879,7 +878,7 @@ public void checkDeletedReleaseListInLoop(int loopCount, List deletedRe assertTrue(componentExists(COMPONENT_ID_D)); assertTrue(componentExists(COMPONENT_ID_E)); assertTrue(componentExists(COMPONENT_ID_F)); - + BulkOperationNode level1Component = bulkDeleteUtil.deleteBulkRelease(RELEASE_ID_A1, user1, false); assertTrue(releaseExists(RELEASE_ID_A1)); @@ -897,7 +896,7 @@ public void checkDeletedReleaseListInLoop(int loopCount, List deletedRe assertTrue(componentExists(COMPONENT_ID_E)); assertTrue(componentExists(COMPONENT_ID_F)); - //Check BulkOperationNodes + //Check BulkOperationNodes //Object[0] : NodeType, Object[1] : ResultState Map expectedResults = new HashMap(); expectedResults.put(RELEASE_ID_A1, new Object[]{BulkOperationNodeType.RELEASE, BulkOperationResultState.FAILED}); @@ -911,7 +910,7 @@ public void checkDeletedReleaseListInLoop(int loopCount, List deletedRe expectedResults.put(COMPONENT_ID_D, new Object[]{BulkOperationNodeType.COMPONENT, BulkOperationResultState.EXCLUDED}); expectedResults.put(COMPONENT_ID_F, new Object[]{BulkOperationNodeType.COMPONENT, BulkOperationResultState.EXCLUDED}); checkBulkOperationNode(level1Component, expectedResults); - + //check links of remained releases Release a1= databaseConnector.get(Release.class, RELEASE_ID_A1); Map relationShip_a1 = a1.getReleaseIdToRelationship(); @@ -922,7 +921,7 @@ public void checkDeletedReleaseListInLoop(int loopCount, List deletedRe Map relationShip_b1 = b1.getReleaseIdToRelationship(); assertTrue(relationShip_b1.containsKey(RELEASE_ID_D1)); assertEquals(1, relationShip_b1.size()); - + Release d1= databaseConnector.get(Release.class, RELEASE_ID_D1); Map relationShip_d1 = d1.getReleaseIdToRelationship(); assertTrue(CommonUtils.isNullOrEmptyMap(relationShip_d1)); @@ -934,11 +933,11 @@ public void testDeleteBulkRelease_ConflictError003() throws Exception { System.out.println("BulkReleaseDeletion is disabled. these test is Skipped."); return; } - + createTestRecords001(); - + bulkDeleteUtil.setInspector(new BulkDeleteUtil.BulkDeleteUtilInspector() { - + @Override public void checkVariables(Map releaseMap, Map componentMap, Map externalLinkMap, Map> referencingReleaseIdsMap) {} @@ -946,11 +945,11 @@ public void checkVariables(Map releaseMap, Map releaseMap, Map componentMap, Map resultStateMap) {} - + @Override public void checkLeafReleaseIdsInLoop(int loopCount, Set leafReleaseIds) { switch(loopCount) { - case 0: + case 0: assertTrue(leafReleaseIds.contains(RELEASE_ID_D1)); assertTrue(leafReleaseIds.contains(RELEASE_ID_F1)); assertEquals(2, leafReleaseIds.size()); @@ -972,7 +971,7 @@ public void checkLeafReleaseIdsInLoop(int loopCount, Set leafReleaseIds) break; default: fail("unexpected call"); - break; + break; } } @@ -989,12 +988,12 @@ public void checkUpdatedReferencingReleaseListInLoop(int loopCount, List relationMap = release.getReleaseIdToRelationship(); assertEquals(1, relationMap.size()); assertTrue(relationMap.containsKey(RELEASE_ID_B1)); - + //couse RELEASE_ID_A1 confliction Release conflectedRelease = databaseConnector.get(Release.class, RELEASE_ID_A1); conflectedRelease.addToLanguages("java"); databaseConnector.update(conflectedRelease); - + } else if (RELEASE_ID_B1.equals(release.getId())) { Map relationMap = release.getReleaseIdToRelationship(); assertEquals(0, relationMap.size()); @@ -1002,7 +1001,7 @@ public void checkUpdatedReferencingReleaseListInLoop(int loopCount, List relationMap = release.getReleaseIdToRelationship(); assertEquals(1, relationMap.size()); assertTrue(relationMap.containsKey(RELEASE_ID_C1)); - + } else { fail(String.format("Unexpected release id=%s", release.getId())); } @@ -1018,7 +1017,7 @@ public void checkUpdatedReferencingReleaseListInLoop(int loopCount, List updat } } assertEquals(1, updatedComponentList.size()); - break; + break; case 2: assertEquals(0, updatedComponentList.size()); - break; + break; default: fail("unexpected call"); break; @@ -1070,7 +1069,7 @@ public void checkDeletedReleaseListInLoop(int loopCount, List deletedRe break; default: fail("unexpected call"); - break; + break; } } }); @@ -1089,7 +1088,7 @@ public void checkDeletedReleaseListInLoop(int loopCount, List deletedRe assertTrue(componentExists(COMPONENT_ID_D)); assertTrue(componentExists(COMPONENT_ID_E)); assertTrue(componentExists(COMPONENT_ID_F)); - + BulkOperationNode level1Component = bulkDeleteUtil.deleteBulkRelease(RELEASE_ID_A1, user1, false); assertTrue(releaseExists(RELEASE_ID_A1)); @@ -1107,7 +1106,7 @@ public void checkDeletedReleaseListInLoop(int loopCount, List deletedRe assertTrue(componentExists(COMPONENT_ID_E)); assertTrue(componentExists(COMPONENT_ID_F)); - //Check BulkOperationNodes + //Check BulkOperationNodes //Object[0] : NodeType, Object[1] : ResultState Map expectedResults = new HashMap(); expectedResults.put(RELEASE_ID_A1, new Object[]{BulkOperationNodeType.RELEASE, BulkOperationResultState.FAILED}); @@ -1121,84 +1120,84 @@ public void checkDeletedReleaseListInLoop(int loopCount, List deletedRe expectedResults.put(COMPONENT_ID_D, new Object[]{BulkOperationNodeType.COMPONENT, BulkOperationResultState.SUCCEEDED}); expectedResults.put(COMPONENT_ID_F, new Object[]{BulkOperationNodeType.COMPONENT, BulkOperationResultState.EXCLUDED}); checkBulkOperationNode(level1Component, expectedResults); - + //check links of remained releases Release a1= databaseConnector.get(Release.class, RELEASE_ID_A1); Map relationShip_a1 = a1.getReleaseIdToRelationship(); assertTrue(relationShip_a1.containsKey(RELEASE_ID_B1)); assertTrue(relationShip_a1.containsKey(RELEASE_ID_C1)); assertEquals(2, relationShip_a1.size()); - + Release b1= databaseConnector.get(Release.class, RELEASE_ID_B1); Map relationShip_b1 = b1.getReleaseIdToRelationship(); assertTrue(CommonUtils.isNullOrEmptyMap(relationShip_b1)); - + Release c1= databaseConnector.get(Release.class, RELEASE_ID_C1); Map relationShip_c1 = c1.getReleaseIdToRelationship(); assertTrue(CommonUtils.isNullOrEmptyMap(relationShip_c1)); } - + private void createTestRecords001() throws SW360Exception { - + List components = new ArrayList(); Component component_dr_A = new Component().setId(COMPONENT_ID_A).setName("DR_A").setDescription("DR Component A").setCreatedBy(USER_EMAIL1).setMainLicenseIds(new HashSet<>(Arrays.asList("lic1"))).setCreatedOn("2022-07-20"); component_dr_A.addToReleaseIds(RELEASE_ID_A1); component_dr_A.addToCategories(category); components.add(component_dr_A); - + Component component_dr_B = new Component().setId(COMPONENT_ID_B).setName("DR_B").setDescription("DR Component B").setCreatedBy(USER_EMAIL1).setMainLicenseIds(new HashSet<>(Arrays.asList("lic1"))).setCreatedOn("2022-07-20"); component_dr_B.addToReleaseIds(RELEASE_ID_B1); component_dr_B.addToCategories(category); components.add(component_dr_B); - + Component component_dr_C = new Component().setId(COMPONENT_ID_C).setName("DR_C").setDescription("DR Component C").setCreatedBy(USER_EMAIL1).setMainLicenseIds(new HashSet<>(Arrays.asList("lic1"))).setCreatedOn("2022-07-20"); component_dr_C.addToReleaseIds(RELEASE_ID_C1); component_dr_C.addToReleaseIds(RELEASE_ID_C2); component_dr_C.addToCategories(category); components.add(component_dr_C); - + Component component_dr_D = new Component().setId(COMPONENT_ID_D).setName("DR_D").setDescription("DR Component D").setCreatedBy(USER_EMAIL1).setMainLicenseIds(new HashSet<>(Arrays.asList("lic1"))).setCreatedOn("2022-07-20"); component_dr_D.addToReleaseIds(RELEASE_ID_D1); component_dr_D.addToCategories(category); components.add(component_dr_D); - + Component component_dr_E = new Component().setId(COMPONENT_ID_E).setName("DR_E").setDescription("DR Component E").setCreatedBy(USER_EMAIL1).setMainLicenseIds(new HashSet<>(Arrays.asList("lic1"))).setCreatedOn("2022-07-20"); component_dr_E.addToReleaseIds(RELEASE_ID_E1); component_dr_E.addToCategories(category); components.add(component_dr_E); - + Component component_dr_F = new Component().setId(COMPONENT_ID_F).setName("DR_F").setDescription("DR Component F").setCreatedBy(USER_EMAIL1).setMainLicenseIds(new HashSet<>(Arrays.asList("lic1"))).setCreatedOn("2022-07-20"); component_dr_F.addToReleaseIds(RELEASE_ID_F1); component_dr_F.addToCategories(category); components.add(component_dr_F); - + List releases = new ArrayList(); Release release_dr_A1 = new Release().setId(RELEASE_ID_A1).setComponentId(component_dr_A.getId()).setName(component_dr_A.getName()).setVersion("1.00").setCreatedBy(USER_EMAIL1).setVendorId("V1"); release_dr_A1.putToReleaseIdToRelationship(RELEASE_ID_B1, ReleaseRelationship.CONTAINED); release_dr_A1.putToReleaseIdToRelationship(RELEASE_ID_C1, ReleaseRelationship.CONTAINED); releases.add(release_dr_A1); - + Release release_dr_B1 = new Release().setId(RELEASE_ID_B1).setComponentId(component_dr_B.getId()).setName(component_dr_B.getName()).setVersion("1.00").setCreatedBy(USER_EMAIL1).setVendorId("V1"); release_dr_B1.putToReleaseIdToRelationship(RELEASE_ID_D1, ReleaseRelationship.CONTAINED); releases.add(release_dr_B1); - + Release release_dr_C1 = new Release().setId(RELEASE_ID_C1).setComponentId(component_dr_C.getId()).setName(component_dr_C.getName()).setVersion("1.00").setCreatedBy(USER_EMAIL1).setVendorId("V1"); release_dr_C1.putToReleaseIdToRelationship(RELEASE_ID_F1, ReleaseRelationship.CONTAINED); releases.add(release_dr_C1); Release release_dr_C2 = new Release().setId(RELEASE_ID_C2).setComponentId(component_dr_C.getId()).setName(component_dr_C.getName()).setVersion("2.00").setCreatedBy(USER_EMAIL1).setVendorId("V1"); releases.add(release_dr_C2); - + Release release_dr_D1 = new Release().setId(RELEASE_ID_D1).setComponentId(component_dr_D.getId()).setName(component_dr_D.getName()).setVersion("1.00").setCreatedBy(USER_EMAIL1).setVendorId("V1"); releases.add(release_dr_D1); - + Release release_dr_E1 = new Release().setId(RELEASE_ID_E1).setComponentId(component_dr_E.getId()).setName(component_dr_E.getName()).setVersion("1.00").setCreatedBy(USER_EMAIL1).setVendorId("V1"); release_dr_E1.putToReleaseIdToRelationship(RELEASE_ID_F1, ReleaseRelationship.CONTAINED); releases.add(release_dr_E1); - + Release release_dr_F1 = new Release().setId(RELEASE_ID_F1).setComponentId(component_dr_F.getId()).setName(component_dr_F.getName()).setVersion("1.00").setCreatedBy(USER_EMAIL1).setVendorId("V1"); releases.add(release_dr_F1); - + for (Component component : components) { databaseConnector.add(component); } @@ -1206,36 +1205,36 @@ private void createTestRecords001() throws SW360Exception { databaseConnector.add(release); } } - + private void createTestRecords002() throws SW360Exception { - + List components = new ArrayList(); Component component_dr_A = new Component().setId(COMPONENT_ID_A).setName("DR_A").setDescription("DR Component A").setCreatedBy(USER_EMAIL1).setMainLicenseIds(new HashSet<>(Arrays.asList("lic1"))).setCreatedOn("2022-07-20"); component_dr_A.addToReleaseIds(RELEASE_ID_A1); component_dr_A.addToCategories(category); components.add(component_dr_A); - + Component component_dr_B = new Component().setId(COMPONENT_ID_B).setName("DR_B").setDescription("DR Component B").setCreatedBy(USER_EMAIL1).setMainLicenseIds(new HashSet<>(Arrays.asList("lic1"))).setCreatedOn("2022-07-20"); component_dr_B.addToReleaseIds(RELEASE_ID_B1); component_dr_B.addToCategories(category); components.add(component_dr_B); - + Component component_dr_C = new Component().setId(COMPONENT_ID_C).setName("DR_C").setDescription("DR Component C").setCreatedBy(USER_EMAIL1).setMainLicenseIds(new HashSet<>(Arrays.asList("lic1"))).setCreatedOn("2022-07-20"); component_dr_C.addToReleaseIds(RELEASE_ID_C1); component_dr_C.addToCategories(category); components.add(component_dr_C); - + Component component_dr_D = new Component().setId(COMPONENT_ID_D).setName("DR_D").setDescription("DR Component D").setCreatedBy(USER_EMAIL1).setMainLicenseIds(new HashSet<>(Arrays.asList("lic1"))).setCreatedOn("2022-07-20"); component_dr_D.addToReleaseIds(RELEASE_ID_D1); component_dr_D.addToCategories(category); components.add(component_dr_D); - + Component component_dr_E = new Component().setId(COMPONENT_ID_E).setName("DR_E").setDescription("DR Component E").setCreatedBy(USER_EMAIL1).setMainLicenseIds(new HashSet<>(Arrays.asList("lic1"))).setCreatedOn("2022-07-20"); component_dr_E.addToReleaseIds(RELEASE_ID_E1); component_dr_E.addToCategories(category); components.add(component_dr_E); - + Component component_dr_F = new Component().setId(COMPONENT_ID_F).setName("DR_F").setDescription("DR Component F").setCreatedBy(USER_EMAIL1).setMainLicenseIds(new HashSet<>(Arrays.asList("lic1"))).setCreatedOn("2022-07-20"); component_dr_F.addToReleaseIds(RELEASE_ID_F1); component_dr_F.addToCategories(category); @@ -1251,18 +1250,18 @@ private void createTestRecords002() throws SW360Exception { component_dr_H.addToCategories(category); components.add(component_dr_H); - + List releases = new ArrayList(); Release release_dr_A1 = new Release().setId(RELEASE_ID_A1).setComponentId(component_dr_A.getId()).setName(component_dr_A.getName()).setVersion("1.00").setCreatedBy(USER_EMAIL1).setVendorId("V1"); release_dr_A1.putToReleaseIdToRelationship(RELEASE_ID_B1, ReleaseRelationship.CONTAINED); release_dr_A1.putToReleaseIdToRelationship(RELEASE_ID_C1, ReleaseRelationship.CONTAINED); release_dr_A1.putToReleaseIdToRelationship(RELEASE_ID_D1, ReleaseRelationship.CONTAINED); releases.add(release_dr_A1); - + Release release_dr_B1 = new Release().setId(RELEASE_ID_B1).setComponentId(component_dr_B.getId()).setName(component_dr_B.getName()).setVersion("1.00").setCreatedBy(USER_EMAIL1).setVendorId("V1"); release_dr_B1.putToReleaseIdToRelationship(RELEASE_ID_F1, ReleaseRelationship.CONTAINED); releases.add(release_dr_B1); - + Release release_dr_C1 = new Release().setId(RELEASE_ID_C1).setComponentId(component_dr_C.getId()).setName(component_dr_C.getName()).setVersion("1.00").setCreatedBy(USER_EMAIL1).setVendorId("V1"); release_dr_C1.putToReleaseIdToRelationship(RELEASE_ID_G1, ReleaseRelationship.CONTAINED); releases.add(release_dr_C1); @@ -1270,25 +1269,25 @@ private void createTestRecords002() throws SW360Exception { Release release_dr_D1 = new Release().setId(RELEASE_ID_D1).setComponentId(component_dr_D.getId()).setName(component_dr_D.getName()).setVersion("1.00").setCreatedBy(USER_EMAIL1).setVendorId("V1"); release_dr_D1.putToReleaseIdToRelationship(RELEASE_ID_H1, ReleaseRelationship.CONTAINED); releases.add(release_dr_D1); - + Release release_dr_E1 = new Release().setId(RELEASE_ID_E1).setComponentId(component_dr_E.getId()).setName(component_dr_E.getName()).setVersion("1.00").setCreatedBy(USER_EMAIL1).setVendorId("V1"); release_dr_E1.putToReleaseIdToRelationship(RELEASE_ID_D1, ReleaseRelationship.CONTAINED); releases.add(release_dr_E1); - + Release release_dr_F1 = new Release().setId(RELEASE_ID_F1).setComponentId(component_dr_F.getId()).setName(component_dr_F.getName()).setVersion("1.00").setCreatedBy(USER_EMAIL1).setVendorId("V1"); releases.add(release_dr_F1); - + Release release_dr_G1 = new Release().setId(RELEASE_ID_G1).setComponentId(component_dr_G.getId()).setName(component_dr_G.getName()).setVersion("1.00").setCreatedBy(USER_EMAIL1).setVendorId("V1"); releases.add(release_dr_G1); Release release_dr_H1 = new Release().setId(RELEASE_ID_H1).setComponentId(component_dr_H.getId()).setName(component_dr_H.getName()).setVersion("1.00").setCreatedBy(USER_EMAIL1).setVendorId("V1"); releases.add(release_dr_H1); - + Listprojects = new ArrayList(); Project project_A = new Project().setId(PROJECT_ID_A).setName("PROJECT_A").setVisbility(Visibility.EVERYONE); project_A.putToReleaseIdToUsage(RELEASE_ID_C1, new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.OPEN)); projects.add(project_A); - + for (Component component : components) { databaseConnector.add(component); } @@ -1312,17 +1311,17 @@ private void createTestRecords002(int maxLink, int depth, List releaseId rootComponent.addToCategories(category); databaseConnector.add(rootComponent); componentIdList.add(componentId); - + Release rootRelease = new Release().setId(releaseId).setComponentId(componentId).setName(releaseId).setVersion(version).setCreatedBy(USER_EMAIL1).setVendorId("V1"); databaseConnector.add(rootRelease); releaseIdList.add(releaseId); - + //create tree nodes treeNodeMaxLink = maxLink; treeNodeDepth = depth; createReleaseTree(releaseId, 0, releaseIdList, componentIdList); } - + private void createReleaseTree(String parentId, int level, List outReleaseIdList, List< String> outComponentIdList) throws SW360Exception { //create a compoent String componentId = String.format("dr_%08x", treeNodeCreateReleaseCounter); @@ -1332,7 +1331,7 @@ private void createReleaseTree(String parentId, int level, List outRelea databaseConnector.add(component); assertFalse(outComponentIdList.contains(componentId)); outComponentIdList.add(componentId); - + //create releases for (int i = 0; i < treeNodeMaxLink; i++) { //add release @@ -1342,12 +1341,12 @@ private void createReleaseTree(String parentId, int level, List outRelea databaseConnector.add(release); assertFalse(outReleaseIdList.contains(releaseId)); outReleaseIdList.add(releaseId); - + //update compoennt Component updatedComponent = databaseConnector.get(Component.class, componentId); updatedComponent.addToReleaseIds(releaseId); databaseConnector.update(updatedComponent); - + //update parent release if (parentId != null) { Release parentRelease = databaseConnector.get(Release.class, parentId); @@ -1355,7 +1354,7 @@ private void createReleaseTree(String parentId, int level, List outRelea parentRelease.putToReleaseIdToRelationship(releaseId, ReleaseRelationship.CONTAINED); databaseConnector.update(parentRelease); } - + //create child releases if (level + 1 < treeNodeDepth) { createReleaseTree(releaseId, level + 1, outReleaseIdList, outComponentIdList); @@ -1372,17 +1371,17 @@ private boolean componentExists(String componentId) throws SW360Exception { Component component = databaseConnector.get(Component.class, componentId); return component != null; } - + private boolean isFeatureEnable() { - if (!BackendUtils.IS_BULK_RELEASE_DELETING_ENABLED) { + if (!SW360Constants.IS_BULK_RELEASE_DELETING_ENABLED) { return false; } - if (!PermissionUtils.IS_ADMIN_PRIVATE_ACCESS_ENABLED) { + if (!SW360Constants.IS_ADMIN_PRIVATE_ACCESS_ENABLED) { return false; } return true; } - + public boolean startTimeLog(String filePath) { try { timeLogWriter = new BufferedWriter(new FileWriter(filePath)); diff --git a/backend/components/src/test/java/org/eclipse/sw360/components/db/ComponentDatabaseHandlerTest.java b/backend/components/src/test/java/org/eclipse/sw360/components/db/ComponentDatabaseHandlerTest.java index 5920c59018..ae095e6234 100644 --- a/backend/components/src/test/java/org/eclipse/sw360/components/db/ComponentDatabaseHandlerTest.java +++ b/backend/components/src/test/java/org/eclipse/sw360/components/db/ComponentDatabaseHandlerTest.java @@ -13,7 +13,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import org.eclipse.sw360.common.utils.BackendUtils; import org.eclipse.sw360.datahandler.TestUtils; import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant; import org.eclipse.sw360.datahandler.common.SW360Constants; @@ -858,7 +857,7 @@ public void testUpdateComponentSentToModeration() throws Exception { @Test public void testForceUpdateComponent() throws Exception { - if (!BackendUtils.IS_FORCE_UPDATE_ENABLED) { + if (!SW360Constants.IS_FORCE_UPDATE_ENABLED) { return; } // Make some changes in the component @@ -876,7 +875,7 @@ public void testForceUpdateComponent() throws Exception { assertEquals(expected, actual.getName()); verify(moderator, never()).updateComponent(component, user2); } - + @Test public void testUpdateRelease() throws Exception { Release expected = releases.get(1); @@ -928,7 +927,7 @@ public void testUpdateSentToModeration() throws Exception { @Test public void testForceUpdateRelease() throws Exception { - if (!BackendUtils.IS_FORCE_UPDATE_ENABLED) { + if (!SW360Constants.IS_FORCE_UPDATE_ENABLED) { return; } Release release = releases.get(1); @@ -943,7 +942,7 @@ public void testForceUpdateRelease() throws Exception { assertEquals(expected, actual.getName()); verify(releaseModerator, never()).updateRelease(release, user1); } - + @Test public void testEccUpdateSentToEccModeration() throws Exception { Release release = releases.get(1); @@ -961,7 +960,7 @@ public void testEccUpdateSentToEccModeration() throws Exception { @Test public void testForceEccUpdate() throws Exception { - if (!BackendUtils.IS_FORCE_UPDATE_ENABLED) { + if (!SW360Constants.IS_FORCE_UPDATE_ENABLED) { return; } Release release = releases.get(1); @@ -976,7 +975,7 @@ public void testForceEccUpdate() throws Exception { assertEquals(expected, actual.getEccInformation().getAl()); verify(releaseModerator, never()).updateReleaseEccInfo(release, user1); } - + @Test public void testDeleteComponent() throws Exception { RequestStatus status = handler.deleteComponent("C3", user1); @@ -999,7 +998,7 @@ public void testDeleteComponentNotModerator() throws Exception { @Test public void testForceDeleteComponent() throws Exception { - if (!BackendUtils.IS_FORCE_UPDATE_ENABLED) { + if (!SW360Constants.IS_FORCE_UPDATE_ENABLED) { return; } lenient().when(moderator.deleteComponent(any(Component.class), eq(user2))).thenReturn(RequestStatus.SENT_TO_MODERATOR); @@ -1010,7 +1009,7 @@ public void testForceDeleteComponent() throws Exception { assertFalse("Component deleted", componentsContain(componentSummary, "C3")); verify(moderator, never()).deleteComponent(any(Component.class), eq(user2)); } - + @Test public void testDontDeleteUsedComponent() throws Exception { final Release r1A = handler.getRelease("R1A", user1); @@ -1067,7 +1066,7 @@ public void testDeleteReleaseNotModerator() throws Exception { @Test public void testForceDeleteRelease() throws Exception { - if (!BackendUtils.IS_FORCE_UPDATE_ENABLED) { + if (!SW360Constants.IS_FORCE_UPDATE_ENABLED) { return; } lenient().when(releaseModerator.deleteRelease(any(Release.class), eq(user1))).thenReturn(RequestStatus.SENT_TO_MODERATOR); @@ -1078,7 +1077,7 @@ public void testForceDeleteRelease() throws Exception { assertFalse("Release deleted", releasesContain(releaseSummary, "R1B")); verify(releaseModerator, never()).deleteRelease(any(Release.class), eq(user1)); } - + private static boolean componentsContain(Collection components, @NotNull String id) { for (Component component : components) { if (id.equals(component.getId())) diff --git a/backend/components/src/test/java/org/eclipse/sw360/components/db/ComponentSearchHandlerTest.java b/backend/components/src/test/java/org/eclipse/sw360/components/db/ComponentSearchHandlerTest.java index 5db44dbe5c..e1925328db 100644 --- a/backend/components/src/test/java/org/eclipse/sw360/components/db/ComponentSearchHandlerTest.java +++ b/backend/components/src/test/java/org/eclipse/sw360/components/db/ComponentSearchHandlerTest.java @@ -14,8 +14,8 @@ import org.eclipse.sw360.datahandler.TestUtils; import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant; import org.eclipse.sw360.datahandler.common.DatabaseSettingsTest; +import org.eclipse.sw360.datahandler.common.ThriftConstants; import org.eclipse.sw360.datahandler.db.ComponentSearchHandler; -import org.eclipse.sw360.datahandler.thrift.ThriftClients; import org.eclipse.sw360.datahandler.thrift.components.Component; import org.junit.After; import org.junit.Before; @@ -44,7 +44,7 @@ public class ComponentSearchHandlerTest { @Before public void setUp() throws Exception { - assumeCanConnectTo(ThriftClients.BACKEND_URL + "/couchdblucene/"); + assumeCanConnectTo(ThriftConstants.BACKEND_URL + "/couchdblucene/"); components = new ArrayList<>(); Component component1 = new Component().setId("C1").setName("component1").setDescription("d1").setCreatedBy(email1); diff --git a/backend/cvesearch/src/main/java/org/eclipse/sw360/cvesearch/datasource/heuristics/SearchLevels.java b/backend/cvesearch/src/main/java/org/eclipse/sw360/cvesearch/datasource/heuristics/SearchLevels.java index 15d98de6f0..e2127c0807 100644 --- a/backend/cvesearch/src/main/java/org/eclipse/sw360/cvesearch/datasource/heuristics/SearchLevels.java +++ b/backend/cvesearch/src/main/java/org/eclipse/sw360/cvesearch/datasource/heuristics/SearchLevels.java @@ -16,14 +16,12 @@ import org.eclipse.sw360.cvesearch.datasource.CveSearchApi; import org.eclipse.sw360.cvesearch.datasource.CveSearchGuesser; import org.eclipse.sw360.cvesearch.datasource.matcher.Match; -import org.eclipse.sw360.datahandler.common.CommonUtils; import org.eclipse.sw360.datahandler.thrift.components.Release; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Properties; import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -31,6 +29,9 @@ import static java.util.Collections.singletonList; import static org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString; +import static org.eclipse.sw360.datahandler.common.SW360Constants.CVE_CUTOFF; +import static org.eclipse.sw360.datahandler.common.SW360Constants.CVE_PRODUCT_THRESHOLD; +import static org.eclipse.sw360.datahandler.common.SW360Constants.CVE_VENDOR_THRESHOLD; public class SearchLevels { @@ -41,15 +42,6 @@ public class SearchLevels { private static final String CPE_WILDCARD = ".*"; private static final String CPE_NEEDLE_PREFIX = CPE_PREFIX + ".:"; - private static final String PROPERTIES_FILE_PATH = "/sw360.properties"; - private static final String VENDOR_THRESHOLD_PROPERTY = "cvesearch.vendor.threshold"; - private static final String PRODUCT_THRESHOLD_PROPERTY = "cvesearch.product.threshold"; - private static final String CUTOFF_PROPERTY = "cvesearch.cutoff"; - - private static final int DEFAULT_VENDOR_THRESHOLD = 1; - private static final int DEFAULT_PRODUCT_THRESHOLD = 0; - private static final int DEFAULT_CUTOFF = 6; - private final List searchLevels = new ArrayList<>(); public class NeedleWithMeta { @@ -69,18 +61,8 @@ public interface SearchLevel { public SearchLevels(CveSearchApi cveSearchApi) { log.info("Preparing Search Levels"); - Properties props = CommonUtils.loadProperties(SearchLevels.class, PROPERTIES_FILE_PATH); - int vendorThreshold = getIntFromProperties(props, VENDOR_THRESHOLD_PROPERTY, DEFAULT_VENDOR_THRESHOLD); - int productThreshold = getIntFromProperties(props, PRODUCT_THRESHOLD_PROPERTY, DEFAULT_PRODUCT_THRESHOLD); - int cutoff = getIntFromProperties(props, CUTOFF_PROPERTY, DEFAULT_CUTOFF); - - setup(cveSearchApi, vendorThreshold, productThreshold, cutoff); - } - private static int getIntFromProperties(Properties properties, String key, int defaultValue) { - int value = CommonUtils.getIntOrDefault(properties.getProperty(key), defaultValue); - log.info("SearchLevels " + key + ": " + value); - return value; + setup(cveSearchApi, CVE_VENDOR_THRESHOLD, CVE_PRODUCT_THRESHOLD, CVE_CUTOFF); } private void setup(CveSearchApi cveSearchApi, int vendorThreshold, int productThreshold, int cutoff) { diff --git a/backend/cvesearch/src/main/resources/cvesearch.properties b/backend/cvesearch/src/main/resources/cvesearch.properties deleted file mode 100644 index cd36bc1d13..0000000000 --- a/backend/cvesearch/src/main/resources/cvesearch.properties +++ /dev/null @@ -1,11 +0,0 @@ -# -# Copyright (c) Bosch Software Innovations GmbH 2016. -# -# This program and the accompanying materials are made -# available under the terms of the Eclipse Public License 2.0 -# which is available at https://www.eclipse.org/legal/epl-2.0/ -# -# SPDX-License-Identifier: EPL-2.0 - -cvesearch.host=https://cve.circl.lu - diff --git a/backend/cvesearch/src/main/resources/sw360.properties b/backend/cvesearch/src/main/resources/sw360.properties deleted file mode 100644 index 97e8f8ab8f..0000000000 --- a/backend/cvesearch/src/main/resources/sw360.properties +++ /dev/null @@ -1,12 +0,0 @@ -# -# Copyright (c) Bosch Software Innovations GmbH 2016. -# -# This program and the accompanying materials are made -# available under the terms of the Eclipse Public License 2.0 -# which is available at https://www.eclipse.org/legal/epl-2.0/ -# -# SPDX-License-Identifier: EPL-2.0 - -cvesearch.default.vendor.threshold=1 -cvesearch.default.product.threshold=0 -cvesearch.default.cutoff=6 diff --git a/backend/fossology/src/main/java/org/eclipse/sw360/fossology/FossologyHandler.java b/backend/fossology/src/main/java/org/eclipse/sw360/fossology/FossologyHandler.java index 0fa7b984a1..6c109ef78e 100644 --- a/backend/fossology/src/main/java/org/eclipse/sw360/fossology/FossologyHandler.java +++ b/backend/fossology/src/main/java/org/eclipse/sw360/fossology/FossologyHandler.java @@ -9,9 +9,9 @@ */ package org.eclipse.sw360.fossology; -import org.eclipse.sw360.common.utils.BackendUtils; import org.eclipse.sw360.datahandler.common.CommonUtils; import org.eclipse.sw360.datahandler.common.FossologyUtils; +import org.eclipse.sw360.datahandler.common.SW360Constants; import org.eclipse.sw360.datahandler.common.SW360Utils; import org.eclipse.sw360.datahandler.couchdb.AttachmentConnector; import org.eclipse.sw360.datahandler.thrift.ConfigContainer; @@ -159,12 +159,12 @@ public ExternalToolProcess process(String releaseId, User user, String uploadDes FossologyUtils.ensureOrderOfProcessSteps(fossologyProcess); - ExternalToolProcessStep furthestStep = fossologyProcess.getProcessSteps().get(fossologyProcess.getProcessSteps().size() - 1); + ExternalToolProcessStep furthestStep = fossologyProcess.getProcessSteps().get(fossologyProcess.getProcessSteps().size() - 1); if (FossologyUtils.FOSSOLOGY_STEP_NAME_UPLOAD.equals(furthestStep.getStepName())) { handleUploadStep(componentClient, release, user, fossologyProcess, sourceAttachment, uploadDescription); } else if (FossologyUtils.FOSSOLOGY_STEP_NAME_SCAN.equals(furthestStep.getStepName())) { handleScanStep(componentClient, release, user, fossologyProcess); - } else if(!BackendUtils.DISABLE_CLEARING_FOSSOLOGY_REPORT_DOWNLOAD && FossologyUtils.FOSSOLOGY_STEP_NAME_REPORT.equals(furthestStep.getStepName())) { + } else if(!SW360Constants.DISABLE_CLEARING_FOSSOLOGY_REPORT_DOWNLOAD && FossologyUtils.FOSSOLOGY_STEP_NAME_REPORT.equals(furthestStep.getStepName())) { handleReportStep(componentClient, release, user, fossologyProcess); } else if(reportStep && FossologyUtils.FOSSOLOGY_STEP_NAME_REPORT.equals(furthestStep.getStepName())) { handleReportStep(componentClient, release, user, fossologyProcess); @@ -397,7 +397,7 @@ private void handleScanStep(Iface componentClient, Release release, User user, break; case DONE: // start report - if(!BackendUtils.DISABLE_CLEARING_FOSSOLOGY_REPORT_DOWNLOAD) { + if(!SW360Constants.DISABLE_CLEARING_FOSSOLOGY_REPORT_DOWNLOAD) { fossologyProcess.addToProcessSteps(createFossologyProcessStep(user, FossologyUtils.FOSSOLOGY_STEP_NAME_REPORT)); handleReportStep(componentClient, release, user, fossologyProcess); } @@ -505,7 +505,7 @@ public RequestStatus triggerReportGenerationFossology(String releaseId, User use if (extToolProcess.getProcessSteps().size() > 2) { extToolProcess.getProcessSteps().get(extToolProcess.getProcessSteps().size() - 1) .setStepStatus(ExternalToolProcessStatus.NEW); - } else if (extToolProcess.getProcessSteps().size() == 2 && BackendUtils.DISABLE_CLEARING_FOSSOLOGY_REPORT_DOWNLOAD) { + } else if (extToolProcess.getProcessSteps().size() == 2 && SW360Constants.DISABLE_CLEARING_FOSSOLOGY_REPORT_DOWNLOAD) { extToolProcess.addToProcessSteps(createFossologyProcessStep(user, FossologyUtils.FOSSOLOGY_STEP_NAME_REPORT)); reportStep = true; } else { diff --git a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/DocxGenerator.java b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/DocxGenerator.java index 6a9bd149e9..d3b2dec8a5 100644 --- a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/DocxGenerator.java +++ b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/DocxGenerator.java @@ -55,6 +55,7 @@ import java.util.stream.Collectors; import static org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString; +import static org.eclipse.sw360.datahandler.common.SW360Constants.FRIENDLY_RELEASE_URL; import static org.eclipse.sw360.datahandler.common.WrappedException.wrapTException; import static org.eclipse.sw360.licenseinfo.outputGenerators.DocxUtils.*; @@ -90,13 +91,9 @@ public class DocxGenerator extends OutputGenerator { private static final String EXT_ID_TABLE_HEADER_COL1 = "Identifier Name"; private static final String EXT_ID_TABLE_HEADER_COL2 = "Identifier Value"; - public static final String PROPERTIES_FILE_PATH = "/sw360.properties"; - public static String FRIENDLY_RELEASE_URL; public DocxGenerator(OutputFormatVariant outputFormatVariant, String description) { super(DOCX_OUTPUT_TYPE, description, true, DOCX_MIME_TYPE, outputFormatVariant); - Properties props = CommonUtils.loadProperties(DocxGenerator.class, PROPERTIES_FILE_PATH); - FRIENDLY_RELEASE_URL = props.getProperty("release.friendly.url", ""); } @Override diff --git a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/JsonGenerator.java b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/JsonGenerator.java index abf0bde184..436973e253 100644 --- a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/JsonGenerator.java +++ b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/JsonGenerator.java @@ -11,9 +11,7 @@ import java.util.Collection; import java.util.Map; -import java.util.Properties; -import org.eclipse.sw360.datahandler.common.CommonUtils; import org.eclipse.sw360.datahandler.thrift.SW360Exception; import org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult; import org.eclipse.sw360.datahandler.thrift.licenseinfo.ObligationParsingResult; @@ -29,11 +27,8 @@ public class JsonGenerator extends OutputGenerator { private static final String JSON_MIME_TYPE = "application/json"; private static final String JSON_OUTPUT_TYPE = "json"; - public static final String PROPERTIES_FILE_PATH = "/sw360.properties"; - public JsonGenerator(OutputFormatVariant outputFormatVariant, String description) { super(JSON_OUTPUT_TYPE, description, true, JSON_MIME_TYPE, outputFormatVariant); - Properties props = CommonUtils.loadProperties(JsonGenerator.class, PROPERTIES_FILE_PATH); } @Override diff --git a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/parsers/CombinedCLIParser.java b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/parsers/CombinedCLIParser.java index c62690c092..2ede65e546 100644 --- a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/parsers/CombinedCLIParser.java +++ b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/parsers/CombinedCLIParser.java @@ -14,7 +14,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.thrift.TException; -import org.eclipse.sw360.datahandler.common.CommonUtils; import org.eclipse.sw360.datahandler.common.SW360Utils; import org.eclipse.sw360.datahandler.couchdb.AttachmentConnector; import org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler; @@ -42,6 +41,7 @@ import static com.google.common.base.Strings.isNullOrEmpty; import static org.eclipse.sw360.datahandler.common.CommonUtils.closeQuietly; +import static org.eclipse.sw360.datahandler.common.SW360Constants.CLI_RELEASE_EXTERNAL_ID_CORRELATION_KEY; /** * Class for extracting copyright and license information from a simple XML file @@ -57,9 +57,6 @@ public class CombinedCLIParser extends AbstractCLIParser{ private static final String COMBINED_CLI_ROOT_ELEMENT_NAME = "CombinedCLI"; private static final String COMBINED_CLI_ROOT_ELEMENT_NAMESPACE = null; - private static final String PROPERTIES_FILE_PATH = "/sw360.properties"; - public static final String EXTERNAL_ID_CORRELATION_KEY = "combined.cli.parser.external.id.correlation.key"; - private ComponentDatabaseHandler componentDatabaseHandler; public CombinedCLIParser(AttachmentConnector attachmentConnector, AttachmentContentProvider attachmentContentProvider, ComponentDatabaseHandler componentDatabaseHandler) { @@ -68,8 +65,7 @@ public CombinedCLIParser(AttachmentConnector attachmentConnector, AttachmentCont } String getCorrelationKey(){ - Properties props = CommonUtils.loadProperties(CombinedCLIParser.class, PROPERTIES_FILE_PATH); - String releaseExternalIdCorrelationKey = props.getProperty(EXTERNAL_ID_CORRELATION_KEY); + String releaseExternalIdCorrelationKey = CLI_RELEASE_EXTERNAL_ID_CORRELATION_KEY; if (isNullOrEmpty(releaseExternalIdCorrelationKey)){ log.warn("Property combined.cli.parser.external.id.correlation.key is not set. Combined CLI parsing will not be able to load names of referenced releases"); } diff --git a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/parsers/SPDXParserTools.java b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/parsers/SPDXParserTools.java index a38e5e34bd..91457d67d2 100644 --- a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/parsers/SPDXParserTools.java +++ b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/parsers/SPDXParserTools.java @@ -13,7 +13,7 @@ import com.google.common.collect.Sets; -import org.eclipse.sw360.datahandler.common.CommonUtils; +import org.eclipse.sw360.datahandler.common.SW360Constants; import org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent; import org.eclipse.sw360.datahandler.thrift.licenseinfo.*; import org.apache.jena.util.XMLChar; @@ -38,10 +38,6 @@ import static org.eclipse.sw360.datahandler.common.CommonUtils.isNullEmptyOrWhitespace; public class SPDXParserTools { - private static final String PROPERTIES_FILE_PATH = "/sw360.properties"; - private static final String PROPERTY_KEY_USE_LICENSE_INFO_FROM_FILES = "licenseinfo.spdxparser.use-license-info-from-files"; - private static final boolean USE_LICENSE_INFO_FROM_FILES; - private static final String XML_LITERAL = "^^http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral"; private static final String LICENSE_REF_PREFIX = "LicenseRef-"; private static final String RELATIONSHIP_TYPE_DESCRIBES = "relationshipType_describes"; @@ -90,12 +86,6 @@ public class SPDXParserTools { // Store spdx:referencesFile index by their nodeID private static HashMap nodeIDFileMap = new HashMap(); - static { - Properties properties = CommonUtils.loadProperties(SPDXParserTools.class, PROPERTIES_FILE_PATH); - USE_LICENSE_INFO_FROM_FILES = Boolean - .valueOf(properties.getOrDefault(PROPERTY_KEY_USE_LICENSE_INFO_FROM_FILES, "true").toString()); - } - // Make NodeList be iterable private static Iterable iterable(final NodeList nodeList) { return () -> new Iterator() { @@ -676,7 +666,7 @@ protected static LicenseInfoParsingResult getLicenseInfoFromSpdx(AttachmentConte for (Node spdxItem : getDocumentDescribes(doc)) { licenseInfo.getLicenseNamesWithTexts() - .addAll(getAllLicenseTexts(spdxItem, USE_LICENSE_INFO_FROM_FILES, includeConcludedLicense)); + .addAll(getAllLicenseTexts(spdxItem, SW360Constants.SPDX_USE_LICENSE_INFO_FROM_FILES, includeConcludedLicense)); licenseInfo.getCopyrights().addAll(getAllCopyrights(spdxItem).collect(Collectors.toSet())); if (getNodeName(spdxItem).equals(SPDX_PACKAGE)) { concludedLicenseIds.addAll(getAllConcludedLicenseIds(getLicenseConcluded(spdxItem))); diff --git a/backend/licenseinfo/src/main/resources/sw360.properties b/backend/licenseinfo/src/main/resources/sw360.properties deleted file mode 100644 index cadff481f1..0000000000 --- a/backend/licenseinfo/src/main/resources/sw360.properties +++ /dev/null @@ -1,13 +0,0 @@ -# -# Copyright Siemens AG, 2013-2015. Part of the SW360 Portal Project. -# -# This program and the accompanying materials are made -# available under the terms of the Eclipse Public License 2.0 -# which is available at https://www.eclipse.org/legal/epl-2.0/ -# -# SPDX-License-Identifier: EPL-2.0 -# - -# This is a friendly url to generate Report with Release hyperlink. -# Replace protocol, hostname and port according to setup. -release.friendly.url=http://localhost:8080/group/guest/components/-/component/release/detailRelease/releaseId \ No newline at end of file diff --git a/backend/schedule/src/main/java/org/eclipse/sw360/schedule/service/ScheduleHandler.java b/backend/schedule/src/main/java/org/eclipse/sw360/schedule/service/ScheduleHandler.java index 20b426b4b4..684a360841 100644 --- a/backend/schedule/src/main/java/org/eclipse/sw360/schedule/service/ScheduleHandler.java +++ b/backend/schedule/src/main/java/org/eclipse/sw360/schedule/service/ScheduleHandler.java @@ -13,7 +13,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.thrift.TException; -import org.eclipse.sw360.datahandler.common.SW360Utils; import org.eclipse.sw360.datahandler.permissions.PermissionUtils; import org.eclipse.sw360.datahandler.thrift.RequestStatus; import org.eclipse.sw360.datahandler.thrift.RequestStatusWithBoolean; @@ -21,7 +20,7 @@ import org.eclipse.sw360.datahandler.thrift.ThriftClients; import org.eclipse.sw360.datahandler.thrift.schedule.ScheduleService; import org.eclipse.sw360.datahandler.thrift.users.User; -import org.eclipse.sw360.schedule.timer.ScheduleConstants; +import org.eclipse.sw360.datahandler.common.ScheduleConstants; import org.eclipse.sw360.schedule.timer.Scheduler; import java.util.Date; diff --git a/backend/schedule/src/main/java/org/eclipse/sw360/schedule/service/ScheduleServlet.java b/backend/schedule/src/main/java/org/eclipse/sw360/schedule/service/ScheduleServlet.java index 003f11c2be..9fd3f390a8 100644 --- a/backend/schedule/src/main/java/org/eclipse/sw360/schedule/service/ScheduleServlet.java +++ b/backend/schedule/src/main/java/org/eclipse/sw360/schedule/service/ScheduleServlet.java @@ -10,7 +10,7 @@ */ package org.eclipse.sw360.schedule.service; -import org.eclipse.sw360.schedule.timer.ScheduleConstants; +import org.eclipse.sw360.datahandler.common.ScheduleConstants; import org.eclipse.sw360.datahandler.thrift.schedule.ScheduleService; import org.eclipse.sw360.projects.Sw360ThriftServlet; import org.apache.logging.log4j.LogManager; diff --git a/backend/schedule/src/main/java/org/eclipse/sw360/schedule/timer/Scheduler.java b/backend/schedule/src/main/java/org/eclipse/sw360/schedule/timer/Scheduler.java index 5bdb321d84..bdd6cc4a3f 100644 --- a/backend/schedule/src/main/java/org/eclipse/sw360/schedule/timer/Scheduler.java +++ b/backend/schedule/src/main/java/org/eclipse/sw360/schedule/timer/Scheduler.java @@ -12,6 +12,7 @@ import org.eclipse.sw360.datahandler.common.CommonUtils; import org.eclipse.sw360.datahandler.common.SW360Utils; +import org.eclipse.sw360.datahandler.common.ScheduleConstants; import org.eclipse.sw360.datahandler.thrift.RequestStatus; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/backend/schedule/src/main/resources/sw360.properties b/backend/schedule/src/main/resources/sw360.properties deleted file mode 100644 index 380eaecf4a..0000000000 --- a/backend/schedule/src/main/resources/sw360.properties +++ /dev/null @@ -1,27 +0,0 @@ - -# Copyright (c) Bosch Software Innovations GmbH 2016. -# -# This program and the accompanying materials are made -# available under the terms of the Eclipse Public License 2.0 -# which is available at https://www.eclipse.org/legal/epl-2.0/ -# -# SPDX-License-Identifier: EPL-2.0 - -#in seconds of today: 0*60*60 = 0 means midnight -schedule.cvesearch.firstOffset.seconds = 0 - -#in seconds: 24*60*60 = 86400 means every 24 hours -schedule.cvesearch.interval.seconds = 86400 - -#general pattern for scheduling multiple services: autostart = service1,service2,service3,... -#for scheduling the cvesearchService, uncomment the following line: -#autostart = cvesearchService - -schedule.delete.attachment.firstOffset.seconds = 0 - -schedule.delete.attachment.interval.seconds = 86400 - -#in seconds of today: 0*60*60 = 0 means midnight -schedule.department.firstOffset.seconds = 0 -#in seconds: 60*60 = 3600 means every 1 hours -schedule.department.interval.seconds = 3600 diff --git a/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/VMComponentHandler.java b/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/VMComponentHandler.java index f4f22931cc..0b1bda6d3f 100644 --- a/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/VMComponentHandler.java +++ b/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/VMComponentHandler.java @@ -5,6 +5,7 @@ package org.eclipse.sw360.vmcomponents; import org.eclipse.sw360.datahandler.common.DatabaseSettings; +import org.eclipse.sw360.datahandler.common.SW360Constants; import org.eclipse.sw360.datahandler.common.SW360Utils; import org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler; import org.eclipse.sw360.datahandler.permissions.PermissionUtils; @@ -12,7 +13,6 @@ import org.eclipse.sw360.datahandler.thrift.RequestSummary; import org.eclipse.sw360.datahandler.thrift.SW360Exception; import org.eclipse.sw360.datahandler.thrift.users.User; -import org.eclipse.sw360.vmcomponents.common.SVMConstants; import org.eclipse.sw360.vmcomponents.db.VMDatabaseHandler; import org.eclipse.sw360.vmcomponents.process.VMProcessHandler; @@ -69,19 +69,19 @@ public RequestSummary synchronizeComponents() throws TException { // synchronize VMAction String actionStart = SW360Utils.getCreatedOnTime(); dbHandler.add(new VMProcessReporting(VMAction.class.getSimpleName(), actionStart)); - VMProcessHandler.getElementIds(VMAction.class, SVMConstants.ACTIONS_URL, true); + VMProcessHandler.getElementIds(VMAction.class, SW360Constants.SVM_ACTIONS_URL, true); log.info("Storing and getting master data of "+VMAction.class.getSimpleName()+" triggered. waiting for completion..."); // synchronize VMPriority String prioStart = SW360Utils.getCreatedOnTime(); dbHandler.add(new VMProcessReporting(VMPriority.class.getSimpleName(), prioStart)); - VMProcessHandler.getElementIds(VMPriority.class, SVMConstants.PRIORITIES_URL, true); + VMProcessHandler.getElementIds(VMPriority.class, SW360Constants.SVM_PRIORITIES_URL, true); log.info("Storing and getting master data of "+VMPriority.class.getSimpleName()+" triggered. waiting for completion..."); // synchronize VMComponent String compStart = SW360Utils.getCreatedOnTime(); dbHandler.add(new VMProcessReporting(VMComponent.class.getSimpleName(), compStart)); - VMProcessHandler.getElementIds(VMComponent.class, SVMConstants.COMPONENTS_URL, true); + VMProcessHandler.getElementIds(VMComponent.class, SW360Constants.SVM_COMPONENTS_URL, true); log.info("Storing and getting master data of "+VMComponent.class.getSimpleName()+" triggered. waiting for completion..."); // triggerReporting diff --git a/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/common/SVMConstants.java b/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/common/SVMConstants.java index 09fdeb25b1..9b1c745ace 100644 --- a/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/common/SVMConstants.java +++ b/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/common/SVMConstants.java @@ -4,10 +4,6 @@ */ package org.eclipse.sw360.vmcomponents.common; -import org.eclipse.sw360.datahandler.common.CommonUtils; - -import java.util.Properties; - /** * @author stefan.jaeger@evosoft.com * @author alex.borodin@evosoft.com @@ -16,16 +12,6 @@ public class SVMConstants { private SVMConstants(){} - public static final String PROPERTIES_FILE_PATH = "/sw360.properties"; - - // urls of SVM server - public static final String COMPONENTS_URL; - public static final String ACTIONS_URL; - public static final String PRIORITIES_URL; - public static final String COMPONENTS_ID_WILDCARD = "#compVmId#"; - public static final String VULNERABILITIES_PER_COMPONENT_URL; - public static final String VULNERABILITIES_URL; - // JSON components field names public static final String COMPONENT_VENDOR = "vendor"; public static final String COMPONENT_NAME = "component_name"; @@ -68,21 +54,4 @@ private SVMConstants(){} public static final int PROCESSING_CORE_POOL_SIZE = 20; public static final int PROCESSING_MAX_POOL_SIZE = 20; public static final int PROCESSING_KEEP_ALIVE_SECONDS = 60; - - private static final String SVM_BASE_HOST_URL; - private static final String SVM_API_ROOT_PATH; - - static { - Properties props = CommonUtils.loadProperties(SVMConstants.class, PROPERTIES_FILE_PATH); - - SVM_BASE_HOST_URL = props.getProperty("svm.base.path", ""); - SVM_API_ROOT_PATH = props.getProperty("svm.api.root.path", ""); - COMPONENTS_URL = props.getProperty("svm.components.url", SVM_BASE_HOST_URL + SVM_API_ROOT_PATH + "/components"); - ACTIONS_URL = props.getProperty("svm.actions.url", SVM_BASE_HOST_URL + SVM_API_ROOT_PATH + "/actions"); - PRIORITIES_URL = props.getProperty("svm.priorities.url", SVM_BASE_HOST_URL + SVM_API_ROOT_PATH + "/priorities"); - VULNERABILITIES_PER_COMPONENT_URL = props.getProperty("svm.components.vulnerabilities.url", - SVM_BASE_HOST_URL + SVM_API_ROOT_PATH + "/components/" +COMPONENTS_ID_WILDCARD+"/notifications"); - VULNERABILITIES_URL = props.getProperty("svm.vulnerabilities.url", SVM_BASE_HOST_URL + SVM_API_ROOT_PATH + "/notifications"); - } - } diff --git a/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/handler/SVMSyncHandler.java b/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/handler/SVMSyncHandler.java index 23307f9c56..e34b306639 100644 --- a/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/handler/SVMSyncHandler.java +++ b/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/handler/SVMSyncHandler.java @@ -11,6 +11,7 @@ import org.apache.log4j.Logger; import org.apache.thrift.TBase; import org.eclipse.sw360.datahandler.common.DatabaseSettings; +import org.eclipse.sw360.datahandler.common.SW360Constants; import org.eclipse.sw360.datahandler.common.SW360Utils; import org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler; import org.eclipse.sw360.datahandler.thrift.RequestStatus; @@ -631,7 +632,7 @@ private VMResult getVulnerabilitiesByComponent(VMComponent component, St private Set getVulIdsPerComponentVmId(String componentVmId, String url){ if (!StringUtils.isEmpty(componentVmId)){ try { - url = url.replace(SVMConstants.COMPONENTS_ID_WILDCARD, componentVmId); + url = url.replace(SW360Constants.SVM_COMPONENTS_ID_WILDCARD, componentVmId); String response = SVMUtils.prepareJSONRequestAndGetResponse(url); JsonArray ids = Jsoner.deserialize(response, new JsonArray()); diff --git a/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/process/VMProcessor.java b/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/process/VMProcessor.java index a99210614f..d5d939a346 100644 --- a/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/process/VMProcessor.java +++ b/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/process/VMProcessor.java @@ -4,6 +4,7 @@ */ package org.eclipse.sw360.vmcomponents.process; +import org.eclipse.sw360.datahandler.common.SW360Constants; import org.eclipse.sw360.datahandler.thrift.vmcomponents.VMAction; import org.eclipse.sw360.datahandler.thrift.vmcomponents.VMComponent; import org.eclipse.sw360.datahandler.thrift.vmcomponents.VMMatch; @@ -14,7 +15,6 @@ import org.eclipse.sw360.datahandler.thrift.RequestStatus; import org.eclipse.sw360.datahandler.thrift.components.Release; import org.eclipse.sw360.datahandler.thrift.vulnerabilities.Vulnerability; -import org.eclipse.sw360.vmcomponents.common.SVMConstants; import org.eclipse.sw360.vmcomponents.common.SVMUtils; import org.eclipse.sw360.vmcomponents.common.VMResult; import org.eclipse.sw360.vmcomponents.handler.SVMSyncHandler; @@ -144,7 +144,7 @@ public void run() { } break; - case MATCH_SVM: + case MATCH_SVM: // try to find a match via cpe and text VMResult componentMatchResult = syncHandler.findMatchByComponent(this.input.get(0)); if (triggerNextStep @@ -154,7 +154,7 @@ public void run() { && !componentMatchResult.elements.isEmpty() && componentMatchResult.requestSummary.totalAffectedElements > 0){ // re-queue for get Vulnerabilities - VMProcessHandler.getVulnerabilitiesByComponentId(this.input.get(0), SVMConstants.VULNERABILITIES_PER_COMPONENT_URL, triggerNextStep); + VMProcessHandler.getVulnerabilitiesByComponentId(this.input.get(0), SW360Constants.SVM_VULNERABILITIES_PER_COMPONENT_URL, triggerNextStep); } break; @@ -168,7 +168,7 @@ public void run() { && !releaseMatchResult.elements.isEmpty() && releaseMatchResult.requestSummary.totalAffectedElements > 0){ // re-queue for get Vulnerabilities - VMProcessHandler.getVulnerabilitiesByComponentIds(releaseMatchResult.elements, SVMConstants.VULNERABILITIES_PER_COMPONENT_URL, triggerNextStep); + VMProcessHandler.getVulnerabilitiesByComponentIds(releaseMatchResult.elements, SW360Constants.SVM_VULNERABILITIES_PER_COMPONENT_URL, triggerNextStep); } break; @@ -181,7 +181,7 @@ public void run() { && !vulResult.elements.isEmpty() && vulResult.requestSummary.totalAffectedElements > 0){ // get master data of the vulnerabilities - VMProcessHandler.getMasterData(Vulnerability.class, vulResult.elements, SVMConstants.VULNERABILITIES_URL, true); + VMProcessHandler.getMasterData(Vulnerability.class, vulResult.elements, SW360Constants.SVM_VULNERABILITIES_URL, true); } break; diff --git a/build-configuration/resources/sw360.properties b/build-configuration/resources/sw360.properties deleted file mode 100644 index 39ff558651..0000000000 --- a/build-configuration/resources/sw360.properties +++ /dev/null @@ -1,13 +0,0 @@ -# -# Copyright Siemens AG, 2013-2015. Part of the SW360 Portal Project. -# -# This program and the accompanying materials are made -# available under the terms of the Eclipse Public License 2.0 -# which is available at https://www.eclipse.org/legal/epl-2.0/ -# -# SPDX-License-Identifier: EPL-2.0 -# - -# N.B this is the default build property file, defined in module build-configuration - -backend.url= http://localhost:8080 \ No newline at end of file diff --git a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/DatabaseConstants.java b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/DatabaseConstants.java new file mode 100644 index 0000000000..e93a4f327e --- /dev/null +++ b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/DatabaseConstants.java @@ -0,0 +1,41 @@ +/* + * Copyright Siemens AG, 2024. Part of the SW360 Portal Project. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ + +package org.eclipse.sw360.datahandler.common; + +public class DatabaseConstants extends SW360Constants { + + public static final String SVM_JSON_LOG_OUTPUT_LOCATION; + public static final boolean IS_STORE_ATTACHMENT_TO_FILE_SYSTEM_ENABLED; + public static final String ATTACHMENT_STORE_FILE_SYSTEM_LOCATION; + public static final String ATTACHMENT_STORE_FILE_SYSTEM_PERMISSION; + public static final String ATTACHMENT_DELETE_NO_OF_DAYS; + public static final boolean IS_SW360CHANGELOG_ENABLED; + public static final String CHANGE_LOG_CONFIG_FILE_PATH; + public static final String SW360CHANGELOG_OUTPUT_PATH; + public static final boolean AUTO_SET_ECC_STATUS; + + static { + SVM_JSON_LOG_OUTPUT_LOCATION = props.getProperty("svm.json.log.output.location", "/tmp"); + ATTACHMENT_STORE_FILE_SYSTEM_LOCATION = props.getProperty("attachment.store.file.system.location", + "/opt/sw360tempattachments"); + ATTACHMENT_STORE_FILE_SYSTEM_PERMISSION = props.getProperty("attachment.store.file.system.permission", + "rwx------"); + IS_STORE_ATTACHMENT_TO_FILE_SYSTEM_ENABLED = Boolean.parseBoolean(props.getProperty("enable.attachment.store.to.file.system", "false")); + ATTACHMENT_DELETE_NO_OF_DAYS = props.getProperty("attachemnt.delete.no.of.days", + "30"); + IS_SW360CHANGELOG_ENABLED = Boolean.parseBoolean(props.getProperty("enable.sw360.change.log", "false")); + CHANGE_LOG_CONFIG_FILE_PATH = props.getProperty("sw360changelog.config.file.location", + "/etc/sw360/log4j2.xml"); + SW360CHANGELOG_OUTPUT_PATH = props.getProperty("sw360changelog.output.path", + "sw360changelog/sw360changelog"); + AUTO_SET_ECC_STATUS = Boolean.parseBoolean(props.getProperty("auto.set.ecc.status", "false")); + } +} diff --git a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/SW360Constants.java b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/SW360Constants.java index a71520adf6..5c72f1d2f0 100644 --- a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/SW360Constants.java +++ b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/SW360Constants.java @@ -106,14 +106,31 @@ public class SW360Constants { public static final String OTHER_LICENSE_IDS_KEY = "otherLicenseIds"; public static final String POSSIBLE_MAIN_LICENSE_IDS = "Possible Main License Ids"; public static final String TOTAL_FILE_COUNT = "totalFileCount"; + + // SVM Constants public static final String SVM_COMPONENT_ID; public static final String SVM_MONITORINGLIST_ID; public static final Boolean SPDX_DOCUMENT_ENABLED; + public static final Boolean SPDX_USE_LICENSE_INFO_FROM_FILES; public static final String MAINLINE_COMPONENT_ID; public static final String SVM_COMPONENT_ID_KEY; public static final String SVM_SHORT_STATUS; public static final String SVM_SHORT_STATUS_KEY; public static final String SVM_SCHEDULER_EMAIL; + public static final String SVM_MONITORING_LIST_API_URL; + public static final String SVM_COMPONENT_MAPPINGS_API_URL; + public static final char[] SVM_KEY_STORE_PASSPHRASE; + public static final String SVM_KEY_STORE_FILENAME; + public static final char[] SVM_JAVA_KEYSTORE_PASSWORD; + public static final String SVM_BASE_HOST_URL; + public static final String SVM_API_ROOT_PATH; + public static final String SVM_COMPONENTS_URL; + public static final String SVM_ACTIONS_URL; + public static final String SVM_PRIORITIES_URL; + public static final String SVM_VULNERABILITIES_PER_COMPONENT_URL; + public static final String SVM_VULNERABILITIES_URL; + public static final String SVM_COMPONENTS_ID_WILDCARD = "#compVmId#"; + public static final String DATA_HANDLER_POM_FILE_PATH; public static final UserGroup PACKAGE_PORTLET_WRITE_ACCESS_USER_ROLE; public static final boolean IS_PACKAGE_PORTLET_ENABLED; @@ -128,6 +145,78 @@ public class SW360Constants { public static final Boolean MAIL_REQUEST_FOR_PROJECT_REPORT; public static final Boolean MAIL_REQUEST_FOR_COMPONENT_REPORT; + public static final Boolean MAINLINE_STATE_ENABLED_FOR_USER; + public static final Boolean IS_BULK_RELEASE_DELETING_ENABLED; + public static final Boolean IS_FORCE_UPDATE_ENABLED; + public static final boolean IS_COMPONENT_VISIBILITY_RESTRICTION_ENABLED; + public static final boolean IS_ADMIN_PRIVATE_ACCESS_ENABLED; + public static final Boolean DISABLE_CLEARING_FOSSOLOGY_REPORT_DOWNLOAD; + public static final String FRIENDLY_RELEASE_URL; + + // Authorization server + private static final String DEFAULT_WRITE_ACCESS_USERGROUP = UserGroup.SW360_ADMIN.name(); + private static final String DEFAULT_ADMIN_ACCESS_USERGROUP = UserGroup.SW360_ADMIN.name(); + public static final String SW360_LIFERAY_COMPANY_ID; + public static final String CONFIG_ACCESS_TOKEN_VALIDITY_SECONDS; + public static final UserGroup CONFIG_WRITE_ACCESS_USERGROUP; + public static final UserGroup CONFIG_ADMIN_ACCESS_USERGROUP; + + // CLI Constants + public static final String CLI_RELEASE_EXTERNAL_ID_CORRELATION_KEY; + + // CVE Constants + public static final int CVE_VENDOR_THRESHOLD; + public static final int CVE_PRODUCT_THRESHOLD; + public static final int CVE_CUTOFF; + + // REST Constants + public static final String REST_API_TOKEN_HASH_SALT; + public static final String REST_API_TOKEN_MAX_VALIDITY_READ_IN_DAYS; + public static final String REST_API_TOKEN_MAX_VALIDITY_WRITE_IN_DAYS; + public static final Boolean REST_API_TOKEN_GENERATOR_ENABLE; + public static final Boolean REST_API_WRITE_ACCESS_TOKEN_ENABLE; + public static final Set DOMAIN; + public static final String REST_REPORT_FILENAME_MAPPING; + public static final String REST_JWKS_ISSUER_URL; + public static final String REST_JWKS_ENDPOINT_URL; + public static final Boolean REST_IS_JWKS_VALIDATION_ENABLED; + public static final String REST_SERVER_PATH_URL; + + // UI Portlet Constants + public static final String CLEARING_TEAMS; + public static final Boolean CLEARING_TEAM_UNKNOWN_ENABLED; + public static final Set COMPONENT_CATEGORIES; + public static final Set COMPONENT_EXTERNAL_ID_KEYS; + public static final Set COMPONENTS_ACTIVATE; + public static final Set COMPONENT_ROLES; + public static final Set PROJECT_ROLES; + public static final Set RELEASE_EXTERNAL_IDS; + public static final Set RELEASE_ROLES; + public static final Boolean CUSTOM_WELCOME_PAGE_GUIDELINE; + public static final Boolean ENABLE_ADD_LIC_INFO_TO_RELEASE; + public static final Boolean IS_SVM_ENABLED; + public static final Set LICENSE_IDENTIFIERS; + public static final Set OPERATING_SYSTEMS; + public static final Boolean DISABLE_CLEARING_REQUEST_FOR_PROJECT_WITH_GROUPS; + public static final String LICENSE_INFO_HEADER_TEXT_FILE_NAME_BY_PROJECT_GROUP; + public static final String CLEARING_REPORT_TEMPLATE_FORMAT; + public static final Set PROGRAMMING_LANGUAGES; + public static final Set PROJECT_EXTERNAL_ID_KEYS; + public static final Set PROJECT_EXTERNAL_URL_KEYS; + public static final String PROJECTIMPORT_HOSTS; + public static final Set PROJECT_OBLIGATIONS_ACTION_SET; + public static final Boolean IS_PROJECT_OBLIGATIONS_ENABLED; + public static final Set PREDEFINED_TAGS; + public static final Set PROJECT_TYPE; + public static final Set SET_RELATIONSHIP_TYPE; + public static final Set RELEASE_EXTERNAL_ID_KEYS; + public static final Boolean SEND_PROJECT_LICENSE_INFO_SPREADSHEET_EXPORT_TO_MAIL_ENABLED; + public static final Set SOFTWARE_PLATFORMS; + public static final Set STATE; + public static final UserGroup USER_ROLE_ALLOWED_TO_MERGE_OR_SPLIT_COMPONENT; + + public static final Properties props; + /** * Hashmap containing the name field for each type. * Used by the search service to fill the search results @@ -209,12 +298,13 @@ public static Collection allowedAttachmentTypes(String documentT } } - private SW360Constants() { + SW360Constants() { // Utility class with only static functions } static { - Properties props = CommonUtils.loadProperties(SW360Constants.class, PROPERTIES_FILE_PATH); + props = CommonUtils.loadProperties(SW360Constants.class, PROPERTIES_FILE_PATH); + SVM_COMPONENT_ID = props.getProperty("svm.component.id", ""); MAINLINE_COMPONENT_ID = props.getProperty("mainline.component.id", ""); SVM_COMPONENT_ID_KEY = props.getProperty("svm.component.id.key", ""); @@ -222,7 +312,25 @@ private SW360Constants() { SVM_SHORT_STATUS_KEY = props.getProperty("svm.short.status.key", ""); SVM_SCHEDULER_EMAIL = props.getProperty("svm.scheduler.email", ""); SVM_MONITORINGLIST_ID = props.getProperty("svm.monitoringlist.id", ""); + SVM_MONITORING_LIST_API_URL = props.getProperty("svm.sw360.api.url", ""); + SVM_COMPONENT_MAPPINGS_API_URL = props.getProperty("svm.sw360.componentmappings.api.url", ""); + SVM_KEY_STORE_FILENAME = props.getProperty("svm.sw360.certificate.filename", "not-configured"); + SVM_KEY_STORE_PASSPHRASE = props.getProperty("svm.sw360.certificate.passphrase", "").toCharArray(); + SVM_JAVA_KEYSTORE_PASSWORD = props.getProperty("svm.sw360.jks.password", "changeit").toCharArray(); + + SVM_BASE_HOST_URL = props.getProperty("svm.base.path", ""); + SVM_API_ROOT_PATH = props.getProperty("svm.api.root.path", ""); + SVM_COMPONENTS_URL = props.getProperty("svm.components.url", SVM_BASE_HOST_URL + SVM_API_ROOT_PATH + "/components"); + SVM_ACTIONS_URL = props.getProperty("svm.actions.url", SVM_BASE_HOST_URL + SVM_API_ROOT_PATH + "/actions"); + SVM_PRIORITIES_URL = props.getProperty("svm.priorities.url", SVM_BASE_HOST_URL + SVM_API_ROOT_PATH + "/priorities"); + SVM_VULNERABILITIES_PER_COMPONENT_URL = props.getProperty("svm.components.vulnerabilities.url", + SVM_BASE_HOST_URL + SVM_API_ROOT_PATH + "/components/" + SVM_COMPONENTS_ID_WILDCARD + "/notifications"); + SVM_VULNERABILITIES_URL = props.getProperty("svm.vulnerabilities.url", SVM_BASE_HOST_URL + SVM_API_ROOT_PATH + "/notifications"); + SPDX_DOCUMENT_ENABLED = Boolean.parseBoolean(props.getProperty("spdx.document.enabled", "false")); + SPDX_USE_LICENSE_INFO_FROM_FILES = Boolean + .valueOf(props.getProperty("licenseinfo.spdxparser.use-license-info-from-files", "true")); + DATA_HANDLER_POM_FILE_PATH = props.getProperty("datahandler.pom.file.path", "/META-INF/maven/org.eclipse.sw360/datahandler/pom.xml"); PACKAGE_PORTLET_WRITE_ACCESS_USER_ROLE = UserGroup.valueOf(props.getProperty("package.portlet.write.access.usergroup", UserGroup.USER.name())); IS_PACKAGE_PORTLET_ENABLED = Boolean.parseBoolean(props.getProperty("package.portlet.enabled", "true")); @@ -237,6 +345,74 @@ private SW360Constants() { PREFERRED_CLEARING_DATE_LIMIT = props.getProperty("preferred.clearing.date.limit",""); MAIL_REQUEST_FOR_PROJECT_REPORT = Boolean.parseBoolean(props.getProperty("send.project.spreadsheet.export.to.mail.enabled", "false")); MAIL_REQUEST_FOR_COMPONENT_REPORT = Boolean.parseBoolean(props.getProperty("send.component.spreadsheet.export.to.mail.enabled", "false")); + + MAINLINE_STATE_ENABLED_FOR_USER = Boolean.parseBoolean(props.getProperty("mainline.state.enabled.for.user", "false")); + IS_BULK_RELEASE_DELETING_ENABLED = Boolean.parseBoolean(System.getProperty("RunBulkReleaseDeletingTest", props.getProperty("bulk.release.deleting.enabled", "false"))); + IS_FORCE_UPDATE_ENABLED = Boolean.parseBoolean( + System.getProperty("RunRestForceUpdateTest", props.getProperty("rest.force.update.enabled", "false"))); + IS_COMPONENT_VISIBILITY_RESTRICTION_ENABLED = Boolean.parseBoolean( + System.getProperty("RunComponentVisibilityRestrictionTest", props.getProperty("component.visibility.restriction.enabled", "false"))); + IS_ADMIN_PRIVATE_ACCESS_ENABLED = Boolean.parseBoolean( + System.getProperty("RunPrivateProjectAccessTest", props.getProperty("admin.private.project.access.enabled", "false"))); + DISABLE_CLEARING_FOSSOLOGY_REPORT_DOWNLOAD = Boolean.parseBoolean(props.getProperty("disable.clearing.fossology.report.download", "false")); + + FRIENDLY_RELEASE_URL = props.getProperty("release.friendly.url", ""); + + CONFIG_WRITE_ACCESS_USERGROUP = UserGroup.valueOf(props.getProperty("rest.write.access.usergroup", DEFAULT_WRITE_ACCESS_USERGROUP)); + CONFIG_ADMIN_ACCESS_USERGROUP = UserGroup.valueOf(props.getProperty("rest.admin.access.usergroup", DEFAULT_ADMIN_ACCESS_USERGROUP)); + CONFIG_ACCESS_TOKEN_VALIDITY_SECONDS = props.getProperty("rest.access.token.validity.seconds", null); + SW360_LIFERAY_COMPANY_ID = props.getProperty("sw360.liferay.company.id", null); + + CLI_RELEASE_EXTERNAL_ID_CORRELATION_KEY = props.getProperty("combined.cli.parser.external.id.correlation.key"); + + CVE_VENDOR_THRESHOLD = CommonUtils.getIntOrDefault(props.getProperty("cvesearch.vendor.threshold"), 1); + CVE_PRODUCT_THRESHOLD = CommonUtils.getIntOrDefault(props.getProperty("cvesearch.product.threshold"), 0); + CVE_CUTOFF = CommonUtils.getIntOrDefault(props.getProperty("cvesearch.cutoff"), 6); + + REST_API_TOKEN_MAX_VALIDITY_READ_IN_DAYS = props.getProperty("rest.apitoken.read.validity.days", "90"); + REST_API_TOKEN_MAX_VALIDITY_WRITE_IN_DAYS = props.getProperty("rest.apitoken.write.validity.days", "30"); + REST_API_TOKEN_GENERATOR_ENABLE = Boolean.parseBoolean(props.getProperty("rest.apitoken.generator.enable", "false")); + REST_API_WRITE_ACCESS_TOKEN_ENABLE = Boolean.parseBoolean(props.getProperty("rest.api.write.access.token.in.preferences.enabled", "true")); + REST_API_TOKEN_HASH_SALT = props.getProperty("rest.apitoken.hash.salt", "$2a$04$Software360RestApiSalt"); + DOMAIN = CommonUtils.splitToSet(props.getProperty("domain", + "Application Software, Documentation, Embedded Software, Hardware, Test and Diagnostics")); + REST_REPORT_FILENAME_MAPPING = props.getProperty("org.eclipse.sw360.licensinfo.projectclearing.templatemapping", ""); + REST_JWKS_ISSUER_URL = props.getProperty("jwks.issuer.url", null); + REST_JWKS_ENDPOINT_URL = props.getProperty("jwks.endpoint.url", null); + REST_IS_JWKS_VALIDATION_ENABLED = Boolean.parseBoolean(props.getProperty("jwks.validation.enabled", "false")); + REST_SERVER_PATH_URL = props.getProperty("backend.url", "http://localhost:8080"); + + CLEARING_TEAMS = props.getProperty("clearing.teams", "org1,org2,org3"); + CLEARING_TEAM_UNKNOWN_ENABLED = Boolean.valueOf(props.getProperty("clearing.team.unknown.enabled", "true")); + COMPONENT_CATEGORIES = CommonUtils.splitToSet(props.getProperty("component.categories", "framework,SDK,big-data,build-management,cloud,content,database,graphics,http,javaee,library,mail,mobile,security,testing,virtual-machine,web-framework,xml")); + COMPONENT_EXTERNAL_ID_KEYS = CommonUtils.splitToSet(props.getProperty("component.externalkeys", "com.github.id,com.gitlab.id,purl.id")); + COMPONENTS_ACTIVATE = CommonUtils.splitToSet(props.getProperty("components.activate", "")); + COMPONENT_ROLES = CommonUtils.splitToSet(props.getProperty("custommap.component.roles", "Committer,Contributor,Expert")); + PROJECT_ROLES = CommonUtils.splitToSet(props.getProperty("custommap.project.roles", "Stakeholder,Analyst,Contributor,Accountant,End user,Quality manager,Test manager,Technical writer,Key user")); + RELEASE_EXTERNAL_IDS = CommonUtils.splitToSet(props.getProperty("custommap.release.externalIds", "")); + RELEASE_ROLES = CommonUtils.splitToSet(props.getProperty("custommap.release.roles", "Committer,Contributor,Expert")); + CUSTOM_WELCOME_PAGE_GUIDELINE = Boolean.parseBoolean(props.getProperty("custom.welcome.page.guideline", "false")); + ENABLE_ADD_LIC_INFO_TO_RELEASE = Boolean.parseBoolean(props.getProperty("enable.add.license.info.to.release.button", "false")); + IS_SVM_ENABLED = Boolean.parseBoolean(props.getProperty("enable.security.vulnerability.monitoring", "false")); + LICENSE_IDENTIFIERS = CommonUtils.splitToSet(props.getProperty("license.identifiers", "")); + OPERATING_SYSTEMS = CommonUtils.splitToSet(props.getProperty("operating.systems", "Android,BSD,iOS,Linux,OS X,QNX,Microsoft Windows,Windows Phone,IBM z/OS")); + DISABLE_CLEARING_REQUEST_FOR_PROJECT_WITH_GROUPS = Boolean.parseBoolean(props.getProperty("org.eclipse.sw360.disable.clearing.request.for.project.group", "false")); + LICENSE_INFO_HEADER_TEXT_FILE_NAME_BY_PROJECT_GROUP = props.getProperty("org.eclipse.sw360.licensinfo.header.by.group", ""); + CLEARING_REPORT_TEMPLATE_FORMAT = props.getProperty("org.eclipse.sw360.licensinfo.projectclearing.templateformat", "docx"); + PROGRAMMING_LANGUAGES = CommonUtils.splitToSet(props.getProperty("programming.languages", "ActionScript,AppleScript,Asp,Bash,BASIC,C,C++,C#,Cocoa,Clojure,COBOL,ColdFusion,D,Delphi,Erlang,Fortran,Go,Groovy,Haskell,JSP,Java,JavaScript,Objective-C,Ocaml,Lisp,Perl,PHP,Python,Ruby,SQL,SVG,Scala,SmallTalk,Scheme,Tcl,XML,Node.js,JSON")); + PROJECT_EXTERNAL_ID_KEYS = CommonUtils.splitToSet(props.getProperty("project.externalkeys", "internal.id")); + PROJECT_EXTERNAL_URL_KEYS = CommonUtils.splitToSet(props.getProperty("project.externalurls", "homepage,wiki,clearing")); + PROJECTIMPORT_HOSTS = props.getProperty("projectimport.hosts", ""); + PROJECT_OBLIGATIONS_ACTION_SET = CommonUtils.splitToSet(props.getProperty("project.obligation.actions", "Action 1,Action 2,Action 3")); + IS_PROJECT_OBLIGATIONS_ENABLED = Boolean.parseBoolean(props.getProperty("project.obligations.enabled", "true")); + PREDEFINED_TAGS = CommonUtils.splitToSet(props.getProperty("project.tag", "")); + PROJECT_TYPE = CommonUtils.splitToSet(props.getProperty("project.type","Customer Project,Internal Project,Product,Service,Inner Source")); + SET_RELATIONSHIP_TYPE = CommonUtils.splitToSet(props.getProperty("relationship.type", "DESCRIBES,DESCRIBED_BY,CONTAINS,CONTAINED_BY,DEPENDS_ON,DEPENDENCY_OF,DEPENDENCY_MANIFEST_OF,BUILD_DEPENDENCY_OF,DEV_DEPENDENCY_OF,OPTIONAL_DEPENDENCY_OF,PROVIDED_DEPENDENCY_OF,TEST_DEPENDENCY_OF,RUNTIME_DEPENDENCY_OF,EXAMPLE_OF,GENERATES,GENERATED_FROM,ANCESTOR_OF,DESCENDANT_OF,VARIANT_OF,DISTRIBUTION_ARTIFACT,PATCH_FOR,PATCH_APPLIED,COPY_OF,FILE_ADDED,FILE_DELETED,FILE_MODIFIED,EXPANDED_FROM_ARCHIVE,DYNAMIC_LINK,STATIC_LINK,DATA_FILE_OF,TEST_CASE_OF,BUILD_TOOL_OF,DEV_TOOL_OF,TEST_OF,TEST_TOOL_OF,DOCUMENTATION_OF,OPTIONAL_COMPONENT_OF,METAFILE_OF,PACKAGE_OF,AMENDS,PREREQUISITE_FOR,HAS_PREREQUISITE,REQUIREMENT_DESCRIPTION_FOR,SPECIFICATION_FOR,OTHER")); + RELEASE_EXTERNAL_ID_KEYS = CommonUtils.splitToSet(props.getProperty("release.externalkeys", "org.maven.id,com.github.id,com.gitlab.id,purl.id")); + SEND_PROJECT_LICENSE_INFO_SPREADSHEET_EXPORT_TO_MAIL_ENABLED = Boolean.parseBoolean(props.getProperty("send.project.license.info.spreadsheet.export.to.mail.enabled", "true")); + SOFTWARE_PLATFORMS = CommonUtils.splitToSet(props.getProperty("software.platforms", "Adobe AIR,Adobe Flash,Adobe Shockwave,Binary Runtime Environment for Wireless,Cocoa (API),Cocoa Touch,Java (software platform)|Java platform,Java Platform - Micro Edition,Java Platform - Standard Edition,Java Platform - Enterprise Edition,JavaFX,JavaFX Mobile,Microsoft XNA,Mono (software)|Mono,Mozilla Prism,.NET Framework,Silverlight,Open Web Platform,Oracle Database,Qt (framework)|Qt,SAP NetWeaver,Smartface,Vexi,Windows Runtime")); + STATE = CommonUtils.splitToSet(props.getProperty("state","Active,Phase out,Unknown")); + USER_ROLE_ALLOWED_TO_MERGE_OR_SPLIT_COMPONENT = UserGroup.valueOf(props.getProperty("user.role.allowed.to.merge.or.split.component", UserGroup.ADMIN.name())); } private static Map.Entry pair(TFieldIdEnum field, String displayName){ diff --git a/backend/schedule/src/main/java/org/eclipse/sw360/schedule/timer/ScheduleConstants.java b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/ScheduleConstants.java similarity index 97% rename from backend/schedule/src/main/java/org/eclipse/sw360/schedule/timer/ScheduleConstants.java rename to libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/ScheduleConstants.java index e1985642e3..663de1361d 100644 --- a/backend/schedule/src/main/java/org/eclipse/sw360/schedule/timer/ScheduleConstants.java +++ b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/ScheduleConstants.java @@ -9,10 +9,9 @@ * SPDX-License-Identifier: EPL-2.0 */ -package org.eclipse.sw360.schedule.timer; +package org.eclipse.sw360.datahandler.common; -import org.eclipse.sw360.datahandler.common.CommonUtils; import org.eclipse.sw360.datahandler.thrift.ThriftClients; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -25,12 +24,11 @@ /** * @author stefan.jaeger@evosoft.com */ -public class ScheduleConstants { +public class ScheduleConstants extends SW360Constants { private static final Logger log = LogManager.getLogger(ScheduleConstants.class); private ScheduleConstants(){} - public static final String PROPERTIES_FILE_PATH = "/sw360.properties"; public static final String CVESEARCH_OFFSET_PROPERTY_NAME = "schedule.cvesearch.firstOffset.seconds"; public static final String CVESEARCH_INTERVAL_PROPERTY_NAME = "schedule.cvesearch.interval.seconds"; public static final String AUTOSTART_PROPERTY_NAME = "autostart"; @@ -73,8 +71,6 @@ private ScheduleConstants(){} public static Set invalidConfiguredServices = new HashSet<>(); static { - Properties props = CommonUtils.loadProperties(ScheduleConstants.class, PROPERTIES_FILE_PATH); - loadScheduledServiceProperties(props, ThriftClients.CVESEARCH_SERVICE, CVESEARCH_OFFSET_PROPERTY_NAME, CVESEARCH_OFFSET_DEFAULT, CVESEARCH_INTERVAL_PROPERTY_NAME, CVESEARCH_INTERVAL_DEFAULT); loadScheduledServiceProperties(props, ThriftClients.SVMSYNC_SERVICE, SVMSYNC_OFFSET_PROPERTY_NAME, SVMSYNC_OFFSET_DEFAULT, SVMSYNC_INTERVAL_PROPERTY_NAME, SVMSYNC_INTERVAL_DEFAULT); loadScheduledServiceProperties(props, ThriftClients.SVMMATCH_SERVICE, SVMMATCH_OFFSET_PROPERTY_NAME, SVMMATCH_OFFSET_DEFAULT, SVMMATCH_INTERVAL_PROPERTY_NAME, SVMMATCH_INTERVAL_DEFAULT); diff --git a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/ThriftConstants.java b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/ThriftConstants.java new file mode 100644 index 0000000000..cefd3d0596 --- /dev/null +++ b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/common/ThriftConstants.java @@ -0,0 +1,45 @@ +/* + * Copyright Siemens AG, 2024. Part of the SW360 Portal Project. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ + +package org.eclipse.sw360.datahandler.common; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.thrift.TConfiguration; + +public class ThriftConstants extends SW360Constants { + + private final static Logger log = LogManager.getLogger(ThriftConstants.class); + + public static final String BACKEND_URL; + public static final String BACKEND_PROXY_URL; + public static final int THRIFT_CONNECTION_TIMEOUT; + public static final int THRIFT_READ_TIMEOUT; + public static final int THRIFT_MAX_MESSAGE_SIZE; + public static final int THRIFT_MAX_FRAME_SIZE; + + static { + BACKEND_URL = props.getProperty("backend.url", "http://127.0.0.1:8080"); + //Proxy can be set e.g. with "http://localhost:3128". if set all request to the thrift backend are routed through the proxy + BACKEND_PROXY_URL = props.getProperty("backend.proxy.url", null); + // maximum timeout for connecting and reading + THRIFT_CONNECTION_TIMEOUT = Integer.valueOf(props.getProperty("backend.timeout.connection", "5000")); + THRIFT_READ_TIMEOUT = Integer.valueOf(props.getProperty("backend.timeout.read", "600000")); + + THRIFT_MAX_MESSAGE_SIZE = Integer.valueOf(props.getProperty("backend.thrift.max.message.size", String.valueOf(TConfiguration.DEFAULT_MAX_MESSAGE_SIZE))); + THRIFT_MAX_FRAME_SIZE = Integer.valueOf(props.getProperty("backend.thrift.max.frame.size", String.valueOf(TConfiguration.DEFAULT_MAX_FRAME_SIZE))); + + log.info("The following configuration will be used for connections to the backend:\n" + + "\tURL : " + BACKEND_URL + "\n" + + "\tProxy : " + BACKEND_PROXY_URL + "\n" + + "\tTimeout Connecting (ms) : " + THRIFT_CONNECTION_TIMEOUT + "\n" + + "\tTimeout Read (ms) : " + THRIFT_READ_TIMEOUT + "\n"); + } +} diff --git a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/permissions/ComponentPermissions.java b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/permissions/ComponentPermissions.java index bce510de7b..150533d7ec 100644 --- a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/permissions/ComponentPermissions.java +++ b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/permissions/ComponentPermissions.java @@ -10,6 +10,7 @@ package org.eclipse.sw360.datahandler.permissions; import com.google.common.collect.Sets; +import org.eclipse.sw360.datahandler.common.SW360Constants; import org.eclipse.sw360.datahandler.thrift.Visibility; import org.eclipse.sw360.datahandler.common.CommonUtils; import org.eclipse.sw360.datahandler.thrift.components.Component; @@ -29,7 +30,6 @@ import static org.eclipse.sw360.datahandler.common.CommonUtils.toSingletonSet; import static org.eclipse.sw360.datahandler.common.SW360Utils.getBUFromOrganisation; import static org.eclipse.sw360.datahandler.permissions.PermissionUtils.*; -import static org.eclipse.sw360.datahandler.thrift.users.UserGroup.ADMIN; import static org.eclipse.sw360.datahandler.thrift.users.UserGroup.CLEARING_ADMIN; @@ -72,10 +72,10 @@ public static boolean userIsEquivalentToModeratorInComponent(Component input, St public static Predicate isVisible(final User user) { return input -> { - if(!PermissionUtils.IS_COMPONENT_VISIBILITY_RESTRICTION_ENABLED) { + if(!SW360Constants.IS_COMPONENT_VISIBILITY_RESTRICTION_ENABLED) { return true; } - + Visibility visibility = input.getVisbility(); if (visibility == null) { visibility = Visibility.BUISNESSUNIT_AND_MODERATORS; // the current default @@ -147,7 +147,7 @@ protected Set getUserEquivalentOwnerGroup(){ departments.addAll(user.getSecondaryDepartmentsAndRoles().keySet()); } departments.add(user.getDepartment()); - if(!PermissionUtils.IS_COMPONENT_VISIBILITY_RESTRICTION_ENABLED) { + if(!SW360Constants.IS_COMPONENT_VISIBILITY_RESTRICTION_ENABLED) { return departments; } Set finalDepartments = new HashSet(); @@ -155,7 +155,7 @@ protected Set getUserEquivalentOwnerGroup(){ finalDepartments.add(departmentIfUserInBU); return departmentIfUserInBU == null ? null : finalDepartments; } - + private static String getDepartmentIfUserInBU(Component document, Set BUs) { for (String bu:BUs) { String buFromOrganisation = getBUFromOrganisation(bu); diff --git a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/permissions/PermissionUtils.java b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/permissions/PermissionUtils.java index 4fdee04b83..fc0d9548f6 100644 --- a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/permissions/PermissionUtils.java +++ b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/permissions/PermissionUtils.java @@ -9,11 +9,8 @@ */ package org.eclipse.sw360.datahandler.permissions; -import java.util.Properties; import java.util.Set; -import org.eclipse.sw360.datahandler.common.CommonUtils; -import org.eclipse.sw360.datahandler.common.DatabaseSettings; import org.eclipse.sw360.datahandler.thrift.components.Component; import org.eclipse.sw360.datahandler.thrift.components.Release; import org.eclipse.sw360.datahandler.thrift.licenses.License; @@ -36,18 +33,6 @@ */ public class PermissionUtils { - public static final String PROPERTIES_FILE_PATH = "/sw360.properties"; - public static final boolean IS_COMPONENT_VISIBILITY_RESTRICTION_ENABLED; - public static final boolean IS_ADMIN_PRIVATE_ACCESS_ENABLED; - - static { - Properties props = CommonUtils.loadProperties(DatabaseSettings.class, PROPERTIES_FILE_PATH); - IS_COMPONENT_VISIBILITY_RESTRICTION_ENABLED = Boolean.parseBoolean( - System.getProperty("RunComponentVisibilityRestrictionTest", props.getProperty("component.visibility.restriction.enabled", "false"))); - IS_ADMIN_PRIVATE_ACCESS_ENABLED = Boolean.parseBoolean( - System.getProperty("RunPrivateProjectAccessTest", props.getProperty("admin.private.project.access.enabled", "false"))); - } - public static boolean isNormalUser(User user) { return isInGroup(user, UserGroup.USER); } diff --git a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/permissions/ProjectPermissions.java b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/permissions/ProjectPermissions.java index dcfb5cf268..ca93445ea1 100644 --- a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/permissions/ProjectPermissions.java +++ b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/permissions/ProjectPermissions.java @@ -12,6 +12,7 @@ import com.google.common.collect.ImmutableSet; import org.eclipse.sw360.datahandler.common.CommonUtils; +import org.eclipse.sw360.datahandler.common.SW360Constants; import org.eclipse.sw360.datahandler.thrift.Visibility; import org.eclipse.sw360.datahandler.thrift.projects.Project; import org.eclipse.sw360.datahandler.thrift.projects.ProjectClearingState; @@ -89,7 +90,7 @@ public static Predicate isVisible(final User user) { visibility = Visibility.BUISNESSUNIT_AND_MODERATORS; // the current default } - boolean isPrivateAccessAllowed = PermissionUtils.IS_ADMIN_PRIVATE_ACCESS_ENABLED && isUserAtLeast(ADMIN, user); + boolean isPrivateAccessAllowed = SW360Constants.IS_ADMIN_PRIVATE_ACCESS_ENABLED && isUserAtLeast(ADMIN, user); switch (visibility) { case PRIVATE: diff --git a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/thrift/ThriftClients.java b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/thrift/ThriftClients.java index eb25b413de..36decdd25c 100644 --- a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/thrift/ThriftClients.java +++ b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/thrift/ThriftClients.java @@ -23,7 +23,7 @@ import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.transport.THttpClient; import org.apache.thrift.transport.TTransportException; -import org.eclipse.sw360.datahandler.common.CommonUtils; +import org.eclipse.sw360.datahandler.common.ThriftConstants; import org.eclipse.sw360.datahandler.thrift.attachments.AttachmentService; import org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogsService; import org.eclipse.sw360.datahandler.thrift.components.ComponentService; @@ -49,7 +49,6 @@ import java.net.MalformedURLException; import java.net.URL; -import java.util.Properties; /** * Created by bodet on 11/02/15. @@ -61,15 +60,6 @@ public class ThriftClients { private final static Logger log = LogManager.getLogger(ThriftClients.class); - public static final String PROPERTIES_FILE_PATH = "/sw360.properties"; - - public static final String BACKEND_URL; - public static final String BACKEND_PROXY_URL; - public static final int THRIFT_CONNECTION_TIMEOUT; - public static final int THRIFT_READ_TIMEOUT; - public static final int THRIFT_MAX_MESSAGE_SIZE; - public static final int THRIFT_MAX_FRAME_SIZE; - //! Service addresses private static final String ATTACHMENT_SERVICE_URL = "/attachments/thrift"; private static final String COMPONENT_SERVICE_URL = "/components/thrift"; @@ -107,25 +97,6 @@ public class ThriftClients { public static final String SRC_UPLOAD_SERVICE = "srcAttachmentUploadService"; - static { - Properties props = CommonUtils.loadProperties(ThriftClients.class, PROPERTIES_FILE_PATH); - - BACKEND_URL = props.getProperty("backend.url", "http://127.0.0.1:8080"); - //Proxy can be set e.g. with "http://localhost:3128". if set all request to the thrift backend are routed through the proxy - BACKEND_PROXY_URL = props.getProperty("backend.proxy.url", null); - // maximum timeout for connecting and reading - THRIFT_CONNECTION_TIMEOUT = Integer.valueOf(props.getProperty("backend.timeout.connection", "5000")); - THRIFT_READ_TIMEOUT = Integer.valueOf(props.getProperty("backend.timeout.read", "600000")); - - THRIFT_MAX_MESSAGE_SIZE = Integer.valueOf(props.getProperty("backend.thrift.max.message.size", String.valueOf(TConfiguration.DEFAULT_MAX_MESSAGE_SIZE))); - THRIFT_MAX_FRAME_SIZE = Integer.valueOf(props.getProperty("backend.thrift.max.frame.size", String.valueOf(TConfiguration.DEFAULT_MAX_FRAME_SIZE))); - - log.info("The following configuration will be used for connections to the backend:\n" + - "\tURL : " + BACKEND_URL + "\n" + - "\tProxy : " + BACKEND_PROXY_URL + "\n" + - "\tTimeout Connecting (ms) : " + THRIFT_CONNECTION_TIMEOUT + "\n" + - "\tTimeout Read (ms) : " + THRIFT_READ_TIMEOUT + "\n"); - } public ThriftClients() { } @@ -135,12 +106,12 @@ public ThriftClients() { private static TProtocol makeProtocol(String url, String service) { THttpClient thriftClient = null; final String destinationAddress = url + service; - final TConfiguration thriftConfigure = TConfiguration.custom().setMaxMessageSize(THRIFT_MAX_MESSAGE_SIZE) - .setMaxFrameSize(THRIFT_MAX_FRAME_SIZE).build(); + final TConfiguration thriftConfigure = TConfiguration.custom().setMaxMessageSize(ThriftConstants.THRIFT_MAX_MESSAGE_SIZE) + .setMaxFrameSize(ThriftConstants.THRIFT_MAX_FRAME_SIZE).build(); try { - if (BACKEND_PROXY_URL != null) { - URL proxyUrl = new URL(BACKEND_PROXY_URL); + if (ThriftConstants.BACKEND_PROXY_URL != null) { + URL proxyUrl = new URL(ThriftConstants.BACKEND_PROXY_URL); HttpHost proxy = new HttpHost(proxyUrl.getProtocol(), proxyUrl.getHost(), proxyUrl.getPort()); DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy); CloseableHttpClient httpClient = HttpClients.custom().setRoutePlanner(routePlanner).build(); @@ -148,8 +119,8 @@ private static TProtocol makeProtocol(String url, String service) { } else { thriftClient = new THttpClient(thriftConfigure, destinationAddress); } - thriftClient.setConnectTimeout(THRIFT_CONNECTION_TIMEOUT); - thriftClient.setReadTimeout(THRIFT_READ_TIMEOUT); + thriftClient.setConnectTimeout(ThriftConstants.THRIFT_CONNECTION_TIMEOUT); + thriftClient.setReadTimeout(ThriftConstants.THRIFT_READ_TIMEOUT); } catch (TTransportException e) { log.error("cannot connect to backend on " + destinationAddress, e); } catch (MalformedURLException e) { @@ -159,94 +130,94 @@ private static TProtocol makeProtocol(String url, String service) { } public AttachmentService.Iface makeAttachmentClient() { - return new AttachmentService.Client(makeProtocol(BACKEND_URL, ATTACHMENT_SERVICE_URL)); + return new AttachmentService.Client(makeProtocol(ThriftConstants.BACKEND_URL, ATTACHMENT_SERVICE_URL)); } public ComponentService.Iface makeComponentClient() { - return new ComponentService.Client(makeProtocol(BACKEND_URL, COMPONENT_SERVICE_URL)); + return new ComponentService.Client(makeProtocol(ThriftConstants.BACKEND_URL, COMPONENT_SERVICE_URL)); } public CveSearchService.Iface makeCvesearchClient() { - return new CveSearchService.Client(makeProtocol(BACKEND_URL, CVESEARCH_SERVICE_URL)); + return new CveSearchService.Client(makeProtocol(ThriftConstants.BACKEND_URL, CVESEARCH_SERVICE_URL)); } public FossologyService.Iface makeFossologyClient() { - return new FossologyService.Client(makeProtocol(BACKEND_URL, FOSSOLOGY_SERVICE_URL)); + return new FossologyService.Client(makeProtocol(ThriftConstants.BACKEND_URL, FOSSOLOGY_SERVICE_URL)); } public LicenseService.Iface makeLicenseClient() { - return new LicenseService.Client(makeProtocol(BACKEND_URL, LICENSE_SERVICE_URL)); + return new LicenseService.Client(makeProtocol(ThriftConstants.BACKEND_URL, LICENSE_SERVICE_URL)); } public ModerationService.Iface makeModerationClient() { - return new ModerationService.Client(makeProtocol(BACKEND_URL, MODERATION_SERVICE_URL)); + return new ModerationService.Client(makeProtocol(ThriftConstants.BACKEND_URL, MODERATION_SERVICE_URL)); } public ProjectService.Iface makeProjectClient() { - return new ProjectService.Client(makeProtocol(BACKEND_URL, PROJECT_SERVICE_URL)); + return new ProjectService.Client(makeProtocol(ThriftConstants.BACKEND_URL, PROJECT_SERVICE_URL)); } public SearchService.Iface makeSearchClient() { - return new SearchService.Client(makeProtocol(BACKEND_URL, SEARCH_SERVICE_URL)); + return new SearchService.Client(makeProtocol(ThriftConstants.BACKEND_URL, SEARCH_SERVICE_URL)); } public UserService.Iface makeUserClient() { - return new UserService.Client(makeProtocol(BACKEND_URL, USER_SERVICE_URL)); + return new UserService.Client(makeProtocol(ThriftConstants.BACKEND_URL, USER_SERVICE_URL)); } public VendorService.Iface makeVendorClient() { - return new VendorService.Client(makeProtocol(BACKEND_URL, VENDOR_SERVICE_URL)); + return new VendorService.Client(makeProtocol(ThriftConstants.BACKEND_URL, VENDOR_SERVICE_URL)); } public ProjectImportService.Iface makeProjectImportClient() { - return new ProjectImportService.Client(makeProtocol(BACKEND_URL, PROJECTIMPORT_SERVICE_URL)); + return new ProjectImportService.Client(makeProtocol(ThriftConstants.BACKEND_URL, PROJECTIMPORT_SERVICE_URL)); } public VulnerabilityService.Iface makeVulnerabilityClient() { - return new VulnerabilityService.Client(makeProtocol(BACKEND_URL, VULNERABILITY_SERVICE_URL)); + return new VulnerabilityService.Client(makeProtocol(ThriftConstants.BACKEND_URL, VULNERABILITY_SERVICE_URL)); } public VMComponentService.Iface makeVMClient() { - return new VMComponentService.Client(makeProtocol(BACKEND_URL, VM_SERVICE_URL)); + return new VMComponentService.Client(makeProtocol(ThriftConstants.BACKEND_URL, VM_SERVICE_URL)); } public LicenseInfoService.Client makeLicenseInfoClient() { - return new LicenseInfoService.Client(makeProtocol(BACKEND_URL, LICENSEINFO_SERVICE_URL)); + return new LicenseInfoService.Client(makeProtocol(ThriftConstants.BACKEND_URL, LICENSEINFO_SERVICE_URL)); } public ScheduleService.Iface makeScheduleClient() { - return new ScheduleService.Client(makeProtocol(BACKEND_URL, SCHEDULE_SERVICE_URL)); + return new ScheduleService.Client(makeProtocol(ThriftConstants.BACKEND_URL, SCHEDULE_SERVICE_URL)); } public ProjectImportService.Iface makeWsImportClient() { - return new ProjectImportService.Client(makeProtocol(BACKEND_URL, WSIMPORT_SERVICE_URL)); + return new ProjectImportService.Client(makeProtocol(ThriftConstants.BACKEND_URL, WSIMPORT_SERVICE_URL)); } public ChangeLogsService.Iface makeChangeLogsClient() { - return new ChangeLogsService.Client(makeProtocol(BACKEND_URL, CHANGELOGS_SERVICE_URL)); + return new ChangeLogsService.Client(makeProtocol(ThriftConstants.BACKEND_URL, CHANGELOGS_SERVICE_URL)); } public HealthService.Iface makeHealthClient() { - return new HealthService.Client(makeProtocol(BACKEND_URL, HEALTH_SERVICE_URL)); + return new HealthService.Client(makeProtocol(ThriftConstants.BACKEND_URL, HEALTH_SERVICE_URL)); } public SPDXDocumentService.Iface makeSPDXClient() { - return new SPDXDocumentService.Client(makeProtocol(BACKEND_URL, SPDX_SERVICE_URL)); + return new SPDXDocumentService.Client(makeProtocol(ThriftConstants.BACKEND_URL, SPDX_SERVICE_URL)); } public DocumentCreationInformationService.Iface makeSPDXDocumentInfoClient() { - return new DocumentCreationInformationService.Client(makeProtocol(BACKEND_URL, SPDX_DOCUMENT_INFO_SERVICE_URL)); + return new DocumentCreationInformationService.Client(makeProtocol(ThriftConstants.BACKEND_URL, SPDX_DOCUMENT_INFO_SERVICE_URL)); } public PackageInformationService.Iface makeSPDXPackageInfoClient() { - return new PackageInformationService.Client(makeProtocol(BACKEND_URL, SPDX_PACKAGE_INFO_SERVICE_URL)); + return new PackageInformationService.Client(makeProtocol(ThriftConstants.BACKEND_URL, SPDX_PACKAGE_INFO_SERVICE_URL)); } public FileInformationService.Iface makeSPDXFileInfoClient() { - return new FileInformationService.Client(makeProtocol(BACKEND_URL, SPDX_FILE_INFO_SERVICE_URL)); + return new FileInformationService.Client(makeProtocol(ThriftConstants.BACKEND_URL, SPDX_FILE_INFO_SERVICE_URL)); } public PackageService.Iface makePackageClient() { - return new PackageService.Client(makeProtocol(BACKEND_URL, PACKAGE_SERVICE_URL)); + return new PackageService.Client(makeProtocol(ThriftConstants.BACKEND_URL, PACKAGE_SERVICE_URL)); } } diff --git a/libraries/datahandler/src/main/resources/sw360.properties b/libraries/datahandler/src/main/resources/sw360.properties index b69b916174..d8595e4c1f 100644 --- a/libraries/datahandler/src/main/resources/sw360.properties +++ b/libraries/datahandler/src/main/resources/sw360.properties @@ -1,5 +1,5 @@ # -# Copyright Siemens AG, 2019. Part of the SW360 Portal Project. +# Copyright Siemens AG, 2019,2024. Part of the SW360 Portal Project. # # This program and the accompanying materials are made # available under the terms of the Eclipse Public License 2.0 @@ -53,3 +53,325 @@ ## This property is used to enable the dependency management function. ## To enable the function, you should also run the migration script (scripts/migrations/060_migrate_project_dependency_network.py). #enable.flexible.project.release.relationship=true + +licenseinfo.spdxparser.use-license-info-from-files=true +mainline.state.enabled.for.user=false + +# *************************************** +# Mail Utility Properties +# *************************************** + +# if host is not set, e-mailing is disabled +MailUtil_host= +MailUtil_from=__No_Reply__@sw360.org +MailUtil_port=25 +MailUtil_enableStarttls= +MailUtil_enableSsl= +MailUtil_isAuthenticationNecessary= +MailUtil_login= +MailUtil_password= +MailUtil_enableDebug= +MailUtil_supportMailAddress= +MailUtil_smtpSSLProtocol= +MailUtil_smtpSSLTrust= + +# text patterns for mail utility +defaultBegin = \ + *** This is an automatically generated email, please do not reply. ***\n\n\ + Dear SW360-user,\n\n +defaultEnd = \ + With best regards,\n\ + SW360-support +unsubscribeNoticeBefore =\n\n*** If you do not wish to receive mails from SW360, please notify: +unsubscribeNoticeAfter =. *** + +subjectForNewModerationRequest= New moderation request +subjectForUpdateModerationRequest= Update on moderation request +subjectForAcceptedModerationRequest= Your moderation request has been accepted +subjectForDeclinedModerationRequest= Your moderation request has been declined +subjectForDeclinedUserModerationRequest= Your request for a SW360 user account has been declined +subjectForNewComponent= New component created +subjectForUpdateComponent= Component updated +subjectForNewRelease= New release created +subjectForUpdateRelease= Release updated +subjectForNewProject= New project created +subjectForUpdateProject= Project updated +subjectForNewClearingRequest= New clearing request <%s> for Project <%s> +subjectForClearingRequestComment= New comment added in clearing request <%s> for Project <%s> +subjectForUpdatedClearingRequest= Your clearing request <%s> has been updated for Project <%s> +subjectForClosedClearingRequest= Your clearing request <%s> has been closed for Project <%s> +subjectForRejectedClearingRequest= Your clearing request <%s> has been rejected for Project <%s> +subjectForUpdatedProjectWithClearingRequest= Project <%s> with clearing request <%s> updated +subjectForSuccessfulExport = Spreadsheet Export Successful + +textForSuccessfulExport = The %s spreadsheet export successfully completed. Please find the download link(%s) here. +textForNewModerationRequest= a new moderation request has been added to your SW360-account.\n\n +textForUpdateModerationRequest= \ + one of the moderation requests previously added to your \ + SW360-account has been updated.\n\n +textForAcceptedModerationRequest= your moderation request to change the %s %s has been accepted by one of the moderators.\n\n +textForDeclinedModerationRequest= your moderation request to change the %s %s has been declined by one of the moderators.\n\n +textForDeclinedUserModerationRequest= your request for a SW360 user account has been declined by one of the administrators.\n\n +textForNewComponent= a new component %s, in which you take part, has been created.\n\n +textForUpdateComponent= the component %s, in which you take part, has been updated.\n\n +textForNewRelease= a new release %s %s, in which you take part, has been created.\n\n +textForUpdateRelease= the release %s %s, in which you take part, has been updated.\n\n +textForNewProject= a new project %s %s, in which you take part, has been created.\n\n +textForUpdateProject= the project %s %s, in which you take part, has been updated.\n\n + +textForClosedClearingRequest= your clearing request with id: %s for the project %s has been closed by the clearing team.\n\n +textForRejectedClearingRequest= your clearing request with id: %s for the project %s has been rejected by the clearing team.\n\n + +# *************************************** +# SVM module Properties +# *************************************** +svm.components.url= +svm.actions.url= +svm.priorities.url= +svm.components.vulnerabilities.url= +svm.vulnerabilities.url= +svm.sw360.api.url= +svm.sw360.certificate.filename= +svm.sw360.certificate.passphrase= +svm.sw360.jks.password=changeit +svm.json.log.output.location=/tmp +svm.component.id= +mainline.component.id= +svm.component.id.key= +svm.short.status= +svm.short.status.key= +svm.scheduler.email= +svm.monitoringlist.id= + +# *************************************** +# Scheduler Properties +# *************************************** +# sync="today 00:00:00"+firstOffset, time between sync and now will be skipped +# default is 01:00 am (1*60*60=3600) +schedule.svmsync.firstOffset.seconds=3600 +# default is 24h (24*60*60sec=86400) +schedule.svmsync.interval.seconds=86400 + +# default is 02:00 am (2*60*60=7200) +schedule.svmmatch.firstOffset.seconds=7200 +# default is 24h (24*60*60sec=86400) +schedule.svmmatch.interval.seconds=86400 + +# default is 03:00 am (3*60*60=10800) +schedule.svmlistupdate.firstOffset.seconds=10800 +# default is 24h (24*60*60sec=86400) +schedule.svmlistupdate.interval.seconds=86400 + +# default is 03:00 am (3*60*60=10800) +schedule.trackingfeedback.firstOffset.seconds=10800 +# default is 24h (24*60*60sec=86400) +schedule.trackingfeedback.interval.seconds=86400 + +#in seconds of today: 0*60*60 = 0 means midnight +schedule.cvesearch.firstOffset.seconds=0 + +#in seconds: 24*60*60 = 86400 means every 24 hours +schedule.cvesearch.interval.seconds=86400 + +#general pattern for scheduling multiple services: autostart = service1,service2,service3,... +#for scheduling the cvesearchService, uncomment the following line: +#autostart = cvesearchService + +schedule.delete.attachment.firstOffset.seconds=0 + +schedule.delete.attachment.interval.seconds=86400 + +#in seconds of today: 0*60*60 = 0 means midnight +schedule.department.firstOffset.seconds=0 +#in seconds: 60*60 = 3600 means every 1 hour +schedule.department.interval.seconds=3600 + +#attachment.store.file.system.location=/opt/sw360tempattachments +#enable.attachment.store.to.file.system=false +#attachment.store.file.system.permission=rwx------ +#attachemnt.delete.no.of.days=30 + +#Uncomment the below file location if the log4j2.xml file is placed inside etc/sw360 folder. +#sw360changelog.config.file.location=/etc/sw360/log4j2.xml +enable.sw360.change.log=false +sw360changelog.output.path=sw360changelog/sw360changelog +auto.set.ecc.status=false + +##This property is used to enable mail request for projects/components report. +#send.project.spreadsheet.export.to.mail.enabled=false +#send.component.spreadsheet.export.to.mail.enabled=false + +## This property is used to enable the bulk release deleting feature. +#bulk.release.deleting.enabled=true + +## This property is used to disable the ISR generation in fossology process +disable.clearing.fossology.report.download=false + +# *************************************** +# CVE Search Properties +# *************************************** +cvesearch.host=https://cve.circl.lu +cvesearch.default.vendor.threshold=1 +cvesearch.default.product.threshold=0 +cvesearch.default.cutoff=6 + +# This is a friendly url to generate Report with Release hyperlink. +# Replace protocol, hostname and port according to setup. +release.friendly.url=http://localhost:8080/group/guest/components/-/component/release/detailRelease/releaseId + +# *************************************** +# Frontend Properties +# *************************************** + +# --------------------------------------- +# Predefined values for select boxes and +# autocompletion +# +# They are only used in the UI and not +# for validation. +# --------------------------------------- + +## Should be in sync with fossology config +#clearing.teams=org1,org2,org3 + +#component.categories=framework,SDK,big-data,build-management,cloud,content,database,graphics,http,javaee,library,mail,mobile,network-client,network-server,osgi,security,testing,virtual-machine,web-framework,xml + +#component.externalkeys=com.github.id,com.gitlab.id,purl.id + +#custommap.component.roles=Committer,Contributor,Expert + +#custommap.project.roles=Stakeholder,Analyst,Contributor,Accountant,End user,Quality manager,Test manager,Technical writer,Key user + +#custommap.release.roles=Committer,Contributor,Expert + +#custommap.release.external.externalIds= + +#domain=Application Software,Documentation,Embedded Software,Hardware,Test and Diagnostics + +## list of license identifiers from http://spdx.org/licenses +#license.identifiers=Glide,Abstyles,AFL-1.1,AFL-1.2,AFL-2.0,AFL-2.1,AFL-3.0,AMPAS,APL-1.0,Adobe-Glyph,APAFML,Adobe-2006,AGPL-1.0,Afmparse,Aladdin,ADSL,AMDPLPA,ANTLR-PD,Apache-1.0,Apache-1.1,Apache-2.0,AML,APSL-1.0,APSL-1.1,APSL-1.2,APSL-2.0,Artistic-1.0,Artistic-1.0-Perl,Artistic-1.0-cl8,Artistic-2.0,AAL,Bahyph,Barr,Beerware,BitTorrent-1.0,BitTorrent-1.1,BSL-1.0,Borceux,BSD-2-Clause,BSD-2-Clause-FreeBSD,BSD-2-Clause-NetBSD,BSD-3-Clause,BSD-3-Clause-Clear,BSD-4-Clause,BSD-Protection,BSD-3-Clause-Attribution,0BSD,BSD-4-Clause-UC,bzip2-1.0.5,bzip2-1.0.6,Caldera,CECILL-1.0,CECILL-1.1,CECILL-2.0,CECILL-2.1,CECILL-B,CECILL-C,ClArtistic,MIT-CMU,CNRI-Jython,CNRI-Python,CNRI-Python-GPL-Compatible,CPOL-1.02,CDDL-1.0,CDDL-1.1,CPAL-1.0,CPL-1.0,CATOSL-1.1,Condor-1.1,CC-BY-1.0,CC-BY-2.0,CC-BY-2.5,CC-BY-3.0,CC-BY-4.0,CC-BY-ND-1.0,CC-BY-ND-2.0,CC-BY-ND-2.5,CC-BY-ND-3.0,CC-BY-ND-4.0,CC-BY-NC-1.0,CC-BY-NC-2.0,CC-BY-NC-2.5,CC-BY-NC-3.0,CC-BY-NC-4.0,CC-BY-NC-ND-1.0,CC-BY-NC-ND-2.0,CC-BY-NC-ND-2.5,CC-BY-NC-ND-3.0,CC-BY-NC-ND-4.0,CC-BY-NC-SA-1.0,CC-BY-NC-SA-2.0,CC-BY-NC-SA-2.5,CC-BY-NC-SA-3.0,CC-BY-NC-SA-4.0,CC-BY-SA-1.0,CC-BY-SA-2.0,CC-BY-SA-2.5,CC-BY-SA-3.0,CC-BY-SA-4.0,CC0-1.0,Crossword,CrystalStacker,CUA-OPL-1.0,Cube,curl,D-FSL-1.0,diffmark,WTFPL,DOC,Dotseqn,DSDP,dvipdfm,EPL-1.0,ECL-1.0,ECL-2.0,eGenix,EFL-1.0,EFL-2.0,MIT-advertising,MIT-enna,Entessa,ErlPL-1.1,EUDatagrid,EUPL-1.0,EUPL-1.1,Eurosym,Fair,MIT-feh,Frameworx-1.0,FreeImage,FTL,FSFAP,FSFUL,FSFULLR,Giftware,GL2PS,Glulxe,AGPL-3.0,GFDL-1.1,GFDL-1.2,GFDL-1.3,GPL-1.0,GPL-2.0,GPL-3.0,LGPL-2.1,LGPL-3.0,LGPL-2.0,gnuplot,gSOAP-1.3b,HaskellReport,HPND,IBM-pibs,IPL-1.0,ICU,ImageMagick,iMatix,Imlib2,IJG,Info-ZIP,Intel-ACPI,Intel,Interbase-1.0,IPA,ISC,JasPer-2.0,JSON,LPPL-1.0,LPPL-1.1,LPPL-1.2,LPPL-1.3a,LPPL-1.3c,Latex2e,BSD-3-Clause-LBNL,Leptonica,LGPLLR,Libpng,libtiff,LAL-1.2,LAL-1.3,LiLiQ-P-1.1,LiLiQ-Rplus-1.1,LiLiQ-R-1.1,LPL-1.02,LPL-1.0,MakeIndex,MTLL,MS-PL,MS-RL,MirOS,MITNFA,MIT,Motosoto,MPL-1.0,MPL-1.1,MPL-2.0,MPL-2.0-no-copyleft-exception,mpich2,Multics,Mup,NASA-1.3,Naumen,NBPL-1.0,NetCDF,NGPL,NOSL,NPL-1.0,NPL-1.1,Newsletr,NLPL,Nokia,NPOSL-3.0,NLOD-1.0,Noweb,NRL,NTP,Nunit,OCLC-2.0,ODbL-1.0,PDDL-1.0,OCCT-PL,OGTSL,OLDAP-2.2.2,OLDAP-1.1,OLDAP-1.2,OLDAP-1.3,OLDAP-1.4,OLDAP-2.0,OLDAP-2.0.1,OLDAP-2.1,OLDAP-2.2,OLDAP-2.2.1,OLDAP-2.3,OLDAP-2.4,OLDAP-2.5,OLDAP-2.6,OLDAP-2.7,OLDAP-2.8,OML,OPL-1.0,OSL-1.0,OSL-1.1,OSL-2.0,OSL-2.1,OSL-3.0,OpenSSL,OSET-PL-2.1,PHP-3.0,PHP-3.01,Plexus,PostgreSQL,psfrag,psutils,Python-2.0,QPL-1.0,Qhull,Rdisc,RPSL-1.0,RPL-1.1,RPL-1.5,RHeCos-1.1,RSCPL,RSA-MD,Ruby,SAX-PD,Saxpath,SCEA,SWL,SMPPL,Sendmail,SGI-B-1.0,SGI-B-1.1,SGI-B-2.0,OFL-1.0,OFL-1.1,SimPL-2.0,Sleepycat,SNIA,Spencer-86,Spencer-94,Spencer-99,SMLNJ,SugarCRM-1.1.3,SISSL,SISSL-1.2,SPL-1.0,Watcom-1.0,TCL,Unlicense,TMate,TORQUE-1.1,TOSL,Unicode-TOU,UPL-1.0,NCSA,Vim,VOSTROM,VSL-1.0,W3C-19980720,W3C,Wsuipa,Xnet,X11,Xerox,XFree86-1.1,xinetd,xpp,XSkat,YPL-1.0,YPL-1.1,Zed,Zend-2.0,Zimbra-1.3,Zimbra-1.4,Zlib,zlib-acknowledgement,ZPL-1.1,ZPL-2.0,ZPL-2.1 + +#operating.systems=Android,BSD,iOS,Linux,Mac OS X,QNX,Microsoft Windows,Windows Phone,IBM z/OS + +#preferred.country.codes=DE,AT,CH,US + +#project.obligation.actions=Action 1,Action 2,Action 3 + +#programming.languages=ActionScript,AppleScript,Asp,Bash,BASIC,C,C++,C#,Cocoa,Clojure,COBOL,ColdFusion,D,Delphi,Erlang,Fortran,Go,Groovy,Haskell,JSP,Java,JavaScript,Objective-C,Ocaml,Lisp,Perl,PHP,Python,Ruby,SQL,SVG,Scala,SmallTalk,Scheme,Tcl,XML,Node.js,JSON + +#project.externalkeys=internal.id + +#clearing.team.unknown.enabled=true + +#project.obligations.enabled=true + +## used in the project import UI, comma separated list of hosts +## Example: https://some.host.domain,https://some.other.host.domain +#projectimport.hosts= + +#project.type=Customer Project,Internal Project,Product,Service,Inner Source + +#release.externalkeys=org.maven.id,com.github.id,com.gitlab.id,purl.id + +#software.platforms=Adobe AIR,Adobe Flash,Adobe Shockwave,Binary Runtime Environment for Wireless,Cocoa,Cocoa Touch,Java (software platform)|Java platform,Java Platform - Micro Edition,Java Platform - Standard Edition,Java Platform - Enterprise Edition,JavaFX,JavaFX Mobile,Microsoft XNA,Mono (software)|Mono,Mozilla Prism,.NET Framework,Silverlight,Open Web Platform,Oracle Database,Qt (framework)|Qt,SAP NetWeaver,Smartface,Vexi,Windows Runtime + +#state=Active,Phase out,Unknown + + +# --------------------------------------- +# Other +# --------------------------------------- + +## OrganizationHelper +#match.prefix=false +#enable.custom.mapping=false + +## API Token generation +#rest.apitoken.generator.enable=false +#rest.apitoken.read.validity.days=90 +#rest.apitoken.write.validity.days=30 +#rest.apitoken.hash.salt=$2a$04$Software360RestApiSalt +#rest.write.access.usergroup=Administrator +#rest.force.update.enabled=false + + +# --------------------------------------- +# Activation of components +# +# There are no default values for these +# settings therefore they should be +# configured in any case +# --------------------------------------- + +## Activation of Dynamic Components +## Possible components to be enabled: +## - org.eclipse.sw360.portal.users.TestAutoLogin (A stub for testing single sign on. Everyone will be logged in as user@sw360.org) +## - org.eclipse.sw360.portal.users.SSOAutoLogin (A single sign on class relaying on headers in the request) +## - org.eclipse.sw360.portal.users.LoginAction (Default login action. Do not disable unless you know what you are doing) +## - org.eclipse.sw360.portal.users.LandingPageAction (Liferay does not redirect to landing page when the login is taken over by SSOAutoLogin. Activate this one if using SSOAutoLogin component) +## - org.eclipse.sw360.portal.components.BuildInfoTemplateContextContributor (Provide build information of SW360 for templates) +## - org.eclipse.sw360.portal.components.FossologyCheckConnectionOnStartupHook (Checks at startup if fossology is reachable) +## - org.eclipse.sw360.portal.users.LogoutAction (Used to clear browser cookies, cache, storage upon logout) +components.activate= \ + org.eclipse.sw360.portal.users.LoginAction, \ + org.eclipse.sw360.portal.components.BuildInfoTemplateContextContributor, \ + org.eclipse.sw360.portal.components.FossologyCheckConnectionOnStartupHook + +#list of predefined tags +project.tag= + +rest.api.write.access.token.in.preferences.enabled=true +# Possible values are "ADMIN,SW360_ADMIN,CLEARING_ADMIN,CLEARING_EXPERT,ECC_ADMIN,SECURITY_ADMIN,USER" +# ADMIN by default has merge/split access +# Access follows isUserAtLeast(ROLE) +#user.role.allowed.to.merge.or.split.component=ADMIN + +# This property is used to put mapping of template to corresponding filename viz. template:filename. This +# property is optional. If there is no value. it will pick the default one. + +#org.eclipse.sw360.licensinfo.projectclearing.templatemapping= + +#Here we can put template formats such as docx,json,xml etc. +#org.eclipse.sw360.licensinfo.projectclearing.templateformat= + +## This property is used to enable the component visibility restriction feature. +#component.visibility.restriction.enabled=true + +## This property is used to enable the bulk release deleting feature. +#bulk.release.deleting.enabled=true + + +# This property is used to disable the Clearing Request feature for the projects based on project Business Unit (BU) / Group. +# Add the list of BU for which you want to disable the Clearing Request feature. +#org.eclipse.sw360.disable.clearing.request.for.project.group=DEPARTMENT + +## This property is to set the default country for Liferay +#liferay.default.country.name=unites-states +enable.security.vulnerability.monitoring=false + +## This property is used to enable the tab SPDX Document feature. +#spdx.document.enabled = false + +## This property is used to control the user role for SBOM import and export. +sbom.import.export.access.usergroup=USER + +## This property is used to set the tool name in exported CycloneDx SBOM +sw360.tool.name = SW360 + +## This property is used to set the tool vendor in exported CycloneDx SBOM +sw360.tool.vendor = Eclipse Foundation + +## This property is used to get the version of SW360 automatically from pom.xml of datahandler module. +#datahandler.pom.file.path=/META-INF/maven/org.eclipse.sw360/datahandler/pom.xml + +## This property is used to disable the package portlet feature. +#package.portlet.enabled=false + +## This property is used to control the write access user role for Packages. +package.portlet.write.access.usergroup=USER + +## This property is used to control the mail request for download license info file +#send.project.license.info.spreadsheet.export.to.mail.enabled=false + +## This property is used to control enable or disable the licenseInfoToRelease button on project page. +enable.add.license.info.to.release.button=false diff --git a/libraries/datahandler/src/test/java/org/eclipse/sw360/datahandler/permissions/ComponentPermissionsVisibilityTest.java b/libraries/datahandler/src/test/java/org/eclipse/sw360/datahandler/permissions/ComponentPermissionsVisibilityTest.java index bd5f5b217e..5c8b7881eb 100644 --- a/libraries/datahandler/src/test/java/org/eclipse/sw360/datahandler/permissions/ComponentPermissionsVisibilityTest.java +++ b/libraries/datahandler/src/test/java/org/eclipse/sw360/datahandler/permissions/ComponentPermissionsVisibilityTest.java @@ -14,7 +14,7 @@ import static org.eclipse.sw360.datahandler.thrift.Visibility.*; import static org.eclipse.sw360.datahandler.thrift.users.UserGroup.*; -import org.eclipse.sw360.datahandler.permissions.PermissionUtils; +import org.eclipse.sw360.datahandler.common.SW360Constants; import org.eclipse.sw360.datahandler.permissions.jgivens.GivenComponent; import org.eclipse.sw360.datahandler.permissions.jgivens.GivenComponent.ComponentRole; import org.eclipse.sw360.datahandler.permissions.jgivens.ThenVisible; @@ -50,10 +50,10 @@ public class ComponentPermissionsVisibilityTest extends ScenarioTest generateFromUser(User user) { grantedAuthorities.add(new SimpleGrantedAuthority(READ.getAuthority())); if (user != null) { - if (PermissionUtils.isUserAtLeast(Sw360AuthorizationServer.CONFIG_WRITE_ACCESS_USERGROUP, user)) { + if (PermissionUtils.isUserAtLeast(SW360Constants.CONFIG_WRITE_ACCESS_USERGROUP, user)) { grantedAuthorities.add(new SimpleGrantedAuthority(Sw360GrantedAuthority.WRITE.getAuthority())); } - if (PermissionUtils.isUserAtLeast(Sw360AuthorizationServer.CONFIG_ADMIN_ACCESS_USERGROUP, user)) { + if (PermissionUtils.isUserAtLeast(SW360Constants.CONFIG_ADMIN_ACCESS_USERGROUP, user)) { grantedAuthorities.add(new SimpleGrantedAuthority(Sw360GrantedAuthority.ADMIN.getAuthority())); } } @@ -60,7 +59,7 @@ public List intersectWithClient(List granted grantedAuthorities = grantedAuthorities.stream() .filter(ga -> clientScopes.contains(ga.toString())) .collect(Collectors.toList()); - + return grantedAuthorities; } diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/Sw360ResourceServer.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/Sw360ResourceServer.java index 051443da05..715e72aacf 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/Sw360ResourceServer.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/Sw360ResourceServer.java @@ -24,7 +24,6 @@ import io.swagger.v3.oas.models.security.SecurityScheme; import io.swagger.v3.oas.models.servers.Server; import org.eclipse.sw360.datahandler.common.CommonUtils; -import org.eclipse.sw360.datahandler.thrift.users.UserGroup; import org.eclipse.sw360.rest.common.PropertyUtils; import org.eclipse.sw360.rest.common.Sw360CORSFilter; import org.eclipse.sw360.rest.resourceserver.core.OpenAPIPaginationHelper; @@ -49,6 +48,8 @@ import java.util.*; +import static org.eclipse.sw360.datahandler.common.SW360Constants.REST_SERVER_PATH_URL; + @SpringBootApplication @Import(Sw360CORSFilter.class) public class Sw360ResourceServer extends SpringBootServletInitializer { @@ -58,48 +59,15 @@ public class Sw360ResourceServer extends SpringBootServletInitializer { @Value("${spring.data.rest.default-page-size:10}") private int defaultPageSize; - private static final String SW360_PROPERTIES_FILE_PATH = "/sw360.properties"; private static final String VERSION_INFO_PROPERTIES_FILE = "/restInfo.properties"; private static final String VERSION_INFO_KEY = "sw360RestVersion"; private static final String CURIE_NAMESPACE = "sw360"; private static final String APPLICATION_ID = "rest"; - public static final String API_TOKEN_HASH_SALT; - public static final String API_TOKEN_MAX_VALIDITY_READ_IN_DAYS; - public static final String API_TOKEN_MAX_VALIDITY_WRITE_IN_DAYS; - public static final UserGroup API_WRITE_ACCESS_USERGROUP; - public static final Set DOMAIN; - public static final String REPORT_FILENAME_MAPPING; - public static final String JWKS_ISSUER_URL; - public static final String JWKS_ENDPOINT_URL; - public static final Boolean IS_JWKS_VALIDATION_ENABLED; - public static final Boolean IS_FORCE_UPDATE_ENABLED; - public static final UserGroup CONFIG_WRITE_ACCESS_USERGROUP; - public static final UserGroup CONFIG_ADMIN_ACCESS_USERGROUP; - private static final String DEFAULT_WRITE_ACCESS_USERGROUP = UserGroup.SW360_ADMIN.name(); - private static final String DEFAULT_ADMIN_ACCESS_USERGROUP = UserGroup.SW360_ADMIN.name(); - private static final String SERVER_PATH_URL; private static final String APPLICATION_NAME = "/resource"; private static final Map versionInfo; static { - Properties props = CommonUtils.loadProperties(Sw360ResourceServer.class, SW360_PROPERTIES_FILE_PATH); - API_TOKEN_MAX_VALIDITY_READ_IN_DAYS = props.getProperty("rest.apitoken.read.validity.days", "90"); - API_TOKEN_MAX_VALIDITY_WRITE_IN_DAYS = props.getProperty("rest.apitoken.write.validity.days", "30"); - API_TOKEN_HASH_SALT = props.getProperty("rest.apitoken.hash.salt", "$2a$04$Software360RestApiSalt"); - API_WRITE_ACCESS_USERGROUP = UserGroup.valueOf(props.getProperty("rest.write.access.usergroup", UserGroup.ADMIN.name())); - DOMAIN = CommonUtils.splitToSet(props.getProperty("domain", - "Application Software, Documentation, Embedded Software, Hardware, Test and Diagnostics")); - REPORT_FILENAME_MAPPING = props.getProperty("org.eclipse.sw360.licensinfo.projectclearing.templatemapping", ""); - JWKS_ISSUER_URL = props.getProperty("jwks.issuer.url", null); - JWKS_ENDPOINT_URL = props.getProperty("jwks.endpoint.url", null); - IS_JWKS_VALIDATION_ENABLED = Boolean.parseBoolean(props.getProperty("jwks.validation.enabled", "false")); - IS_FORCE_UPDATE_ENABLED = Boolean.parseBoolean( - System.getProperty("RunRestForceUpdateTest", props.getProperty("rest.force.update.enabled", "false"))); - CONFIG_WRITE_ACCESS_USERGROUP = UserGroup.valueOf(props.getProperty("rest.write.access.usergroup", DEFAULT_WRITE_ACCESS_USERGROUP)); - CONFIG_ADMIN_ACCESS_USERGROUP = UserGroup.valueOf(props.getProperty("rest.admin.access.usergroup", DEFAULT_ADMIN_ACCESS_USERGROUP)); - SERVER_PATH_URL = props.getProperty("backend.url", "http://localhost:8080"); - versionInfo = new HashMap<>(); Properties properties = CommonUtils.loadProperties(Sw360ResourceServer.class, VERSION_INFO_PROPERTIES_FILE, false); versionInfo.putAll(properties); @@ -156,7 +124,7 @@ public FilterRegistrationBean forwardedHeaderFilter() { @Bean public OpenAPI customOpenAPI() { Server server = new Server(); - server.setUrl(SERVER_PATH_URL + APPLICATION_NAME + REST_BASE_PATH); + server.setUrl(REST_SERVER_PATH_URL + APPLICATION_NAME + REST_BASE_PATH); server.setDescription("Current instance."); Object restVersion = versionInfo.get(VERSION_INFO_KEY); String restVersionString = "1.0.0"; diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/SW360RestHealthIndicator.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/actuator/SW360RestHealthIndicator.java similarity index 98% rename from rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/SW360RestHealthIndicator.java rename to rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/actuator/SW360RestHealthIndicator.java index 5ef543d554..0c20191f24 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/SW360RestHealthIndicator.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/actuator/SW360RestHealthIndicator.java @@ -8,7 +8,7 @@ * SPDX-License-Identifier: EPL-2.0 */ -package org.eclipse.sw360.rest.resourceserver; +package org.eclipse.sw360.rest.resourceserver.actuator; import com.fasterxml.jackson.annotation.JsonInclude; import org.apache.thrift.TException; diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/component/Sw360ComponentService.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/component/Sw360ComponentService.java index c32b7cbf63..6a51fa31cb 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/component/Sw360ComponentService.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/component/Sw360ComponentService.java @@ -20,6 +20,7 @@ import org.apache.thrift.transport.THttpClient; import org.apache.thrift.transport.TTransportException; import org.eclipse.sw360.datahandler.common.CommonUtils; +import org.eclipse.sw360.datahandler.common.SW360Constants; import org.eclipse.sw360.datahandler.common.SW360Utils; import org.eclipse.sw360.datahandler.thrift.*; import org.eclipse.sw360.datahandler.thrift.attachments.Attachment; @@ -34,7 +35,6 @@ import org.eclipse.sw360.datahandler.thrift.components.Release; import org.eclipse.sw360.datahandler.thrift.users.User; import org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityDTO; -import org.eclipse.sw360.rest.resourceserver.Sw360ResourceServer; import org.eclipse.sw360.rest.resourceserver.core.AwareOfRestServices; import org.eclipse.sw360.rest.resourceserver.core.RestControllerHelper; import org.eclipse.sw360.rest.resourceserver.vulnerability.Sw360VulnerabilityService; @@ -147,7 +147,7 @@ public Component createComponent(Component component, User sw360User) throws TEx public RequestStatus updateComponent(Component component, User sw360User) throws TException { ComponentService.Iface sw360ComponentClient = getThriftComponentClient(); RequestStatus requestStatus; - if (Sw360ResourceServer.IS_FORCE_UPDATE_ENABLED) { + if (SW360Constants.IS_FORCE_UPDATE_ENABLED) { requestStatus = sw360ComponentClient.updateComponentWithForceFlag(component, sw360User, true); } else { requestStatus = sw360ComponentClient.updateComponent(component, sw360User); @@ -164,7 +164,7 @@ public RequestStatus updateComponent(Component component, User sw360User) throws public RequestStatus deleteComponent(String componentId, User sw360User) throws TException { ComponentService.Iface sw360ComponentClient = getThriftComponentClient(); - if (Sw360ResourceServer.IS_FORCE_UPDATE_ENABLED) { + if (SW360Constants.IS_FORCE_UPDATE_ENABLED) { return sw360ComponentClient.deleteComponentWithForceFlag(componentId, sw360User, true); } else { return sw360ComponentClient.deleteComponent(componentId, sw360User); @@ -252,7 +252,7 @@ public List getMyComponentsForUser(User sw360User) throws TException ComponentService.Iface sw360ComponentClient = getThriftComponentClient(); return sw360ComponentClient.getMyComponents(sw360User); } - + public List getVulnerabilitiesByComponent(String componentId, User sw360User) throws TException { ComponentService.Iface sw360ComponentClient = getThriftComponentClient(); List releaseIds = sw360ComponentClient.getReleaseIdsFromComponentId(componentId, sw360User); diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/ProjectController.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/ProjectController.java index 1dc8104e3f..e717a97696 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/ProjectController.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/ProjectController.java @@ -167,7 +167,6 @@ import static org.eclipse.sw360.datahandler.common.CommonUtils.wrapThriftOptionalReplacement; import static org.eclipse.sw360.datahandler.common.WrappedException.wrapTException; -import static org.eclipse.sw360.rest.resourceserver.Sw360ResourceServer.REPORT_FILENAME_MAPPING; import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; @BasePathAwareController @@ -1439,8 +1438,8 @@ public void downloadLicenseInfo( outputFormatInfo.getFileExtension()); String fileName = ""; - if (CommonUtils.isNotNullEmptyOrWhitespace(template) && CommonUtils.isNotNullEmptyOrWhitespace(REPORT_FILENAME_MAPPING)) { - Map orgToTemplate = Arrays.stream(REPORT_FILENAME_MAPPING.split(",")) + if (CommonUtils.isNotNullEmptyOrWhitespace(template) && CommonUtils.isNotNullEmptyOrWhitespace(SW360Constants.REST_REPORT_FILENAME_MAPPING)) { + Map orgToTemplate = Arrays.stream(SW360Constants.REST_REPORT_FILENAME_MAPPING.split(",")) .collect(Collectors.toMap(k -> k.split(":")[0], v -> v.split(":")[1])); fileName = orgToTemplate.get(template); } diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/Sw360ProjectService.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/Sw360ProjectService.java index b2f22779c2..93eb5c8a62 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/Sw360ProjectService.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/Sw360ProjectService.java @@ -57,7 +57,6 @@ import org.eclipse.sw360.datahandler.thrift.projects.ProjectService; import org.eclipse.sw360.datahandler.thrift.projects.ProjectProjectRelationship; import org.eclipse.sw360.datahandler.thrift.users.User; -import org.eclipse.sw360.rest.resourceserver.Sw360ResourceServer; import org.eclipse.sw360.rest.resourceserver.core.AwareOfRestServices; import org.eclipse.sw360.rest.resourceserver.core.HalResource; import org.eclipse.sw360.rest.resourceserver.core.RestControllerHelper; @@ -775,7 +774,7 @@ public RequestStatus updateProject(Project project, User sw360User) throws TExce } RequestStatus requestStatus; - if (Sw360ResourceServer.IS_FORCE_UPDATE_ENABLED) { + if (SW360Constants.IS_FORCE_UPDATE_ENABLED) { requestStatus = sw360ProjectClient.updateProjectWithForceFlag(project, sw360User, true); } else { requestStatus = sw360ProjectClient.updateProject(project, sw360User); @@ -796,7 +795,7 @@ public RequestStatus updateProject(Project project, User sw360User) throws TExce public RequestStatus deleteProject(String projectId, User sw360User) throws TException { ProjectService.Iface sw360ProjectClient = getThriftProjectClient(); - if (Sw360ResourceServer.IS_FORCE_UPDATE_ENABLED) { + if (SW360Constants.IS_FORCE_UPDATE_ENABLED) { return sw360ProjectClient.deleteProjectWithForceFlag(projectId, sw360User, true); } else { return sw360ProjectClient.deleteProject(projectId, sw360User); @@ -807,7 +806,7 @@ public void deleteAllProjects(User sw360User) throws TException { ProjectService.Iface sw360ProjectClient = getThriftProjectClient(); List projects = sw360ProjectClient.getAccessibleProjectsSummary(sw360User); for (Project project : projects) { - if (Sw360ResourceServer.IS_FORCE_UPDATE_ENABLED) { + if (SW360Constants.IS_FORCE_UPDATE_ENABLED) { sw360ProjectClient.deleteProjectWithForceFlag(project.getId(), sw360User, true); } else { sw360ProjectClient.deleteProject(project.getId(), sw360User); diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/release/Sw360ReleaseService.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/release/Sw360ReleaseService.java index 1216edc23b..1c2f3e9490 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/release/Sw360ReleaseService.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/release/Sw360ReleaseService.java @@ -37,7 +37,6 @@ import org.eclipse.sw360.datahandler.thrift.projects.ProjectService; import org.eclipse.sw360.datahandler.thrift.users.RequestedAction; import org.eclipse.sw360.datahandler.thrift.users.User; -import org.eclipse.sw360.rest.resourceserver.Sw360ResourceServer; import org.eclipse.sw360.rest.resourceserver.attachment.Sw360AttachmentService; import org.eclipse.sw360.rest.resourceserver.core.AwareOfRestServices; import org.eclipse.sw360.rest.resourceserver.core.HalResource; @@ -48,15 +47,12 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.data.rest.webmvc.ResourceNotFoundException; -import org.springframework.hateoas.Link; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.stereotype.Service; import org.springframework.util.FileCopyUtils; import static org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString; import static org.eclipse.sw360.datahandler.common.WrappedException.wrapTException; -import static org.eclipse.sw360.datahandler.permissions.PermissionUtils.makePermission; -import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -175,7 +171,7 @@ public List setComponentDependentFieldsInRelease(List releases } catch (TException e) { throw new HttpMessageNotReadableException("No Components found"); } - + for (Release release : releases) { String componentId = release.getComponentId(); if (CommonUtils.isNullEmptyOrWhitespace(componentId)) { @@ -189,7 +185,7 @@ public List setComponentDependentFieldsInRelease(List releases } return releases; } - + public List getReleaseSubscriptions(User sw360User) throws TException { ComponentService.Iface sw360ComponentClient = getThriftComponentClient(); return sw360ComponentClient.getSubscribedReleases(sw360User); @@ -248,7 +244,7 @@ public RequestStatus updateRelease(Release release, User sw360User) throws TExce rch.checkForCyclicOrInvalidDependencies(sw360ComponentClient, release, sw360User); RequestStatus requestStatus; - if (Sw360ResourceServer.IS_FORCE_UPDATE_ENABLED) { + if (SW360Constants.IS_FORCE_UPDATE_ENABLED) { requestStatus = sw360ComponentClient.updateReleaseWithForceFlag(release, sw360User, true); } else { requestStatus = sw360ComponentClient.updateRelease(release, sw360User); @@ -275,7 +271,7 @@ public RequestStatus deleteRelease(String releaseId, User sw360User) throws TExc } } - if (Sw360ResourceServer.IS_FORCE_UPDATE_ENABLED) { + if (SW360Constants.IS_FORCE_UPDATE_ENABLED) { deleteStatus = sw360ComponentClient.deleteReleaseWithForceFlag(releaseId, sw360User, true); } else { deleteStatus = sw360ComponentClient.deleteRelease(releaseId, sw360User); diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/report/SW360ReportService.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/report/SW360ReportService.java index 81436d3506..e1e739d34a 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/report/SW360ReportService.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/report/SW360ReportService.java @@ -23,7 +23,6 @@ import lombok.RequiredArgsConstructor; -import static org.eclipse.sw360.rest.resourceserver.Sw360ResourceServer.REPORT_FILENAME_MAPPING; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -233,8 +232,8 @@ public ByteBuffer getLicenseInfoBuffer(User sw360User, String id, String generat String outputGeneratorClassNameWithVariant = generatorClassName + "::" + variant; String fileName = ""; if (CommonUtils.isNotNullEmptyOrWhitespace(template) - && CommonUtils.isNotNullEmptyOrWhitespace(REPORT_FILENAME_MAPPING)) { - Map orgToTemplate = Arrays.stream(REPORT_FILENAME_MAPPING.split(",")) + && CommonUtils.isNotNullEmptyOrWhitespace(SW360Constants.REST_REPORT_FILENAME_MAPPING)) { + Map orgToTemplate = Arrays.stream(SW360Constants.REST_REPORT_FILENAME_MAPPING.split(",")) .collect(Collectors.toMap(k -> k.split(":")[0], v -> v.split(":")[1])); fileName = orgToTemplate.get(template); } @@ -297,7 +296,7 @@ private Set getExcludedLicenses(Set excludedLicense return licenseInfoParsingResult.stream().map(LicenseInfoParsingResult::getLicenseInfo) .flatMap(streamLicenseNameWithTexts).filter(filteredLicense).collect(Collectors.toSet()); } - + public ByteBuffer getLicenseResourceBundleBuffer() throws TException { return licenseClient.getLicenseReportDataStream(); } @@ -438,4 +437,4 @@ private InputStream getStreamToServeAFile(AttachmentStreamConnector attachmentSt return attachmentStreamConnector.getAttachmentBundleStream(new HashSet<>(attachments), sw360User, context); } } -} \ No newline at end of file +} diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/security/apiToken/ApiTokenAuthenticationFilter.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/security/apiToken/ApiTokenAuthenticationFilter.java index d780db3d98..cf76e5ca02 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/security/apiToken/ApiTokenAuthenticationFilter.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/security/apiToken/ApiTokenAuthenticationFilter.java @@ -12,7 +12,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.eclipse.sw360.rest.resourceserver.Sw360ResourceServer; +import org.eclipse.sw360.datahandler.common.SW360Constants; import org.springframework.context.annotation.Profile; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; @@ -58,7 +58,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha Authentication auth = new ApiTokenAuthentication(token[1]).setType(AuthType.JWKS); SecurityContextHolder.getContext().setAuthentication(auth); } - } else if (Sw360ResourceServer.IS_JWKS_VALIDATION_ENABLED && !headers.isEmpty() + } else if (SW360Constants.REST_IS_JWKS_VALIDATION_ENABLED && !headers.isEmpty() && headers.containsKey(OIDC_AUTHENTICATION_TOKEN_PARAMETER)) { String authorization = headers.get(OIDC_AUTHENTICATION_TOKEN_PARAMETER); String[] token = authorization.trim().split("\\s+"); diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/security/apiToken/ApiTokenAuthenticationProvider.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/security/apiToken/ApiTokenAuthenticationProvider.java index e176d08a53..86da0acece 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/security/apiToken/ApiTokenAuthenticationProvider.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/security/apiToken/ApiTokenAuthenticationProvider.java @@ -14,12 +14,11 @@ import org.apache.commons.lang3.time.DateUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.eclipse.sw360.datahandler.common.CommonUtils; +import org.eclipse.sw360.datahandler.common.SW360Constants; import org.eclipse.sw360.datahandler.common.SW360Utils; import org.eclipse.sw360.datahandler.thrift.users.RestApiToken; import org.eclipse.sw360.datahandler.thrift.users.User; import org.eclipse.sw360.datahandler.thrift.users.UserAccess; -import org.eclipse.sw360.rest.resourceserver.Sw360ResourceServer; import org.eclipse.sw360.rest.resourceserver.security.apiToken.ApiTokenAuthenticationFilter.ApiTokenAuthentication; import org.eclipse.sw360.rest.resourceserver.security.apiToken.ApiTokenAuthenticationFilter.AuthType; import org.eclipse.sw360.rest.resourceserver.security.jwksvalidation.JWTValidator; @@ -49,7 +48,6 @@ import java.util.stream.Stream; import static java.lang.Math.min; -import static org.eclipse.sw360.rest.resourceserver.Sw360ResourceServer.*; @Profile("!SECURITY_MOCK") @Component @@ -60,7 +58,7 @@ public class ApiTokenAuthenticationProvider implements AuthenticationProvider { @NotNull private final Sw360UserService userService; - + @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { log.info("Authenticating for the user with authentication {}", authentication); @@ -71,10 +69,10 @@ public Authentication authenticate(Authentication authentication) throws Authent // Get the corresponding sw360 user and restApiToken based on entered token String tokenFromAuthentication = (String) authentication.getCredentials(); - if (Sw360ResourceServer.IS_JWKS_VALIDATION_ENABLED && authentication instanceof ApiTokenAuthentication + if (SW360Constants.REST_IS_JWKS_VALIDATION_ENABLED && authentication instanceof ApiTokenAuthentication && ((ApiTokenAuthentication) authentication).getType() == AuthType.JWKS) { - JWTValidator validator = new JWTValidator(Sw360ResourceServer.JWKS_ISSUER_URL, - Sw360ResourceServer.JWKS_ENDPOINT_URL); + JWTValidator validator = new JWTValidator(SW360Constants.REST_JWKS_ISSUER_URL, + SW360Constants.REST_JWKS_ENDPOINT_URL); JwtClaims jwtClaims = null; try { jwtClaims = validator.validateJWT(tokenFromAuthentication); @@ -90,7 +88,7 @@ public Authentication authenticate(Authentication authentication) throws Authent User sw360User = getUserFromClientId(clientIdAsStr); return authenticatedOidcUser(sw360User, clientIdAsStr); } else { - String tokenHash = BCrypt.hashpw(tokenFromAuthentication, API_TOKEN_HASH_SALT); + String tokenHash = BCrypt.hashpw(tokenFromAuthentication, SW360Constants.REST_API_TOKEN_HASH_SALT); User sw360User = getUserFromTokenHash(tokenHash); if (sw360User == null || sw360User.isDeactivated()) { throw new DisabledException("User is deactivated"); @@ -130,7 +128,7 @@ private User getUserFromClientId(String clientId) { "Your entered OIDC token is not associated with any user for authorization."); } } - + private Optional getApiTokenFromUser(String tokenHash, User sw360User) { return sw360User.getRestApiTokens() .stream() @@ -140,7 +138,7 @@ private Optional getApiTokenFromUser(String tokenHash, User sw360U private boolean isApiTokenExpired(RestApiToken restApiToken) { String configExpireDays = restApiToken.getAuthorities().contains("WRITE") ? - API_TOKEN_MAX_VALIDITY_WRITE_IN_DAYS : API_TOKEN_MAX_VALIDITY_READ_IN_DAYS; + SW360Constants.REST_API_TOKEN_MAX_VALIDITY_WRITE_IN_DAYS : SW360Constants.REST_API_TOKEN_MAX_VALIDITY_READ_IN_DAYS; Date createdOn = SW360Utils.getDateFromTimeString(restApiToken.createdOn); Date tokenExpireDate = DateUtils.addDays(createdOn, min(restApiToken.getNumberOfDaysValid(), Integer.parseInt(configExpireDays))); @@ -153,7 +151,7 @@ private Set getGrantedAuthoritiesFromApiToken(RestApiToken res .map(SimpleGrantedAuthority::new) .collect(Collectors.toSet()); } - + private Set getGrantedAuthoritiesFromUserAccess(UserAccess userAccess) { return Stream.of(userAccess.name().split("_")) .map(SimpleGrantedAuthority::new) diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/security/basic/Sw360GrantedAuthoritiesCalculator.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/security/basic/Sw360GrantedAuthoritiesCalculator.java index 4f2f5a4aea..98d8646bab 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/security/basic/Sw360GrantedAuthoritiesCalculator.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/security/basic/Sw360GrantedAuthoritiesCalculator.java @@ -9,9 +9,9 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.eclipse.sw360.datahandler.common.SW360Constants; import org.eclipse.sw360.datahandler.permissions.PermissionUtils; import org.eclipse.sw360.datahandler.thrift.users.User; -import org.eclipse.sw360.rest.resourceserver.Sw360ResourceServer; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; @@ -29,11 +29,11 @@ public static List generateFromUser(User user) { grantedAuthorities.add(new SimpleGrantedAuthority(Sw360GrantedAuthority.READ.getAuthority())); if (user != null) { - if (PermissionUtils.isUserAtLeast(Sw360ResourceServer.CONFIG_WRITE_ACCESS_USERGROUP, user)) { + if (PermissionUtils.isUserAtLeast(SW360Constants.CONFIG_WRITE_ACCESS_USERGROUP, user)) { log.debug("User {} has write access", user.getEmail()); grantedAuthorities.add(new SimpleGrantedAuthority(Sw360GrantedAuthority.WRITE.getAuthority())); } - if (PermissionUtils.isUserAtLeast(Sw360ResourceServer.CONFIG_ADMIN_ACCESS_USERGROUP, user)) { + if (PermissionUtils.isUserAtLeast(SW360Constants.CONFIG_ADMIN_ACCESS_USERGROUP, user)) { log.debug("User {} has admin access", user.getEmail()); grantedAuthorities.add(new SimpleGrantedAuthority(Sw360GrantedAuthority.ADMIN.getAuthority())); } diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/user/Sw360UserService.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/user/Sw360UserService.java index 4fca7772d2..b38308e241 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/user/Sw360UserService.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/user/Sw360UserService.java @@ -18,6 +18,7 @@ import org.apache.thrift.transport.THttpClient; import org.apache.thrift.transport.TTransportException; import org.eclipse.sw360.datahandler.common.CommonUtils; +import org.eclipse.sw360.datahandler.common.SW360Constants; import org.eclipse.sw360.datahandler.common.SW360Utils; import org.eclipse.sw360.datahandler.permissions.PermissionUtils; import org.eclipse.sw360.datahandler.thrift.AddDocumentRequestStatus; @@ -32,7 +33,6 @@ import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.stereotype.Service; -import java.util.Collection; import java.time.LocalDate; import java.time.temporal.ChronoUnit; import java.util.List; @@ -40,10 +40,6 @@ import java.util.Map; import java.util.stream.Collectors; -import static org.eclipse.sw360.rest.resourceserver.Sw360ResourceServer.API_TOKEN_MAX_VALIDITY_READ_IN_DAYS; -import static org.eclipse.sw360.rest.resourceserver.Sw360ResourceServer.API_TOKEN_MAX_VALIDITY_WRITE_IN_DAYS; -import static org.eclipse.sw360.rest.resourceserver.Sw360ResourceServer.API_WRITE_ACCESS_USERGROUP; - @Service public class Sw360UserService { @Value("${sw360.thrift-server-url:http://localhost:8080}") @@ -217,7 +213,7 @@ public boolean isTokenNameExisted(User user, String tokenName) { private boolean isValidExpireDays(RestApiToken restApiToken) { String configExpireDays = restApiToken.getAuthorities().contains(AUTHORITIES_WRITE) ? - API_TOKEN_MAX_VALIDITY_WRITE_IN_DAYS : API_TOKEN_MAX_VALIDITY_READ_IN_DAYS; + SW360Constants.REST_API_TOKEN_MAX_VALIDITY_WRITE_IN_DAYS : SW360Constants.REST_API_TOKEN_MAX_VALIDITY_READ_IN_DAYS; try { return restApiToken.getNumberOfDaysValid() >= 0 && @@ -243,7 +239,7 @@ private void validateRestApiToken(RestApiToken restApiToken, User sw360User) { if (restApiToken.getAuthorities().contains(AUTHORITIES_WRITE)) { // User needs at least the role which is defined in sw360.properties (default admin) - if (!PermissionUtils.isUserAtLeast(API_WRITE_ACCESS_USERGROUP, sw360User)) + if (!PermissionUtils.isUserAtLeast(SW360Constants.CONFIG_WRITE_ACCESS_USERGROUP, sw360User)) throw new IllegalArgumentException("User permission [WRITE] is not allowed for user"); if (!isValidExpireDays(restApiToken)) { throw new IllegalArgumentException("Token expiration days is not valid for user"); diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/user/UserController.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/user/UserController.java index 5ea5261767..506f203708 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/user/UserController.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/user/UserController.java @@ -58,7 +58,6 @@ import java.net.URISyntaxException; import java.net.URLDecoder; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -67,7 +66,6 @@ import java.util.Collections; import java.util.stream.Collectors; -import static org.eclipse.sw360.rest.resourceserver.Sw360ResourceServer.API_TOKEN_HASH_SALT; import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; @BasePathAwareController @@ -344,7 +342,7 @@ public ResponseEntity createUserRestApiToken( User sw360User = restControllerHelper.getSw360UserFromAuthentication(); RestApiToken restApiToken = userService.convertToRestApiToken(requestBody, sw360User); String token = RandomStringUtils.random(20, true, true); - restApiToken.setToken(BCrypt.hashpw(token, API_TOKEN_HASH_SALT)); + restApiToken.setToken(BCrypt.hashpw(token, SW360Constants.REST_API_TOKEN_HASH_SALT)); sw360User.addToRestApiTokens(restApiToken); userService.updateUser(sw360User); diff --git a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/SW360RestHealthIndicatorTest.java b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/actuator/SW360RestHealthIndicatorTest.java similarity index 98% rename from rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/SW360RestHealthIndicatorTest.java rename to rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/actuator/SW360RestHealthIndicatorTest.java index ed2db2ebb5..80602f8f74 100644 --- a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/SW360RestHealthIndicatorTest.java +++ b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/actuator/SW360RestHealthIndicatorTest.java @@ -7,7 +7,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.eclipse.sw360.rest.resourceserver; +package org.eclipse.sw360.rest.resourceserver.actuator; import org.apache.thrift.TException; import org.apache.thrift.transport.TTransportException; @@ -16,6 +16,7 @@ import org.eclipse.sw360.datahandler.thrift.health.Health; import org.eclipse.sw360.datahandler.thrift.health.HealthService; import org.eclipse.sw360.datahandler.thrift.health.Status; +import org.eclipse.sw360.rest.resourceserver.Sw360ResourceServer; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/HealthSpecTest.java b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/HealthSpecTest.java index 87a4b538d7..a608e6464d 100644 --- a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/HealthSpecTest.java +++ b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/HealthSpecTest.java @@ -9,7 +9,7 @@ */ package org.eclipse.sw360.rest.resourceserver.restdocs; -import org.eclipse.sw360.rest.resourceserver.SW360RestHealthIndicator; +import org.eclipse.sw360.rest.resourceserver.actuator.SW360RestHealthIndicator; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.actuate.health.Health; diff --git a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ProjectSpecTest.java b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ProjectSpecTest.java index 5533d1fdab..08fba187fb 100644 --- a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ProjectSpecTest.java +++ b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ProjectSpecTest.java @@ -999,7 +999,7 @@ public void should_document_get_projects_with_all_details() throws Exception { subsectionWithPath("_embedded.sw360:projects.[]createdOn").description("The date the project was created"), subsectionWithPath("_embedded.sw360:projects.[]description").description("The project description"), subsectionWithPath("_embedded.sw360:projects.[]projectType").description("The project type, possible values are: " + Arrays.asList(ProjectType.values())), - subsectionWithPath("_embedded.sw360:projects.[]domain").description("The domain, possible values are:" + Sw360ResourceServer.DOMAIN.toString()).optional(), + subsectionWithPath("_embedded.sw360:projects.[]domain").description("The domain, possible values are:" + SW360Constants.DOMAIN).optional(), subsectionWithPath("_embedded.sw360:projects.[]visibility").description("The project visibility, possible values are: " + Arrays.asList(Visibility.values())), subsectionWithPath("_embedded.sw360:projects.[]businessUnit").description("The business unit this project belongs to"), subsectionWithPath("_embedded.sw360:projects.[]externalIds").description("When projects are imported from other tools, the external ids can be stored here. Store as 'Single String' when single value, or 'Array of String' when multi-values"), @@ -1066,7 +1066,7 @@ public void should_document_get_project() throws Exception { fieldWithPath("createdOn").description("The date the project was created"), fieldWithPath("description").description("The project description"), fieldWithPath("projectType").description("The project type, possible values are: " + Arrays.asList(ProjectType.values())), - fieldWithPath("domain").description("The domain, possible values are:" + Sw360ResourceServer.DOMAIN.toString()), + fieldWithPath("domain").description("The domain, possible values are:" + SW360Constants.DOMAIN), fieldWithPath("visibility").description("The project visibility, possible values are: " + Arrays.asList(Visibility.values())), fieldWithPath("businessUnit").description("The business unit this project belongs to"), subsectionWithPath("externalIds").description("When projects are imported from other tools, the external ids can be stored here. Store as 'Single String' when single value, or 'Array of String' when multi-values"), @@ -1989,7 +1989,7 @@ public void should_document_update_project() throws Exception { fieldWithPath("version").description("The project version"), fieldWithPath("createdOn").description("The date the project was created"), fieldWithPath("description").description("The project description"), - fieldWithPath("domain").description("The domain, possible values are:" + Sw360ResourceServer.DOMAIN.toString()), + fieldWithPath("domain").description("The domain, possible values are:" + SW360Constants.DOMAIN), fieldWithPath("projectType").description("The project type, possible values are: " + Arrays.asList(ProjectType.values())), fieldWithPath("visibility").description("The project visibility, possible values are: " @@ -2159,7 +2159,7 @@ public void should_document_get_download_license_info() throws Exception { parameterWithName("externalIds").description("The external Ids of the project") ))); } - + @Test public void should_document_get_download_license_info_without_release_version() throws Exception { this.mockMvc.perform(get("/api/projects/" + project.getId()+ "/licenseinfo?generatorClassName=XhtmlGenerator&variant=DISCLOSURE&excludeReleaseVersion=true") @@ -2404,7 +2404,7 @@ public void should_document_create_summary_administration() throws Exception { fieldWithPath("version").description("The project version"), fieldWithPath("createdOn").description("The date the project was created"), fieldWithPath("projectType").description("The project type, possible values are: " + Arrays.asList(ProjectType.values())), - fieldWithPath("domain").description("The domain, possible values are:" + Sw360ResourceServer.DOMAIN.toString()), + fieldWithPath("domain").description("The domain, possible values are:" + SW360Constants.DOMAIN), fieldWithPath("visibility").description("The project visibility, possible values are: " + Arrays.asList(Visibility.values())), subsectionWithPath("externalIds").description("When projects are imported from other tools, the external ids can be stored here. Store as 'Single String' when single value, or 'Array of String' when multi-values"), subsectionWithPath("additionalData").description("A place to store additional data used by external tools"), @@ -2531,7 +2531,7 @@ public void should_document_get_project_with_dependencies_network() throws Excep fieldWithPath("createdOn").description("The date the project was created"), fieldWithPath("description").description("The project description"), fieldWithPath("projectType").description("The project type, possible values are: " + Arrays.asList(ProjectType.values())), - fieldWithPath("domain").description("The domain, possible values are:" + Sw360ResourceServer.DOMAIN.toString()), + fieldWithPath("domain").description("The domain, possible values are:" + SW360Constants.DOMAIN), fieldWithPath("visibility").description("The project visibility, possible values are: " + Arrays.asList(Visibility.values())), fieldWithPath("businessUnit").description("The business unit this project belongs to"), subsectionWithPath("externalIds").description("When projects are imported from other tools, the external ids can be stored here. Store as 'Single String' when single value, or 'Array of String' when multi-values"), @@ -2703,7 +2703,7 @@ public void should_document_update_project_with_network() throws Exception { fieldWithPath("version").description("The project version"), fieldWithPath("createdOn").description("The date the project was created"), fieldWithPath("description").description("The project description"), - fieldWithPath("domain").description("The domain, possible values are:" + Sw360ResourceServer.DOMAIN.toString()), + fieldWithPath("domain").description("The domain, possible values are:" + SW360Constants.DOMAIN), fieldWithPath("projectType").description("The project type, possible values are: " + Arrays.asList(ProjectType.values())), fieldWithPath("visibility").description("The project visibility, possible values are: " From 95397c9ead804e6f8fb1a8e031c2466461cb12de Mon Sep 17 00:00:00 2001 From: Gaurav Mishra Date: Mon, 2 Dec 2024 15:49:18 +0530 Subject: [PATCH 3/4] feat(api): expose properties as /config actuator Add a new actuator at `/config` to expose the contents of properties files. Signed-off-by: Gaurav Mishra --- .../actuator/SW360ConfigActuator.java | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/actuator/SW360ConfigActuator.java diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/actuator/SW360ConfigActuator.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/actuator/SW360ConfigActuator.java new file mode 100644 index 0000000000..03429cff1f --- /dev/null +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/actuator/SW360ConfigActuator.java @@ -0,0 +1,85 @@ +/* + * Copyright Siemens AG, 2024. Part of the SW360 Portal Project. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ + +package org.eclipse.sw360.rest.resourceserver.actuator; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.sw360.datahandler.common.SW360Constants; +import org.springframework.boot.actuate.endpoint.annotation.Endpoint; +import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; +import org.springframework.boot.actuate.endpoint.annotation.Selector; +import org.springframework.stereotype.Component; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +@Component +@Endpoint(id = "config") +public class SW360ConfigActuator { + + private final Map properties = new ConcurrentHashMap<>(); + + public SW360ConfigActuator() { + properties.put("admin.private.project.access.enabled", String.valueOf(SW360Constants.IS_ADMIN_PRIVATE_ACCESS_ENABLED)); + properties.put("clearing.teams", SW360Constants.CLEARING_TEAMS); + properties.put("clearing.team.unknown.enabled", String.valueOf(SW360Constants.CLEARING_TEAM_UNKNOWN_ENABLED)); + properties.put("component.categories", StringUtils.join(SW360Constants.COMPONENT_CATEGORIES, ",")); + properties.put("component.externalkeys", StringUtils.join(SW360Constants.COMPONENT_EXTERNAL_ID_KEYS, ",")); + properties.put("component.visibility.restriction.enabled", String.valueOf(SW360Constants.IS_COMPONENT_VISIBILITY_RESTRICTION_ENABLED)); + properties.put("components.activate", StringUtils.join(SW360Constants.COMPONENTS_ACTIVATE, ",")); + properties.put("custommap.component.roles", StringUtils.join(SW360Constants.COMPONENT_ROLES, ",")); + properties.put("custommap.project.roles", StringUtils.join(SW360Constants.PROJECT_ROLES, ",")); + properties.put("custommap.release.externalIds", StringUtils.join(SW360Constants.RELEASE_EXTERNAL_IDS, ",")); + properties.put("custommap.release.roles", StringUtils.join(SW360Constants.RELEASE_ROLES, ",")); + properties.put("custom.welcome.page.guideline", String.valueOf(SW360Constants.CUSTOM_WELCOME_PAGE_GUIDELINE)); + properties.put("disable.clearing.fossology.report.download", String.valueOf(SW360Constants.DISABLE_CLEARING_FOSSOLOGY_REPORT_DOWNLOAD)); + properties.put("domain", StringUtils.join(SW360Constants.DOMAIN, ", ")); + properties.put("enable.add.license.info.to.release.button", String.valueOf(SW360Constants.ENABLE_ADD_LIC_INFO_TO_RELEASE)); + properties.put("enable.security.vulnerability.monitoring", String.valueOf(SW360Constants.IS_SVM_ENABLED)); + properties.put("license.identifiers", StringUtils.join(SW360Constants.LICENSE_IDENTIFIERS, ",")); + properties.put("mainline.state.enabled.for.user", String.valueOf(SW360Constants.MAINLINE_STATE_ENABLED_FOR_USER)); + properties.put("operating.systems", StringUtils.join(SW360Constants.OPERATING_SYSTEMS, ",")); + properties.put("org.eclipse.sw360.disable.clearing.request.for.project.group", String.valueOf(SW360Constants.DISABLE_CLEARING_REQUEST_FOR_PROJECT_WITH_GROUPS)); + properties.put("org.eclipse.sw360.licensinfo.header.by.group", SW360Constants.LICENSE_INFO_HEADER_TEXT_FILE_NAME_BY_PROJECT_GROUP); + properties.put("org.eclipse.sw360.licensinfo.projectclearing.templateformat", SW360Constants.CLEARING_REPORT_TEMPLATE_FORMAT); + properties.put("org.eclipse.sw360.licensinfo.projectclearing.templatemapping", SW360Constants.REST_REPORT_FILENAME_MAPPING); + properties.put("programming.languages", StringUtils.join(SW360Constants.PROGRAMMING_LANGUAGES, ",")); + properties.put("project.externalkeys", StringUtils.join(SW360Constants.PROJECT_EXTERNAL_ID_KEYS, ",")); + properties.put("project.externalurls", StringUtils.join(SW360Constants.PROJECT_EXTERNAL_URL_KEYS, ",")); + properties.put("projectimport.hosts", SW360Constants.PROJECTIMPORT_HOSTS); + properties.put("project.obligation.actions", StringUtils.join(SW360Constants.PROJECT_OBLIGATIONS_ACTION_SET, ",")); + properties.put("project.obligations.enabled", String.valueOf(SW360Constants.IS_PROJECT_OBLIGATIONS_ENABLED)); + properties.put("project.tag", StringUtils.join(SW360Constants.PREDEFINED_TAGS, ",")); + properties.put("project.type", StringUtils.join(SW360Constants.PROJECT_TYPE, ",")); + properties.put("relationship.type", StringUtils.join(SW360Constants.SET_RELATIONSHIP_TYPE, ",")); + properties.put("release.externalkeys", StringUtils.join(SW360Constants.RELEASE_EXTERNAL_ID_KEYS, ",")); + properties.put("rest.apitoken.generator.enable", String.valueOf(SW360Constants.REST_API_TOKEN_GENERATOR_ENABLE)); + properties.put("rest.apitoken.read.validity.days", SW360Constants.REST_API_TOKEN_MAX_VALIDITY_READ_IN_DAYS); + properties.put("rest.apitoken.write.validity.days", SW360Constants.REST_API_TOKEN_MAX_VALIDITY_WRITE_IN_DAYS); + properties.put("rest.api.write.access.token.in.preferences.enabled", String.valueOf(SW360Constants.REST_API_WRITE_ACCESS_TOKEN_ENABLE)); + properties.put("rest.force.update.enabled", String.valueOf(SW360Constants.IS_FORCE_UPDATE_ENABLED)); + properties.put("rest.write.access.usergroup", SW360Constants.CONFIG_WRITE_ACCESS_USERGROUP.name()); + properties.put("send.component.spreadsheet.export.to.mail.enabled", String.valueOf(SW360Constants.MAIL_REQUEST_FOR_COMPONENT_REPORT)); + properties.put("send.project.spreadsheet.export.to.mail.enabled", String.valueOf(SW360Constants.MAIL_REQUEST_FOR_PROJECT_REPORT)); + properties.put("software.platforms", StringUtils.join(SW360Constants.SOFTWARE_PLATFORMS, ",")); + properties.put("state", StringUtils.join(SW360Constants.STATE, ",")); + properties.put("user.role.allowed.to.merge.or.split.component", SW360Constants.USER_ROLE_ALLOWED_TO_MERGE_OR_SPLIT_COMPONENT.name()); + } + + @ReadOperation + public Map config() { + return properties; + } + + @ReadOperation + public String config(@Selector String name) { + return properties.get(name); + } +} From fb171c99dc6c03c40f7a761f70c2535e6c286ab8 Mon Sep 17 00:00:00 2001 From: Gaurav Mishra Date: Mon, 2 Dec 2024 16:48:50 +0530 Subject: [PATCH 4/4] test(config): add test docs for /config actuator Signed-off-by: Gaurav Mishra --- .../src/docs/asciidoc/api-guide.adoc | 1 + .../src/docs/asciidoc/config.adoc | 46 +++++++++++ .../resourceserver/Sw360ResourceServer.java | 37 ++++++++- .../actuator/SW360ConfigActuator.java | 3 +- .../security/ResourceServerConfiguration.java | 4 +- .../src/main/resources/application.yml | 3 +- .../actuator/SW360ConfigActuatorTest.java | 64 +++++++++++++++ ...Sw360AuthorizationServerConfiguration.java | 2 + .../restdocs/ConfigSpecTest.java | 79 +++++++++++++++++++ .../src/test/resources/application.yml | 3 +- 10 files changed, 237 insertions(+), 5 deletions(-) create mode 100644 rest/resource-server/src/docs/asciidoc/config.adoc create mode 100644 rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/actuator/SW360ConfigActuatorTest.java create mode 100644 rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ConfigSpecTest.java diff --git a/rest/resource-server/src/docs/asciidoc/api-guide.adoc b/rest/resource-server/src/docs/asciidoc/api-guide.adoc index 17fafca60d..9439b133f7 100644 --- a/rest/resource-server/src/docs/asciidoc/api-guide.adoc +++ b/rest/resource-server/src/docs/asciidoc/api-guide.adoc @@ -300,6 +300,7 @@ include::vendors.adoc[] include::licenses.adoc[] include::vulnerabilities.adoc[] include::health.adoc[] +include::config.adoc[] include::search.adoc[] include::changeLogs.adoc[] include::clearingRequests.adoc[] diff --git a/rest/resource-server/src/docs/asciidoc/config.adoc b/rest/resource-server/src/docs/asciidoc/config.adoc new file mode 100644 index 0000000000..a61e636606 --- /dev/null +++ b/rest/resource-server/src/docs/asciidoc/config.adoc @@ -0,0 +1,46 @@ +// +// Copyright Siemens AG, 2024. Part of the SW360 Portal Project. +// +// This program and the accompanying materials are made +// available under the terms of the Eclipse Public License 2.0 +// which is available at https://www.eclipse.org/legal/epl-2.0/ +// +// SPDX-License-Identifier: EPL-2.0 +// +[[resources-config]] +=== Config + +The config resource is used to give information from the `sw360.properties` file. +The configurations exposed are useful for the frontend UI. The backend only configs are not exposed. + +[[resources-config-get]] +==== Getting config + +A `GET` request will get the service's configurations. + +===== Example request +include::{snippets}/should_document_get_config/curl-request.adoc[] + +The response structure is the config object of the config actuator. + +===== Response structure +include::{snippets}/should_document_get_config/response-fields.adoc[] + +===== Example response +include::{snippets}/should_document_get_config/http-response.adoc[] + +The response structure is not complete as it will grow overtime. But it is a key-value pair of strings. + +[[resources-config-get-single]] +==== Getting single config value + +A `GET` request will get the service's single configuration. + +===== Request Parameters +include::{snippets}/should_document_get_single_config/path-parameters.adoc[] + +===== Example request +include::{snippets}/should_document_get_single_config/curl-request.adoc[] + +===== Example response +include::{snippets}/should_document_get_single_config/http-response.adoc[] diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/Sw360ResourceServer.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/Sw360ResourceServer.java index 715e72aacf..8f1db1f514 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/Sw360ResourceServer.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/Sw360ResourceServer.java @@ -19,6 +19,7 @@ import io.swagger.v3.oas.models.media.Content; import io.swagger.v3.oas.models.media.MediaType; import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.parameters.PathParameter; import io.swagger.v3.oas.models.responses.ApiResponse; import io.swagger.v3.oas.models.responses.ApiResponses; import io.swagger.v3.oas.models.security.SecurityScheme; @@ -151,7 +152,7 @@ public OpenAPI customOpenAPI() { .responses(new ApiResponses().addApiResponse("200", new ApiResponse().description("OK") .content(new Content() - .addMediaType("application/json", new MediaType() + .addMediaType(org.springframework.http.MediaType.APPLICATION_JSON_VALUE, new MediaType() .example(""" { "status": "UP", @@ -174,6 +175,40 @@ public OpenAPI customOpenAPI() { .schema(new Schema()) )) )) + )) + .path("/config", new PathItem().get( + new Operation().tags(Collections.singletonList("Health")) + .summary("Configuration properties").operationId("get-config") + .responses(new ApiResponses().addApiResponse("200", + new ApiResponse().description("OK") + .content(new Content() + .addMediaType(org.springframework.http.MediaType.APPLICATION_JSON_VALUE, new MediaType() + .example(""" + { + "property.1": "value1", + "property.2": "false", + "property.3": "value3,value4" + } + """) + .schema(new Schema>()) + )) + )) + )) + .path("/config/{key}", new PathItem().get( + new Operation().tags(Collections.singletonList("Health")) + .summary("Get single configuration property").operationId("get-single-config") + .addParametersItem(new PathParameter() + .required(true).in("path").description("Property key").example("operating.systems") + .name("key") + ) + .responses(new ApiResponses().addApiResponse("200", + new ApiResponse().description("OK") + .content(new Content() + .addMediaType(org.springframework.http.MediaType.TEXT_PLAIN_VALUE, new MediaType() + .example("Android,BSD,iOS,Linux,OS X,QNX,Microsoft Windows,Windows Phone,IBM z/OS") + .schema(new Schema>()) + )) + )) )); } } diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/actuator/SW360ConfigActuator.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/actuator/SW360ConfigActuator.java index 03429cff1f..056265228b 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/actuator/SW360ConfigActuator.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/actuator/SW360ConfigActuator.java @@ -15,6 +15,7 @@ import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import org.springframework.boot.actuate.endpoint.annotation.Selector; +import org.springframework.http.MediaType; import org.springframework.stereotype.Component; import java.util.Map; @@ -78,7 +79,7 @@ public Map config() { return properties; } - @ReadOperation + @ReadOperation(produces = MediaType.TEXT_PLAIN_VALUE) public String config(@Selector String name) { return properties.get(name); } diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/security/ResourceServerConfiguration.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/security/ResourceServerConfiguration.java index b9ac930ad0..dcec42a1fd 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/security/ResourceServerConfiguration.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/security/ResourceServerConfiguration.java @@ -62,7 +62,7 @@ public class ResourceServerConfiguration { public WebSecurityCustomizer webSecurityCustomizer() { return (web) -> web.ignoring().requestMatchers("/", "/*/*.html", "/*/*.css", "/*/*.js", "/*.js", "/*.json", "/*/*.json", "/*/*.png", "/*/*.gif", "/*/*.ico", "/*/*.woff/*", "/*/*.ttf", "/*/*.html", "/*/*/*.html", - "/*/*.yaml", "/v3/api-docs/**", "/api/health", "/api/info"); + "/*/*.yaml", "/v3/api-docs/**", "/api/health", "/api/info", "/api/config", "/api/config/*"); } @Bean @@ -84,6 +84,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti return http.addFilterBefore(filter, BasicAuthenticationFilter.class).authorizeHttpRequests(auth -> { auth.requestMatchers(HttpMethod.GET, "/api/health").permitAll(); auth.requestMatchers(HttpMethod.GET, "/api/info").hasAuthority("WRITE"); + auth.requestMatchers(HttpMethod.GET, "/api/config").permitAll(); + auth.requestMatchers(HttpMethod.GET, "/api/config/*").permitAll(); auth.requestMatchers(HttpMethod.GET, "/api").permitAll(); auth.requestMatchers(HttpMethod.GET, "/api/reports/download").permitAll(); auth.requestMatchers(HttpMethod.GET, "/api/**").hasAuthority("READ"); diff --git a/rest/resource-server/src/main/resources/application.yml b/rest/resource-server/src/main/resources/application.yml index 02d3c90f62..8ebfb080db 100644 --- a/rest/resource-server/src/main/resources/application.yml +++ b/rest/resource-server/src/main/resources/application.yml @@ -19,10 +19,11 @@ management: web: base-path: / exposure: - include: health,info + include: health,info,config path-mapping: health: /api/health info: /api/info + config: /api/config endpoint: health: show-details: always diff --git a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/actuator/SW360ConfigActuatorTest.java b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/actuator/SW360ConfigActuatorTest.java new file mode 100644 index 0000000000..1fbb952b52 --- /dev/null +++ b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/actuator/SW360ConfigActuatorTest.java @@ -0,0 +1,64 @@ +/* + * Copyright Siemens AG, 2024. Part of the SW360 Portal Project. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.sw360.rest.resourceserver.actuator; + +import org.eclipse.sw360.rest.resourceserver.Sw360ResourceServer; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.SpyBean; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.test.web.server.LocalServerPort; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.Map; + +import static org.assertj.core.api.BDDAssertions.then; + +/* @DirtiesContext is necessary because the context needs to be reloaded inbetween the tests + otherwise the responses of previous tests are taken. NoOpCacheManager through @AutoConfigureCache + was not enough to avoid this bug. + */ +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Sw360ResourceServer.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class SW360ConfigActuatorTest { + + @LocalServerPort + private int port; + + @SpyBean + private SW360ConfigActuator restConfigActuatorMock; + + @Autowired + private TestRestTemplate testRestTemplate; + + /** + * Makes a request to localhost with the default server port and returns + * the response as a response entity with type Map + * @param endpoint endpoint that will be called + * @return response of request + */ + private ResponseEntity getMapResponseEntityForHealthEndpointRequest(String endpoint) { + return this.testRestTemplate.getForEntity( + "http://localhost:" + this.port + Sw360ResourceServer.REST_BASE_PATH + endpoint, Map.class); + } + + @Test + public void config_should_return_200() { + ResponseEntity entity = getMapResponseEntityForHealthEndpointRequest("/config"); + + then(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + } +} diff --git a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/configuration/security/Sw360AuthorizationServerConfiguration.java b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/configuration/security/Sw360AuthorizationServerConfiguration.java index 21b51000f7..81deb7543f 100644 --- a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/configuration/security/Sw360AuthorizationServerConfiguration.java +++ b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/configuration/security/Sw360AuthorizationServerConfiguration.java @@ -42,6 +42,8 @@ public SecurityFilterChain appSecurtiy(HttpSecurity httpSecurity) throws Excepti authz -> authz .requestMatchers(HttpMethod.GET, "/api/health").permitAll() .requestMatchers(HttpMethod.GET, "/api/info").permitAll() + .requestMatchers(HttpMethod.GET, "/api/config").permitAll() + .requestMatchers(HttpMethod.GET, "/api/config/*").permitAll() .anyRequest().authenticated() ).httpBasic(Customizer.withDefaults()).formLogin(Customizer.withDefaults()) .exceptionHandling(x -> x.authenticationEntryPoint(saep)); diff --git a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ConfigSpecTest.java b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ConfigSpecTest.java new file mode 100644 index 0000000000..12d815bcd6 --- /dev/null +++ b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ConfigSpecTest.java @@ -0,0 +1,79 @@ +/* + * Copyright Siemens AG, 2024. Part of the SW360 Portal Project. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.sw360.rest.resourceserver.restdocs; + +import org.eclipse.sw360.rest.resourceserver.actuator.SW360ConfigActuator; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import java.util.HashMap; +import java.util.Map; + +import static org.mockito.BDDMockito.given; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; +import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@RunWith(SpringJUnit4ClassRunner.class) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) +public class ConfigSpecTest extends TestRestDocsSpecBase{ + + @MockBean + private SW360ConfigActuator restConfigActuatorMock; + + Map properties; + + { + properties = new HashMap<>(); + properties.put("admin.private.project.access.enabled", "true"); + properties.put("clearing.teams", "org1,org2,org3"); + properties.put("rest.apitoken.read.validity.days", "90"); + properties.put("rest.write.access.usergroup", "ADMIN"); + } + + @Test + public void should_document_get_config() throws Exception { + given(this.restConfigActuatorMock.config()).willReturn(properties); + + mockMvc.perform(get("/api/config") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andDo(this.documentationHandler.document( + responseFields( + fieldWithPath("['admin.private.project.access.enabled']").description("Sample boolean property."), + fieldWithPath("['clearing.teams']").description("Sample set property (separated by comma)."), + fieldWithPath("['rest.apitoken.read.validity.days']").description("Sample integer property."), + fieldWithPath("['rest.write.access.usergroup']").description("Sample string property.") + ) + )); + } + + @Test + public void should_document_get_single_config() throws Exception { + given(this.restConfigActuatorMock.config("rest.apitoken.read.validity.days")).willReturn(properties.get("rest.apitoken.read.validity.days")); + + mockMvc.perform(RestDocumentationRequestBuilders.get("/api/config/{key}", "rest.apitoken.read.validity.days") + .accept(MediaType.TEXT_PLAIN)) + .andExpect(status().isOk()) + .andExpect(header().string("Content-Type", "text/plain;charset=UTF-8")) + .andDo(this.documentationHandler.document( + pathParameters(parameterWithName("key").description("Property key")) + )); + } +} diff --git a/rest/resource-server/src/test/resources/application.yml b/rest/resource-server/src/test/resources/application.yml index 3db9ecabe9..4dd86e03c4 100644 --- a/rest/resource-server/src/test/resources/application.yml +++ b/rest/resource-server/src/test/resources/application.yml @@ -10,10 +10,11 @@ management: web: base-path: / exposure: - include: health,info + include: health,info,config path-mapping: health: /api/health info: /api/info + config: /api/config endpoint: health: show-details: always