├── .github └── workflows │ ├── release.yaml │ └── snapshot.yaml ├── .gitignore ├── .whitesource ├── LICENSE.txt ├── pom.xml ├── readme.md ├── renovate.json ├── src └── etc │ └── header.txt ├── wss-agent-api ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── whitesource │ │ └── agent │ │ └── api │ │ ├── APIConstants.java │ │ ├── AgentApiVersion.java │ │ ├── dispatch │ │ ├── AppFlags.java │ │ ├── AsyncCheckPolicyComplianceRequest.java │ │ ├── AsyncCheckPolicyComplianceResponseRequest.java │ │ ├── AsyncCheckPolicyComplianceResponseResult.java │ │ ├── AsyncCheckPolicyComplianceResult.java │ │ ├── AsyncCheckPolicyComplianceStatusRequest.java │ │ ├── AsyncCheckPolicyComplianceStatusResult.java │ │ ├── BaseCheckPoliciesResult.java │ │ ├── BaseRequest.java │ │ ├── BaseResult.java │ │ ├── CheckPoliciesRequest.java │ │ ├── CheckPoliciesResult.java │ │ ├── CheckPolicyComplianceRequest.java │ │ ├── CheckPolicyComplianceResult.java │ │ ├── CheckVulnerabilitiesRequest.java │ │ ├── CheckVulnerabilitiesResult.java │ │ ├── ConfigurationRequest.java │ │ ├── ConfigurationResult.java │ │ ├── FsaConfiguration.java │ │ ├── GetCloudNativeVulnerabilitiesRequest.java │ │ ├── GetCloudNativeVulnerabilitiesResult.java │ │ ├── GetDependencyDataRequest.java │ │ ├── GetDependencyDataResult.java │ │ ├── JwtAccessTokenRequest.java │ │ ├── JwtAccessTokenResult.java │ │ ├── RequestFactory.java │ │ ├── RequestType.java │ │ ├── ResultEnvelope.java │ │ ├── SendMetricsRequest.java │ │ ├── SendMetricsResult.java │ │ ├── ServiceRequest.java │ │ ├── SummaryScanRequest.java │ │ ├── SummaryScanResult.java │ │ ├── UpdateInventoryRequest.java │ │ ├── UpdateInventoryResult.java │ │ ├── UpdateType.java │ │ ├── UploadScaLogsRequest.java │ │ └── UploadScaLogsResult.java │ │ └── model │ │ ├── AgentProjectInfo.java │ │ ├── AnalysisInputs.java │ │ ├── ChecksumType.java │ │ ├── CloudNativeInfo.java │ │ ├── Code.java │ │ ├── Coordinates.java │ │ ├── CopyrightInfo.java │ │ ├── CvssInfo.java │ │ ├── DependencyHintsInfo.java │ │ ├── DependencyInfo.java │ │ ├── DependencyType.java │ │ ├── ExclusionInfo.java │ │ ├── FilesMathchingStepInfo.java │ │ ├── Line.java │ │ ├── OSInfo.java │ │ ├── PolicyCheckResourceNode.java │ │ ├── ProjectDetails.java │ │ ├── ProjectSetupStatus.java │ │ ├── ProjectTag.java │ │ ├── RequestPolicyInfo.java │ │ ├── ResolverStepInfo.java │ │ ├── ResourceInfo.java │ │ ├── ScanMethod.java │ │ ├── ScanSummaryInfo.java │ │ ├── SecretFinding.java │ │ ├── StepCompletionStatus.java │ │ ├── StepInfo.java │ │ ├── VulnerabilityInfo.java │ │ ├── VulnerabilityMetadata.java │ │ ├── VulnerableEntity.java │ │ └── contribution │ │ ├── ContributingDeveloperInfo.java │ │ ├── ContributionInfo.java │ │ └── ContributionInfoCollection.java │ └── test │ └── java │ └── org │ └── whitesource │ └── agent │ └── api │ └── model │ ├── DependencyInfoTest.java │ └── PolicyCheckResourceNodeTest.java ├── wss-agent-client ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── whitesource │ │ └── agent │ │ └── client │ │ ├── ClientConstants.java │ │ ├── WhitesourceService.java │ │ ├── WssSSLSocketFactory.java │ │ ├── WssServiceClient.java │ │ ├── WssServiceClientImpl.java │ │ └── WssServiceException.java │ └── test │ └── java │ └── org │ └── whitesource │ └── agent │ └── client │ ├── ModelSerializationTest.java │ ├── WhitesourceServiceTest.java │ └── WssServiceClientTest.java ├── wss-agent-hash-calculator ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── whitesource │ │ └── agent │ │ ├── hash │ │ ├── ChecksumUtils.java │ │ ├── FileExtensions.java │ │ ├── FileHandler.java │ │ ├── FileUtils.java │ │ ├── HashAlgorithm.java │ │ ├── HashCalculationResult.java │ │ ├── HashCalculator.java │ │ ├── HintUtils.java │ │ ├── RegexUtils.java │ │ └── WssHashException.java │ │ └── parser │ │ ├── JavaScriptParser.java │ │ └── ParseResult.java │ └── test │ ├── java │ └── org │ │ └── whitesource │ │ └── agent │ │ └── hash │ │ ├── ChecksumUtilsTest.java │ │ ├── HashCalculatorTest.java │ │ ├── HintUtilsTest.java │ │ └── JavaScriptHashCalculatorTest.java │ └── resources │ ├── empty-file.txt │ ├── js │ └── jquery.justifiedGallery.js │ ├── non-empty-file.txt │ ├── pecoff4j │ ├── 3ba03ffe.msi │ ├── Signature.dll │ ├── ZedGraph.dll │ ├── aopalliance-1.0.jar │ └── java-rmi.exe │ ├── superHash │ ├── lsb-test.txt │ ├── msb-test.txt │ ├── origin.txt │ ├── small-file.txt │ └── whitespace-changes.txt │ └── utf-bom │ ├── jquery-1.8.1-utf8.txt │ └── jquery-1.8.1-utf8bom.txt ├── wss-agent-report ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── whitesource │ │ │ └── agent │ │ │ └── report │ │ │ ├── FileUtils.java │ │ │ ├── OfflineUpdateRequest.java │ │ │ ├── PolicyCheckReport.java │ │ │ ├── model │ │ │ └── LicenseHistogramDataPoint.java │ │ │ └── summary │ │ │ ├── PolicyRejectionReport.java │ │ │ ├── PolicyRejectionSummary.java │ │ │ ├── RejectedLibrary.java │ │ │ └── RejectingPolicy.java │ └── resources │ │ └── templates │ │ └── policy-check.ftl │ └── test │ └── java │ └── org │ └── whitesource │ └── agent │ └── report │ └── PolicyCheckReportTest.java ├── wss-agent-utils ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── whitesource │ │ └── agent │ │ └── utils │ │ ├── JsonUtils.java │ │ └── ZipUtils.java │ └── test │ ├── java │ └── org │ │ └── whitesource │ │ └── agent │ │ └── utils │ │ ├── JsonUtilsTest.java │ │ └── ZipUtilsTest.java │ └── resources │ ├── plain_request.txt │ └── zipped_projects.txt └── wss-agent-via-api ├── pom.xml └── src └── main └── java └── org └── whitesource └── agent └── via └── api ├── CodeInvocation.java ├── InvocationType.java ├── VulnerabilityAnalysisResult.java ├── VulnerabilityTrace.java ├── VulnerableElement.java └── VulnerableElementInfo.java /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | releaseVersion: 7 | description: "Release version" 8 | required: true 9 | default: "2.9.9.99" 10 | nextDevVersion: 11 | description: "Next development version (must end with -SNAPSHOT)" 12 | required: true 13 | default: "2.9.9.100-SNAPSHOT" 14 | 15 | permissions: 16 | contents: write 17 | 18 | jobs: 19 | release: 20 | runs-on: ubuntu-latest 21 | steps: 22 | - name: Checkout code 23 | uses: actions/checkout@v4 24 | with: 25 | fetch-depth: 0 26 | token: ${{ secrets.GITHUB_TOKEN }} 27 | 28 | - name: Set up JDK 8 29 | uses: actions/setup-java@v4 30 | with: 31 | java-version: "8" 32 | distribution: "temurin" 33 | server-id: sonatype-nexus-staging 34 | server-username: ${{ secrets.OSSRH_USERNAME }} 35 | server-password: ${{ secrets.OSSRH_TOKEN }} 36 | gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} 37 | gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }} 38 | 39 | - name: Configure Git 40 | run: | 41 | git config user.email "hudson@whitesourcesoftware.com" 42 | git config user.name "whitesource-ci" 43 | # Configure Git to use HTTPS instead of SSH 44 | git config --global url."https://x-access-token:${{ github.token }}@github.com/".insteadOf "git@github.com:" 45 | 46 | - name: Configure GPG 47 | run: | 48 | mkdir -p ~/.gnupg 49 | chmod 700 ~/.gnupg 50 | echo "allow-loopback-pinentry" > ~/.gnupg/gpg-agent.conf 51 | echo "pinentry-mode loopback" > ~/.gnupg/gpg.conf 52 | 53 | - name: Create Maven settings.xml 54 | run: | 55 | mkdir -p ~/.m2 56 | echo " 57 | 58 | 59 | sonatype-nexus-staging 60 | ${{ secrets.OSSRH_USERNAME }} 61 | ${{ secrets.OSSRH_TOKEN }} 62 | 63 | 64 | 65 | 66 | gpg-settings 67 | 68 | gpg 69 | ${{ secrets.GPG_PASSPHRASE }} 70 | 71 | 72 | 73 | 74 | gpg-settings 75 | 76 | " > ~/.m2/settings.xml 77 | 78 | - name: Maven Release 79 | run: | 80 | export GPG_TTY=$(tty) 81 | mvn -B -DsourceLevel=1.8 -Djava.version=1.8 \ 82 | -DreleaseVersion=${{ github.event.inputs.releaseVersion }} \ 83 | -DdevelopmentVersion=${{ github.event.inputs.nextDevVersion }} \ 84 | -DscmCommentPrefix="[maven-release-plugin] [skip ci] " \ 85 | -Darguments="-Dgpg.passphrase=${{ secrets.GPG_PASSPHRASE }} -Pci-build -PRelease" \ 86 | release:clean release:prepare release:perform 87 | env: 88 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 89 | GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} 90 | -------------------------------------------------------------------------------- /.github/workflows/snapshot.yaml: -------------------------------------------------------------------------------- 1 | name: Deploy Snapshot 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | paths-ignore: 8 | - "**/*.md" 9 | 10 | jobs: 11 | deploy-snapshot: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout code 15 | uses: actions/checkout@v4 16 | 17 | - name: Set up JDK 18 | uses: actions/setup-java@v4 19 | with: 20 | java-version: "8" 21 | distribution: "temurin" 22 | server-id: sonatype-nexus-snapshots 23 | server-username: ${{ secrets.OSSRH_USERNAME }} 24 | server-password: ${{ secrets.OSSRH_TOKEN }} 25 | gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} 26 | gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }} 27 | 28 | - name: Create Maven settings.xml 29 | run: | 30 | mkdir -p ~/.m2 31 | echo " 32 | 33 | 34 | sonatype-nexus-snapshots 35 | ${{ secrets.OSSRH_USERNAME }} 36 | ${{ secrets.OSSRH_TOKEN }} 37 | 38 | 39 | " > ~/.m2/settings.xml 40 | 41 | - name: Verify SNAPSHOT version 42 | run: | 43 | VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) 44 | if [[ $VERSION != *"-SNAPSHOT" ]]; then 45 | echo "Error: Version must be a SNAPSHOT" 46 | exit 1 47 | fi 48 | 49 | - name: Build and deploy 50 | run: mvn -B clean deploy -Pci-build 51 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | *.iml 3 | 4 | target/ 5 | 6 | wss-agent-client/dependency-reduced-pom.xml -------------------------------------------------------------------------------- /.whitesource: -------------------------------------------------------------------------------- 1 | { 2 | "settingsInheritedFrom": "whitesource/whitesource-config@main", 3 | "scanSettings": { 4 | "baseBranches": [ 5 | "master" 6 | ] 7 | }, 8 | "remediateSettings": { 9 | "enableRenovate": true, 10 | "extends": [ 11 | "config:base" 12 | ], 13 | "baseBranches": [ 14 | "master" 15 | ], 16 | "dependencyDashboard": true 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | [White Source agents][1] 2 | =================== 3 | 4 | Agents keep your [White Source][2] account up to date automatically. 5 | They send a statement of the current use of open source software in your project to [White Source][2]. 6 | 7 | This information is used to: 8 | 9 | * Create and setup new projects 10 | * Update existing projects inventories 11 | * Open requests for newly introduced libraries 12 | * Cancel requests for removed libraries. 13 | 14 | An agent is a plugin for one or more components in the your project ecosystem. Build systems, continuous integration servers, etc... 15 | 16 | ### Getting started 17 | Setup and usage instructions for each agent can be found in the [documentation][1]. 18 | We recommend to visit the [service documentation][7] as well. 19 | 20 | ### Available plugins 21 | At the moment we have plugins for [Maven][3], [Ant][10], [Jenkins][4] and [TeamCity][5]. 22 | More plugins will be available soon. 23 | Meanwhile, if you need a plugin for another system please drop a line to our [support team][6]. 24 | 25 | ### Developers 26 | Agents are clients to the service REST api. You can develop your own agent by implementing such a client. 27 | This project provide two modules for Java based agents: 28 | 29 | * Domain model for information and operations in the api 30 | * Client implementation of the api 31 | 32 | More information can be found in the [documentation][1]. 33 | You can have a look in the [technical information][9] if you didn't find what you need. 34 | 35 | ### Support 36 | You can always create an issue or tell our [support team][6] what you think. 37 | 38 | ### License 39 | The project is licensed under the [Apache 2.0][8] license. 40 |
41 | Copyright (C) 2012 White Source Ltd.
42 | 
43 | Licensed under the Apache License, Version 2.0 (the "License");
44 | you may not use this file except in compliance with the License.
45 | You may obtain a copy of the License at
46 | 
47 | http://www.apache.org/licenses/LICENSE-2.0
48 | 
49 | Unless required by applicable law or agreed to in writing, software
50 | distributed under the License is distributed on an "AS IS" BASIS,
51 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
52 | See the License for the specific language governing permissions and
53 | limitations under the License.
54 | 
55 | 56 | [1]: http://docs.whitesourcesoftware.com/display/docs/Agents 57 | [2]: http://www.whitesourcesoftware.com 58 | [3]: http://www.github.com/whitesource/maven-plugin 59 | [4]: http://www.github.com/whitesource/jenkins-whitesource-plugin 60 | [5]: http://www.github.com/whitesource/teamcity-plugin 61 | [6]: mailto:support@whitesourcesoftware.com 62 | [7]: http://docs.whitesourcesoftware.com/display/serviceDocs/Home 63 | [8]: http://www.apache.org/licenses/LICENSE-2.0.html 64 | [9]: http://whitesource.github.com/agents 65 | [10]: http://www.github.com/whitesource/ant-plugin 66 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base" 4 | ], 5 | "dependencyDashboard": true, 6 | "dependencyDashboardApproval": true 7 | } 8 | -------------------------------------------------------------------------------- /src/etc/header.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) 2012 White Source Ltd. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /wss-agent-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | org.whitesource 6 | wss-agent-parent 7 | 2.9.9.101-SNAPSHOT 8 | 9 | wss-agent-api 10 | jar 11 | 12 | API bindings 13 | Java bindings for White Source API 14 | 15 | 16 | 1.8 17 | 1.8 18 | 19 | 20 | 21 | 22 | 23 | org.whitesource 24 | wss-agent-via-api 25 | ${project.version} 26 | 27 | 28 | 29 | org.apache.commons 30 | commons-lang3 31 | 32 | 33 | 34 | junit 35 | junit 36 | test 37 | 38 | 39 | com.google.code.gson 40 | gson 41 | 2.9.0 42 | 43 | 44 | 45 | 46 | 47 | Release 48 | 49 | false 50 | 51 | 52 | 53 | 54 | com.github.github 55 | site-maven-plugin 56 | 57 | wss-agent-api 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/APIConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api; 17 | 18 | /** 19 | * A class to hold constant values used in WhiteSource agents. 20 | * 21 | * @author tom.shapira 22 | */ 23 | public final class APIConstants { 24 | 25 | // TODO: 4/23/2019 check if update is needed 26 | public static final String API_VERSION = "2.7.5"; 27 | 28 | /* --- Parameters --- */ 29 | 30 | public static final String PARAM_TOKEN = "token"; 31 | public static final String USER_KEY = "userKey"; 32 | public static final String PARAM_PRODUCT = "product"; 33 | public static final String PARAM_PRODUCT_VERSION = "productVersion"; 34 | public static final String PARAM_DIFF = "diff"; 35 | public static final String PARAM_UPDATE_TYPE = "updateType"; 36 | public static final String PARAM_DEPENDENCIES = "dependencies"; 37 | public static final String PARAM_AGENT = "agent"; 38 | public static final String PARAM_AGENT_VERSION = "agentVersion"; 39 | public static final String PARAM_PLUGIN_VERSION = "pluginVersion"; 40 | public static final String PARAM_REQUEST_TYPE = "type"; 41 | public static final String PARAM_TIME_STAMP = "timeStamp"; 42 | public static final String PARAM_REQUESTER_EMAIL = "requesterEmail"; 43 | public static final String PARAM_FORCE_CHECK_ALL_DEPENDENCIES = "forceCheckAllDependencies"; 44 | public static final String PARAM_POPULATE_VULNERABILITIES = "populateVulnerabilities"; 45 | public static final String AGGREGATE_MODULES = "aggregateModules"; 46 | public static final String PRESERVE_MODULE_STRUCTURE = "preserveModuleStructure"; 47 | public static final String AGGREGATE_PROJECT_NAME = "aggregateProjectName"; 48 | public static final String AGGREGATE_PROJECT_TOKEN = "aggregateProjectToken"; 49 | public static final String LOG_DATA = "logData"; 50 | public static final String SCAN_COMMENT = "scanComment"; 51 | public static final String PRODUCT_TOKEN = "productToken"; 52 | public static final String EXTRA_PROPERTIES = "extraProperties"; 53 | public static final String SCAN_SUMMARY_INFO = "scanSummaryInfo"; 54 | public static final String CONTRIBUTIONS = "contributions"; 55 | public static final String IDENTIFIER = "identifier"; 56 | public static final int MAX_POST_SIZE = 209715200; //= 200 MegaByte; 57 | 58 | /* --- Messages --- */ 59 | 60 | public static final String TOKEN_INVALID = "Invalid token"; 61 | public static final String USER_KEY__INVALID = "Invalid user key"; 62 | public static final String TIME_STAMP_INVALID = "Invalid request time"; 63 | public static final String DIFF_INVALID = "Invalid diff"; 64 | public static final String UPDATE_SUCCESS = "update success"; 65 | public static final String JSON_ERROR = "Problem parsing json"; 66 | 67 | /* --- Miscellaneous --- */ 68 | 69 | public static final int HASH_CODE_SEED = 133; 70 | public static final int HASH_CODE_FACTOR = 23; 71 | 72 | /* --- Constructors --- */ 73 | 74 | /** 75 | * Private default constructor 76 | */ 77 | private APIConstants() { 78 | // avoid instantiation 79 | } 80 | 81 | } -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/AgentApiVersion.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api; 2 | 3 | /** 4 | * @author eRez Huberman 5 | **/ 6 | public class AgentApiVersion { 7 | 8 | public static final double AGENT_API_VERSION_2_9_8 = 2.98; 9 | } 10 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/AppFlags.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.dispatch; 2 | 3 | public enum AppFlags { 4 | UPLOAD_SCA_LOGS("UPLOAD_SCA_LOGS"), 5 | ASYNC_CHECK_POLICIES_ENABLED("ASYNC_CHECK_POLICIES_ENABLED"); 6 | 7 | 8 | private final String value; 9 | 10 | AppFlags(String value) { 11 | this.value = value; 12 | } 13 | 14 | public String getValue() { 15 | return value; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/AsyncCheckPolicyComplianceResponseRequest.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.dispatch; 2 | 3 | public class AsyncCheckPolicyComplianceResponseRequest extends BaseRequest { 4 | 5 | /* --- Static Members --- */ 6 | 7 | private static final long serialVersionUID = 7267771318691275351L; 8 | 9 | /* --- Members --- */ 10 | 11 | protected String identifier; 12 | 13 | /** 14 | * Default constructor 15 | */ 16 | public AsyncCheckPolicyComplianceResponseRequest(String identifier) { 17 | super(RequestType.ASYNC_CHECK_POLICY_COMPLIANCE_RESPONSE); 18 | this.identifier = identifier; 19 | } 20 | 21 | public AsyncCheckPolicyComplianceResponseRequest() {super(RequestType.ASYNC_CHECK_POLICY_COMPLIANCE_RESPONSE);} 22 | 23 | public String getIdentifier() { 24 | return identifier; 25 | } 26 | 27 | public void setIdentifier(String identifier) { 28 | this.identifier = identifier; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/AsyncCheckPolicyComplianceResponseResult.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.dispatch; 2 | 3 | public class AsyncCheckPolicyComplianceResponseResult extends CheckPolicyComplianceResult { 4 | 5 | /* --- Static Members --- */ 6 | 7 | private static final long serialVersionUID = -9005803185728108040L; 8 | 9 | /* --- Members --- */ 10 | 11 | 12 | /** 13 | * Default constructor 14 | */ 15 | public AsyncCheckPolicyComplianceResponseResult() { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/AsyncCheckPolicyComplianceResult.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.dispatch; 2 | 3 | import java.io.Serializable; 4 | 5 | public class AsyncCheckPolicyComplianceResult extends BaseResult { 6 | 7 | /* --- Static Members --- */ 8 | 9 | private static final long serialVersionUID = 7236121775887105115L; 10 | 11 | /* --- Members --- */ 12 | 13 | private String identifier; 14 | 15 | /** 16 | * Default constructor 17 | */ 18 | public AsyncCheckPolicyComplianceResult() { 19 | } 20 | 21 | public String getIdentifier() { 22 | return identifier; 23 | } 24 | 25 | public void setIdentifier(String identifier) { 26 | this.identifier = identifier; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/AsyncCheckPolicyComplianceStatusRequest.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.dispatch; 2 | 3 | public class AsyncCheckPolicyComplianceStatusRequest extends BaseRequest { 4 | 5 | /* --- Static Members --- */ 6 | 7 | private static final long serialVersionUID = -3011749510680068374L; 8 | 9 | /* --- Members --- */ 10 | 11 | protected String identifier; 12 | 13 | /** 14 | * Default constructor 15 | */ 16 | public AsyncCheckPolicyComplianceStatusRequest(String identifier) { 17 | super(RequestType.ASYNC_CHECK_POLICY_COMPLIANCE_STATUS); 18 | this.identifier = identifier; 19 | } 20 | 21 | public AsyncCheckPolicyComplianceStatusRequest() { 22 | super(RequestType.ASYNC_CHECK_POLICY_COMPLIANCE_STATUS); 23 | } 24 | 25 | public String getIdentifier() { 26 | return identifier; 27 | } 28 | 29 | public void setIdentifier(String identifier) { 30 | this.identifier = identifier; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/AsyncCheckPolicyComplianceStatusResult.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.dispatch; 2 | 3 | import java.io.Serializable; 4 | 5 | public class AsyncCheckPolicyComplianceStatusResult implements Serializable { 6 | 7 | /* --- Static Members --- */ 8 | 9 | private static final long serialVersionUID = -2767549958986147436L; 10 | 11 | /* --- Members --- */ 12 | 13 | // stores the sha1 of the euaDep.json used to calculate the vulnerabilities 14 | private String status; 15 | 16 | /** 17 | * Default constructor 18 | */ 19 | public AsyncCheckPolicyComplianceStatusResult() { 20 | } 21 | 22 | public AsyncCheckPolicyComplianceStatusResult(String status) { 23 | this.status = status; 24 | } 25 | 26 | public String getStatus() { 27 | return status; 28 | } 29 | 30 | public void setStatus(String status) { 31 | this.status = status; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/BaseCheckPoliciesResult.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.dispatch; 17 | 18 | import org.whitesource.agent.api.model.PolicyCheckResourceNode; 19 | import org.whitesource.agent.api.model.ResourceInfo; 20 | 21 | import java.util.*; 22 | 23 | /** 24 | * Base, abstract Result of check policy requests. 25 | * 26 | * @author anna.rozin 27 | */ 28 | public abstract class BaseCheckPoliciesResult extends BaseResult { 29 | 30 | /* --- Static members --- */ 31 | 32 | private static final long serialVersionUID = -4268012175086999291L; 33 | 34 | /* --- Members --- */ 35 | 36 | /** 37 | * Map of project name to the root of its dependency graph with policies application result. 38 | */ 39 | private Map existingProjects; 40 | 41 | /** 42 | * Map of project name to the root of its dependency graph with policies application result. 43 | */ 44 | private Map newProjects; 45 | 46 | /** 47 | * Map of project name to its set of new resources to insert into inventory. 48 | */ 49 | private Map> projectNewResources; 50 | 51 | /* --- Constructors --- */ 52 | 53 | /** 54 | * Default constructor 55 | */ 56 | public BaseCheckPoliciesResult() { 57 | existingProjects = new HashMap(); 58 | newProjects = new HashMap(); 59 | projectNewResources = new HashMap>(); 60 | } 61 | 62 | /** 63 | * Constructor 64 | * 65 | * @param organization Name of the domain. 66 | */ 67 | public BaseCheckPoliciesResult(String organization) { 68 | this(); 69 | setOrganization(organization); 70 | } 71 | 72 | /* --- Public methods --- */ 73 | 74 | /** 75 | * @return True if some project in this result have some rejected dependency. 76 | */ 77 | public boolean hasRejections() { 78 | boolean hasRejections = false; 79 | 80 | Collection roots = new ArrayList(); 81 | roots.addAll(getExistingProjects().values()); 82 | roots.addAll(getNewProjects().values()); 83 | 84 | Iterator iterator = roots.iterator(); 85 | while (iterator.hasNext() && !hasRejections ) { 86 | hasRejections = iterator.next().hasRejections(); 87 | } 88 | 89 | return hasRejections; 90 | } 91 | 92 | /* --- Getters / Setters --- */ 93 | 94 | public Map getNewProjects() { 95 | return newProjects; 96 | } 97 | 98 | public void setNewProjects(Map newProjects) { 99 | this.newProjects = newProjects; 100 | } 101 | 102 | public Map getExistingProjects() { 103 | return existingProjects; 104 | } 105 | 106 | public void setExistingProjects(Map existingProjects) { 107 | this.existingProjects = existingProjects; 108 | } 109 | 110 | public Map> getProjectNewResources() { 111 | return projectNewResources; 112 | } 113 | 114 | public void setProjectNewResources(Map> projectNewResources) { 115 | this.projectNewResources = projectNewResources; 116 | } 117 | 118 | } -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/BaseResult.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.dispatch; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * @author tom.shapira 7 | */ 8 | public class BaseResult implements Serializable { 9 | 10 | /* --- Static members --- */ 11 | 12 | private static final long serialVersionUID = 6143216164199328453L; 13 | 14 | /* --- Members --- */ 15 | 16 | /** 17 | * Name of organization in. 18 | */ 19 | private String organization; 20 | 21 | private String requestToken; 22 | 23 | /* --- Constructors --- */ 24 | 25 | public BaseResult() { 26 | } 27 | 28 | /* --- Getters / Setters --- */ 29 | 30 | public String getOrganization() { 31 | return organization; 32 | } 33 | 34 | public void setOrganization(String organization) { 35 | this.organization = organization; 36 | } 37 | 38 | public String getRequestToken() { 39 | return requestToken; 40 | } 41 | 42 | public void setRequestToken(String requestToken) { 43 | this.requestToken = requestToken; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/CheckPoliciesRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.dispatch; 17 | 18 | import org.whitesource.agent.api.model.AgentProjectInfo; 19 | 20 | import java.util.ArrayList; 21 | import java.util.Collection; 22 | 23 | /** 24 | * Request to check policies application results before actual inventory update inventory. 25 | * 26 | * @author Edo.Shor 27 | * 28 | * @since 1.2.0 29 | * 30 | * @deprecated Use {@link CheckPolicyComplianceRequest}. 31 | */ 32 | public class CheckPoliciesRequest extends BaseRequest { 33 | 34 | /* --- Static members --- */ 35 | 36 | private static final long serialVersionUID = -6894332358170182935L; 37 | 38 | /* --- Constructors --- */ 39 | 40 | /** 41 | * Default constructor 42 | */ 43 | public CheckPoliciesRequest() { 44 | super(RequestType.CHECK_POLICIES); 45 | } 46 | 47 | /** 48 | * Constructor 49 | * 50 | * @param projects Open Source usage statement to check against policies. 51 | */ 52 | public CheckPoliciesRequest(Collection projects) { 53 | this(); 54 | this.projects = projects; 55 | } 56 | 57 | 58 | /** 59 | * Constructor 60 | * 61 | * @param orgToken WhiteSource organization token. 62 | * @param projects Open Source usage statement to check against policies. 63 | */ 64 | public CheckPoliciesRequest(String orgToken, Collection projects) { 65 | this(projects); 66 | this.orgToken = orgToken; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/CheckPoliciesResult.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.dispatch; 17 | 18 | /** 19 | * Result of the check policies operation. 20 | * 21 | * @author Edo.Shor 22 | * 23 | * @since 1.2.0 24 | * 25 | * @deprecated Use {@link CheckPolicyComplianceResult}. 26 | */ 27 | public class CheckPoliciesResult extends BaseCheckPoliciesResult { 28 | 29 | /* --- Static members --- */ 30 | 31 | private static final long serialVersionUID = 7083481460957821913L; 32 | 33 | /* --- Constructors --- */ 34 | 35 | /** 36 | * Default constructor 37 | */ 38 | public CheckPoliciesResult() { 39 | super(); 40 | } 41 | 42 | /** 43 | * Constructor 44 | * 45 | * @param organization Name of the domain. 46 | */ 47 | public CheckPoliciesResult(String organization) { 48 | super(organization); 49 | } 50 | } -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/CheckPolicyComplianceResult.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.dispatch; 17 | 18 | /** 19 | * Result of the check policies operation. 20 | * 21 | * @author anna.rozin 22 | * 23 | * @since 2.2.7 24 | */ 25 | public class CheckPolicyComplianceResult extends BaseCheckPoliciesResult { 26 | 27 | /* --- Static members --- */ 28 | 29 | private static final long serialVersionUID = -3031495415514845777L; 30 | 31 | /* --- Constructors --- */ 32 | 33 | /** 34 | * Default constructor 35 | */ 36 | public CheckPolicyComplianceResult() { 37 | super(); 38 | } 39 | 40 | /** 41 | * Constructor 42 | * 43 | * @param organization Name of the domain. 44 | */ 45 | public CheckPolicyComplianceResult(String organization) { 46 | super(organization); 47 | } 48 | } -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/CheckVulnerabilitiesRequest.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.dispatch; 2 | 3 | 4 | import org.whitesource.agent.api.model.AgentProjectInfo; 5 | 6 | import java.util.Collection; 7 | 8 | /** 9 | * @author ruslan.gogerman 10 | * @since 2.5.5 11 | */ 12 | public class CheckVulnerabilitiesRequest extends BaseRequest { 13 | 14 | /* --- Static Members --- */ 15 | 16 | private static final long serialVersionUID = -945532206429866395L; 17 | 18 | /* --- Constructors --- */ 19 | 20 | /** 21 | * Default constructor 22 | */ 23 | public CheckVulnerabilitiesRequest() { 24 | super(RequestType.CHECK_VULNERABILITIES); 25 | } 26 | 27 | /** 28 | * Constructor 29 | * 30 | * @param projects Open Source usage statement to check vulnerabilities. 31 | */ 32 | public CheckVulnerabilitiesRequest(Collection projects) { 33 | this(); 34 | this.projects = projects; 35 | } 36 | 37 | /** 38 | * Constructor 39 | * 40 | * @param orgToken WhiteSource organization token. 41 | * @param projects Open Source usage statement to check vulnerabilities. 42 | */ 43 | public CheckVulnerabilitiesRequest(String orgToken, Collection projects) { 44 | this(); 45 | this.orgToken = orgToken; 46 | this.projects = projects; 47 | } 48 | 49 | /** 50 | * Constructor 51 | * 52 | * @param orgToken WhiteSource organization token. 53 | * @param product The product name or token to update. 54 | * @param productVersion The product version. 55 | * @param projects Open Source usage statement to check vulnerabilities. 56 | */ 57 | public CheckVulnerabilitiesRequest(String orgToken, String product, String productVersion, Collection projects) { 58 | this(orgToken, projects); 59 | this.product = product; 60 | this.productVersion = productVersion; 61 | 62 | } 63 | } -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/CheckVulnerabilitiesResult.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.dispatch; 2 | 3 | import org.whitesource.agent.api.model.VulnerabilityInfo; 4 | 5 | import java.io.Serializable; 6 | import java.util.Collection; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | /** 11 | * Result for {@link CheckVulnerabilitiesRequest}. 12 | * 13 | * @author ruslan.gogerman 14 | * 15 | * @since 2.5.5 16 | */ 17 | public class CheckVulnerabilitiesResult implements Serializable { 18 | 19 | /* --- Static Members --- */ 20 | 21 | private static final long serialVersionUID = - 6580191828869055056L; 22 | 23 | /* --- Members --- */ 24 | 25 | // stores the sha1 of the euaDep.json used to calculate the vulnerabilities 26 | private String euaDepFileSha1; 27 | private Map> sha1ToVulnerabilitiesMap; 28 | 29 | /* --- Constructors --- */ 30 | 31 | /** 32 | * Default constructor 33 | */ 34 | public CheckVulnerabilitiesResult() { 35 | sha1ToVulnerabilitiesMap = new HashMap<>(); 36 | } 37 | 38 | public CheckVulnerabilitiesResult(Map> sha1ToVulnerabilitiesMap) { 39 | this.sha1ToVulnerabilitiesMap = sha1ToVulnerabilitiesMap; 40 | } 41 | 42 | /* --- Getters / Setters --- */ 43 | 44 | public Map> getSha1ToVulnerabilitiesMap() { 45 | return sha1ToVulnerabilitiesMap; 46 | } 47 | 48 | public void setSha1ToVulnerabilitiesMap(Map> sha1ToVulnerabilitiesMap) { 49 | this.sha1ToVulnerabilitiesMap = sha1ToVulnerabilitiesMap; 50 | } 51 | 52 | public String getzEuaDepFileSha1() { 53 | return euaDepFileSha1; 54 | } 55 | 56 | public void setEuaDepFileSha1(String euaDepFileSha1) { 57 | this.euaDepFileSha1 = euaDepFileSha1; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/ConfigurationRequest.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.dispatch; 2 | 3 | /** 4 | * Created by anna.rozin 5 | */ 6 | public class ConfigurationRequest extends BaseRequest { 7 | 8 | 9 | /* --- Static members --- */ 10 | 11 | private static final long serialVersionUID = 1565062936737064054L; 12 | 13 | /* --- Constructors --- */ 14 | 15 | /** 16 | * Default constructor 17 | */ 18 | public ConfigurationRequest() { 19 | super(RequestType.GET_CONFIGURATION); 20 | } 21 | 22 | /** 23 | * Constructor 24 | * 25 | * @param orgToken Organization token uniquely identifying the account at white source. 26 | * @param product The product name or token to update. 27 | * @param productVersion The product version. 28 | * @param userKey user key uniquely identifying the account at white source. 29 | * @param requesterEmail Email of the WhiteSource user that requests to update WhiteSource. 30 | * @param productToken The product token 31 | */ 32 | public ConfigurationRequest(String orgToken, String product, String productVersion, String userKey, String requesterEmail, String productToken) { 33 | this(); 34 | this.orgToken = orgToken; 35 | this.product = product; 36 | this.productVersion = productVersion; 37 | this.userKey = userKey; 38 | this.requesterEmail = requesterEmail; 39 | this.productToken = productToken; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/GetCloudNativeVulnerabilitiesRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.dispatch; 17 | 18 | import org.whitesource.agent.api.model.AgentProjectInfo; 19 | import org.whitesource.agent.api.model.CloudNativeInfo; 20 | 21 | import java.io.Serializable; 22 | import java.util.Collection; 23 | 24 | /** 25 | * Result of the get cloud native vulnerabilities check. 26 | * 27 | * @author sami salami 28 | * 29 | * @since 2.9.9.81 30 | */ 31 | public class GetCloudNativeVulnerabilitiesRequest extends BaseRequest { 32 | 33 | /* --- Static members --- */ 34 | 35 | private static final long serialVersionUID = -3031495415514845777L; 36 | 37 | /* --- Members --- */ 38 | 39 | 40 | /* --- Constructors --- */ 41 | 42 | /** 43 | * Default constructor 44 | */ 45 | public GetCloudNativeVulnerabilitiesRequest() { 46 | super(RequestType.GET_CLOUD_NATIVE_VULNERABILITIES); 47 | } 48 | 49 | /** 50 | * Constructor 51 | * 52 | * @param projects Open Source usage statement to check vulnerabilities. 53 | */ 54 | public GetCloudNativeVulnerabilitiesRequest(Collection projects) { 55 | this(); 56 | this.projects = projects; 57 | } 58 | 59 | } -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/GetCloudNativeVulnerabilitiesResult.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.dispatch; 17 | 18 | import org.whitesource.agent.api.model.CloudNativeInfo; 19 | 20 | import java.io.Serializable; 21 | 22 | /** 23 | * Result of the get cloud native vulnerabilities check. 24 | * 25 | * @author sami salami 26 | * 27 | * @since 2.9.9.80 28 | */ 29 | public class GetCloudNativeVulnerabilitiesResult implements Serializable { 30 | 31 | /* --- Static members --- */ 32 | 33 | private static final long serialVersionUID = -3031495415514845777L; 34 | 35 | /* --- Members --- */ 36 | private CloudNativeInfo cloudNativeInfo; 37 | 38 | /* --- Constructors --- */ 39 | 40 | /** 41 | * Default constructor 42 | */ 43 | public GetCloudNativeVulnerabilitiesResult() {} 44 | 45 | public CloudNativeInfo getCloudNativeInfo() { 46 | return cloudNativeInfo; 47 | } 48 | 49 | public void setCloudNativeInfo(CloudNativeInfo cloudNativeInfo) { 50 | this.cloudNativeInfo = cloudNativeInfo; 51 | } 52 | } -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/GetDependencyDataRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 White Source Ltd. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.dispatch; 17 | 18 | import org.whitesource.agent.api.model.AgentProjectInfo; 19 | 20 | import java.util.Collection; 21 | 22 | /** 23 | * @author anna.rozin 24 | * @since 2.2.8 25 | */ 26 | public class GetDependencyDataRequest extends BaseRequest { 27 | 28 | /* --- Static members --- */ 29 | 30 | private static final long serialVersionUID = -2644123740414663681L; 31 | 32 | /* --- Constructors --- */ 33 | 34 | /** 35 | * Default constructor 36 | */ 37 | public GetDependencyDataRequest() { 38 | super(RequestType.GET_DEPENDENCY_DATA); 39 | } 40 | 41 | /** 42 | * Constructor 43 | * 44 | * @param projects Open Source usage statement to get dependency data. 45 | */ 46 | public GetDependencyDataRequest(Collection projects) { 47 | this(); 48 | this.projects = projects; 49 | } 50 | 51 | 52 | /** 53 | * Constructor 54 | * 55 | * @param orgToken Organization token uniquely identifying the account at white source. 56 | * @param product The product name or token to update. 57 | * @param productVersion The product version. 58 | * @param projects Open Source usage statement to check against policies. 59 | */ 60 | public GetDependencyDataRequest(String orgToken, String product, String productVersion, Collection projects) { 61 | this(projects); 62 | this.orgToken = orgToken; 63 | this.product = product; 64 | this.productVersion = productVersion; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/GetDependencyDataResult.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.dispatch; 17 | 18 | import org.whitesource.agent.api.model.ResourceInfo; 19 | 20 | import java.io.Serializable; 21 | import java.util.ArrayList; 22 | import java.util.Collection; 23 | 24 | /** 25 | * Result for {@link GetDependencyDataRequest}. 26 | * 27 | * @author anna.rozin 28 | * 29 | * @since 2.2.8 30 | */ 31 | public class GetDependencyDataResult implements Serializable { 32 | 33 | /* --- Static members --- */ 34 | 35 | private static final long serialVersionUID = -6064404450850954766L; 36 | 37 | /* --- Members --- */ 38 | 39 | /** 40 | * Name of organization in. 41 | */ 42 | private String organization; 43 | 44 | /** 45 | * Resources Info Collection. 46 | */ 47 | 48 | private Collection resources; 49 | 50 | /* --- Constructors --- */ 51 | 52 | /** 53 | * Default constructor 54 | */ 55 | public GetDependencyDataResult() { 56 | resources = new ArrayList(); 57 | } 58 | 59 | /** 60 | * Constructor 61 | * 62 | * @param organization Name of the domain. 63 | */ 64 | public GetDependencyDataResult(String organization) { 65 | this(); 66 | this.organization = organization; 67 | } 68 | 69 | /* --- Getters / Setters --- */ 70 | 71 | public String getOrganization() { 72 | return organization; 73 | } 74 | 75 | public void setOrganization(String organization) { 76 | this.organization = organization; 77 | } 78 | 79 | public Collection getResources() { 80 | return resources; 81 | } 82 | 83 | public void setResources(Collection resources) { 84 | this.resources = resources; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/JwtAccessTokenRequest.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.dispatch; 2 | 3 | public class JwtAccessTokenRequest extends BaseRequest { 4 | 5 | private static final long serialVersionUID = -2280907846002128613L; 6 | 7 | public JwtAccessTokenRequest() { 8 | super(RequestType.JWT_ACCESS_TOKEN); 9 | } 10 | 11 | public JwtAccessTokenRequest(String orgToken) { 12 | this(); 13 | this.orgToken = orgToken; 14 | } 15 | 16 | public JwtAccessTokenRequest(String orgToken, String userKey) { 17 | this(orgToken); 18 | this.userKey = userKey; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/JwtAccessTokenResult.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.dispatch; 2 | 3 | public class JwtAccessTokenResult extends BaseResult { 4 | 5 | private static final long serialVersionUID = 4617440013556093604L; 6 | 7 | private String jwtAccessToken; 8 | 9 | public JwtAccessTokenResult() { 10 | super(); 11 | } 12 | 13 | public JwtAccessTokenResult(String jwtAccessToken) { 14 | super(); 15 | this.jwtAccessToken = jwtAccessToken; 16 | } 17 | 18 | public String getJwtAccessToken() { 19 | return jwtAccessToken; 20 | } 21 | 22 | public void setJwtAccessToken(String jwtAccessToken) { 23 | this.jwtAccessToken = jwtAccessToken; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/RequestType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.dispatch; 17 | 18 | /** 19 | * Enumeration of the service available methods. 20 | * 21 | * @author Edo.Shor 22 | */ 23 | public enum RequestType { 24 | UPDATE("UPDATE"), 25 | CHECK_POLICIES("CHECK_POLICIES"), 26 | CHECK_POLICY_COMPLIANCE("CHECK_POLICY_COMPLIANCE"), 27 | CHECK_VULNERABILITIES("CHECK_VULNERABILITIES"), 28 | GET_CLOUD_NATIVE_VULNERABILITIES("GET_CLOUD_NATIVE_VULNERABILITIES"), 29 | GET_DEPENDENCY_DATA("GET_DEPENDENCY_DATA"), 30 | SUMMARY_SCAN("SUMMARY_SCAN"), 31 | GET_CONFIGURATION("GET_CONFIGURATION"), 32 | ASYNC_CHECK_POLICY_COMPLIANCE ("ASYNC_CHECK_POLICY_COMPLIANCE"), 33 | ASYNC_CHECK_POLICY_COMPLIANCE_STATUS ("ASYNC_CHECK_POLICY_COMPLIANCE_STATUS"), 34 | ASYNC_CHECK_POLICY_COMPLIANCE_RESPONSE ("ASYNC_CHECK_POLICY_COMPLIANCE_RESPONSE"), 35 | UPLOAD_SCA_LOGS("UPLOAD_SCA_LOGS"), 36 | JWT_ACCESS_TOKEN("JWT_ACCESS_TOKEN"), 37 | SEND_METRICS("SEND_METRICS"); 38 | private final String value; 39 | 40 | RequestType(String value) { 41 | this.value = value; 42 | } 43 | 44 | public String getValue() { 45 | return value; 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/ResultEnvelope.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.dispatch; 17 | 18 | import org.whitesource.agent.api.APIConstants; 19 | 20 | import java.io.Serializable; 21 | 22 | /** 23 | * Wrapper for any response form the White Source service. 24 | * 25 | * @author Edo.Shor 26 | */ 27 | public class ResultEnvelope implements Serializable { 28 | 29 | /* --- Static members --- */ 30 | 31 | public static final int STATUS_SUCCESS = 1; 32 | public static final int STATUS_BAD_REQUEST = 2; 33 | public static final int STATUS_SERVER_ERROR = 3; 34 | 35 | public static final String MESSAGE_OK = "ok"; 36 | public static final String MESSAGE_ILLEGAL_ARGUMENTS = "Illegal arguments"; 37 | public static final String MESSAGE_SERVER_ERROR = "Server error"; 38 | 39 | private static final long serialVersionUID = -3835912575385728376L; 40 | 41 | /* --- Members --- */ 42 | 43 | private String envelopeVersion = APIConstants.API_VERSION; 44 | 45 | /** Status code of the operation. */ 46 | private int status; 47 | 48 | /** Human readable message. */ 49 | private String message; 50 | 51 | /** Data associated with the result */ 52 | private String data; 53 | 54 | /** Identifier of the request for support purposes */ 55 | private String requestToken; 56 | 57 | /* --- Constructors --- */ 58 | 59 | /** 60 | * Default constructor 61 | */ 62 | public ResultEnvelope() { 63 | 64 | } 65 | 66 | /** 67 | * Constructor 68 | * 69 | * @param status 70 | * @param message 71 | * @param data 72 | */ 73 | public ResultEnvelope(int status, String message, String data) { 74 | this.status = status; 75 | this.message = message; 76 | this.data = data; 77 | } 78 | 79 | /** 80 | * Constructor 81 | * 82 | * @param status 83 | * @param message 84 | * @param data 85 | * @param requestToken 86 | */ 87 | public ResultEnvelope(int status, String message, String data, String requestToken) { 88 | this.status = status; 89 | this.message = message; 90 | this.data = data; 91 | this.requestToken = requestToken; 92 | } 93 | 94 | /* --- Overridden methods --- */ 95 | 96 | @Override 97 | public String toString() { 98 | StringBuilder sb = new StringBuilder(); 99 | 100 | sb.append("ResultEnvelope@").append(Integer.toHexString(hashCode())).append("[") 101 | .append("\n").append("envelopeVersion=").append(envelopeVersion).append(",") 102 | .append("\n").append("status=").append(status).append(",") 103 | .append("\n").append("message=").append(message).append(",") 104 | .append("\n").append("data=").append(data) 105 | .append("\n").append("requestToken=").append(requestToken) 106 | .append("\n]"); 107 | 108 | return sb.toString(); 109 | } 110 | 111 | /* --- Getters / Setters --- */ 112 | 113 | public String getEnvelopeVersion() { 114 | return envelopeVersion; 115 | } 116 | 117 | public int getStatus() { 118 | return status; 119 | } 120 | 121 | public void setStatus(int status) { 122 | this.status = status; 123 | } 124 | 125 | public String getMessage() { 126 | return message; 127 | } 128 | 129 | public void setMessage(String message) { 130 | this.message = message; 131 | } 132 | 133 | public String getData() { 134 | return data; 135 | } 136 | 137 | public void setData(String data) { 138 | this.data = data; 139 | } 140 | 141 | public String getRequestToken() { 142 | return requestToken; 143 | } 144 | 145 | public void setRequestToken(String requestToken) { 146 | this.requestToken = requestToken; 147 | } 148 | } -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/SendMetricsRequest.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.dispatch; 2 | 3 | import java.util.Map; 4 | 5 | public class SendMetricsRequest extends BaseRequest { 6 | 7 | private static final long serialVersionUID = -6575498573910995957L; 8 | 9 | public SendMetricsRequest() { 10 | super(RequestType.SEND_METRICS); 11 | } 12 | 13 | public SendMetricsRequest(String orgToken) { 14 | this(); 15 | this.orgToken = orgToken; 16 | } 17 | 18 | public SendMetricsRequest(String orgToken, String userKey, String productName, Map metrics) { 19 | this(orgToken); 20 | this.userKey = userKey; 21 | this.product = productName; 22 | this.extraProperties = metrics; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/SendMetricsResult.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.dispatch; 2 | 3 | public class SendMetricsResult extends BaseResult { 4 | private static final long serialVersionUID = 7986011495688324618L; 5 | 6 | public SendMetricsResult() { 7 | super(); 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/ServiceRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.dispatch; 17 | 18 | import java.io.Serializable; 19 | import java.util.Map; 20 | 21 | /** 22 | * The interface describe the functionality to be exposed by any request to the WhiteSource service. 23 | * 24 | * @author Edo.Shor 25 | * 26 | * @param Result type 27 | */ 28 | public interface ServiceRequest extends Serializable { 29 | 30 | /** 31 | * @return Request type. 32 | */ 33 | RequestType type(); 34 | 35 | /** 36 | * @return Agent type identifier. 37 | */ 38 | String agent(); 39 | 40 | /** 41 | * @return Agent API version. 42 | */ 43 | String agentVersion(); 44 | 45 | /** 46 | * @return WhiteSource service token of the organization to update. 47 | */ 48 | String orgToken(); 49 | 50 | /** 51 | * @return Name or WhiteSource service token of the product to update. 52 | */ 53 | String product(); 54 | 55 | /** 56 | * @return Version of the product to update. 57 | */ 58 | String productVersion(); 59 | 60 | /** 61 | * @return Time stamp when the request created (client side) 62 | */ 63 | long timeStamp(); 64 | 65 | /** 66 | * @return Email of the WhiteSource user that issues this request. 67 | */ 68 | String requesterEmail(); 69 | 70 | /** 71 | * @return Plugin version. 72 | */ 73 | String pluginVersion(); 74 | 75 | /** 76 | * @return WhiteSource user key who sent the request. 77 | */ 78 | String userKey(); 79 | 80 | /** 81 | * @return aggregate modules boolean property. 82 | */ 83 | boolean aggregateModules(); 84 | 85 | /** 86 | * @return preserve module structure boolean property. 87 | */ 88 | boolean preserveModuleStructure(); 89 | 90 | /** 91 | * @return aggregate project name (name identifier). 92 | */ 93 | String aggregateProjectName(); 94 | 95 | /** 96 | * @return aggregate project token (token identifier). 97 | */ 98 | String aggregateProjectToken(); 99 | 100 | /** 101 | * @return log data. 102 | */ 103 | String logData(); 104 | 105 | /** 106 | * @return scan comment. 107 | */ 108 | String scanComment(); 109 | 110 | /** 111 | * @return product token. 112 | */ 113 | String productToken(); 114 | 115 | /** 116 | * @return extra Properties. 117 | */ 118 | Map extraProperties(); 119 | 120 | } 121 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/SummaryScanRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.dispatch; 17 | 18 | import org.whitesource.agent.api.model.AgentProjectInfo; 19 | 20 | import java.util.Collection; 21 | 22 | /** 23 | * Request to update organization inventory. 24 | * 25 | * @author tom.shapira 26 | */ 27 | public class SummaryScanRequest extends BaseRequest { 28 | 29 | /* --- Static members --- */ 30 | 31 | private static final long serialVersionUID = -276101415154446987L; 32 | 33 | /* --- Constructors --- */ 34 | 35 | /** 36 | * Default constructor 37 | */ 38 | public SummaryScanRequest() { 39 | super(RequestType.SUMMARY_SCAN); 40 | } 41 | 42 | /** 43 | * Constructor 44 | * 45 | * @param projects Open Source usage statement to update White Source. 46 | */ 47 | public SummaryScanRequest(Collection projects) { 48 | this(); 49 | this.projects = projects; 50 | } 51 | 52 | /** 53 | * Constructor 54 | * 55 | * @param orgToken WhiteSource organization token. 56 | * @param projects Open Source usage statement to update White Source. 57 | */ 58 | public SummaryScanRequest(String orgToken, Collection projects) { 59 | this(projects); 60 | this.orgToken = orgToken; 61 | } 62 | 63 | /** 64 | * Constructor 65 | * 66 | * @param orgToken Organization token uniquely identifying the account at white source. 67 | * @param product The product name or token to update. 68 | * @param productVersion The product version. 69 | * @param projects Open Source usage statement to check against policies. 70 | */ 71 | public SummaryScanRequest(String orgToken, String product, String productVersion, Collection projects) { 72 | this(orgToken, projects); 73 | this.product = product; 74 | this.productVersion = productVersion; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/SummaryScanResult.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.dispatch; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Collection; 20 | 21 | 22 | /** 23 | * Result of the update inventory operation. 24 | * 25 | * @author Edo.Shor 26 | */ 27 | public class SummaryScanResult extends BaseResult { 28 | 29 | /* --- Static members --- */ 30 | 31 | private static final long serialVersionUID = 5277673506168727608L; 32 | 33 | /* --- Members --- */ 34 | 35 | private Collection updatedProjects; 36 | 37 | private Collection createdProjects; 38 | 39 | /* --- Constructors --- */ 40 | 41 | /** 42 | * Default constructor (for JSON parsing) 43 | * 44 | */ 45 | public SummaryScanResult() { 46 | updatedProjects = new ArrayList(); 47 | createdProjects = new ArrayList(); 48 | } 49 | 50 | /** 51 | * Constructor 52 | * 53 | * @param organization Name of the domain. 54 | */ 55 | public SummaryScanResult(String organization) { 56 | this(); 57 | setOrganization(organization); 58 | } 59 | 60 | /* --- Getters / Setters --- */ 61 | 62 | public Collection getUpdatedProjects() { 63 | return updatedProjects; 64 | } 65 | 66 | public void setUpdatedProjects(Collection updatedProjects) { 67 | this.updatedProjects = updatedProjects; 68 | } 69 | 70 | public Collection getCreatedProjects() { 71 | return createdProjects; 72 | } 73 | 74 | public void setCreatedProjects(Collection createdProjects) { 75 | this.createdProjects = createdProjects; 76 | } 77 | 78 | } -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/UpdateInventoryResult.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.dispatch; 17 | 18 | import com.google.gson.annotations.Since; 19 | import org.whitesource.agent.api.AgentApiVersion; 20 | import org.whitesource.agent.api.model.ProjectDetails; 21 | 22 | import java.util.ArrayList; 23 | import java.util.Collection; 24 | import java.util.HashMap; 25 | 26 | 27 | /** 28 | * Result of the update inventory operation. 29 | * 30 | * @author Edo.Shor 31 | */ 32 | public class UpdateInventoryResult extends BaseResult { 33 | 34 | /* --- Static members --- */ 35 | 36 | private static final long serialVersionUID = 9074828488465436483L; 37 | 38 | /* --- Members --- */ 39 | 40 | private boolean removeIfExist = false; 41 | 42 | private Collection updatedProjects; 43 | 44 | private Collection createdProjects; 45 | 46 | private HashMap projectNamesToIds; 47 | 48 | /* 49 | * @since 2.9.8 50 | */ 51 | @Since(AgentApiVersion.AGENT_API_VERSION_2_9_8) 52 | private HashMap projectNamesToDetails; 53 | 54 | 55 | /* --- Constructors --- */ 56 | /** 57 | * Default constructor (for JSON parsing) 58 | * 59 | */ 60 | public UpdateInventoryResult() { 61 | updatedProjects = new ArrayList(); 62 | createdProjects = new ArrayList(); 63 | projectNamesToIds = new HashMap<>(); 64 | projectNamesToDetails = new HashMap<>(); 65 | } 66 | 67 | /** 68 | * Constructor 69 | * 70 | * @param organization Name of the domain. 71 | */ 72 | public UpdateInventoryResult(String organization) { 73 | this(); 74 | setOrganization(organization); 75 | } 76 | 77 | public UpdateInventoryResult(String organization,boolean removeIfExist) { 78 | this(organization); 79 | this.removeIfExist = removeIfExist; 80 | } 81 | 82 | 83 | /* --- Getters / Setters --- */ 84 | public Collection getUpdatedProjects() { 85 | return updatedProjects; 86 | } 87 | 88 | public void setUpdatedProjects(Collection updatedProjects) { 89 | this.updatedProjects = updatedProjects; 90 | } 91 | 92 | public Collection getCreatedProjects() { 93 | return createdProjects; 94 | } 95 | 96 | public void setCreatedProjects(Collection createdProjects) { 97 | this.createdProjects = createdProjects; 98 | } 99 | 100 | public HashMap getProjectNamesToIds() { 101 | return projectNamesToIds; 102 | } 103 | 104 | public void setProjectNamesToIds(HashMap projectNamesToIds) { 105 | this.projectNamesToIds = projectNamesToIds; 106 | } 107 | 108 | public HashMap getProjectNamesToDetails(){ 109 | return projectNamesToDetails; 110 | } 111 | 112 | public void setProjectNamesToDetails(HashMap value){ 113 | this.projectNamesToDetails = value; 114 | } 115 | } -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/UpdateType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.dispatch; 17 | 18 | /** 19 | * Enumeration of the Update Types available methods. 20 | * 21 | * @author Eugen.Horovitz 22 | */ 23 | public enum UpdateType { 24 | OVERRIDE, 25 | APPEND, 26 | REMOVE 27 | } 28 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/UploadScaLogsRequest.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.dispatch; 2 | 3 | public class UploadScaLogsRequest extends BaseRequest { 4 | 5 | /* --- Static members --- */ 6 | 7 | private static final long serialVersionUID = -6634396300199014567L; 8 | 9 | /* --- Members --- */ 10 | 11 | 12 | /* --- Constructors --- */ 13 | 14 | /** 15 | * Default constructor 16 | */ 17 | public UploadScaLogsRequest() { 18 | super(RequestType.UPLOAD_SCA_LOGS); 19 | } 20 | 21 | /** 22 | * Constructor 23 | * 24 | * @param orgToken Organization token uniquely identifying the account at white source. 25 | * @param userKey user key uniquely identifying the account at white source. 26 | * @param requesterEmail Email of the WhiteSource user that requests to update WhiteSource. 27 | */ 28 | public UploadScaLogsRequest(String orgToken, String userKey, String requesterEmail) { 29 | this(); 30 | this.orgToken = orgToken; 31 | this.userKey = userKey; 32 | this.requesterEmail = requesterEmail; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/dispatch/UploadScaLogsResult.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.dispatch; 2 | 3 | public class UploadScaLogsResult extends BaseResult { 4 | 5 | /* --- Static members --- */ 6 | private static final long serialVersionUID = -8474225446757628208L; 7 | /* --- Constructors ---*/ 8 | 9 | /*** 10 | * default constructor 11 | */ 12 | public UploadScaLogsResult() { 13 | super(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/AnalysisInputs.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.model; 2 | 3 | import java.io.Serializable; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | /** 8 | * This class holds all information necessary for the Effective Usage Analysis to run successfully. 9 | * 10 | * @author noam.dolovich 11 | */ 12 | public class AnalysisInputs implements Serializable { 13 | 14 | private static final long serialVersionUID = -1209587213611770019L; 15 | 16 | private Map modulesToPaths; 17 | private String euaArtifactId; 18 | private boolean emptyDependency; 19 | 20 | public AnalysisInputs() { 21 | } 22 | 23 | public AnalysisInputs(String euaArtifactId) { 24 | this.euaArtifactId = euaArtifactId; 25 | } 26 | 27 | public Map getModulesToPaths() { 28 | if (modulesToPaths == null) { 29 | modulesToPaths = new HashMap<>(); 30 | } 31 | return modulesToPaths; 32 | } 33 | 34 | public void setModulesToPaths(Map modulesToPaths) { 35 | this.modulesToPaths = modulesToPaths; 36 | } 37 | 38 | public void addDependencyModulesToPaths(String key, String value) { 39 | getModulesToPaths().put(key, value); 40 | } 41 | 42 | public String getEuaArtifactId() { 43 | return euaArtifactId; 44 | } 45 | 46 | public void setEuaArtifactId(String euaArtifactId) { 47 | this.euaArtifactId = euaArtifactId; 48 | } 49 | 50 | public boolean isEmptyDependency() { 51 | return emptyDependency; 52 | } 53 | 54 | public void setEmptyDependency(boolean emptyDependency) { 55 | this.emptyDependency = emptyDependency; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/ChecksumType.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.model; 2 | 3 | /** 4 | * @author asaf.savich 5 | */ 6 | public enum ChecksumType { 7 | SHA1, 8 | SHA256, 9 | SHA1_SUPER_HASH, 10 | SHA1_SUPER_HASH_MSB, 11 | SHA1_SUPER_HASH_LSB, 12 | SHA1_NO_HEADER, 13 | SHA1_NO_HEADER_SUPER_HASH, 14 | SHA1_NO_COMMENTS, 15 | SHA1_NO_COMMENTS_SUPER_HASH, 16 | SHA1_OTHER_PLATFORM, 17 | SHA1_UTF8, 18 | MD5, 19 | ADDITIONAL_SHA1 20 | } -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/CloudNativeInfo.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.model; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | public class CloudNativeInfo implements Serializable { 7 | private String packageName; 8 | private String sourcePackageName; 9 | private String sourcePackageVersion; 10 | private String distribution; 11 | private String distributionVersion; 12 | private List vulnerabilitiesMetadata; 13 | 14 | /* --- Constructors --- */ 15 | 16 | /** 17 | * Default constructor 18 | */ 19 | public CloudNativeInfo() {} 20 | 21 | 22 | public String getPackageName() { 23 | return packageName; 24 | } 25 | 26 | public void setPackageName(String packageName) { 27 | this.packageName = packageName; 28 | } 29 | 30 | public String getSourcePackageName() { 31 | return sourcePackageName; 32 | } 33 | 34 | public void setSourcePackageName(String sourcePackageName) { 35 | this.sourcePackageName = sourcePackageName; 36 | } 37 | 38 | public String getSourcePackageVersion() { 39 | return sourcePackageVersion; 40 | } 41 | 42 | public void setSourcePackageVersion(String sourcePackageVersion) { 43 | this.sourcePackageVersion = sourcePackageVersion; 44 | } 45 | 46 | public String getDistribution() { 47 | return distribution; 48 | } 49 | 50 | public void setDistribution(String distribution) { 51 | this.distribution = distribution; 52 | } 53 | 54 | public String getDistributionVersion() { 55 | return distributionVersion; 56 | } 57 | 58 | public void setDistributionVersion(String distributionVersion) { 59 | this.distributionVersion = distributionVersion; 60 | } 61 | 62 | public List getVulnerabilitiesMetadata() { 63 | return vulnerabilitiesMetadata; 64 | } 65 | 66 | public void setVulnerabilitiesMetadata(List vulnerabilitiesMetadata) { 67 | this.vulnerabilitiesMetadata = vulnerabilitiesMetadata; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/Code.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.model; 2 | 3 | import java.util.List; 4 | 5 | public class Code { 6 | private List lines; 7 | public List getLines() { 8 | return lines; 9 | } 10 | public void setLines(List lines) { 11 | this.lines = lines; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/Coordinates.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.model; 17 | 18 | import org.whitesource.agent.api.APIConstants; 19 | 20 | import java.io.Serializable; 21 | 22 | /** 23 | * WhiteSource model for artifact's coordinates. 24 | * 25 | * @author tom.shapira 26 | */ 27 | public class Coordinates implements Serializable { 28 | 29 | /* --- Static members --- */ 30 | 31 | private static final long serialVersionUID = 4962222806117752812L; 32 | 33 | /* --- Members --- */ 34 | 35 | private String groupId; 36 | 37 | private String artifactId; 38 | 39 | private String version; 40 | 41 | /* --- Constructors --- */ 42 | 43 | /** 44 | * Default constructor 45 | */ 46 | public Coordinates() { 47 | 48 | } 49 | 50 | /** 51 | * Constructor 52 | * 53 | * @param groupId 54 | * @param artifactId 55 | * @param version 56 | */ 57 | public Coordinates(String groupId, String artifactId, String version) { 58 | this.groupId = groupId; 59 | this.artifactId = artifactId; 60 | this.version = version; 61 | } 62 | 63 | /* --- Overridden methods --- */ 64 | 65 | @Override 66 | public String toString() { 67 | StringBuilder sb = new StringBuilder(); 68 | 69 | sb.append("Coordinates@").append(Integer.toHexString(hashCode())) 70 | .append("[") 71 | .append("groupId= ").append(groupId).append(",") 72 | .append("artifactId= ").append(artifactId).append(",") 73 | .append("version= ").append(version) 74 | .append(" ]"); 75 | 76 | return sb.toString(); 77 | } 78 | 79 | @Override 80 | public int hashCode() { 81 | int code = APIConstants.HASH_CODE_SEED; 82 | code = APIConstants.HASH_CODE_FACTOR * code + ((groupId == null) ? 0 : groupId.hashCode()); 83 | code = APIConstants.HASH_CODE_FACTOR * code + ((artifactId == null) ? 0 : artifactId.hashCode()); 84 | code = APIConstants.HASH_CODE_FACTOR * code + ((version == null) ? 0 : version.hashCode()); 85 | 86 | return code; 87 | } 88 | 89 | @Override 90 | public boolean equals(Object obj) { 91 | if (obj == null) { return false; } 92 | if (obj == this) { return true; } 93 | if (obj.getClass() != getClass()) { return false; } 94 | 95 | Coordinates other = (Coordinates) obj; 96 | 97 | return (groupId == null) ? (other.groupId == null) : groupId.equals(other.groupId) 98 | && ((artifactId == null) ? (other.artifactId == null) : artifactId.equals(other.artifactId)) 99 | && ((version == null) ? (other.version == null) : version.equals(other.version)); 100 | } 101 | 102 | /* --- Getters / Setters --- */ 103 | 104 | public String getGroupId() { 105 | return groupId; 106 | } 107 | 108 | public void setGroupId(String groupId) { 109 | this.groupId = groupId; 110 | } 111 | 112 | public String getArtifactId() { 113 | return artifactId; 114 | } 115 | 116 | public void setArtifactId(String artifactId) { 117 | this.artifactId = artifactId; 118 | } 119 | 120 | public String getVersion() { 121 | return version; 122 | } 123 | 124 | public void setVersion(String version) { 125 | this.version = version; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/CopyrightInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014 WhiteSource Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.model; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | * Holds the copyright information found in a file. 22 | * 23 | * @author tom.shapira 24 | */ 25 | public class CopyrightInfo implements Serializable { 26 | 27 | /* --- Static members --- */ 28 | 29 | private static final long serialVersionUID = 7366184386342223073L; 30 | 31 | /* --- Members --- */ 32 | 33 | private String copyright; 34 | 35 | private int line; 36 | 37 | /* --- Constructors --- */ 38 | 39 | /** 40 | * Default constructor. 41 | */ 42 | public CopyrightInfo() { 43 | } 44 | 45 | /** 46 | * Constructor. 47 | * 48 | * @param copyright The actual line of code containing the copyright information. 49 | * @param line The code line number. 50 | */ 51 | public CopyrightInfo(String copyright, int line) { 52 | this.copyright = copyright; 53 | this.line = line; 54 | } 55 | 56 | /* --- Getters / Setters --- */ 57 | 58 | public String getCopyright() { 59 | return copyright; 60 | } 61 | 62 | public void setCopyright(String copyright) { 63 | this.copyright = copyright; 64 | } 65 | 66 | public int getLine() { 67 | return line; 68 | } 69 | 70 | public void setLine(int line) { 71 | this.line = line; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/CvssInfo.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.model; 2 | 3 | import java.io.Serializable; 4 | 5 | public class CvssInfo implements Serializable { 6 | private String V2Vector; 7 | private String V3Vector; 8 | private String V2Score; 9 | private String V3Score; 10 | 11 | /* --- Constructors --- */ 12 | 13 | /** 14 | * Default constructor 15 | */ 16 | public CvssInfo() {} 17 | 18 | public String getV2Vector() { 19 | return V2Vector; 20 | } 21 | 22 | public void setV2Vector(String v2Vector) { 23 | V2Vector = v2Vector; 24 | } 25 | 26 | public String getV3Vector() { 27 | return V3Vector; 28 | } 29 | 30 | public void setV3Vector(String v3Vector) { 31 | V3Vector = v3Vector; 32 | } 33 | 34 | public String getV2Score() { 35 | return V2Score; 36 | } 37 | 38 | public void setV2Score(String v2Score) { 39 | V2Score = v2Score; 40 | } 41 | 42 | public String getV3Score() { 43 | return V3Score; 44 | } 45 | 46 | public void setV3Score(String v3Score) { 47 | V3Score = v3Score; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/DependencyHintsInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 White Source Ltd. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.model; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | * This class holds all extra information that will help identify a file scanned. 22 | * 23 | * @author chen.luigi 24 | */ 25 | public class DependencyHintsInfo implements Serializable { 26 | 27 | /* --- Static members --- */ 28 | 29 | private static final long serialVersionUID = 776719618926129849L; 30 | 31 | /* --- Members --- */ 32 | 33 | // hints for portable executables (dll, exe) 34 | private String companyName; 35 | private String fileVersion; 36 | private String copyright; 37 | private String originalFilename; 38 | private String productName; 39 | private String productVersion; 40 | 41 | // signature details 42 | private String issuerCommonName; 43 | private String subjectCommonName; 44 | 45 | /* --- Constructors --- */ 46 | 47 | public DependencyHintsInfo() { 48 | } 49 | 50 | /* --- Getters / Setters --- */ 51 | 52 | public String getCompanyName() { 53 | return companyName; 54 | } 55 | 56 | public void setCompanyName(String companyName) { 57 | this.companyName = companyName; 58 | } 59 | 60 | public String getFileVersion() { 61 | return fileVersion; 62 | } 63 | 64 | public void setFileVersion(String fileVersion) { 65 | this.fileVersion = fileVersion; 66 | } 67 | 68 | public String getCopyright() { 69 | return copyright; 70 | } 71 | 72 | public void setCopyright(String copyright) { 73 | this.copyright = copyright; 74 | } 75 | 76 | public String getOriginalFilename() { 77 | return originalFilename; 78 | } 79 | 80 | public void setOriginalFilename(String originalFilename) { 81 | this.originalFilename = originalFilename; 82 | } 83 | 84 | public String getProductName() { 85 | return productName; 86 | } 87 | 88 | public void setProductName(String productName) { 89 | this.productName = productName; 90 | } 91 | 92 | public String getProductVersion() { 93 | return productVersion; 94 | } 95 | 96 | public void setProductVersion(String productVersion) { 97 | this.productVersion = productVersion; 98 | } 99 | 100 | public String getIssuerCommonName() { 101 | return issuerCommonName; 102 | } 103 | 104 | public void setIssuerCommonName(String issuerCommonName) { 105 | this.issuerCommonName = issuerCommonName; 106 | } 107 | 108 | public String getSubjectCommonName() { 109 | return subjectCommonName; 110 | } 111 | 112 | public void setSubjectCommonName(String subjectCommonName) { 113 | this.subjectCommonName = subjectCommonName; 114 | } 115 | } -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/DependencyType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.model; 17 | 18 | /** 19 | * Enum for describing the type of dependency sent to the server. 20 | * 21 | * @author tom.shapira 22 | */ 23 | public enum DependencyType { 24 | 25 | MAVEN, 26 | GRADLE, 27 | JAVA, //(For additionalSha1 purpose do not send it to application) 28 | 29 | NPM, 30 | BOWER, 31 | GRUNT, 32 | 33 | GO, 34 | PYTHON, 35 | 36 | RUBY, 37 | 38 | NUGET, 39 | PHP, 40 | 41 | RPM, 42 | DEBIAN, 43 | ALPINE, 44 | ARCH_LINUX, 45 | 46 | COCOAPODS, 47 | HEX, 48 | 49 | R, 50 | CRATE, 51 | CABAL, 52 | OPAM, 53 | PUB, 54 | CONDA, 55 | CONAN, 56 | 57 | DOCKER, 58 | DOCKER_LAYER, 59 | 60 | YOCTO, 61 | SWIFT, 62 | ML_MODEL; 63 | 64 | @Override 65 | public String toString() { 66 | switch(this) { 67 | case COCOAPODS: return "CocoaPods"; 68 | case CRATE: return "Crate"; 69 | case CABAL: return "Cabal"; 70 | case OPAM: return "Opam"; 71 | case DEBIAN: return "Debian"; 72 | case ALPINE: return "Alpine"; 73 | case ARCH_LINUX: return "Arch Linux"; 74 | case PUB: return "Pub"; 75 | case DOCKER: return "Docker"; 76 | case YOCTO: return "Yocto"; 77 | default: return super.toString(); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/ExclusionInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.model; 17 | 18 | import java.io.Serializable; 19 | import java.util.Objects; 20 | 21 | /** 22 | * WhiteSource model for exclusion of transitive dependencies. 23 | * 24 | * @author tom.shapira 25 | */ 26 | public class ExclusionInfo implements Serializable { 27 | 28 | /* --- Static members --- */ 29 | 30 | private static final long serialVersionUID = -3900555692407177279L; 31 | 32 | /* --- Members --- */ 33 | 34 | private String artifactId; 35 | 36 | private String groupId; 37 | 38 | /* --- Constructors --- */ 39 | 40 | /** 41 | * Default constructor 42 | */ 43 | public ExclusionInfo() { 44 | 45 | } 46 | 47 | /** 48 | * Constructor 49 | * 50 | * @param artifactId 51 | * @param groupId 52 | */ 53 | public ExclusionInfo(String artifactId, String groupId) { 54 | this.artifactId = artifactId; 55 | this.groupId = groupId; 56 | } 57 | 58 | /* --- Overridden methods --- */ 59 | 60 | @Override 61 | public String toString() { 62 | StringBuilder sb = new StringBuilder(); 63 | 64 | sb.append("ExclusionInfo@").append(Integer.toHexString(hashCode())) 65 | .append("[") 66 | .append("groupId= ").append(groupId).append(",") 67 | .append("artifactId= ").append(artifactId) 68 | .append(" ]"); 69 | 70 | return sb.toString(); 71 | } 72 | 73 | @Override 74 | public boolean equals(Object o) { 75 | if (this == o) return true; 76 | if (!(o instanceof ExclusionInfo)) return false; 77 | ExclusionInfo that = (ExclusionInfo) o; 78 | return Objects.equals(artifactId, that.artifactId) && 79 | Objects.equals(groupId, that.groupId); 80 | } 81 | 82 | @Override 83 | public int hashCode() { 84 | return Objects.hash(artifactId, groupId); 85 | } 86 | 87 | /* --- Getters / Setters --- */ 88 | 89 | public String getArtifactId() { 90 | return artifactId; 91 | } 92 | 93 | public void setArtifactId(String artifactId) { 94 | this.artifactId = artifactId; 95 | } 96 | 97 | public String getGroupId() { 98 | return groupId; 99 | } 100 | 101 | public void setGroupId(String groupId) { 102 | this.groupId = groupId; 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/FilesMathchingStepInfo.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.model; 2 | 3 | import java.util.Objects; 4 | 5 | /** 6 | * @author chen.luigi 7 | */ 8 | public class FilesMathchingStepInfo extends StepInfo { 9 | 10 | /* --- Private Members --- */ 11 | 12 | private int totalSourceBinariesFound; 13 | 14 | /* --- Constructors --- */ 15 | 16 | public FilesMathchingStepInfo(int totalSourceBinariesFound) { 17 | super(); 18 | this.totalSourceBinariesFound = totalSourceBinariesFound; 19 | } 20 | 21 | /* --- Overridden methods --- */ 22 | 23 | @Override 24 | public boolean equals(Object o) { 25 | if (this == o) return true; 26 | if (!(o instanceof FilesMathchingStepInfo)) return false; 27 | if (!super.equals(o)) return false; 28 | FilesMathchingStepInfo that = (FilesMathchingStepInfo) o; 29 | return totalSourceBinariesFound == that.totalSourceBinariesFound; 30 | } 31 | 32 | @Override 33 | public int hashCode() { 34 | return Objects.hash(super.hashCode(), totalSourceBinariesFound); 35 | } 36 | 37 | /* --- Getters / Setters --- */ 38 | 39 | public int getTotalSourceBinariesFound() { 40 | return totalSourceBinariesFound; 41 | } 42 | 43 | public void setTotalSourceBinariesFound(int totalSourceBinariesFound) { 44 | this.totalSourceBinariesFound = totalSourceBinariesFound; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/Line.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.model; 2 | 3 | 4 | public class Line { 5 | private int number; 6 | private String content; 7 | private boolean isCause; 8 | private String annotation; 9 | private boolean truncated; 10 | private String highlighted; 11 | private boolean firstCause; 12 | private boolean lastCause; 13 | 14 | public int getNumber() { 15 | return number; 16 | } 17 | 18 | public void setNumber(int number) { 19 | this.number = number; 20 | } 21 | 22 | public String getContent() { 23 | return content; 24 | } 25 | 26 | public void setContent(String content) { 27 | this.content = content; 28 | } 29 | 30 | public boolean isCause() { 31 | return isCause; 32 | } 33 | 34 | public void setCause(boolean cause) { 35 | isCause = cause; 36 | } 37 | 38 | public String getAnnotation() { 39 | return annotation; 40 | } 41 | 42 | public void setAnnotation(String annotation) { 43 | this.annotation = annotation; 44 | } 45 | 46 | public boolean isTruncated() { 47 | return truncated; 48 | } 49 | 50 | public void setTruncated(boolean truncated) { 51 | this.truncated = truncated; 52 | } 53 | 54 | public String getHighlighted() { 55 | return highlighted; 56 | } 57 | 58 | public void setHighlighted(String highlighted) { 59 | this.highlighted = highlighted; 60 | } 61 | 62 | public boolean isFirstCause() { 63 | return firstCause; 64 | } 65 | 66 | public void setFirstCause(boolean firstCause) { 67 | this.firstCause = firstCause; 68 | } 69 | 70 | public boolean isLastCause() { 71 | return lastCause; 72 | } 73 | 74 | public void setLastCause(boolean lastCause) { 75 | this.lastCause = lastCause; 76 | } 77 | 78 | 79 | 80 | } 81 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/OSInfo.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.model; 2 | 3 | 4 | public class OSInfo { 5 | 6 | /* 7 | * examples: 8 | * ID=ubuntu + VERSION=20.04 9 | * ID=fedora + VERSION=33 10 | */ 11 | private String id; 12 | private String version; 13 | 14 | public String getId() { 15 | return id; 16 | } 17 | 18 | public void setId(String id) { 19 | this.id = id; 20 | } 21 | 22 | public String getVersion() { 23 | return version; 24 | } 25 | 26 | public void setVersion(String version) { 27 | this.version = version; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/PolicyCheckResourceNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.model; 17 | 18 | import java.io.Serializable; 19 | import java.util.ArrayList; 20 | import java.util.Collection; 21 | import java.util.Iterator; 22 | 23 | /** 24 | * A node for each resource in a dependency graph with associated policy application results. 25 | * 26 | * @author Edo.Shor 27 | * @since 1.2.0 28 | */ 29 | public class PolicyCheckResourceNode implements Serializable { 30 | 31 | /* --- Static members --- */ 32 | 33 | private static final long serialVersionUID = -3206810244665473L; 34 | 35 | /* --- Members --- */ 36 | 37 | private ResourceInfo resource; 38 | 39 | private RequestPolicyInfo policy; 40 | 41 | private Collection children; 42 | 43 | /* --- Constructors --- */ 44 | 45 | /** 46 | * Default constructor 47 | */ 48 | public PolicyCheckResourceNode() { 49 | children = new ArrayList(); 50 | } 51 | 52 | /** 53 | * Constructor 54 | * 55 | * @param resource 56 | * @param policy 57 | */ 58 | public PolicyCheckResourceNode(ResourceInfo resource, RequestPolicyInfo policy) { 59 | this(); 60 | this.resource = resource; 61 | this.policy = policy; 62 | } 63 | 64 | /* --- Public methods --- */ 65 | 66 | public boolean hasRejections() { 67 | boolean rejections = policy != null && "Reject".equals(policy.getActionType()); 68 | 69 | Iterator it = children.iterator(); 70 | while (it.hasNext() && !rejections) { 71 | rejections = it.next().hasRejections(); 72 | } 73 | 74 | return rejections; 75 | } 76 | 77 | /* --- Getters / Setters --- */ 78 | 79 | public ResourceInfo getResource() { 80 | return resource; 81 | } 82 | 83 | public void setResource(ResourceInfo resource) { 84 | this.resource = resource; 85 | } 86 | 87 | public RequestPolicyInfo getPolicy() { 88 | return policy; 89 | } 90 | 91 | public void setPolicy(RequestPolicyInfo policy) { 92 | this.policy = policy; 93 | } 94 | 95 | public Collection getChildren() { 96 | return children; 97 | } 98 | 99 | public void setChildren(Collection children) { 100 | this.children = children; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/ProjectDetails.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.model; 2 | 3 | import com.google.gson.annotations.Since; 4 | import org.whitesource.agent.api.AgentApiVersion; 5 | 6 | import java.io.Serializable; 7 | import java.util.Objects; 8 | 9 | /** 10 | * @author eRez Huberman 11 | * @since 2.9.8 12 | **/ 13 | @Since(AgentApiVersion.AGENT_API_VERSION_2_9_8) 14 | public class ProjectDetails implements Serializable{ 15 | 16 | private static final long serialVersionUID = 6155870504657108377L; 17 | 18 | /* --- Members --- */ 19 | private String projectName; 20 | private Integer projectId; 21 | private String projectToken; 22 | 23 | /* --- Constructors --- */ 24 | 25 | public ProjectDetails(String name, Integer id, String token){ 26 | this.projectName = name; 27 | this.projectId = id; 28 | this.projectToken = token; 29 | } 30 | 31 | /* --- Getters / Setters --- */ 32 | public String getProjectName() { 33 | return projectName; 34 | } 35 | 36 | public void setProjectName(String projectName) { 37 | this.projectName = projectName; 38 | } 39 | 40 | public Integer getProjectId() { 41 | return projectId; 42 | } 43 | 44 | public void setProjectId(Integer projectId) { 45 | this.projectId = projectId; 46 | } 47 | 48 | public String getProjectToken() { 49 | return projectToken; 50 | } 51 | 52 | public void setProjectToken(String projectToken) { 53 | this.projectToken = projectToken; 54 | } 55 | 56 | /* --- Overridden methods --- */ 57 | 58 | @Override 59 | public boolean equals(Object o) { 60 | if (this == o) return true; 61 | if (o == null || getClass() != o.getClass()) return false; 62 | ProjectDetails that = (ProjectDetails) o; 63 | return Objects.equals(projectName, that.projectName) && 64 | Objects.equals(projectId, that.projectId) && 65 | Objects.equals(projectToken, that.projectToken); 66 | } 67 | 68 | @Override 69 | public int hashCode() { 70 | 71 | return Objects.hash(projectName, projectId, projectToken); 72 | } 73 | } -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/ProjectSetupStatus.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.model; 17 | 18 | /** 19 | * Enum for describing the type of dependency sent to the server. 20 | * 21 | * @author tom.shapira 22 | */ 23 | public enum ProjectSetupStatus { 24 | 25 | FAILURE { 26 | @Override 27 | public String statusTypeValue() { 28 | return "Failure"; 29 | } 30 | }, 31 | SUCCESS { 32 | @Override 33 | public String statusTypeValue() { 34 | return "Success"; 35 | } 36 | }; 37 | 38 | public abstract String statusTypeValue(); 39 | } 40 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/ProjectTag.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.model; 17 | 18 | import java.io.Serializable; 19 | import java.util.Objects; 20 | 21 | public class ProjectTag implements Serializable { 22 | private static final long serialVersionUID = 1835100904098326933L; 23 | 24 | /* --- Members --- */ 25 | 26 | private String tagKey; 27 | 28 | private String tagValue; 29 | 30 | /* --- Constructors --- */ 31 | 32 | /** 33 | * Default constructor 34 | */ 35 | public ProjectTag() { 36 | 37 | } 38 | 39 | /** 40 | * Constructor 41 | * 42 | * @param tagKey 43 | * @param tagValue 44 | */ 45 | public ProjectTag(String tagKey, String tagValue) { 46 | this.tagKey = tagKey; 47 | this.tagValue = tagValue; 48 | } 49 | 50 | /* --- Overridden methods --- */ 51 | 52 | @Override 53 | public String toString() { 54 | StringBuilder sb = new StringBuilder(); 55 | 56 | sb.append("ProjectTag@").append(Integer.toHexString(hashCode())) 57 | .append("[") 58 | .append("tagKey= ").append(tagKey).append(",") 59 | .append("tagValue= ").append(tagValue) 60 | .append(" ]"); 61 | 62 | return sb.toString(); 63 | } 64 | 65 | @Override 66 | public boolean equals(Object o) { 67 | if (this == o) return true; 68 | if (!(o instanceof ProjectTag)) return false; 69 | ProjectTag that = (ProjectTag) o; 70 | return Objects.equals(tagKey, that.tagKey) && 71 | Objects.equals(tagValue, that.tagValue); 72 | } 73 | 74 | @Override 75 | public int hashCode() { 76 | return Objects.hash(tagKey, tagValue); 77 | } 78 | 79 | public String getTagKey() { 80 | return tagKey; 81 | } 82 | 83 | public void setTagKey(String tagKey) { 84 | this.tagKey = tagKey; 85 | } 86 | 87 | public String getTagValue() { 88 | return tagValue; 89 | } 90 | 91 | public void setTagValue(String tagValue) { 92 | this.tagValue = tagValue; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/ResolverStepInfo.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.model; 2 | 3 | import java.util.Collection; 4 | import java.util.Objects; 5 | 6 | /** 7 | * @author chen.luigi 8 | */ 9 | public class ResolverStepInfo extends StepInfo { 10 | 11 | /* --- Private Members --- */ 12 | 13 | private int totalUniqueDependenciesFound; 14 | private int totalDuplicateDependenciesFound; 15 | 16 | /* --- Constructors --- */ 17 | 18 | public ResolverStepInfo(int totalUniqueDependenciesFound, int totalDuplicateDependenciesFound) { 19 | this.totalUniqueDependenciesFound = totalUniqueDependenciesFound; 20 | this.totalDuplicateDependenciesFound = totalDuplicateDependenciesFound; 21 | } 22 | 23 | public ResolverStepInfo(String stepName, long totalElapsedTime, boolean isSubStep, StepCompletionStatus stepCompletionStatus, Collection subStepsInfo, int totalUniqueDependenciesFound, int totalDuplicateDependenciesFound) { 24 | super(stepName, totalElapsedTime, isSubStep, stepCompletionStatus, subStepsInfo); 25 | this.totalUniqueDependenciesFound = totalUniqueDependenciesFound; 26 | this.totalDuplicateDependenciesFound = totalDuplicateDependenciesFound; 27 | } 28 | 29 | /* --- Overridden methods --- */ 30 | 31 | @Override 32 | public boolean equals(Object o) { 33 | if (this == o) return true; 34 | if (!(o instanceof ResolverStepInfo)) return false; 35 | if (!super.equals(o)) return false; 36 | ResolverStepInfo that = (ResolverStepInfo) o; 37 | return totalUniqueDependenciesFound == that.totalUniqueDependenciesFound && 38 | totalDuplicateDependenciesFound == that.totalDuplicateDependenciesFound; 39 | } 40 | 41 | @Override 42 | public int hashCode() { 43 | return Objects.hash(super.hashCode(), totalUniqueDependenciesFound, totalDuplicateDependenciesFound); 44 | } 45 | 46 | /* --- Getters / Setters --- */ 47 | 48 | public int getTotalUniqueDependenciesFound() { 49 | return totalUniqueDependenciesFound; 50 | } 51 | 52 | public void setTotalUniqueDependenciesFound(int totalUniqueDependenciesFound) { 53 | this.totalUniqueDependenciesFound = totalUniqueDependenciesFound; 54 | } 55 | 56 | public int getTotalDuplicateDependenciesFound() { 57 | return totalDuplicateDependenciesFound; 58 | } 59 | 60 | public void setTotalDuplicateDependenciesFound(int totalDuplicateDependenciesFound) { 61 | this.totalDuplicateDependenciesFound = totalDuplicateDependenciesFound; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/ScanMethod.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.model; 2 | 3 | 4 | import java.io.Serializable; 5 | 6 | public class ScanMethod implements Serializable { 7 | 8 | private static final long serialVersionUID = -1327471352027972845L; 9 | private String type; 10 | private String version; 11 | 12 | public ScanMethod(String type, String version) { 13 | this.type = type; 14 | this.version = version; 15 | } 16 | 17 | public String getType() { 18 | return type; 19 | } 20 | 21 | public void setType(String type) { 22 | this.type = type; 23 | } 24 | 25 | public String getVersion() { 26 | return version; 27 | } 28 | 29 | public void setVersion(String version) { 30 | this.version = version; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/ScanSummaryInfo.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.model; 2 | 3 | import java.io.Serializable; 4 | import java.util.*; 5 | 6 | /** 7 | * @author chen.luigi 8 | */ 9 | public class ScanSummaryInfo implements Serializable { 10 | 11 | /* --- Static members --- */ 12 | 13 | private static final long serialVersionUID = -3801913583253812987L; 14 | 15 | /* --- Private Members --- */ 16 | 17 | private long totalElapsedTime; 18 | private Collection stepsSummaryInfo; 19 | private List packageManagers; 20 | private List sourceControlManagers; 21 | private List containerRegistries; 22 | private List otherIntegrationTypes; 23 | private boolean isPrivileged; 24 | private ScanMethod scanMethod; 25 | private Map scanStatistics; 26 | 27 | /* --- Constructors --- */ 28 | 29 | public ScanSummaryInfo() { 30 | stepsSummaryInfo = new LinkedList<>(); 31 | packageManagers = new LinkedList<>(); 32 | containerRegistries = new LinkedList<>(); 33 | sourceControlManagers = new LinkedList<>(); 34 | otherIntegrationTypes = new LinkedList<>(); 35 | scanStatistics = new HashMap<>(); 36 | } 37 | 38 | public ScanSummaryInfo(long totalElapsedTime, Collection stepsSummaryInfo) { 39 | this(); 40 | this.totalElapsedTime = totalElapsedTime; 41 | this.stepsSummaryInfo = stepsSummaryInfo; 42 | } 43 | 44 | /* --- Overridden methods --- */ 45 | 46 | @Override 47 | public boolean equals(Object o) { 48 | if (this == o) return true; 49 | if (!(o instanceof ScanSummaryInfo)) return false; 50 | ScanSummaryInfo that = (ScanSummaryInfo) o; 51 | return totalElapsedTime == that.totalElapsedTime && 52 | Objects.equals(stepsSummaryInfo, that.stepsSummaryInfo); 53 | } 54 | 55 | @Override 56 | public int hashCode() { 57 | return Objects.hash(totalElapsedTime, stepsSummaryInfo); 58 | } 59 | 60 | /* --- Getters / Setters --- */ 61 | 62 | public Map getScanStatistics() { 63 | return scanStatistics; 64 | } 65 | 66 | public void setScanStatistics(Map scanStatistics) { 67 | this.scanStatistics = scanStatistics; 68 | } 69 | 70 | public long getTotalElapsedTime() { 71 | return totalElapsedTime; 72 | } 73 | 74 | public void setTotalElapsedTime(long totalElapsedTime) { 75 | this.totalElapsedTime = totalElapsedTime; 76 | } 77 | 78 | public Collection getStepsSummaryInfo() { 79 | return stepsSummaryInfo; 80 | } 81 | 82 | public void setStepsSummaryInfo(Collection stepsSummaryInfo) { 83 | this.stepsSummaryInfo = stepsSummaryInfo; 84 | } 85 | 86 | public List getPackageManagers() { 87 | return packageManagers; 88 | } 89 | 90 | public void setPackageManagers(List packageManagers) { 91 | this.packageManagers = packageManagers; 92 | } 93 | 94 | public List getSourceControlManagers() { 95 | return sourceControlManagers; 96 | } 97 | 98 | public void setSourceControlManagers(List sourceControlManagers) { 99 | this.sourceControlManagers = sourceControlManagers; 100 | } 101 | 102 | public List getContainerRegistries() { 103 | return containerRegistries; 104 | } 105 | 106 | public void setContainerRegistries(List containerRegistries) { 107 | this.containerRegistries = containerRegistries; 108 | } 109 | 110 | public List getOtherIntegrationTypes() { 111 | return otherIntegrationTypes; 112 | } 113 | 114 | public void setOtherIntegrationTypes(List otherIntegrationTypes) { 115 | this.otherIntegrationTypes = otherIntegrationTypes; 116 | } 117 | 118 | public boolean isPrivileged() { 119 | return isPrivileged; 120 | } 121 | 122 | public void setPrivileged(boolean privileged) { 123 | isPrivileged = privileged; 124 | } 125 | 126 | public ScanMethod getScanMethod() { 127 | return scanMethod; 128 | } 129 | 130 | public void setScanMethod(ScanMethod scanMethod) { 131 | this.scanMethod = scanMethod; 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/SecretFinding.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.model; 2 | 3 | 4 | public class SecretFinding { 5 | 6 | private int layerNumber; 7 | private String ruleId; 8 | private String category; 9 | private String severity; 10 | private String description; 11 | private int startLine; 12 | private int endLine; 13 | private String filePath; 14 | private Code code; 15 | private String match; 16 | 17 | public String getRuleId() { 18 | return ruleId; 19 | } 20 | 21 | public void setRuleId(String ruleId) { 22 | this.ruleId = ruleId; 23 | } 24 | 25 | public String getCategory() { 26 | return category; 27 | } 28 | 29 | public void setCategory(String category) { 30 | this.category = category; 31 | } 32 | 33 | public String getSeverity() { 34 | return severity; 35 | } 36 | 37 | public void setSeverity(String severity) { 38 | this.severity = severity; 39 | } 40 | 41 | public String getDescription() { 42 | return description; 43 | } 44 | 45 | public void setDescription(String description) { 46 | this.description = description; 47 | } 48 | 49 | public int getStartLine() { 50 | return startLine; 51 | } 52 | 53 | public void setStartLine(int startLine) { 54 | this.startLine = startLine; 55 | } 56 | 57 | public int getEndLine() { 58 | return endLine; 59 | } 60 | 61 | public void setEndLine(int endLine) { 62 | this.endLine = endLine; 63 | } 64 | 65 | public String getFilePath() { 66 | return filePath; 67 | } 68 | 69 | public void setFilePath(String filePath) { 70 | this.filePath = filePath; 71 | } 72 | 73 | public Code getCode() { 74 | return code; 75 | } 76 | 77 | public void setCode(Code code) { 78 | this.code = code; 79 | } 80 | 81 | public String getMatch() { 82 | return match; 83 | } 84 | 85 | public void setMatch(String match) { 86 | this.match = match; 87 | } 88 | 89 | public int getLayerNumber() { 90 | return layerNumber; 91 | } 92 | 93 | public void setLayerNumber(int layerNumber) { 94 | this.layerNumber = layerNumber; 95 | } 96 | 97 | } -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/StepCompletionStatus.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.model; 2 | 3 | /** 4 | * @author chen.luigi 5 | */ 6 | public enum StepCompletionStatus { 7 | COMPLETED, 8 | SKIPPED, 9 | FAILED 10 | } 11 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/StepInfo.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.model; 2 | 3 | import java.io.Serializable; 4 | import java.util.Collection; 5 | import java.util.LinkedList; 6 | import java.util.Objects; 7 | 8 | /** 9 | * @author chen.luigi 10 | */ 11 | public class StepInfo implements Serializable { 12 | 13 | /* --- Static Members --- */ 14 | 15 | private static final long serialVersionUID = 7972930644057281908L; 16 | 17 | /* --- Private Members --- */ 18 | 19 | private String stepName; 20 | private long totalElapsedTime; 21 | private boolean isSubStep; 22 | private StepCompletionStatus stepCompletionStatus; 23 | private Collection subStepsInfo; 24 | 25 | /* --- Constructors --- */ 26 | 27 | public StepInfo() { 28 | subStepsInfo = new LinkedList<>(); 29 | } 30 | 31 | public StepInfo(String stepName, long totalElapsedTime, boolean isSubStep, StepCompletionStatus stepCompletionStatus, Collection subStepsInfo) { 32 | this(); 33 | this.stepName = stepName; 34 | this.totalElapsedTime = totalElapsedTime; 35 | this.isSubStep = isSubStep; 36 | this.stepCompletionStatus = stepCompletionStatus; 37 | this.subStepsInfo = subStepsInfo; 38 | } 39 | 40 | /* --- Overridden Methods --- */ 41 | 42 | @Override 43 | public boolean equals(Object o) { 44 | if (this == o) return true; 45 | if (!(o instanceof StepInfo)) return false; 46 | StepInfo stepInfo = (StepInfo) o; 47 | return totalElapsedTime == stepInfo.totalElapsedTime && 48 | isSubStep == stepInfo.isSubStep && 49 | Objects.equals(stepName, stepInfo.stepName) && 50 | stepCompletionStatus == stepInfo.stepCompletionStatus && 51 | Objects.equals(subStepsInfo, stepInfo.subStepsInfo); 52 | } 53 | 54 | @Override 55 | public int hashCode() { 56 | return Objects.hash(stepName, totalElapsedTime, isSubStep, stepCompletionStatus, subStepsInfo); 57 | } 58 | 59 | /* --- Getters / Setters --- */ 60 | 61 | public String getStepName() { 62 | return stepName; 63 | } 64 | 65 | public void setStepName(String stepName) { 66 | this.stepName = stepName; 67 | } 68 | 69 | public long getTotalElapsedTime() { 70 | return totalElapsedTime; 71 | } 72 | 73 | public void setTotalElapsedTime(long totalElapsedTime) { 74 | this.totalElapsedTime = totalElapsedTime; 75 | } 76 | 77 | public boolean isSubStep() { 78 | return isSubStep; 79 | } 80 | 81 | public void setSubStep(boolean subStep) { 82 | isSubStep = subStep; 83 | } 84 | 85 | public StepCompletionStatus getStepCompletionStatus() { 86 | return stepCompletionStatus; 87 | } 88 | 89 | public void setStepCompletionStatus(StepCompletionStatus stepCompletionStatus) { 90 | this.stepCompletionStatus = stepCompletionStatus; 91 | } 92 | 93 | public Collection getSubStepsInfo() { 94 | return subStepsInfo; 95 | } 96 | 97 | public void setSubStepsInfo(Collection subStepsInfo) { 98 | this.subStepsInfo = subStepsInfo; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/VulnerabilityInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 White Source Ltd. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.model; 17 | 18 | import java.io.Serializable; 19 | import java.util.Collection; 20 | import java.util.LinkedList; 21 | 22 | /** 23 | * Info object describing a Vulnerability info 24 | * 25 | * Created by anna.rozin 26 | * 27 | * @since 2.2.8 28 | */ 29 | public class VulnerabilityInfo implements Serializable { 30 | 31 | /* --- Static members --- */ 32 | 33 | private static final long serialVersionUID = 86315184735909079L; 34 | 35 | /* --- Members --- */ 36 | 37 | private String name; 38 | private String severity; 39 | private float score; 40 | private Collection elements; 41 | private Collection vulnerableEntities; 42 | 43 | 44 | /* --- Constructors --- */ 45 | 46 | public VulnerabilityInfo () { 47 | this.elements = new LinkedList<>(); 48 | this.vulnerableEntities = new LinkedList<>(); 49 | } 50 | 51 | /* --- Getters / Setters --- */ 52 | 53 | public String getName() { 54 | return name; 55 | } 56 | 57 | public void setName(String name) { 58 | this.name = name; 59 | } 60 | 61 | public String getSeverity() { 62 | return severity; 63 | } 64 | 65 | public void setSeverity(String severity) { 66 | this.severity = severity; 67 | } 68 | 69 | public float getScore() { 70 | return score; 71 | } 72 | 73 | public void setScore(float score) { 74 | this.score = score; 75 | } 76 | 77 | public Collection getElements() { 78 | return elements; 79 | } 80 | 81 | public void setElements(Collection elements) { 82 | this.elements = elements; 83 | } 84 | 85 | public Collection getVulnerableEntities() { 86 | return vulnerableEntities; 87 | } 88 | 89 | public void setVulnerableEntities(Collection vulnerableEntities) { 90 | this.vulnerableEntities = vulnerableEntities; 91 | } 92 | } -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/VulnerabilityMetadata.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.model; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | public class VulnerabilityMetadata implements Serializable { 9 | private String fixVersion; 10 | private String cveId; 11 | private String title; 12 | private String description; 13 | private String severity; 14 | private Map vendorSeverity; 15 | private List cweIDs; 16 | private Map cvss; 17 | private List references; 18 | private Date publishDate; 19 | private Date lastModifiedDate; 20 | 21 | /* --- Constructors --- */ 22 | 23 | /** 24 | * Default constructor 25 | */ 26 | public VulnerabilityMetadata() {} 27 | 28 | 29 | public String getFixVersion() { 30 | return fixVersion; 31 | } 32 | 33 | public void setFixVersion(String fixVersion) { 34 | this.fixVersion = fixVersion; 35 | } 36 | 37 | public String getCveId() { 38 | return cveId; 39 | } 40 | 41 | public void setCveId(String cveId) { 42 | this.cveId = cveId; 43 | } 44 | 45 | public String getTitle() { 46 | return title; 47 | } 48 | 49 | public void setTitle(String title) { 50 | this.title = title; 51 | } 52 | 53 | public String getDescription() { 54 | return description; 55 | } 56 | 57 | public void setDescription(String description) { 58 | this.description = description; 59 | } 60 | 61 | public String getSeverity() { 62 | return severity; 63 | } 64 | 65 | public void setSeverity(String severity) { 66 | this.severity = severity; 67 | } 68 | 69 | public Map getVendorSeverity() { 70 | return vendorSeverity; 71 | } 72 | 73 | public void setVendorSeverity(Map vendorSeverity) { 74 | this.vendorSeverity = vendorSeverity; 75 | } 76 | 77 | public List getCweIDs() { 78 | return cweIDs; 79 | } 80 | 81 | public void setCweIDs(List cweIDs) { 82 | this.cweIDs = cweIDs; 83 | } 84 | 85 | public Map getCvss() { 86 | return cvss; 87 | } 88 | 89 | public void setCvss(Map cvss) { 90 | this.cvss = cvss; 91 | } 92 | 93 | public List getReferences() { 94 | return references; 95 | } 96 | 97 | public void setReferences(List references) { 98 | this.references = references; 99 | } 100 | 101 | public Date getPublishDate() { 102 | return publishDate; 103 | } 104 | 105 | public void setPublishDate(Date publishDate) { 106 | this.publishDate = publishDate; 107 | } 108 | 109 | public Date getLastModifiedDate() { 110 | return lastModifiedDate; 111 | } 112 | 113 | public void setLastModifiedDate(Date lastModifiedDate) { 114 | this.lastModifiedDate = lastModifiedDate; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/VulnerableEntity.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.model; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * @author chen.luigi 7 | */ 8 | public class VulnerableEntity implements Serializable { 9 | 10 | /* --- Static members --- */ 11 | 12 | private static final long serialVersionUID = 6521642112001095631L; 13 | 14 | /* --- Private Members --- */ 15 | 16 | private String element; 17 | private int startLine; 18 | private int endLine; 19 | 20 | //since 2.9.9.51 21 | private String namespace; 22 | private String className; 23 | private String method; 24 | private String language; 25 | private String type; 26 | private String extraData; 27 | 28 | /* --- Constructors --- */ 29 | 30 | public VulnerableEntity(String element, int startLine, int endLine) { 31 | this.element = element; 32 | this.startLine = startLine; 33 | this.endLine = endLine; 34 | } 35 | 36 | public VulnerableEntity(String element, int startLine, int endLine, String namespace, String className, 37 | String method, String language, String type, String extraData) { 38 | this(element, startLine, endLine); 39 | this.namespace = namespace; 40 | this.className = className; 41 | this.method = method; 42 | this.language = language; 43 | this.type = type; 44 | this.extraData = extraData; 45 | } 46 | 47 | /* --- Getters / Setters --- */ 48 | 49 | public String getElement() { 50 | return element; 51 | } 52 | 53 | public void setElement(String element) { 54 | this.element = element; 55 | } 56 | 57 | public int getStartLine() { 58 | return startLine; 59 | } 60 | 61 | public void setStartLine(int startLine) { 62 | this.startLine = startLine; 63 | } 64 | 65 | public int getEndLine() { 66 | return endLine; 67 | } 68 | 69 | public void setEndLine(int endLine) { 70 | this.endLine = endLine; 71 | } 72 | 73 | public String getNamespace() { 74 | return namespace; 75 | } 76 | 77 | public void setNamespace(String namespace) { 78 | this.namespace = namespace; 79 | } 80 | 81 | public String getClassName() { 82 | return className; 83 | } 84 | 85 | public void setClassName(String className) { 86 | this.className = className; 87 | } 88 | 89 | public String getMethod() { 90 | return method; 91 | } 92 | 93 | public void setMethod(String method) { 94 | this.method = method; 95 | } 96 | 97 | public String getLanguage() { 98 | return language; 99 | } 100 | 101 | public void setLanguage(String language) { 102 | this.language = language; 103 | } 104 | 105 | public String getType() { 106 | return type; 107 | } 108 | 109 | public void setType(String type) { 110 | this.type = type; 111 | } 112 | 113 | public String getExtraData() { 114 | return extraData; 115 | } 116 | 117 | public void setExtraData(String extraData) { 118 | this.extraData = extraData; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/contribution/ContributingDeveloperInfo.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.model.contribution; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * This object represents the contribution of a developer in a single repository. 7 | * 8 | * @author tom.shapira 9 | */ 10 | public class ContributingDeveloperInfo implements Serializable { 11 | 12 | private static final long serialVersionUID = 8797583403121221703L; 13 | 14 | private String email; 15 | private int commits; 16 | 17 | public ContributingDeveloperInfo() { 18 | } 19 | 20 | public ContributingDeveloperInfo(String email, int commits) { 21 | this.email = email; 22 | this.commits = commits; 23 | } 24 | 25 | public String getEmail() { 26 | return email; 27 | } 28 | 29 | public void setEmail(String email) { 30 | this.email = email; 31 | } 32 | 33 | public int getCommits() { 34 | return commits; 35 | } 36 | 37 | public void setCommits(int commits) { 38 | this.commits = commits; 39 | } 40 | } -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/contribution/ContributionInfo.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.model.contribution; 2 | 3 | import java.io.Serializable; 4 | import java.util.Collection; 5 | import java.util.LinkedList; 6 | 7 | /** 8 | * This object represents the code contributions made in a single repository. 9 | * 10 | * @author tom.shapira 11 | */ 12 | public class ContributionInfo implements Serializable { 13 | 14 | private static final long serialVersionUID = 6052569974965476656L; 15 | 16 | private String repository; 17 | private Collection contributingDevelopers; 18 | 19 | public ContributionInfo() { 20 | contributingDevelopers = new LinkedList<>(); 21 | } 22 | 23 | public ContributionInfo(String repository) { 24 | this.repository = repository; 25 | } 26 | 27 | public String getRepository() { 28 | return repository; 29 | } 30 | 31 | public void setRepository(String repository) { 32 | this.repository = repository; 33 | } 34 | 35 | public Collection getContributingDevelopers() { 36 | return contributingDevelopers; 37 | } 38 | 39 | public void setContributingDevelopers(Collection contributingDevelopers) { 40 | this.contributingDevelopers = contributingDevelopers; 41 | } 42 | } -------------------------------------------------------------------------------- /wss-agent-api/src/main/java/org/whitesource/agent/api/model/contribution/ContributionInfoCollection.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.api.model.contribution; 2 | 3 | import java.util.Collection; 4 | import java.util.LinkedList; 5 | 6 | /** 7 | * This object represents a collection of code contributions made in a single repository. 8 | * 9 | * @author tom.shapira 10 | */ 11 | public class ContributionInfoCollection extends LinkedList { 12 | 13 | private static final long serialVersionUID = -5141569905340706621L; 14 | 15 | public ContributionInfoCollection() { 16 | } 17 | 18 | public ContributionInfoCollection(Collection c) { 19 | super(c); 20 | } 21 | } -------------------------------------------------------------------------------- /wss-agent-api/src/test/java/org/whitesource/agent/api/model/PolicyCheckResourceNodeTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.api.model; 17 | 18 | import org.junit.Test; 19 | 20 | import static org.junit.Assert.assertTrue; 21 | 22 | /** 23 | * @author Edo.Shor 24 | */ 25 | public class PolicyCheckResourceNodeTest { 26 | 27 | @Test 28 | public void testGetRejections() { 29 | RequestPolicyInfo approvePolicy = new RequestPolicyInfo("Approve something"); 30 | approvePolicy.setActionType("Approve"); 31 | RequestPolicyInfo rejectPolicy = new RequestPolicyInfo("Reject something"); 32 | rejectPolicy.setActionType("Reject"); 33 | 34 | PolicyCheckResourceNode root = new PolicyCheckResourceNode(); 35 | 36 | root.getChildren().add(new PolicyCheckResourceNode(new ResourceInfo("resource-1"), rejectPolicy)); 37 | root.getChildren().add(new PolicyCheckResourceNode(new ResourceInfo("resource-2"), null)); 38 | root.getChildren().add(new PolicyCheckResourceNode(new ResourceInfo("resource-3"), approvePolicy)); 39 | 40 | PolicyCheckResourceNode node = new PolicyCheckResourceNode(new ResourceInfo("resource-4"), null); 41 | node.getChildren().add(new PolicyCheckResourceNode(new ResourceInfo("resource-44"), rejectPolicy)); 42 | node.getChildren().add(new PolicyCheckResourceNode(new ResourceInfo("resource-45"), rejectPolicy)); 43 | node.getChildren().add(new PolicyCheckResourceNode(new ResourceInfo("resource-46"), null)); 44 | node.getChildren().add(new PolicyCheckResourceNode(new ResourceInfo("resource-47"), approvePolicy)); 45 | root.getChildren().add(node); 46 | 47 | assertTrue(root.hasRejections()); 48 | assertTrue(node.hasRejections()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /wss-agent-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | wss-agent-parent 6 | org.whitesource 7 | 2.9.9.101-SNAPSHOT 8 | 9 | 10 | wss-agent-api-client 11 | jar 12 | 13 | API client implementation 14 | Java client implementation for the API 15 | 16 | 17 | 18 | 19 | org.whitesource 20 | wss-agent-api 21 | ${project.version} 22 | 23 | 24 | org.whitesource 25 | wss-agent-hash-calculator 26 | ${project.version} 27 | 28 | 29 | org.whitesource 30 | wss-agent-utils 31 | ${project.version} 32 | 33 | 34 | 35 | 36 | com.google.code.gson 37 | gson 38 | 39 | 40 | org.apache.httpcomponents 41 | httpclient 42 | 43 | 44 | org.bidib.com.github.markusbernhardt 45 | proxy-vole 46 | 1.1.6 47 | 48 | 49 | net.java.dev.jna 50 | jna-platform 51 | 52 | 53 | net.java.dev.jna 54 | jna 55 | 56 | 57 | 58 | 59 | 60 | 61 | junit 62 | junit 63 | 64 | 65 | org.hamcrest 66 | hamcrest-core 67 | 68 | 69 | 70 | 71 | org.hamcrest 72 | hamcrest-integration 73 | 74 | 75 | org.apache.httpcomponents 76 | httpclient 77 | tests 78 | 79 | 80 | org.mockito 81 | mockito-core 82 | 83 | 84 | org.hamcrest 85 | hamcrest-core 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | commons-logging 95 | commons-logging 96 | 1.3.2 97 | 98 | 99 | 100 | 101 | 102 | 103 | Release 104 | 105 | false 106 | 107 | 108 | 109 | 110 | com.github.github 111 | site-maven-plugin 112 | 113 | wss-agent-api-client 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /wss-agent-client/src/main/java/org/whitesource/agent/client/ClientConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.client; 17 | 18 | /** 19 | * WhiteSource service API client constants. 20 | * 21 | * @author tom.shapira 22 | */ 23 | public final class ClientConstants { 24 | 25 | /* --- Service info --- */ 26 | 27 | public static final String SERVICE_URL_KEYWORD = "wss.url"; 28 | 29 | public static final String CONNECTION_TIMEOUT_KEYWORD = "wss.connectionTimeoutMinutes"; 30 | 31 | public static final String DEFAULT_SERVICE_URL = "https://saas.whitesourcesoftware.com/agent"; 32 | 33 | public static final String APPLICATION_JSON = "application/json"; 34 | 35 | public static final int DEFAULT_CONNECTION_TIMEOUT_MINUTES = 60; 36 | 37 | /* --- Constructors --- */ 38 | 39 | /** 40 | * Private default constructor 41 | */ 42 | private ClientConstants() { 43 | // avoid instantiation 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /wss-agent-client/src/main/java/org/whitesource/agent/client/WssSSLSocketFactory.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.client; 2 | 3 | import java.io.IOException; 4 | import java.net.Socket; 5 | import java.net.UnknownHostException; 6 | import java.security.KeyManagementException; 7 | import java.security.KeyStore; 8 | import java.security.KeyStoreException; 9 | import java.security.NoSuchAlgorithmException; 10 | import java.security.UnrecoverableKeyException; 11 | import java.security.cert.CertificateException; 12 | import java.security.cert.X509Certificate; 13 | 14 | import javax.net.ssl.SSLContext; 15 | import javax.net.ssl.TrustManager; 16 | import javax.net.ssl.X509TrustManager; 17 | 18 | import org.apache.http.conn.ssl.SSLSocketFactory; 19 | public class WssSSLSocketFactory extends SSLSocketFactory { 20 | SSLContext sslContext = SSLContext.getInstance("TLS"); 21 | 22 | public WssSSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { 23 | super(truststore); 24 | 25 | TrustManager tm = new X509TrustManager() { 26 | public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { 27 | } 28 | 29 | public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { 30 | } 31 | 32 | public X509Certificate[] getAcceptedIssuers() { 33 | return null; 34 | } 35 | }; 36 | 37 | sslContext.init(null, new TrustManager[] { tm }, null); 38 | } 39 | 40 | @Override 41 | public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException { 42 | return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose); 43 | } 44 | 45 | @Override 46 | public Socket createSocket() throws IOException { 47 | return sslContext.getSocketFactory().createSocket(); 48 | } 49 | } -------------------------------------------------------------------------------- /wss-agent-client/src/main/java/org/whitesource/agent/client/WssServiceException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.client; 17 | 18 | 19 | /** 20 | * Exception for errors encountered while interacting with the WhiteSource service. 21 | * 22 | * @author Edo.Shor 23 | */ 24 | public class WssServiceException extends Exception { 25 | 26 | /* --- Static members --- */ 27 | 28 | private static final long serialVersionUID = -6703395740692354154L; 29 | 30 | /* --- Members --- */ 31 | 32 | private String requestToken; 33 | private int statusCode; 34 | 35 | /* --- Constructors --- */ 36 | 37 | public WssServiceException(){ 38 | super(); 39 | } 40 | 41 | public WssServiceException(String message){ 42 | super(message); 43 | } 44 | 45 | public WssServiceException(String message, String requestToken) { 46 | super(message); 47 | this.requestToken = requestToken; 48 | } 49 | 50 | public WssServiceException(Throwable cause){ 51 | super(cause); 52 | } 53 | 54 | public WssServiceException(String message, Throwable cause){ 55 | super(message, cause); 56 | } 57 | 58 | public WssServiceException(String message, Throwable cause, int statusCode) { 59 | super(message, cause); 60 | this.statusCode = statusCode; 61 | } 62 | 63 | /* --- Getters / Setters --- */ 64 | 65 | public String getRequestToken() { 66 | return requestToken; 67 | } 68 | 69 | public void setRequestToken(String requestToken) { 70 | this.requestToken = requestToken; 71 | } 72 | 73 | public int getStatusCode() { 74 | return statusCode; 75 | } 76 | 77 | public void setStatusCode(int statusCode) { 78 | this.statusCode = statusCode; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /wss-agent-client/src/test/java/org/whitesource/agent/client/WhitesourceServiceTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.client; 17 | 18 | import org.junit.Test; 19 | import org.junit.runner.RunWith; 20 | import org.mockito.ArgumentCaptor; 21 | import org.mockito.Mock; 22 | import org.mockito.runners.MockitoJUnitRunner; 23 | import org.whitesource.agent.api.dispatch.CheckPoliciesRequest; 24 | import org.whitesource.agent.api.dispatch.UpdateInventoryRequest; 25 | import org.whitesource.agent.api.model.AgentProjectInfo; 26 | 27 | import java.util.ArrayList; 28 | 29 | import static org.junit.Assert.assertEquals; 30 | import static org.junit.Assert.assertTrue; 31 | import static org.mockito.Mockito.verify; 32 | 33 | /** 34 | * @author Edo.Shor 35 | */ 36 | @RunWith(MockitoJUnitRunner.class) 37 | public class WhitesourceServiceTest { 38 | 39 | /* --- Members --- */ 40 | 41 | @Mock 42 | private WssServiceClient client; 43 | 44 | /* --- Test methods --- */ 45 | 46 | @Test 47 | public void testDefaultConstructor() { 48 | WhitesourceService service = new WhitesourceService(); 49 | 50 | UpdateInventoryRequest updateRequest = service.getRequestFactory().newUpdateInventoryRequest("orgToken", null, "userKey" ); 51 | assertEquals("generic", updateRequest.agent()); 52 | assertEquals("1.0", updateRequest.agentVersion()); 53 | assertEquals(ClientConstants.DEFAULT_SERVICE_URL, ((WssServiceClientImpl) service.getClient()).getServiceUrl()); 54 | 55 | service = new WhitesourceService("agent", "agentVersion", "pluginVersion"); 56 | updateRequest = service.getRequestFactory().newUpdateInventoryRequest("orgToken", null, "userKey"); 57 | assertEquals("agent", updateRequest.agent()); 58 | assertEquals("agentVersion", updateRequest.agentVersion()); 59 | assertEquals(ClientConstants.DEFAULT_SERVICE_URL, ((WssServiceClientImpl) service.getClient()).getServiceUrl()); 60 | 61 | System.setProperty(ClientConstants.SERVICE_URL_KEYWORD, "serviceUrl"); 62 | service = new WhitesourceService(); 63 | assertEquals("serviceUrl", ((WssServiceClientImpl) service.getClient()).getServiceUrl()); 64 | 65 | service = new WhitesourceService("agent", "agentVersion", "pluginVersion", "serviceUrl"); 66 | assertEquals("serviceUrl", ((WssServiceClientImpl) service.getClient()).getServiceUrl()); 67 | } 68 | 69 | @Test 70 | public void testServiceMethods() throws WssServiceException { 71 | WhitesourceService service = new WhitesourceService(); 72 | service.setClient(client); 73 | 74 | service.update("orgToken", "product", "productVersion", new ArrayList(), "userKey"); 75 | ArgumentCaptor updateCaptor = ArgumentCaptor.forClass(UpdateInventoryRequest.class); 76 | verify(client).updateInventory(updateCaptor.capture()); 77 | assertEquals("orgToken", updateCaptor.getValue().orgToken()); 78 | assertEquals("product", updateCaptor.getValue().product()); 79 | assertEquals("productVersion", updateCaptor.getValue().productVersion()); 80 | assertTrue(updateCaptor.getValue().getProjects().isEmpty()); 81 | 82 | service.checkPolicies("orgToken", "product", "productVersion", new ArrayList(), "userKey"); 83 | ArgumentCaptor checkPoliciesCaptor = ArgumentCaptor.forClass(CheckPoliciesRequest.class); 84 | verify(client).checkPolicies(checkPoliciesCaptor.capture()); 85 | assertEquals("orgToken", checkPoliciesCaptor.getValue().orgToken()); 86 | assertEquals("product", updateCaptor.getValue().product()); 87 | assertEquals("productVersion", updateCaptor.getValue().productVersion()); 88 | 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /wss-agent-hash-calculator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | org.whitesource 7 | wss-agent-parent 8 | 2.9.9.101-SNAPSHOT 9 | 10 | 11 | org.whitesource 12 | wss-agent-hash-calculator 13 | 2.9.9.101-SNAPSHOT 14 | 15 | 16 | 17 | org.whitesource 18 | wss-agent-api 19 | ${project.version} 20 | 21 | 22 | 23 | org.apache.commons 24 | commons-lang3 25 | 26 | 27 | commons-codec 28 | commons-codec 29 | ${commonscodec.version} 30 | 31 | 32 | commons-io 33 | commons-io 34 | ${commonsio.version} 35 | 36 | 37 | 38 | 39 | org.whitesource 40 | pecoff4j 41 | 0.0.2.1 42 | 43 | 44 | 45 | 46 | net.java.dev.jna 47 | jna-platform 48 | 49 | 5.6.0 50 | 51 | 52 | 53 | 54 | org.mozilla 55 | rhino 56 | 1.7.7.2 57 | 58 | 59 | 60 | 61 | org.slf4j 62 | slf4j-api 63 | 1.7.30 64 | provided 65 | 66 | 67 | ch.qos.logback 68 | logback-classic 69 | 1.2.3 70 | provided 71 | 72 | 73 | org.slf4j 74 | slf4j-api 75 | 76 | 77 | 78 | 79 | 80 | 81 | junit 82 | junit 83 | test 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /wss-agent-hash-calculator/src/main/java/org/whitesource/agent/hash/FileHandler.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.hash; 2 | 3 | import org.apache.commons.io.FileUtils; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.nio.file.Paths; 8 | import java.text.SimpleDateFormat; 9 | import java.util.Date; 10 | import java.util.UUID; 11 | 12 | /** 13 | * @author philip.abed 14 | */ 15 | public class FileHandler { 16 | private static String EMPTY_STRING = ""; 17 | private static String UNDERSCORE = "_"; 18 | /* --- public static methods --- */ 19 | private static final String WHITESOURCE_PLATFORM_DEPENDENT_TMP_DIR = "WhiteSource-PlatformDependentFiles"; 20 | public static final String PLATFORM_DEPENDENT_TMP_DIRECTORY = FileHandler.createUniqueName(WHITESOURCE_PLATFORM_DEPENDENT_TMP_DIR, EMPTY_STRING); 21 | public static final String PATH_TO_PLATFORM_DEPENDENT_TMP_DIR = Paths.get(System.getProperty("java.io.tmpdir"), PLATFORM_DEPENDENT_TMP_DIRECTORY).toString(); 22 | 23 | 24 | public static String createUniqueName(String name, String extension) { 25 | if (name == null) { 26 | name = EMPTY_STRING; 27 | } 28 | if (extension == null) { 29 | extension = EMPTY_STRING; 30 | } 31 | String creationDate = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); 32 | String uuid = UUID.randomUUID().toString(); 33 | return name + UNDERSCORE + creationDate + UNDERSCORE + uuid + extension; 34 | } 35 | 36 | public static void deleteTempFoldersHelper(String path) { 37 | if (path != null) { 38 | File file = new File(path); 39 | if (file != null) { 40 | deleteDirectory(file); 41 | } 42 | } 43 | } 44 | public static void deleteDirectory(File directory) { 45 | if (directory != null) { 46 | try { 47 | FileUtils.forceDelete(directory); 48 | } catch (IOException e) { 49 | // do nothing 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /wss-agent-hash-calculator/src/main/java/org/whitesource/agent/hash/FileUtils.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.hash; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | 9 | /** 10 | * Utility class for modifying files. 11 | * 12 | * @author tom.shapira 13 | */ 14 | public final class FileUtils { 15 | 16 | /* --- Static members --- */ 17 | 18 | private static final Logger logger = LoggerFactory.getLogger(FileUtils.class); 19 | 20 | // private static final String PLATFORM_DEPENDENT_TMP_DIRECTORY = System.getProperty("java.io.tmpdir") + File.separator + "WhiteSource-PlatformDependentFiles"; 21 | 22 | private static final String EMPTY_STRING = ""; 23 | 24 | public static final int MAX_FILE_SIZE = 10 * 1024 * 1024; // 10mb 25 | 26 | private static final String CRLF = "\r\n"; 27 | private static final String NEW_LINE = "\n"; 28 | 29 | 30 | /* --- Constructors --- */ 31 | 32 | /** 33 | * Private default constructor 34 | */ 35 | private FileUtils() { 36 | // avoid instantiation 37 | } 38 | 39 | /* --- Public methods --- */ 40 | 41 | public static File createOtherPlatformFile(File originalPlatform) { 42 | // calculate other platform sha1 for files larger than MAX_FILE_SIZE 43 | long length = originalPlatform.length(); 44 | if (length < MAX_FILE_SIZE && length < Runtime.getRuntime().freeMemory()) { 45 | try { 46 | byte[] byteArray = org.apache.commons.io.FileUtils.readFileToByteArray(originalPlatform); 47 | 48 | String fileText = new String(byteArray); 49 | File otherPlatformFile = new File(FileHandler.PATH_TO_PLATFORM_DEPENDENT_TMP_DIR, originalPlatform.getName()); 50 | if (fileText.contains(CRLF)) { 51 | org.apache.commons.io.FileUtils.write(otherPlatformFile, fileText.replaceAll(CRLF, NEW_LINE)); 52 | } else if (fileText.contains(NEW_LINE)) { 53 | org.apache.commons.io.FileUtils.write(otherPlatformFile, fileText.replaceAll(NEW_LINE, CRLF)); 54 | } 55 | 56 | if (otherPlatformFile.exists()) { 57 | return otherPlatformFile; 58 | } 59 | } catch (IOException e) { 60 | return null; 61 | } 62 | } 63 | return null; 64 | } 65 | 66 | /* --- Private methods --- */ 67 | 68 | private static String cleanLine(String line) { 69 | return line.replace("/**", EMPTY_STRING).replace("/*", EMPTY_STRING) 70 | .replace("*", EMPTY_STRING).replace("#", EMPTY_STRING) 71 | .replace("/", EMPTY_STRING).replace("\\t", EMPTY_STRING) 72 | .replace("\\n", EMPTY_STRING).trim(); 73 | } 74 | 75 | private static void deleteFile(File file) { 76 | if (file != null) { 77 | try { 78 | org.apache.commons.io.FileUtils.forceDelete(file); 79 | } catch (IOException e) { 80 | // do nothing 81 | } 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /wss-agent-hash-calculator/src/main/java/org/whitesource/agent/hash/HashAlgorithm.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.hash; 2 | 3 | /** 4 | * Enum for hash algorithms. 5 | * 6 | * @author chen.luigi 7 | */ 8 | public enum HashAlgorithm { 9 | 10 | MD5("MD5"), 11 | SHA1("SHA1"), 12 | SHA256("SHA-256"), 13 | SHA512("SHA-512"); 14 | 15 | /* --- Private members --- */ 16 | 17 | private String algorithm; 18 | 19 | /* --- Constructor --- */ 20 | 21 | HashAlgorithm(String algorithm) { 22 | this.algorithm = algorithm; 23 | } 24 | 25 | /* --- Public methods --- */ 26 | 27 | public String getAlgorithm() { 28 | return algorithm; 29 | } 30 | } -------------------------------------------------------------------------------- /wss-agent-hash-calculator/src/main/java/org/whitesource/agent/hash/HashCalculationResult.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.hash; 17 | 18 | import org.apache.commons.lang3.builder.CompareToBuilder; 19 | 20 | import java.util.Objects; 21 | 22 | /** 23 | * This object holds the various hashes calculated for a single file. 24 | * 25 | * @author tom.shapira 26 | */ 27 | public class HashCalculationResult implements Comparable { 28 | 29 | /* --- Members --- */ 30 | 31 | private String fullHash; 32 | 33 | /* --- Constructors --- */ 34 | 35 | public HashCalculationResult(String fullHash) { 36 | this.fullHash = fullHash; 37 | } 38 | 39 | /* --- Overridden --- */ 40 | 41 | @Override 42 | public int compareTo(Object o) { 43 | HashCalculationResult myClass = (HashCalculationResult) o; 44 | return new CompareToBuilder() 45 | .append(this.fullHash, myClass.fullHash) 46 | .toComparison(); 47 | } 48 | 49 | @Override 50 | public boolean equals(Object o) { 51 | if (this == o) return true; 52 | if (!(o instanceof HashCalculationResult)) return false; 53 | HashCalculationResult that = (HashCalculationResult) o; 54 | return Objects.equals(fullHash, that.fullHash); 55 | } 56 | 57 | @Override 58 | public int hashCode() { 59 | return Objects.hash(fullHash); 60 | } 61 | 62 | /* --- Getters / Setters --- */ 63 | 64 | public String getFullHash() { 65 | return fullHash; 66 | } 67 | 68 | public void setFullHash(String fullHash) { 69 | this.fullHash = fullHash; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /wss-agent-hash-calculator/src/main/java/org/whitesource/agent/hash/RegexUtils.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.hash; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | /** 6 | * Utility class for regular expressions related functionality. 7 | * 8 | * @author Edo.Shor 9 | */ 10 | public final class RegexUtils { 11 | 12 | /* --- Public methods --- */ 13 | 14 | public static String toJava(String regex) { 15 | if (StringUtils.isBlank(regex)) { 16 | return regex; 17 | } else { 18 | return regex.replaceAll("\\.", "\\\\.") 19 | .replaceAll("\\*",".*"); 20 | } 21 | } 22 | 23 | /* --- Constructors --- */ 24 | 25 | /** 26 | * Private default constructor 27 | */ 28 | private RegexUtils() { 29 | // avoid instantiation 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /wss-agent-hash-calculator/src/main/java/org/whitesource/agent/hash/WssHashException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.hash; 17 | 18 | 19 | /** 20 | * Exception for errors encountered while interacting with the WhiteSource service. 21 | * 22 | * @author Edo.Shor 23 | */ 24 | public class WssHashException extends Exception { 25 | 26 | /* --- Static members --- */ 27 | 28 | private static final long serialVersionUID = -6703395740692354154L; 29 | 30 | /* --- Constructors --- */ 31 | 32 | public WssHashException(){ 33 | super(); 34 | } 35 | 36 | public WssHashException(String message){ 37 | super(message); 38 | } 39 | 40 | public WssHashException(Throwable cause){ 41 | super(cause); 42 | } 43 | 44 | public WssHashException(String message, Throwable cause){ 45 | super(message, cause); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /wss-agent-hash-calculator/src/main/java/org/whitesource/agent/parser/JavaScriptParser.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.parser; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | import org.mozilla.javascript.CompilerEnvirons; 5 | import org.mozilla.javascript.Parser; 6 | import org.mozilla.javascript.ast.AstRoot; 7 | import org.mozilla.javascript.ast.Comment; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import java.io.StringReader; 11 | import java.util.SortedSet; 12 | 13 | /** 14 | * Parser for JavaScript files. 15 | * 16 | * @author tom.shapira 17 | */ 18 | public class JavaScriptParser { 19 | 20 | /* --- Static members --- */ 21 | 22 | private static final org.slf4j.Logger logger = LoggerFactory.getLogger(JavaScriptParser.class); 23 | 24 | private static final String EMPTY_STRING = ""; 25 | 26 | private static final String COMMENT_REGEX = "(/\\*[\\s\\S]*?\\*/)"; 27 | 28 | /* --- Public methods --- */ 29 | 30 | /** 31 | * Parse the file content and return variants of the file. 32 | * 33 | * @param fileContent to parse 34 | * @return the parsing result 35 | */ 36 | public ParseResult parse(String fileContent) { 37 | ParseResult result = null; 38 | 39 | // setup environment and initialize the parser. 40 | CompilerEnvirons environment = new CompilerEnvirons(); 41 | environment.setLanguageVersion(180); 42 | environment.setStrictMode(false); 43 | environment.setRecordingComments(true); 44 | environment.setAllowSharpComments(true); 45 | environment.setRecordingLocalJsDocComments(true); 46 | 47 | // IMPORTANT: the parser can only be used once! 48 | Parser parser = new Parser(environment); 49 | try { 50 | AstRoot root = parser.parse(new StringReader(fileContent), null, 1); 51 | result = new ParseResult(); 52 | 53 | // remove all comments 54 | result.setContentWithoutComments(root.toSource()); 55 | 56 | // remove all header comments 57 | SortedSet comments = root.getComments(); 58 | if (comments != null && !comments.isEmpty()) { 59 | String headerlessFileContent = removeHeaderComments(fileContent, comments); 60 | result.setContentWithoutHeaderComments(headerlessFileContent); 61 | } 62 | } catch (Exception e) { 63 | logger.debug("Error parsing JavaScript file: {}", e.getMessage()); 64 | } 65 | return result; 66 | } 67 | 68 | /* --- Private methods --- */ 69 | 70 | /** 71 | * Go over each comment and remove from content until reaching the beginning of the actual code. 72 | */ 73 | private String removeHeaderComments(String fileContent, SortedSet comments) { 74 | String headerlessFileContent = fileContent; 75 | for (Comment comment : comments) { 76 | String commentValue = comment.getValue(); 77 | if (headerlessFileContent.startsWith(commentValue)) { 78 | headerlessFileContent = headerlessFileContent.replace(commentValue, EMPTY_STRING); 79 | // remove all leading white spaces and new line characters 80 | while (StringUtils.isNotBlank(headerlessFileContent) && Character.isWhitespace(headerlessFileContent.charAt(0))) { 81 | headerlessFileContent = headerlessFileContent.substring(1); 82 | } 83 | } else { 84 | // finished removing all header comments 85 | break; 86 | } 87 | } 88 | return headerlessFileContent; 89 | } 90 | } -------------------------------------------------------------------------------- /wss-agent-hash-calculator/src/main/java/org/whitesource/agent/parser/ParseResult.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.parser; 2 | 3 | /** 4 | * @author tom.shapira 5 | */ 6 | public class ParseResult { 7 | 8 | /* --- Members --- */ 9 | 10 | /** 11 | * Doesn't resemble the file content in terms of spaces, tabs, indentation, but has the same content without comments. 12 | */ 13 | private String contentWithoutComments; 14 | 15 | /** 16 | * Resembles the file content exactly but without comments in the header of the file. 17 | */ 18 | private String contentWithoutHeaderComments; 19 | 20 | /* --- Getters / Setters --- */ 21 | 22 | public String getContentWithoutComments() { 23 | return contentWithoutComments; 24 | } 25 | 26 | public void setContentWithoutComments(String contentWithoutComments) { 27 | this.contentWithoutComments = contentWithoutComments; 28 | } 29 | 30 | public String getContentWithoutHeaderComments() { 31 | return contentWithoutHeaderComments; 32 | } 33 | 34 | public void setContentWithoutHeaderComments(String contentWithoutHeaderComments) { 35 | this.contentWithoutHeaderComments = contentWithoutHeaderComments; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /wss-agent-hash-calculator/src/test/java/org/whitesource/agent/hash/JavaScriptHashCalculatorTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.hash; 17 | 18 | import junit.framework.Assert; 19 | import org.apache.commons.codec.binary.StringUtils; 20 | import org.apache.commons.io.IOUtils; 21 | import org.junit.Test; 22 | import org.whitesource.agent.api.model.ChecksumType; 23 | import org.whitesource.agent.parser.JavaScriptParser; 24 | import org.whitesource.agent.parser.ParseResult; 25 | 26 | import java.io.File; 27 | import java.io.FileInputStream; 28 | import java.io.IOException; 29 | import java.net.URLDecoder; 30 | import java.util.Map; 31 | 32 | import static org.junit.Assert.assertTrue; 33 | 34 | /** 35 | * Test class for {@link HashCalculator}. 36 | * 37 | * @author asaf.savich 38 | */ 39 | public class JavaScriptHashCalculatorTest { 40 | 41 | /* --- Static members --- */ 42 | 43 | private static final String SHA1 = "34b52cd823327013a78bd9c9f10d08e908d4d76d"; 44 | private static final String NO_HEADER_SHA1 = "05a11a55eef5239b3ebb983f6234365014d937c0"; 45 | private static final String NO_COMMENTS_SUPER_HASH = "a8d1acba4fe94512f71d8dd4666653a231abf6e1"; 46 | 47 | private static final String JQUERY_JUSTIFIED_GALLERY_JS = "/js/jquery.justifiedGallery.js"; 48 | private static final String UTF_8 = "utf-8"; 49 | /* --- Test methods --- */ 50 | 51 | @Test 52 | public void testParseJavaScript() throws IOException { 53 | String filePath = getClass().getResource(JQUERY_JUSTIFIED_GALLERY_JS).getFile(); 54 | File file = new File(URLDecoder.decode(filePath, UTF_8)); 55 | String fileContent = IOUtils.toString(new FileInputStream(file), UTF_8); 56 | ParseResult parseResult = new JavaScriptParser().parse(fileContent); 57 | String headerlessContent = parseResult.getContentWithoutHeaderComments(); 58 | assertTrue(headerlessContent.startsWith("(function (factory) {")); 59 | String commentlessContent = parseResult.getContentWithoutComments(); 60 | assertTrue(commentlessContent.startsWith("(function(factory) {")); 61 | } 62 | 63 | // @Ignore 64 | @Test 65 | public void testCalculateJavaScriptHash() throws IOException, WssHashException { 66 | HashCalculator hashCalculator = new HashCalculator(); 67 | String filePath = getClass().getResource(JQUERY_JUSTIFIED_GALLERY_JS).getFile(); 68 | File file = new File(filePath); 69 | String fileContent = IOUtils.toString(new FileInputStream(file)).replaceAll("\\r\\n", "\n"); 70 | byte[] fileBytes = StringUtils.getBytesUtf8(fileContent); 71 | String normalSha1 = hashCalculator.calculateByteArraySHA1(fileBytes); 72 | Map javascriptChecksums = hashCalculator.calculateJavaScriptHashes(fileBytes); 73 | 74 | Assert.assertEquals(SHA1, normalSha1); 75 | Assert.assertEquals(NO_HEADER_SHA1, javascriptChecksums.get(ChecksumType.SHA1_NO_HEADER)); 76 | Assert.assertEquals(NO_COMMENTS_SUPER_HASH, javascriptChecksums.get(ChecksumType.SHA1_NO_COMMENTS_SUPER_HASH)); 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /wss-agent-hash-calculator/src/test/resources/empty-file.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whitesource/agents/c86f687c89c1a93c9e8a4c859b690109342c571b/wss-agent-hash-calculator/src/test/resources/empty-file.txt -------------------------------------------------------------------------------- /wss-agent-hash-calculator/src/test/resources/non-empty-file.txt: -------------------------------------------------------------------------------- 1 | Some text can go in here... 2 | Some text can go in here... 3 | Some text can go in here... 4 | Some text can go in here... 5 | Some text can go in here... 6 | Some text can go in here... 7 | Some text can go in here... 8 | Some text can go in here... 9 | Some text can go in here... 10 | Some text can go in here... 11 | Some text can go in here... 12 | Some text can go in here... 13 | Some text can go in here... 14 | Some text can go in here... 15 | Some text can go in here... 16 | Some text can go in here... 17 | Some text can go in here... 18 | Some text can go in here... 19 | Some text can go in here... 20 | Some text can go in here... 21 | Some text can go in here... 22 | Some text can go in here... 23 | Some text can go in here... 24 | Some text can go in here... 25 | Some text can go in here... -------------------------------------------------------------------------------- /wss-agent-hash-calculator/src/test/resources/pecoff4j/3ba03ffe.msi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whitesource/agents/c86f687c89c1a93c9e8a4c859b690109342c571b/wss-agent-hash-calculator/src/test/resources/pecoff4j/3ba03ffe.msi -------------------------------------------------------------------------------- /wss-agent-hash-calculator/src/test/resources/pecoff4j/Signature.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whitesource/agents/c86f687c89c1a93c9e8a4c859b690109342c571b/wss-agent-hash-calculator/src/test/resources/pecoff4j/Signature.dll -------------------------------------------------------------------------------- /wss-agent-hash-calculator/src/test/resources/pecoff4j/ZedGraph.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whitesource/agents/c86f687c89c1a93c9e8a4c859b690109342c571b/wss-agent-hash-calculator/src/test/resources/pecoff4j/ZedGraph.dll -------------------------------------------------------------------------------- /wss-agent-hash-calculator/src/test/resources/pecoff4j/aopalliance-1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whitesource/agents/c86f687c89c1a93c9e8a4c859b690109342c571b/wss-agent-hash-calculator/src/test/resources/pecoff4j/aopalliance-1.0.jar -------------------------------------------------------------------------------- /wss-agent-hash-calculator/src/test/resources/pecoff4j/java-rmi.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whitesource/agents/c86f687c89c1a93c9e8a4c859b690109342c571b/wss-agent-hash-calculator/src/test/resources/pecoff4j/java-rmi.exe -------------------------------------------------------------------------------- /wss-agent-hash-calculator/src/test/resources/superHash/lsb-test.txt: -------------------------------------------------------------------------------- 1 | public static class HashCalculationResult { 2 | 3 | /* --- Members --- */ 4 | 5 | private String fullHash; 6 | private String mostSigBitsHash; 7 | private String leastSigBitsHash; 8 | 9 | /* --- Constructors --- */ 10 | 11 | public HashCalculationResult(String fullHash) { 12 | this.fullHash = fullHash; 13 | } 14 | 15 | public HashCalculationResult(String fullHash, String mostSigBitsHash, String leastSigBitsHash) { 16 | this.fullHash = fullHash; 17 | this.mostSigBitsHash = mostSigBitsHash; 18 | this.leastSigBitsHash = leastSigBitsHash; 19 | } 20 | 21 | /* --- Getters / Setters --- */ 22 | 23 | public String getFullHash() { 24 | return fullHash; 25 | } 26 | 27 | public void setFullHash(String fullHash) { 28 | this.fullHash = fullHash; 29 | } 30 | 31 | public String getMostSigBitsHash() { 32 | return mostSigBitsHash; 33 | } 34 | 35 | public void setMostSigBitsHash(String mostSigBitsHash) { 36 | this.mostSigBitsHash = mostSigBitsHash; 37 | } 38 | 39 | public String getLeastSigBitsHash() { 40 | return leastSigBitsHash; 41 | } 42 | 43 | public void setLeastSigBitsHash(String leastSigBitsHash) { 44 | this.leastSigBitsHash = leastSigBitsHash; 45 | } 46 | } -------------------------------------------------------------------------------- /wss-agent-hash-calculator/src/test/resources/superHash/msb-test.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * Super hash test 3 | * Copyright 2016 WhiteSource 4 | */ 5 | public static class HashCalculationResult { 6 | 7 | /* --- Members --- */ 8 | 9 | private String fullHash; 10 | private String mostSigBitsHash; 11 | private String leastSigBitsHash; 12 | 13 | /* --- Constructors --- */ 14 | 15 | public HashCalculationResult(String fullHash) { 16 | this.fullHash = fullHash; 17 | } 18 | 19 | public HashCalculationResult(String fullHash, String mostSigBitsHash, String leastSigBitsHash) { 20 | this.fullHash = fullHash; 21 | this.mostSigBitsHash = mostSigBitsHash; 22 | this.leastSigBitsHash = leastSigBitsHash; 23 | } 24 | 25 | /* --- Getters / Setters --- */ 26 | 27 | public String getFullHash() { 28 | return fullHash; 29 | } 30 | 31 | public void setFullHash(String fullHash) { 32 | this.fullHash = fullHash; 33 | } 34 | 35 | public String getMostSigBitsHash() { 36 | return mostSigBitsHash; 37 | } 38 | 39 | public void setMostSigBitsHash(String mostSigBitsHash) { 40 | this.mostSigBitsHash = mostSigBitsHash; 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /wss-agent-hash-calculator/src/test/resources/superHash/origin.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * Super hash test 3 | * Copyright 2016 WhiteSource 4 | */ 5 | public static class HashCalculationResult { 6 | 7 | /* --- Members --- */ 8 | 9 | private String fullHash; 10 | private String mostSigBitsHash; 11 | private String leastSigBitsHash; 12 | 13 | /* --- Constructors --- */ 14 | 15 | public HashCalculationResult(String fullHash) { 16 | this.fullHash = fullHash; 17 | } 18 | 19 | public HashCalculationResult(String fullHash, String mostSigBitsHash, String leastSigBitsHash) { 20 | this.fullHash = fullHash; 21 | this.mostSigBitsHash = mostSigBitsHash; 22 | this.leastSigBitsHash = leastSigBitsHash; 23 | } 24 | 25 | /* --- Getters / Setters --- */ 26 | 27 | public String getFullHash() { 28 | return fullHash; 29 | } 30 | 31 | public void setFullHash(String fullHash) { 32 | this.fullHash = fullHash; 33 | } 34 | 35 | public String getMostSigBitsHash() { 36 | return mostSigBitsHash; 37 | } 38 | 39 | public void setMostSigBitsHash(String mostSigBitsHash) { 40 | this.mostSigBitsHash = mostSigBitsHash; 41 | } 42 | 43 | public String getLeastSigBitsHash() { 44 | return leastSigBitsHash; 45 | } 46 | 47 | public void setLeastSigBitsHash(String leastSigBitsHash) { 48 | this.leastSigBitsHash = leastSigBitsHash; 49 | } 50 | } -------------------------------------------------------------------------------- /wss-agent-hash-calculator/src/test/resources/superHash/small-file.txt: -------------------------------------------------------------------------------- 1 | This is a small file... -------------------------------------------------------------------------------- /wss-agent-hash-calculator/src/test/resources/superHash/whitespace-changes.txt: -------------------------------------------------------------------------------- 1 | /** 2 | * Super hash test 3 | * Copyright 2016 WhiteSource 4 | */ 5 | public static class 6 | HashCalculationResult { 7 | 8 | /* --- Members --- */ 9 | 10 | private String fullHash; private String mostSigBitsHash; private String leastSigBitsHash; 11 | 12 | /* --- Constructors --- */ 13 | 14 | public HashCalculationResult(String fullHash) { 15 | this.fullHash = fullHash; 16 | } 17 | 18 | public HashCalculationResult(String fullHash, String mostSigBitsHash, String leastSigBitsHash) { 19 | this.fullHash = fullHash; 20 | this.mostSigBitsHash = mostSigBitsHash; 21 | this.leastSigBitsHash = leastSigBitsHash; 22 | } 23 | 24 | /* --- Getters / Setters --- */ 25 | 26 | public String getFullHash() { 27 | return fullHash; 28 | } 29 | 30 | public void setFullHash( String fullHash ) { 31 | this.fullHash = fullHash; 32 | } 33 | 34 | public String getMostSigBitsHash() { 35 | return mostSigBitsHash; 36 | 37 | } 38 | 39 | public void setMostSigBitsHash(String mostSigBitsHash) { 40 | this.mostSigBitsHash = mostSigBitsHash; 41 | } 42 | 43 | public String getLeastSigBitsHash() { 44 | return leastSigBitsHash; 45 | } 46 | 47 | public void setLeastSigBitsHash(String leastSigBitsHash) { 48 | this.leastSigBitsHash = leastSigBitsHash; 49 | } 50 | 51 | 52 | 53 | } 54 | 55 | 56 | -------------------------------------------------------------------------------- /wss-agent-report/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | org.whitesource 7 | wss-agent-parent 8 | 2.9.9.101-SNAPSHOT 9 | 10 | 11 | wss-agent-report 12 | jar 13 | 14 | API reports 15 | Report generation for API results 16 | 17 | 18 | 19 | 20 | 21 | org.whitesource 22 | wss-agent-api 23 | ${project.version} 24 | 25 | 26 | org.whitesource 27 | wss-agent-hash-calculator 28 | ${project.version} 29 | 30 | 31 | org.whitesource 32 | wss-agent-utils 33 | ${project.version} 34 | 35 | 36 | 37 | 38 | org.apache.commons 39 | commons-collections4 40 | 4.1 41 | 42 | 43 | com.google.code.gson 44 | gson 45 | 46 | 47 | commons-io 48 | commons-io 49 | ${commonsio.version} 50 | 51 | 52 | junit 53 | junit 54 | 55 | 56 | com.fasterxml.jackson.core 57 | jackson-databind 58 | 2.13.3 59 | 60 | 61 | org.freemarker 62 | freemarker 63 | 2.3.28 64 | 65 | 66 | 67 | 68 | 69 | Release 70 | 71 | false 72 | 73 | 74 | 75 | 76 | com.github.github 77 | site-maven-plugin 78 | 79 | wss-agent-report 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /wss-agent-report/src/main/java/org/whitesource/agent/report/model/LicenseHistogramDataPoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.report.model; 17 | 18 | /** 19 | * Details object for specific data point in a license histogram. 20 | * 21 | * @author tom.shapira 22 | */ 23 | public class LicenseHistogramDataPoint { 24 | 25 | /* --- Static members --- */ 26 | 27 | private static final int LICENSE_NAME_MAX_LENGTH = 16; 28 | 29 | /* --- Members --- */ 30 | 31 | private String name; 32 | 33 | private int occurrences; 34 | 35 | private String height; 36 | 37 | /* --- Constructors --- */ 38 | 39 | /** 40 | * Default constructor 41 | */ 42 | public LicenseHistogramDataPoint() { 43 | this.occurrences = 0; 44 | } 45 | 46 | /** 47 | * Constructor 48 | * @param name of the license 49 | * @param occurrences number 50 | */ 51 | public LicenseHistogramDataPoint(String name, int occurrences) { 52 | this.name = name; 53 | this.occurrences = occurrences; 54 | } 55 | 56 | /* --- Getters / Setters --- */ 57 | 58 | public String getName() { 59 | return name; 60 | } 61 | 62 | public void setName(String name) { 63 | this.name = name; 64 | } 65 | 66 | public int getOccurrences() { 67 | return occurrences; 68 | } 69 | 70 | public void setOccurrences(int occurrences) { 71 | this.occurrences = occurrences; 72 | } 73 | 74 | public String getHeight() { 75 | return height; 76 | } 77 | 78 | public void setHeight(int height) { 79 | this.height = height + "px"; 80 | } 81 | 82 | public String getShortName() { 83 | String shortName = name; 84 | if (name.length() > LICENSE_NAME_MAX_LENGTH) { 85 | shortName = name.substring(0, LICENSE_NAME_MAX_LENGTH - 2) + ".."; 86 | } 87 | return shortName; 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /wss-agent-report/src/main/java/org/whitesource/agent/report/summary/PolicyRejectionReport.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.report.summary; 17 | 18 | import java.io.Serializable; 19 | import java.util.ArrayList; 20 | import java.util.Collection; 21 | 22 | /** 23 | * POJO for holding all information about rejected libraries and policies. 24 | * 25 | * @author tom.shapira 26 | * @since 2.3.2 27 | */ 28 | public class PolicyRejectionReport implements Serializable { 29 | 30 | /* --- Static members --- */ 31 | 32 | private static final long serialVersionUID = -2814747793458938516L; 33 | 34 | /* --- Members --- */ 35 | 36 | private Collection rejectingPolicies; 37 | private PolicyRejectionSummary summary; 38 | 39 | /* --- Constructors --- */ 40 | 41 | public PolicyRejectionReport() { 42 | rejectingPolicies = new ArrayList(); 43 | summary = new PolicyRejectionSummary(); 44 | } 45 | 46 | /* --- Getters / Setters --- */ 47 | 48 | public Collection getRejectingPolicies() { 49 | return rejectingPolicies; 50 | } 51 | 52 | public void setRejectingPolicies(Collection policies) { 53 | this.rejectingPolicies = policies; 54 | } 55 | 56 | public PolicyRejectionSummary getSummary() { 57 | return summary; 58 | } 59 | 60 | public void setSummary(PolicyRejectionSummary summary) { 61 | this.summary = summary; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /wss-agent-report/src/main/java/org/whitesource/agent/report/summary/PolicyRejectionSummary.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.report.summary; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | * POJO for holding the summarized policy rejection information. 22 | * 23 | * @author tom.shapira 24 | * @since 2.3.2 25 | */ 26 | public class PolicyRejectionSummary implements Serializable { 27 | 28 | /* --- Static members --- */ 29 | 30 | private static final long serialVersionUID = -3823743128104175916L; 31 | 32 | /* --- Members --- */ 33 | 34 | private int totalRejectedLibraries; 35 | 36 | /* --- Constructors --- */ 37 | 38 | public PolicyRejectionSummary() { 39 | } 40 | 41 | /* --- Getters / Setters --- */ 42 | 43 | public int getTotalRejectedLibraries() { 44 | return totalRejectedLibraries; 45 | } 46 | 47 | public void setTotalRejectedLibraries(int totalRejectedLibraries) { 48 | this.totalRejectedLibraries = totalRejectedLibraries; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /wss-agent-report/src/main/java/org/whitesource/agent/report/summary/RejectedLibrary.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.report.summary; 17 | 18 | import java.io.Serializable; 19 | import java.util.HashSet; 20 | import java.util.Set; 21 | 22 | /** 23 | * POJO for holding the minimum resource information. 24 | * 25 | * @author tom.shapira 26 | * @since 2.3.2 27 | */ 28 | public class RejectedLibrary implements Serializable { 29 | 30 | /* --- Static members --- */ 31 | 32 | private static final long serialVersionUID = -3757254562564574416L; 33 | 34 | /* --- Members --- */ 35 | 36 | private String name; 37 | private String sha1; 38 | private String link; 39 | private Set projects; 40 | private String systemPath; 41 | private String manifestFile; 42 | /* --- Constructors --- */ 43 | 44 | public RejectedLibrary() { 45 | projects = new HashSet(); 46 | } 47 | 48 | public RejectedLibrary(String name, String sha1, String link,String systemPath,String manifestFile) { 49 | this(); 50 | this.name = name; 51 | this.sha1 = sha1; 52 | this.link = link; 53 | this.systemPath = systemPath; 54 | this.manifestFile = manifestFile; 55 | } 56 | 57 | /* --- Overridden methods --- */ 58 | 59 | @Override 60 | public boolean equals(Object o) { 61 | if (this == o) return true; 62 | if (!(o instanceof RejectedLibrary)) return false; 63 | 64 | RejectedLibrary that = (RejectedLibrary) o; 65 | 66 | if (name != null ? !name.equals(that.name) : that.name != null) return false; 67 | return sha1 != null ? sha1.equals(that.sha1) : that.sha1 == null; 68 | 69 | } 70 | 71 | @Override 72 | public int hashCode() { 73 | int result = name != null ? name.hashCode() : 0; 74 | result = 31 * result + (sha1 != null ? sha1.hashCode() : 0); 75 | return result; 76 | } 77 | 78 | /* --- Getters / Setters --- */ 79 | 80 | public String getName() { 81 | return name; 82 | } 83 | 84 | public void setName(String name) { 85 | this.name = name; 86 | } 87 | 88 | public String getSha1() { 89 | return sha1; 90 | } 91 | 92 | public void setSha1(String sha1) { 93 | this.sha1 = sha1; 94 | } 95 | 96 | public String getLink() { 97 | return link; 98 | } 99 | 100 | public void setLink(String link) { 101 | this.link = link; 102 | } 103 | 104 | public Set getProjects() { 105 | return projects; 106 | } 107 | 108 | public void setProjects(Set projects) { 109 | this.projects = projects; 110 | } 111 | 112 | public String getSystemPath() { 113 | return systemPath; 114 | } 115 | 116 | public void setSystemPath(String systemPath) { 117 | this.systemPath = systemPath; 118 | } 119 | 120 | public String getManifestFile() { 121 | return manifestFile; 122 | } 123 | 124 | public void setManifestFile(String manifestFile) { 125 | this.manifestFile = manifestFile; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /wss-agent-report/src/main/java/org/whitesource/agent/report/summary/RejectingPolicy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 White Source Ltd. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.whitesource.agent.report.summary; 17 | 18 | import java.io.Serializable; 19 | import java.util.HashSet; 20 | import java.util.Set; 21 | 22 | /** 23 | * POJO for holding the summarized policy rejection information about a rejecting policy. 24 | * 25 | * @author tom.shapira 26 | * @since 2.3.2 27 | */ 28 | public class RejectingPolicy implements Serializable { 29 | 30 | /* --- Static members --- */ 31 | 32 | private static final long serialVersionUID = 1062040498656193399L; 33 | 34 | /* --- Members --- */ 35 | 36 | private String policyName; 37 | private String filterType; 38 | private boolean productLevel; 39 | private boolean inclusive; 40 | private Set rejectedLibraries; 41 | 42 | /* --- Constructors --- */ 43 | 44 | public RejectingPolicy() { 45 | rejectedLibraries = new HashSet(); 46 | } 47 | 48 | public RejectingPolicy(String policyName, String filterType, boolean productLevel, boolean inclusive) { 49 | this(); 50 | this.policyName = policyName; 51 | this.filterType = filterType; 52 | this.productLevel = productLevel; 53 | this.inclusive = inclusive; 54 | } 55 | 56 | /* --- Getters / Setters --- */ 57 | 58 | public String getPolicyName() { 59 | return policyName; 60 | } 61 | 62 | public void setPolicyName(String policyName) { 63 | this.policyName = policyName; 64 | } 65 | 66 | public String getFilterType() { 67 | return filterType; 68 | } 69 | 70 | public void setFilterType(String filterType) { 71 | this.filterType = filterType; 72 | } 73 | 74 | public boolean isProductLevel() { 75 | return productLevel; 76 | } 77 | 78 | public void setProductLevel(boolean productLevel) { 79 | this.productLevel = productLevel; 80 | } 81 | 82 | public Set getRejectedLibraries() { 83 | return rejectedLibraries; 84 | } 85 | 86 | public void setRejectedLibraries(Set rejectedLibraries) { 87 | this.rejectedLibraries = rejectedLibraries; 88 | } 89 | 90 | public boolean isInclusive() { 91 | return inclusive; 92 | } 93 | 94 | public void setInclusive(boolean inclusive) { 95 | this.inclusive = inclusive; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /wss-agent-utils/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | org.whitesource 7 | wss-agent-parent 8 | 2.9.9.101-SNAPSHOT 9 | 10 | 11 | org.whitesource 12 | wss-agent-utils 13 | 2.9.9.101-SNAPSHOT 14 | 15 | 16 | 17 | commons-codec 18 | commons-codec 19 | ${commonscodec.version} 20 | 21 | 22 | 23 | org.whitesource 24 | wss-agent-api 25 | ${project.version} 26 | 27 | 28 | 29 | com.google.code.gson 30 | gson 31 | 32 | 33 | 34 | 35 | org.slf4j 36 | slf4j-api 37 | 1.7.30 38 | provided 39 | 40 | 41 | 42 | 43 | junit 44 | junit 45 | test 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /wss-agent-utils/src/test/java/org/whitesource/agent/utils/JsonUtilsTest.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.utils; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Ignore; 5 | import org.junit.Test; 6 | import org.whitesource.agent.api.dispatch.UpdateInventoryRequest; 7 | 8 | import java.io.File; 9 | import java.io.FileInputStream; 10 | import java.io.IOException; 11 | import java.nio.file.Paths; 12 | 13 | public class JsonUtilsTest { 14 | 15 | @Ignore 16 | @Test 17 | public void shouldDeserialize (){ 18 | String currentDir = System.getProperty("user.dir").toString(); 19 | File input = Paths.get(currentDir, "\\src\\test\\resources\\plain_request.txt").toFile(); 20 | try { 21 | try (FileInputStream fileInputStream = new FileInputStream(input)) { 22 | UpdateInventoryRequest updateRequest = JsonUtils.readUpdateInventoryRequest(fileInputStream); 23 | Assert.assertNotNull(updateRequest); 24 | } 25 | } catch (IOException e) { 26 | Assert.assertNull(e); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /wss-agent-utils/src/test/java/org/whitesource/agent/utils/ZipUtilsTest.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.utils; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Ignore; 5 | import org.junit.Test; 6 | import org.whitesource.agent.api.dispatch.UpdateInventoryRequest; 7 | import org.whitesource.agent.api.model.AgentProjectInfo; 8 | 9 | import java.io.*; 10 | import java.nio.file.Files; 11 | import java.nio.file.Path; 12 | import java.nio.file.Paths; 13 | import java.util.List; 14 | 15 | public class ZipUtilsTest { 16 | 17 | private static final String JAVA_TEMP_DIR = System.getProperty("java.io.tmpdir"); 18 | 19 | @Ignore 20 | @Test 21 | public void shouldCompressAndDecompress() throws IOException { 22 | String input = "1234567890qwertyuiop"; 23 | 24 | String output = ZipUtils.compressString(input); 25 | Assert.assertEquals(output, ZipUtils.compress(input)); 26 | 27 | String input2 = ZipUtils.decompressString(output); 28 | Assert.assertEquals(input2, ZipUtils.decompress(output)); 29 | 30 | Assert.assertEquals(input, input2); 31 | } 32 | 33 | @Ignore 34 | @Test 35 | public void shouldCompressAndDecompressFile() throws IOException { 36 | String currentDir = System.getProperty("user.dir").toString(); 37 | File input = Paths.get(currentDir, "\\src\\test\\resources\\plain_request.txt").toFile(); 38 | 39 | String originalInput = new String(Files.readAllBytes(input.toPath())); 40 | 41 | File tempFileZip = File.createTempFile("zip", "stringzip", new File(JAVA_TEMP_DIR)); 42 | File tempFileUnzipZip = File.createTempFile("unzip", "unString", new File(JAVA_TEMP_DIR)); 43 | 44 | try (FileInputStream fileInputStream = new FileInputStream(input); 45 | FileOutputStream outputStream = new FileOutputStream(tempFileZip);) { 46 | ZipUtils.compressString(fileInputStream, outputStream); 47 | } 48 | 49 | try (FileInputStream fileInputStream = new FileInputStream(tempFileZip); 50 | FileOutputStream outputStream = new FileOutputStream(tempFileUnzipZip);) { 51 | ZipUtils.decompressString(fileInputStream, outputStream); 52 | } 53 | 54 | String compressDecompressOutput = new String(Files.readAllBytes(input.toPath())); 55 | Assert.assertEquals(originalInput, compressDecompressOutput); 56 | } 57 | 58 | @Ignore 59 | @Test 60 | public void shouldDecompressChunks() { 61 | String currentDir = System.getProperty("user.dir").toString(); 62 | File input = Paths.get(currentDir, "\\src\\test\\resources\\zipped_projects.txt").toFile(); 63 | 64 | List projects; 65 | try { 66 | String zippedProjects = String.join("", Files.readAllLines(input.toPath())); 67 | 68 | Path decompressedPath = ZipUtils.decompressChunks(zippedProjects); 69 | try (FileInputStream fileInputStream = new FileInputStream(decompressedPath.toString()); 70 | BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream)) { 71 | projects = JsonUtils.readProjects(bufferedInputStream); //? why this works ? 72 | } 73 | 74 | String projectsUnzippedChunks = ZipUtils.decompressString(zippedProjects); 75 | String projectsUnzippedChunks2 = String.join("", Files.readAllLines(decompressedPath)); 76 | Assert.assertEquals(projectsUnzippedChunks, projectsUnzippedChunks2); 77 | } catch (IOException e) { 78 | e.printStackTrace(); 79 | Assert.assertNull(e); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /wss-agent-utils/src/test/resources/plain_request.txt: -------------------------------------------------------------------------------- 1 | { 2 | "type": "UPDATE", 3 | "agent": "fs-agent", 4 | "agentVersion": "2.3.9", 5 | "pluginVersion": "1.8.8-SNAPSHOT", 6 | "orgToken": "not-known", 7 | "product": "not-known", 8 | "timeStamp": 1507436869743, 9 | "projects": [ 10 | { 11 | "coordinates": { 12 | "artifactId": "not-known", 13 | "version": "" 14 | }, 15 | "dependencies": [ 16 | { 17 | "artifactId": "antlr-2.7.7.jar", 18 | "sha1": "83cd2cd674a217ade95a4bb83a8a14f351f48bd0", 19 | "otherPlatformSha1": "5976bf31f2183886231da17c633df9d8035d517a", 20 | "systemPath": "C:\\WhiteSource\\FS-Agent\\Jars1\\Jars1\\antlr-2.7.7.jar", 21 | "optional": false, 22 | "children": [], 23 | "exclusions": [], 24 | "licenses": [], 25 | "copyrights": [], 26 | "lastModified": "Jun 18, 2014 3:46:20 PM", 27 | "checksums": { 28 | "SHA1": "83cd2cd674a217ade95a4bb83a8a14f351f48bd0", 29 | "SHA1_OTHER_PLATFORM": "5976bf31f2183886231da17c633df9d8035d517a", 30 | "MD5": "f8f1352c52a4c6a500b597596501fc64" 31 | } 32 | }, 33 | { 34 | "artifactId": "aopalliance-1.0.jar", 35 | "sha1": "0235ba8b489512805ac13a8f9ea77a1ca5ebe3e8", 36 | "otherPlatformSha1": "06ff7ef5e2dfd459e7b20edafe5f1376ae4a1f05", 37 | "systemPath": "C:\\WhiteSource\\FS-Agent\\Jars1\\Jars1\\aopalliance-1.0.jar", 38 | "optional": false, 39 | "children": [], 40 | "exclusions": [], 41 | "licenses": [], 42 | "copyrights": [], 43 | "lastModified": "Jun 18, 2014 3:13:24 PM", 44 | "checksums": { 45 | "SHA1": "0235ba8b489512805ac13a8f9ea77a1ca5ebe3e8", 46 | "SHA1_OTHER_PLATFORM": "06ff7ef5e2dfd459e7b20edafe5f1376ae4a1f05", 47 | "MD5": "04177054e180d09e3998808efa0401c7" 48 | } 49 | }, 50 | { 51 | "artifactId": "asciitab.h", 52 | "sha1": "00017ce70ceaac0b3df0cc6036479ceac79c69e7", 53 | "fullHash": "307812caadfcbe06285c2ca5c24b198cab909930", 54 | "otherPlatformSha1": "67462447978f02b8a78ce7f054da82ec88e7ffa4", 55 | "systemPath": "C:\\WhiteSource\\FS-Agent\\Jars1\\Jars1\\asciitab.h", 56 | "optional": false, 57 | "children": [], 58 | "exclusions": [], 59 | "licenses": [], 60 | "copyrights": [], 61 | "lastModified": "May 27, 2015 1:37:08 PM", 62 | "checksums": { 63 | "SHA1": "00017ce70ceaac0b3df0cc6036479ceac79c69e7", 64 | "SHA1_SUPER_HASH": "307812caadfcbe06285c2ca5c24b198cab909930", 65 | "SHA1_OTHER_PLATFORM": "67462447978f02b8a78ce7f054da82ec88e7ffa4", 66 | "MD5": "b2c8239fd7aba26911c4b801000166b0" 67 | } 68 | }, 69 | { 70 | "artifactId": "asciitab.h", 71 | "sha1": "00017ce70ceaac0b3df0cc6036479ceac79c69e7", 72 | "fullHash": "307812caadfcbe06285c2ca5c24b198cab909930", 73 | "otherPlatformSha1": "67462447978f02b8a78ce7f054da82ec88e7ffa4", 74 | "systemPath": "C:\\WhiteSource\\FS-Agent\\Jars1\\asciitab.h", 75 | "optional": false, 76 | "children": [], 77 | "exclusions": [], 78 | "licenses": [], 79 | "copyrights": [], 80 | "lastModified": "May 27, 2015 1:37:08 PM", 81 | "checksums": { 82 | "SHA1": "00017ce70ceaac0b3df0cc6036479ceac79c69e7", 83 | "SHA1_SUPER_HASH": "307812caadfcbe06285c2ca5c24b198cab909930", 84 | "SHA1_OTHER_PLATFORM": "67462447978f02b8a78ce7f054da82ec88e7ffa4", 85 | "MD5": "b2c8239fd7aba26911c4b801000166b0" 86 | } 87 | } 88 | ] 89 | } 90 | ] 91 | } -------------------------------------------------------------------------------- /wss-agent-via-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | wss-agent-parent 5 | org.whitesource 6 | 2.9.9.101-SNAPSHOT 7 | 8 | 4.0.0 9 | 10 | wss-agent-via-api 11 | 12 | -------------------------------------------------------------------------------- /wss-agent-via-api/src/main/java/org/whitesource/agent/via/api/CodeInvocation.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.via.api; 2 | 3 | import java.io.Serializable; 4 | import java.util.Objects; 5 | 6 | /** 7 | * Responsible for sorted order of the code invocations, linked to it's corresponding method names 8 | * 9 | * @author artiom.petrov 10 | */ 11 | public class CodeInvocation implements Serializable { 12 | 13 | /* --- Static members --- */ 14 | 15 | private static final long serialVersionUID = -5248494825933425058L; 16 | 17 | /* --- Members --- */ 18 | 19 | private InvocationType invocationType; 20 | private String methodName; 21 | private int order; 22 | private int lineNumber; 23 | private String fileName; 24 | 25 | 26 | /* --- Constructor --- */ 27 | 28 | public CodeInvocation() { 29 | } 30 | 31 | public CodeInvocation(InvocationType invocationType, String methodName,int lineNumber,String fileName, int order) { 32 | this.invocationType = invocationType; 33 | this.methodName = methodName; 34 | this.order = order; 35 | this.lineNumber = lineNumber; 36 | this.fileName = fileName; 37 | } 38 | 39 | /* --- Overridden methods --- */ 40 | 41 | @Override 42 | public boolean equals(Object o) { 43 | if (this == o) return true; 44 | if (!(o instanceof CodeInvocation)) return false; 45 | CodeInvocation that = (CodeInvocation) o; 46 | return lineNumber == that.lineNumber && 47 | invocationType == that.invocationType && 48 | Objects.equals(methodName, that.methodName) && 49 | Objects.equals(fileName, that.fileName); 50 | } 51 | 52 | @Override 53 | public int hashCode() { 54 | return Objects.hash(invocationType, methodName, lineNumber, fileName); 55 | } 56 | 57 | 58 | /* --- Getters / Setters --- */ 59 | 60 | public InvocationType getInvocationType() { 61 | return invocationType; 62 | } 63 | 64 | public void setInvocationType(InvocationType invocationType) { 65 | this.invocationType = invocationType; 66 | } 67 | 68 | public String getMethodName() { 69 | return methodName; 70 | } 71 | 72 | public void setMethodName(String methodName) { 73 | this.methodName = methodName; 74 | } 75 | 76 | public int getOrder() { 77 | return order; 78 | } 79 | 80 | public void setOrder(int order) { 81 | this.order = order; 82 | } 83 | 84 | public void setFileName(String fileName) { 85 | this.fileName = fileName; 86 | } 87 | public String getFileName() { 88 | return fileName; 89 | } 90 | 91 | public int getLineNumber() { 92 | return lineNumber; 93 | } 94 | public void setLineNumber(int lineNumber) { 95 | this.lineNumber = lineNumber; 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /wss-agent-via-api/src/main/java/org/whitesource/agent/via/api/InvocationType.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.via.api; 2 | 3 | /** 4 | * Possible vulnerability invocation types 5 | * 6 | * @author artiom.petrov 7 | */ 8 | public enum InvocationType { 9 | 10 | APPLICATION, 11 | EXTENSION, 12 | FRAMEWORK, 13 | NATIVE 14 | } 15 | -------------------------------------------------------------------------------- /wss-agent-via-api/src/main/java/org/whitesource/agent/via/api/VulnerabilityAnalysisResult.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.via.api; 2 | 3 | import java.io.Serializable; 4 | import java.util.Collection; 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | import java.util.Objects; 8 | 9 | /** 10 | * Result of the Vulnerability Impact Analysis 11 | * 12 | * @author artiom.petrov 13 | */ 14 | public class VulnerabilityAnalysisResult implements Serializable { 15 | 16 | /* --- Static members --- */ 17 | 18 | private static final long serialVersionUID = 8803589031348460812L; 19 | 20 | /* --- Members --- */ 21 | 22 | // map from CVE to vulnerable elements 23 | private Map> vulnerableElements; 24 | 25 | // map from CVE to vulnerable elements status 26 | private Map vulnerableElementsStatus; 27 | 28 | // resource identifier 29 | private String matchValue; 30 | 31 | public enum Status { 32 | SUCCESS, 33 | NO_ELEMENTS_IN_DATABASE, 34 | TIMEOUT_FAILURE, 35 | FAILURE, 36 | CROSS_LANGUAGE; 37 | } 38 | 39 | 40 | /* --- Constructor --- */ 41 | 42 | public VulnerabilityAnalysisResult() { 43 | vulnerableElements = new HashMap<>(); 44 | vulnerableElementsStatus = new HashMap<>(); 45 | } 46 | 47 | public VulnerabilityAnalysisResult(String matchValue, Map> vulnerableElements) { 48 | this.matchValue = matchValue; 49 | this.vulnerableElements = vulnerableElements; 50 | } 51 | 52 | public VulnerabilityAnalysisResult(String matchValue, Map> vulnerableElements, 53 | Map vulnerableElementsStatus) { 54 | assert vulnerableElements.keySet().equals(vulnerableElementsStatus.keySet()); 55 | this.matchValue = matchValue; 56 | this.vulnerableElements = vulnerableElements; 57 | this.vulnerableElementsStatus = vulnerableElementsStatus; 58 | } 59 | 60 | /* --- Overridden methods --- */ 61 | 62 | @Override 63 | public boolean equals(Object o) { 64 | if (this == o) return true; 65 | if (!(o instanceof VulnerabilityAnalysisResult)) return false; 66 | VulnerabilityAnalysisResult that = (VulnerabilityAnalysisResult) o; 67 | return Objects.equals(vulnerableElements, that.vulnerableElements) && 68 | Objects.equals(matchValue, that.matchValue); 69 | } 70 | 71 | @Override 72 | public int hashCode() { 73 | return Objects.hash(vulnerableElements, matchValue); 74 | } 75 | 76 | /* --- Getters / Setters --- */ 77 | 78 | public String getMatchValue() { 79 | return matchValue; 80 | } 81 | 82 | public void setMatchValue(String matchValue) { 83 | this.matchValue = matchValue; 84 | } 85 | 86 | public Map> getVulnerableElements() { 87 | return vulnerableElements; 88 | } 89 | 90 | public void setVulnerableElements(Map> vulnerableElements) { 91 | this.vulnerableElements = vulnerableElements; 92 | } 93 | 94 | public Map getVulnerableElementsStatus() { 95 | return vulnerableElementsStatus; 96 | } 97 | 98 | public void setVulnerableElementsStatus(Map vulnerableElementsStatus) { 99 | this.vulnerableElementsStatus = vulnerableElementsStatus; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /wss-agent-via-api/src/main/java/org/whitesource/agent/via/api/VulnerabilityTrace.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.via.api; 2 | 3 | import java.io.Serializable; 4 | import java.util.LinkedList; 5 | import java.util.List; 6 | import java.util.Objects; 7 | 8 | /** 9 | * Vulnerability sorted trace record, according to it's code invocations 10 | * 11 | * @author artiom.petrov 12 | */ 13 | public class VulnerabilityTrace implements Serializable { 14 | 15 | /* --- Static members --- */ 16 | 17 | private static final long serialVersionUID = 8254336454781349191L; 18 | 19 | /* --- Members --- */ 20 | 21 | private List codeInvocations; 22 | 23 | /* --- Constructor --- */ 24 | 25 | public VulnerabilityTrace() { 26 | codeInvocations = new LinkedList<>(); 27 | } 28 | 29 | /* --- Overridden methods --- */ 30 | 31 | @Override 32 | public boolean equals(Object o) { 33 | if (this == o) return true; 34 | if (!(o instanceof VulnerabilityTrace)) return false; 35 | VulnerabilityTrace that = (VulnerabilityTrace) o; 36 | return Objects.equals(codeInvocations, that.codeInvocations); 37 | } 38 | 39 | @Override 40 | public int hashCode() { 41 | return Objects.hash(codeInvocations); 42 | } 43 | 44 | /* --- Getters / Setters --- */ 45 | 46 | public List getCodeInvocations() { 47 | return codeInvocations; 48 | } 49 | 50 | public void setCodeInvocations(List codeInvocations) { 51 | this.codeInvocations = codeInvocations; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /wss-agent-via-api/src/main/java/org/whitesource/agent/via/api/VulnerableElement.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.via.api; 2 | 3 | import java.io.Serializable; 4 | import java.util.Collection; 5 | import java.util.LinkedList; 6 | import java.util.Objects; 7 | 8 | /** 9 | * Holds all vulnerability traces which address specific element 10 | * 11 | * @author artiom.petrov 12 | */ 13 | public class VulnerableElement implements Serializable { 14 | 15 | /* --- Static members --- */ 16 | 17 | private static final long serialVersionUID = -4764927498260473239L; 18 | 19 | /* --- Members --- */ 20 | 21 | // class or method 22 | private String element; 23 | private Collection vulnerabilityTraces; 24 | private VulnerableElementInfo vulnerableElementInfo; 25 | 26 | /* --- Constructor --- */ 27 | 28 | public VulnerableElement() { 29 | vulnerabilityTraces = new LinkedList<>(); 30 | } 31 | 32 | public VulnerableElement(String element, Collection vulnerabilityTraces) { 33 | this.element = element; 34 | this.vulnerabilityTraces = vulnerabilityTraces; 35 | } 36 | 37 | public VulnerableElement(String element, Collection vulnerabilityTraces, VulnerableElementInfo vulnerableElementInfo) { 38 | this(element, vulnerabilityTraces); 39 | this.vulnerableElementInfo = vulnerableElementInfo; 40 | } 41 | 42 | /* --- Overridden methods --- */ 43 | 44 | @Override 45 | public boolean equals(Object o) { 46 | if (this == o) return true; 47 | if (!(o instanceof VulnerableElement)) return false; 48 | VulnerableElement that = (VulnerableElement) o; 49 | return Objects.equals(element, that.element) && 50 | Objects.equals(vulnerabilityTraces, that.vulnerabilityTraces); 51 | } 52 | 53 | @Override 54 | public int hashCode() { 55 | return Objects.hash(element, vulnerabilityTraces); 56 | } 57 | 58 | /* --- Getters / Setters --- */ 59 | 60 | public String getElement() { 61 | return element; 62 | } 63 | 64 | public void setElement(String element) { 65 | this.element = element; 66 | } 67 | 68 | public Collection getVulnerabilityTraces() { 69 | return vulnerabilityTraces; 70 | } 71 | 72 | public void setVulnerabilityTraces(Collection vulnerabilityTraces) { 73 | this.vulnerabilityTraces = vulnerabilityTraces; 74 | } 75 | 76 | public VulnerableElementInfo getVulnerableElementInfo() { 77 | return vulnerableElementInfo; 78 | } 79 | 80 | public void setVulnerableElementInfo(VulnerableElementInfo vulnerableElementInfo) { 81 | this.vulnerableElementInfo = vulnerableElementInfo; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /wss-agent-via-api/src/main/java/org/whitesource/agent/via/api/VulnerableElementInfo.java: -------------------------------------------------------------------------------- 1 | package org.whitesource.agent.via.api; 2 | 3 | import java.io.Serializable; 4 | import java.util.Objects; 5 | 6 | /** 7 | * Created by anna.rozin 8 | */ 9 | public class VulnerableElementInfo implements Serializable { 10 | 11 | /* --- Static members --- */ 12 | 13 | private static final long serialVersionUID = 7249655682041302822L; 14 | 15 | /* --- Members --- */ 16 | 17 | private Integer startLine; 18 | private Integer endLine; 19 | 20 | /* --- Constructor --- */ 21 | 22 | public VulnerableElementInfo(){ 23 | } 24 | 25 | public VulnerableElementInfo(Integer startLine, Integer endLine){ 26 | this.startLine = startLine; 27 | this.endLine = endLine; 28 | } 29 | 30 | /* --- Overridden methods --- */ 31 | 32 | @Override 33 | public boolean equals(Object o) { 34 | if (this == o) return true; 35 | if (o == null || getClass() != o.getClass()) return false; 36 | VulnerableElementInfo that = (VulnerableElementInfo) o; 37 | return startLine == that.startLine && 38 | endLine == that.endLine; 39 | } 40 | 41 | @Override 42 | public int hashCode() { 43 | 44 | return Objects.hash(startLine, endLine); 45 | } 46 | /* --- Getters / Setters --- */ 47 | 48 | public Integer getStartLine() { 49 | return startLine; 50 | } 51 | 52 | public void setStartLine(Integer startLine) { 53 | this.startLine = startLine; 54 | } 55 | 56 | public Integer getEndLine() { 57 | return endLine; 58 | } 59 | 60 | public void setEndLine(Integer endLine) { 61 | this.endLine = endLine; 62 | } 63 | } 64 | --------------------------------------------------------------------------------