1 /*
  2  * Copyright © [2008-2009] Novell, Inc.  All Rights Reserved.
  3  * 
  4  * USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO THE DEVELOPER LICENSE AGREEMENT
  5  * OR OTHER AGREEMENT THROUGH WHICH NOVELL, INC. MAKES THE WORK AVAILABLE.  THIS WORK 
  6  * MAY NOT BE ADAPTED WITHOUT NOVELL'S PRIOR WRITTEN CONSENT.
  7  * 
  8  * NOVELL PROVIDES THE WORK "AS IS," WITHOUT ANY EXPRESS OR IMPLIED WARRANTY, 
  9  * INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR 
 10  * A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  NOVELL, THE AUTHORS OF THE WORK, AND THE 
 11  * OWNERS OF COPYRIGHT IN THE WORK ARE NOT LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER 
 12  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, 
 13  * OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS IN THE WORK.
 14  */
 15 
 16 /**
 17  * @fileoverview
 18  * This file defines the Customer class, which represents source customers or domains from
 19  * which input data is received (corresponding to the MSSPCustomer field in event data
 20  * and customer flags on all other data).
 21  * @name Customer Class
 22  */
 23 
 24 /**
 25  * Creates an instance of the Customer class.
 26  * @class
 27  * The Customer class represents the MSSP Customer information that is assigned to data stored in Sentinel.
 28  * All data (events, identities, assets, vulnerabilities) are flagged as belonging to one or more
 29  * customers. This is intended for use in Managed Security Service Provider environments where data
 30  * from each customer should be kept separate, but can also be used by single customers to keep 
 31  * different sections of the enterprise's data apart.
 32  * Each customer is identified by a name and an internal ID. In most cases you only need to know
 33  * the name, which is usually set as the <code>instance.CONFIG.params.MSSP_Customer</code> parameter.
 34  * Ordinarily you will just place this name in events sent to the ESM framework. In some cases, however,
 35  * other data objects want the Customer ID instead of the name; use this class for this situation.
 36  * The class accepts these pre-defined attributes:
 37  * <ul>
 38  * <li>Name {String} : The name of the customer 
 39  * <li>ID {String} : The ID of the customer
 40  * </ul>
 41  * Note that if the Customer has not yet been seen by the system, there will be no corresponding record
 42  * in the database and the getId() method will fail. This will only happen the first time, however; after
 43  * a single event or data object referencing the customer has been sent, the Customer object will be
 44  * created and stored.
 45  * @example
 46  * instance.CONFIG.customer = new Customer({"Name":instance.CONFIG.params.MSSP_Customer});
 47  * var asset = new Asset({IPv4:"10.0.0.24",Vendor:"Novell","Customer":instance.CONFIG.customer});
 48  * @author   Novell Engineering
 49  * @version  6.1
 50  * @param {Object} properties  Set of pre-defined properties used to initialize this object
 51  * @constructor
 52  */
 53 function Customer(properties) {
 54 	this.Name = "unknown";
 55 	if( typeof properties != "undefined") {
 56 		// Poor man's Impl
 57 		for (var field in properties) {
 58 			if (typeof CustomerImpl[field] != "undefined") {
 59 				this[field] = properties[field];
 60 			}
 61 		}
 62 	}
 63 	
 64 	if (this.Name) {
 65 		this.ID = Customer.getId(this.Name);
 66 	}
 67 	
 68 	return true;
 69 	
 70 	/**
 71 	 * 
 72 	 * @type String
 73 	 */
 74 	this.Name;
 75 	
 76 	/**
 77 	 * 
 78 	 * @type String
 79 	 */
 80 	this.ID;
 81 
 82 }
 83 
 84 // Used as a reference for what attributes are allowed
 85 CustomerImpl = {"Name":null,"ID":null};
 86 
 87 
 88 /**
 89 * The getId method returns an ID for a given customer name.
 90 * <p>Example:
 91 * <pre>
 92 * var id = Customer.getId("Novell")
 93 * </pre>
 94 * @param {String} The MSSP Customer name, usually stored in <code>instance.CONFIG.params.MSSP_Customer</code>
 95 * @return {ID}	a numeric value associated with the name
 96 * @throws {Exception} Throws an exception if there is a database error
 97 */
 98 Customer.getId = function() {
 99 	var serviceName = Packages.esecurity.db.object.MsspService.SERVICE_NAME;
100 	var serviceManager = Packages.esecurity.base.datamodel.service.ServiceManager.getInstance();
101 	var service = serviceManager.getService(serviceName);
102 	
103 	return function(custName) {
104 		var cust = service.getCustomer(custName,true);
105 		return cust.getStringCustomerId();
106 	};
107 }();
108 
109 
110 
111