Show TOC

Implementing a Virus CheckLocate this document in the navigation structure

Prerequisites

You have set a reference to the development component (DC) tc/bl/vis/api in your project.

For more information, see Defining Development Component Dependencies

Procedure

To implement the virus check, perform the following steps in your program:

  1. Import

    • The JNDI service javax.naming.*

    • The interface com.sap.security.core.server.vsi.api.*

    • The interface com.sap.security.core.server.vsi.api.exception.*

  2. Check if the virus scan provider is available.

  3. Initialize the instance of the service.

  4. Check if the desired scan profile is active. To do this, query the instance for not equal to null. If you do not specify an instance name (for getInstance() ), the system uses the default profile.

  5. Call the virus check using either a file (scanFile) or a memory block (scanBytes) .

    Note

    To use the delivered virus class for testing, use the memory block scanBytes(Virus.EICAR) . The virus class is described in the javadocs.

    For more information, see http://help.sap.com/javadocs.

  6. Release the instance of the service.

Example
Note

You cannot execute this example program as is, since it is only a fragment. However, the individual parts can be used.

      
            
      
javax.naming.*; 
      
com.sap.security.core.server.vsi.api.*; 
      
com.sap.security.core.server.vsi.api.exception.*; /* Virus Scan Interface example */ 
      
VsiTestScan ... { 
      
String myProfile = "blockScriptInFiles"; ... /* Ensure Existance of your own profile with capability to * block active content, e.g. script in HTML, PDF and other * office documents. Perform this in a global * initilization or a static part of your code */ 
      
{ 
      
{ Context ctx = 
      
InitialContext(); Parameter[] paramArray = 
      
Parameter[1]; paramArray[0] = 
      
Parameter("CUST_ACTIVE_CONTENT", "BOOL", "1"); VSIService vsiService = (VSIService)ctx.lookup(VSIService.JNDI_NAME); 
      
(vsiService != 
      
) { vsiService.addProfile(myProfile,"Description", paramArray); } } 
      
(Exception e) { } } ... 
      
{ /* Lookup the VSI service. */ Context ctx = 
      
InitialContext(); VSIService vsiService = (VSIService)ctx.lookup(VSIService.JNDI_NAME); 
      
(vsiService != 
      
) { /* get scan instance */ Instance myInstance = 
      
; 
      
{ myInstance = vsiService.getInstance(myProfile); /* perform virus scan */ 
      
(myInstance.scanBytes(Virus.EICAR) == 
      
) { /* * true means no infection and no scan error: * Scanning the EICAR test pattern virus * must either return false or throw an Exception, * otherwise the underlying scan engine has * not recognized the EICAR pattern. */ /* not expected error */ } } 
      
(VirusInfectionException vse) { Infection[] myInfections = vse.getInfections(); 
      
(myInfections.length == 1) { /* the scan engine has found the infection */ ... } 
      
{ /* not expected error */ ... } } 
      
(Exception e) { /* catch all other Exceptions, * including VirusScanException and * VSIServiceException here as not * expected error */ /* always use the localized error * text for an output */ String error = e. getLocalizedMessage(); ... } 
      
{ /* release the scan instance */ vsiService.releaseInstance(myInstance); } } 
      
{ /* Virus Scan Provider service is not started */ ... } ... }