Example Program for the Virus Scan Provider

The source code below demonstrates the use of the virus scan provider.

      
            
import javax.naming.*; 
import com.sap.security.core.server.vsi.api.*; 
import com.sap.security.core.server.vsi.api.exception.*; 
/* Virus Scan Interface example */ 
public class VsiTestScan ... { 
  public static 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 */ 
static { 
try { 
  Context ctx = new InitialContext(); 
  Parameter[] paramArray = new Parameter[1]; 
  paramArray[0] = new Parameter("CUST_ACTIVE_CONTENT", "BOOL", "1"); 
  VSIService vsiService = (VSIService)ctx.lookup(VSIService.JNDI_NAME); 
  if (vsiService != null) 
     { vsiService.addProfile(myProfile,"Description", paramArray); } 
  } 
catch (Exception e) { 
} 
try { /* Lookup the VSI service. */ 
    Context ctx = new InitialContext(); 
    VSIService vsiService = (VSIService)ctx.lookup(VSIService.JNDI_NAME); 
    if (vsiService != null) 
    { /* get scan instance */ 
      Instance myInstance = null; 
      try { 
         myInstance = vsiService.getInstance(myProfile); 
         /* perform virus scan */ 
        if (myInstance.scanBytes(Virus.EICAR) == true) { 
       /* 
        * 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 */ 
        } 
    } catch (VirusInfectionException vse) { 
         Infection[] myInfections = vse.getInfections(); 
        if (myInfections.length == 1) { 
             /* the scan engine has found the infection */
         } else { 
            /* not expected error */ 
         } 
     } catch (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(); 
     } finally { 
        /* release the scan instance 
         */ vsiService.releaseInstance(myInstance); 
     } 
  } else { 
    /* Virus Scan Provider service is not started */ 
  } 
}