Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.owasp.dependencycheck.analyzer
Class CPEAnalyzer

    java.lang.Object
      org.owasp.dependencycheck.analyzer.CPEAnalyzer

All Implemented Interfaces:
  Analyzer

    public class CPEAnalyzer

extends Object
implements Analyzer

CPEAnalyzer is a utility class that takes a project dependency and attempts to discern if there is an associated CPE. It uses the evidence contained within the dependency to search the Lucene index.

Author:
  Jeremy Long (jeremy.long@owasp.org)

Constructor Summary
`CPEAnalyzer()`

Method Summary
`void` | `analyze(Dependency dependency, Engine engine)` Analyzes a dependency and attempts to determine if there are any CPE identifiers for this dependency.
`protected String` | `buildSearch(String vendor, String product, Set<String> vendorWeighting, Set<String> productWeightings)` Builds a Lucene search string by properly escaping data and constructing a valid search query.
`void` | `close()` Closes the data source.
`protected void` | `determineCPE(Dependency dependency)` Searches the data store of CPE entries, trying to identify the CPE for the given dependency based on the evidence contained within.
`protected void` | `finalize()` Ensures that the Lucene index is closed.
`AnalysisPhase` | `getAnalysisPhase()` Returns the analysis phase that this analyzer should run in.
`String` | `getName()` Returns the name of this analyzer.
`Set<String>` | `getSupportedExtensions()` Returns true because this analyzer supports all dependency types.
`void` | `initialize()` Opens the CPE Lucene Index.
`boolean` | `isOpen()` Returns the status of the data source - is the index open.
`void` | `open()` Opens the data source.
`protected List<IndexEntry>` | `searchCPE(String vendor, String product, Set<String> vendorWeightings, Set<String> productWeightings)` Searches the Lucene CPE index to identify possible CPE entries associated with the supplied vendor, product, and version.
`boolean` | `supportsExtension(String extension)` Returns true because this analyzer supports all dependency types.

Methods inherited from class java.lang.Object
`clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### CPEAnalyzer

    public CPEAnalyzer()

Method Detail

### open

    public void open()
              throws IOException,
                     DatabaseException

  Opens the data source.

  Throws:
    `IOException` - when the Lucene directory to be queried does not exist or is corrupt.
    `DatabaseException` - when the database throws an exception. This usually occurs when the database is in use by another process.

### close

    public void close()

  Closes the data source.

  Specified by:
    `close` in interface `Analyzer`

### isOpen

    public boolean isOpen()

  Returns the status of the data source - is the index open.

  Returns:
    true or false.

### finalize

    protected void finalize()
                     throws Throwable

  Ensures that the Lucene index is closed.

  Overrides:
    `finalize` in class `Object`
  Throws:
    `Throwable` - when a throwable is thrown.

### determineCPE

    protected void determineCPE(Dependency dependency)
                         throws org.apache.lucene.index.CorruptIndexException,
                                IOException,
                                org.apache.lucene.queryparser.classic.ParseException

  Searches the data store of CPE entries, trying to identify the CPE for the given dependency based on the evidence contained within. The dependency passed in is updated with any identified CPE values.

  Parameters:
    `dependency` - the dependency to search for CPE entries on.
  Throws:
    `org.apache.lucene.index.CorruptIndexException` - is thrown when the Lucene index is corrupt.
    `IOException` - is thrown when an IOException occurs.
    `org.apache.lucene.queryparser.classic.ParseException` - is thrown when the Lucene query cannot be parsed.

### searchCPE

    protected List<IndexEntry> searchCPE(String vendor,
                                         String product,
                                         Set<String> vendorWeightings,
                                         Set<String> productWeightings)
                                  throws org.apache.lucene.index.CorruptIndexException,
                                         IOException,
                                         org.apache.lucene.queryparser.classic.ParseException

  Searches the Lucene CPE index to identify possible CPE entries associated with the supplied vendor, product, and version.

  If either the vendorWeightings or productWeightings lists have been populated this data is used to add weighting factors to the search.

  Parameters:
    `vendor` - the text used to search the vendor field
    `product` - the text used to search the product field
    `vendorWeightings` - a list of strings to use to add weighting factors to the vendor field
    `productWeightings` - Adds a list of strings that will be used to add weighting factors to the product search
  Returns:
    a list of possible CPE values
  Throws:
    `org.apache.lucene.index.CorruptIndexException` - when the Lucene index is corrupt
    `IOException` - when the Lucene index is not found
    `org.apache.lucene.queryparser.classic.ParseException` - when the generated query is not valid

### buildSearch

    protected String buildSearch(String vendor,
                                 String product,
                                 Set<String> vendorWeighting,
                                 Set<String> productWeightings)

  Builds a Lucene search string by properly escaping data and constructing a valid search query.

  If either the possibleVendor or possibleProducts lists have been populated this data is used to add weighting factors to the search string generated.

  Parameters:
    `vendor` - text to search the vendor field
    `product` - text to search the product field
    `vendorWeighting` - a list of strings to apply to the vendor to boost the terms weight
    `productWeightings` - a list of strings to apply to the product to boost the terms weight
  Returns:
    the Lucene query

### analyze

    public void analyze(Dependency dependency,
                        Engine engine)
                 throws AnalysisException

  Analyzes a dependency and attempts to determine if there are any CPE identifiers for this dependency.

  Specified by:
    `analyze` in interface `Analyzer`
  Parameters:
    `dependency` - The Dependency to analyze.
    `engine` - The analysis engine
  Throws:
    `AnalysisException` - is thrown if there is an issue analyzing the dependency.

### getSupportedExtensions

    public Set<String> getSupportedExtensions()

  Returns true because this analyzer supports all dependency types.

  Specified by:
    `getSupportedExtensions` in interface `Analyzer`
  Returns:
    true.

### getName

    public String getName()

  Returns the name of this analyzer.

  Specified by:
    `getName` in interface `Analyzer`
  Returns:
    the name of this analyzer.

### supportsExtension

    public boolean supportsExtension(String extension)

  Returns true because this analyzer supports all dependency types.

  Specified by:
    `supportsExtension` in interface `Analyzer`
  Parameters:
    `extension` - the file extension of the dependency being analyzed.
  Returns:
    true.

### getAnalysisPhase

    public AnalysisPhase getAnalysisPhase()

  Returns the analysis phase that this analyzer should run in.

  Specified by:
    `getAnalysisPhase` in interface `Analyzer`
  Returns:
    the analysis phase that this analyzer should run in.

### initialize

    public void initialize()
                    throws Exception

  Opens the CPE Lucene Index.

  Specified by:
    `initialize` in interface `Analyzer`
  Throws:
    `Exception` - is thrown if there is an issue opening the index.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2012-2013 OWASP. All Rights Reserved.