Previous Topic: Step 4: Collect the IP AddressNext Topic: Understanding the APIs for Retrieving DeviceDNA in the Sample Code


Sample Code Reference

The following sample code illustrates how to implement RiskMinder’s DeviceDNA and Device ID collection mechanism. It showcases the collection logic in one file (say, index.jsp). However, you can implement appropriate code snippets in different pages, depending on the number of pages you show before you call the evaluateRisk() method.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<script type="text/javascript" src="<%=request.getContextPath()%>/devicedna/riskminder-client.js"></script>
<script language="javascript">

var client;

 function init(){
try{
client = new ca.rm.Client();
var contextPath = "<%=request.getContextPath()%>";
client.setProperty("baseurl", contextPath);
client.loadFlash(readyCallback);
}catch(e){
alert(e.message);
}
}

 function collectingSystemInfo() {
try{
client.setProperty("externalip", "<%=request.getRemoteHost()%>");
computeDDNA();
}catch(e){
alert(e);
}
}

 function readyCallback(flag){
 configureClient();
 client.processDNA();
 }

 function configureClient(flag){
 //configure the client properties.
 client.setProperty("format", "json");
 client.setProperty("didname", "RISKFORT_COOKIE");
 }
 
 function computeDDNA() {

client.processDNA();

var dna = client.getDNA();
var did = client.getDID();

//forward this info to appropriate servlet to perform risk eval
document.CollectMFPToEvaluate.IpAddress.value = '<%=request.getRemoteHost()%>';
document.CollectMFPToEvaluate.CallerID.value = "MyCallerID";
document.CollectMFPToEvaluate.DeviceID.value = did;
document.CollectMFPToEvaluate.MFP.value = dna;

document.CollectMFPToEvaluate.submit();
 } 
 </script>
</head>

<body onload="init()">
<form name="CollectMFPToEvaluate" method="POST" action="ArRFMFPCollectionServlet">
<input type="hidden" name="MFP" value="">
<input type="hidden" name="IpAddress">
<input type="hidden" name="CallerID">
<input type="hidden" name="DeviceID">
<h1 align="center">Arcot RiskFort Sample Application</h1>
<input type="button" style="width: 150px" name="Login" value="Login"  onclick="collectingSystemInfo();"/>
</form>
</body>
</html>